![]() |
Kea
1.5.0
|
Commands Manager, responsible for processing external commands. More...
#include <base_command_mgr.h>
Inheritance diagram for isc::config::BaseCommandMgr:Classes | |
| struct | HandlersPair |
Public Types | |
| typedef boost::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr ¶ms)> | CommandHandler |
| Defines command handler type. More... | |
| typedef 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. More... | |
Public Member Functions | |
| BaseCommandMgr () | |
| Constructor. More... | |
| virtual | ~BaseCommandMgr () |
| Destructor. More... | |
| void | deregisterAll () |
| Auxiliary method that removes all installed commands. More... | |
| void | deregisterCommand (const std::string &cmd) |
| Deregisters specified command handler. More... | |
| isc::data::ConstElementPtr | processCommand (const isc::data::ConstElementPtr &cmd) |
| Triggers command processing. More... | |
| void | registerCommand (const std::string &cmd, CommandHandler handler) |
| Registers specified command handler for a given command. More... | |
| void | registerExtendedCommand (const std::string &cmd, ExtendedCommandHandler handler) |
| Registers specified command handler for a given command. More... | |
Protected Types | |
| typedef std::map< std::string, HandlersPair > | HandlerContainer |
| Type of the container for command handlers. More... | |
Protected Member Functions | |
| 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. More... | |
Protected Attributes | |
| HandlerContainer | handlers_ |
| Container for command handlers. More... | |
Commands Manager, responsible for processing external commands.
Commands Manager is a generic interface for handling external commands. Commands are received over control sockets. Derivations of this class provide implementations of the control socket layers, e.g. unix domain sockets, TCP sockets etc. This base class merely provides methods to manage command handling functions, i.e. register commands, deregister commands. It also includes a BaseCommandMgr::processCommand method which uses the command as an input and invokes appropriate handlers.
The commands and responses are formatted using JSON. See https://gitlab.isc.org/isc-projects/kea/wikis/designs/Stats-design for details.
Below is an example of the command using JSON format:
And the response is:
BaseCommandsMgr does not implement the commands (except one, "list-commands") itself, but rather provides an interface (see registerCommand, deregisterCommand, processCommand) for other components to use it.
Definition at line 72 of file base_command_mgr.h.
| typedef boost::function<isc::data::ConstElementPtr (const std::string& name, const isc::data::ConstElementPtr& params)> isc::config::BaseCommandMgr::CommandHandler |
Defines command handler type.
Command handlers are expected to use this format.
| name | name of the commands |
| params | parameters specific to the command |
Definition at line 83 of file base_command_mgr.h.
| typedef boost::function<isc::data::ConstElementPtr (const std::string& name, const isc::data::ConstElementPtr& params, const isc::data::ConstElementPtr& original)> isc::config::BaseCommandMgr::ExtendedCommandHandler |
Defines extended command handler type.
This command handler includes third parameter which holds the entire command control message. The handler can retrieve additional information from this parameter, e.g. 'service'.
| name | name of the commands |
| params | parameters specific to the command |
| original | original control command. |
Definition at line 97 of file base_command_mgr.h.
|
protected |
Type of the container for command handlers.
Definition at line 178 of file base_command_mgr.h.
| isc::config::BaseCommandMgr::BaseCommandMgr | ( | ) |
Constructor.
Registers hookpoint "command-processed" Registers "list-commands" command.
Definition at line 42 of file base_command_mgr.cc.
|
inlinevirtual |
Destructor.
Definition at line 106 of file base_command_mgr.h.
| void isc::config::BaseCommandMgr::deregisterAll | ( | ) |
Auxiliary method that removes all installed commands.
The only unwipeable method is list-commands, which is internally handled at all times.
Definition at line 104 of file base_command_mgr.cc.
| void isc::config::BaseCommandMgr::deregisterCommand | ( | const std::string & | cmd | ) |
Deregisters specified command handler.
| cmd | Name of the command that's no longer handled. |
Definition at line 87 of file base_command_mgr.cc.
References isc::config::command_logger, isc::config::DBG_COMMAND, isc_throw, and LOG_DEBUG.
|
protectedvirtual |
Handles the command having a given name and arguments.
This method can be overridden in the derived classes to provide custom logic for processing commands. For example, the HookedCommandMgr extends this method to delegate commands processing to a hook library.
| cmd_name | Command name. |
| params | Command arguments. |
| original_cmd | Pointer to the entire command received. It may be sometimes useful to retrieve additional parameters from this command. |
Reimplemented in isc::config::HookedCommandMgr, and isc::agent::CtrlAgentCommandMgr.
Definition at line 159 of file base_command_mgr.cc.
References isc::config::CONTROL_RESULT_COMMAND_UNSUPPORTED, and isc::config::createAnswer().
Referenced by isc::config::HookedCommandMgr::handleCommand().
Here is the call graph for this function:| isc::data::ConstElementPtr isc::config::BaseCommandMgr::processCommand | ( | const isc::data::ConstElementPtr & | cmd | ) |
Triggers command processing.
This method processes specified command. The command is specified using a single Element. See BaseCommandMgr for description of its syntax. After the command has been handled, callouts for the hook point, "command-processed" will be invoked.
| cmd | Pointer to the data element representing command in JSON format. |
Definition at line 114 of file base_command_mgr.cc.
References isc::config::command_logger, isc::config::CONTROL_RESULT_ERROR, isc::config::createAnswer(), Hooks, LOG_INFO, LOG_WARN, isc::config::parseCommand(), and isc::Exception::what().
Here is the call graph for this function:| void isc::config::BaseCommandMgr::registerCommand | ( | const std::string & | cmd, |
| CommandHandler | handler | ||
| ) |
Registers specified command handler for a given command.
| cmd | Name of the command to be handled. |
| handler | Pointer to the method that will handle the command. |
Definition at line 48 of file base_command_mgr.cc.
References isc::config::command_logger, isc::config::DBG_COMMAND, isc::config::BaseCommandMgr::HandlersPair::handler, isc_throw, and LOG_DEBUG.
| void isc::config::BaseCommandMgr::registerExtendedCommand | ( | const std::string & | cmd, |
| ExtendedCommandHandler | handler | ||
| ) |
Registers specified command handler for a given command.
This variant of the method uses extended command handler which, besides command name and arguments, also has a third parameter 'original_cmd' in its signature. Such handlers can retrieve additional parameters from the command, e.g. 'service' indicating where the command should be routed.
| cmd | Name of the command to be handled. |
| handler | Pointer to the method that will handle the command. |
Definition at line 67 of file base_command_mgr.cc.
References isc::config::command_logger, isc::config::DBG_COMMAND, isc::config::BaseCommandMgr::HandlersPair::extended_handler, isc_throw, and LOG_DEBUG.
|
protected |
Container for command handlers.
Definition at line 181 of file base_command_mgr.h.