14 #include <boost/bind.hpp> 22 struct BaseCommandMgrHooks {
23 int hook_index_command_processed_;
26 BaseCommandMgrHooks() {
27 hook_index_command_processed_ = HooksManager::registerHook(
"command_processed");
35 BaseCommandMgrHooks
Hooks;
42 BaseCommandMgr::BaseCommandMgr() {
43 registerCommand(
"list-commands", boost::bind(&BaseCommandMgr::listCommandsHandler,
48 BaseCommandMgr::registerCommand(
const std::string& cmd,
CommandHandler handler) {
53 HandlerContainer::const_iterator it = handlers_.find(cmd);
54 if (it != handlers_.end()) {
56 <<
"' is already installed.");
61 handlers_.insert(make_pair(cmd, handlers));
67 BaseCommandMgr::registerExtendedCommand(
const std::string& cmd,
73 HandlerContainer::const_iterator it = handlers_.find(cmd);
74 if (it != handlers_.end()) {
76 <<
"' is already installed.");
81 handlers_.insert(make_pair(cmd, handlers));
87 BaseCommandMgr::deregisterCommand(
const std::string& cmd) {
88 if (cmd ==
"list-commands") {
90 "Can't uninstall internal command 'list-commands'");
93 HandlerContainer::iterator it = handlers_.find(cmd);
94 if (it == handlers_.end()) {
104 BaseCommandMgr::deregisterAll() {
109 registerCommand(
"list-commands",
110 boost::bind(&BaseCommandMgr::listCommandsHandler,
this, _1, _2));
117 "Command processing failed: NULL command parameter"));
129 if (HooksManager::calloutsPresent(
Hooks.hook_index_command_processed_)) {
135 callout_handle->setArgument(
"name", name);
136 callout_handle->setArgument(
"arguments", arg);
137 callout_handle->setArgument(
"response", response);
140 HooksManager::callCallouts(
Hooks.hook_index_command_processed_,
145 callout_handle->getArgument(
"response", response);
153 std::string(
"Error during command processing: ")
159 BaseCommandMgr::handleCommand(
const std::string& cmd_name,
162 auto it = handlers_.find(cmd_name);
163 if (it == handlers_.end()) {
166 "'" + cmd_name +
"' command not supported."));
170 if (it->second.handler) {
171 return (it->second.handler(cmd_name, params));
173 return (it->second.extended_handler(cmd_name, params, original_cmd));
177 BaseCommandMgr::listCommandsHandler(
const std::string& ,
181 for (HandlerContainer::const_iterator it = handlers_.begin();
182 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.
boost::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr ¶ms, const isc::data::ConstElementPtr &original)> ExtendedCommandHandler
Defines extended command handler type.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
boost::shared_ptr< Element > ElementPtr
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#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
boost::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr ¶ms)> CommandHandler
Defines command handler type.
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)
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())
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.