14#include <boost/bind.hpp>
22struct BaseCommandMgrHooks {
23 int hook_index_command_processed_;
26 BaseCommandMgrHooks() {
35BaseCommandMgrHooks
Hooks;
43 registerCommand(
"list-commands", boost::bind(&BaseCommandMgr::listCommandsHandler,
53 HandlerContainer::const_iterator it =
handlers_.find(cmd);
56 <<
"' is already installed.");
61 handlers_.insert(make_pair(cmd, handlers));
73 HandlerContainer::const_iterator it =
handlers_.find(cmd);
76 <<
"' is already installed.");
81 handlers_.insert(make_pair(cmd, handlers));
88 if (cmd ==
"list-commands") {
90 "Can't uninstall internal command 'list-commands'");
93 HandlerContainer::iterator it =
handlers_.find(cmd);
110 boost::bind(&BaseCommandMgr::listCommandsHandler,
this, _1, _2));
117 "Command processing failed: NULL command parameter"));
135 callout_handle->setArgument(
"name", name);
136 callout_handle->setArgument(
"arguments", arg);
137 callout_handle->setArgument(
"response", response);
145 callout_handle->getArgument(
"response", response);
153 std::string(
"Error during command processing: ")
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));
177BaseCommandMgr::listCommandsHandler(
const std::string& ,
181 for (HandlerContainer::const_iterator it =
handlers_.begin();
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
HandlerContainer handlers_
Container for command handlers.
isc::data::ConstElementPtr processCommand(const isc::data::ConstElementPtr &cmd)
Triggers command processing.
void registerCommand(const std::string &cmd, CommandHandler handler)
Registers specified command handler for a given command.
BaseCommandMgr()
Constructor.
void deregisterAll()
Auxiliary method that removes all installed commands.
boost::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr ¶ms)> CommandHandler
Defines command handler type.
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.
void registerExtendedCommand(const std::string &cmd, ExtendedCommandHandler handler)
Registers specified command handler for a given command.
virtual isc::data::ConstElementPtr handleCommand(const std::string &cmd_name, const isc::data::ConstElementPtr ¶ms, const isc::data::ConstElementPtr &original_cmd)
Handles the command having a given name and arguments.
void deregisterCommand(const std::string &cmd)
Deregisters specified command handler.
Exception indicating that the handler specified is not valid.
Exception indicating that the command name is not valid.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
static int registerHook(const std::string &name)
Register Hook.
static bool calloutsPresent(int index)
Are callouts present?
static boost::shared_ptr< CalloutHandle > createCalloutHandle()
Return callout handle.
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_COMMAND_UNSUPPORTED
Status code indicating that the specified command is not supported.
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
isc::log::Logger command_logger("commands")
Command processing Logger.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< CalloutHandle > CalloutHandlePtr
A shared pointer to a CalloutHandle object.
Defines the logger used by the top-level component of kea-dhcp-ddns.
ExtendedCommandHandler extended_handler