18 namespace ph = std::placeholders;
23 struct BaseCommandMgrHooks {
24 int hook_index_command_processed_;
27 BaseCommandMgrHooks() {
28 hook_index_command_processed_ = HooksManager::registerHook(
"command_processed");
36 BaseCommandMgrHooks
Hooks;
43 BaseCommandMgr::BaseCommandMgr() {
44 registerCommand(
"list-commands", std::bind(&BaseCommandMgr::listCommandsHandler,
45 this, ph::_1, ph::_2));
49 BaseCommandMgr::registerCommand(
const std::string& cmd,
CommandHandler handler) {
54 HandlerContainer::const_iterator it = handlers_.find(cmd);
55 if (it != handlers_.end()) {
57 <<
"' is already installed.");
62 handlers_.insert(make_pair(cmd, handlers));
68 BaseCommandMgr::registerExtendedCommand(
const std::string& cmd,
74 HandlerContainer::const_iterator it = handlers_.find(cmd);
75 if (it != handlers_.end()) {
77 <<
"' is already installed.");
82 handlers_.insert(make_pair(cmd, handlers));
88 BaseCommandMgr::deregisterCommand(
const std::string& cmd) {
89 if (cmd ==
"list-commands") {
91 "Can't uninstall internal command 'list-commands'");
94 HandlerContainer::iterator it = handlers_.find(cmd);
95 if (it == handlers_.end()) {
105 BaseCommandMgr::deregisterAll() {
110 registerCommand(
"list-commands",
111 std::bind(&BaseCommandMgr::listCommandsHandler,
this, ph::_1, ph::_2));
118 "Command processing failed: NULL command parameter"));
130 if (HooksManager::calloutsPresent(
Hooks.hook_index_command_processed_)) {
136 callout_handle->setArgument(
"name", name);
137 callout_handle->setArgument(
"arguments", arg);
138 callout_handle->setArgument(
"response", response);
141 HooksManager::callCallouts(
Hooks.hook_index_command_processed_,
146 callout_handle->getArgument(
"response", response);
154 std::string(
"Error during command processing: ")
160 BaseCommandMgr::handleCommand(
const std::string& cmd_name,
163 auto it = handlers_.find(cmd_name);
164 if (it == handlers_.end()) {
167 "'" + cmd_name +
"' command not supported."));
171 if (it->second.handler) {
172 return (it->second.handler(cmd_name, params));
174 return (it->second.extended_handler(cmd_name, params, original_cmd));
178 BaseCommandMgr::listCommandsHandler(
const std::string& ,
182 for (HandlerContainer::const_iterator it = handlers_.begin();
183 it != handlers_.end(); ++it) {
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
ConstElementPtr createAnswer(const int status_code, const std::string &text, const ConstElementPtr &arg)
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
const isc::log::MessageID COMMAND_DEREGISTERED
const isc::log::MessageID COMMAND_REGISTERED
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
boost::shared_ptr< Element > ElementPtr
const isc::log::MessageID COMMAND_PROCESS_ERROR2
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
isc::log::Logger command_logger("commands")
Command processing Logger.
ExtendedCommandHandler extended_handler
boost::shared_ptr< const Element > ConstElementPtr
const isc::log::MessageID COMMAND_RECEIVED
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception indicating that the command name is not valid.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
const isc::log::MessageID COMMAND_EXTENDED_REGISTERED
Exception indicating that the handler specified is not valid.
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
This file contains several functions and constants that are used for handling commands and responses ...
static ElementPtr create(const Position &pos=ZERO_POSITION())
std::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr ¶ms, const isc::data::ConstElementPtr &original)> ExtendedCommandHandler
Defines extended command handler type.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr ¶ms)> CommandHandler
Defines command handler type.
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.