Kea: base_command_mgr.h Source File

| Kea 1.5.0

base_command_mgr.h
Go to the documentation of this file.
1 // Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 #ifndef BASE_COMMAND_MGR_H
8 #define BASE_COMMAND_MGR_H
9
10 #include <cc/data.h>
11 #include <exceptions/exceptions.h>
12 #include <boost/function.hpp>
13 #include <map>
14 #include <string>
15
16 namespace isc {
17 namespace config {
18
20 class InvalidCommandHandler : public Exception {
21 public:
22 InvalidCommandHandler(const char* file, size_t line, const char* what) :
23 isc::Exception(file, line, what) { };
24 };
25
27 class InvalidCommandName : public Exception {
28 public:
29 InvalidCommandName(const char* file, size_t line, const char* what) :
30 isc::Exception(file, line, what) { };
31 };
32
72 class BaseCommandMgr {
73 public:
74
82 typedef boost::function<isc::data::ConstElementPtr (const std::string& name,
83 const isc::data::ConstElementPtr& params)> CommandHandler;
84
95 typedef boost::function<isc::data::ConstElementPtr (const std::string& name,
96 const isc::data::ConstElementPtr& params,
97 const isc::data::ConstElementPtr& original)> ExtendedCommandHandler;
98
103 BaseCommandMgr();
104
106 virtual ~BaseCommandMgr() { };
107
117 isc::data::ConstElementPtr
118 processCommand(const isc::data::ConstElementPtr& cmd);
119
124 void registerCommand(const std::string& cmd, CommandHandler handler);
125
136 void registerExtendedCommand(const std::string& cmd,
137 ExtendedCommandHandler handler);
138
142 void deregisterCommand(const std::string& cmd);
143
148 void deregisterAll();
149
150 protected:
151
167 virtual isc::data::ConstElementPtr
168 handleCommand(const std::string& cmd_name,
169 const isc::data::ConstElementPtr& params,
170 const isc::data::ConstElementPtr& original_cmd);
171
172 struct HandlersPair {
173 CommandHandler handler;
174 ExtendedCommandHandler extended_handler;
175 };
176
178 typedef std::map<std::string, HandlersPair> HandlerContainer;
179
181 HandlerContainer handlers_;
182
183 private:
184
195 isc::data::ConstElementPtr
196 listCommandsHandler(const std::string& name,
197 const isc::data::ConstElementPtr& params);
198 };
199
200 } // end of namespace isc::config
201 } // end of namespace isc
202
203 #endif
isc::config::BaseCommandMgr
Commands Manager, responsible for processing external commands.
Definition: base_command_mgr.h:72
isc::config::BaseCommandMgr::HandlersPair::handler
CommandHandler handler
Definition: base_command_mgr.h:173
isc::config::BaseCommandMgr::HandlersPair
Definition: base_command_mgr.h:172
isc::config::BaseCommandMgr::~BaseCommandMgr
virtual ~BaseCommandMgr()
Destructor.
Definition: base_command_mgr.h:106
isc::config::BaseCommandMgr::HandlerContainer
std::map< std::string, HandlersPair > HandlerContainer
Type of the container for command handlers.
Definition: base_command_mgr.h:178
isc::config::InvalidCommandName
Exception indicating that the command name is not valid.
Definition: base_command_mgr.h:27
isc::config::BaseCommandMgr::HandlersPair::extended_handler
ExtendedCommandHandler extended_handler
Definition: base_command_mgr.h:174
isc::config::BaseCommandMgr::registerExtendedCommand
void registerExtendedCommand(const std::string &cmd, ExtendedCommandHandler handler)
Registers specified command handler for a given command.
Definition: base_command_mgr.cc:67
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::config::BaseCommandMgr::BaseCommandMgr
BaseCommandMgr()
Constructor.
Definition: base_command_mgr.cc:42
isc::config::BaseCommandMgr::deregisterAll
void deregisterAll()
Auxiliary method that removes all installed commands.
Definition: base_command_mgr.cc:104
isc::config::BaseCommandMgr::handleCommand
virtual isc::data::ConstElementPtr handleCommand(const std::string &cmd_name, const isc::data::ConstElementPtr &params, const isc::data::ConstElementPtr &original_cmd)
Handles the command having a given name and arguments.
Definition: base_command_mgr.cc:159
isc::config::BaseCommandMgr::CommandHandler
boost::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr &params)> CommandHandler
Defines command handler type.
Definition: base_command_mgr.h:83
isc::config::BaseCommandMgr::ExtendedCommandHandler
boost::function< isc::data::ConstElementPtr(const std::string &name, const isc::data::ConstElementPtr &params, const isc::data::ConstElementPtr &original)> ExtendedCommandHandler
Defines extended command handler type.
Definition: base_command_mgr.h:97
isc::config::BaseCommandMgr::handlers_
HandlerContainer handlers_
Container for command handlers.
Definition: base_command_mgr.h:181
isc::config::InvalidCommandHandler
Exception indicating that the handler specified is not valid.
Definition: base_command_mgr.h:20
isc::config::BaseCommandMgr::registerCommand
void registerCommand(const std::string &cmd, CommandHandler handler)
Registers specified command handler for a given command.
Definition: base_command_mgr.cc:48
data.h
exceptions.h
isc::config::BaseCommandMgr::deregisterCommand
void deregisterCommand(const std::string &cmd)
Deregisters specified command handler.
Definition: base_command_mgr.cc:87
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
isc::config::InvalidCommandName::InvalidCommandName
InvalidCommandName(const char *file, size_t line, const char *what)
Definition: base_command_mgr.h:29
isc::config::InvalidCommandHandler::InvalidCommandHandler
InvalidCommandHandler(const char *file, size_t line, const char *what)
Definition: base_command_mgr.h:22
isc::config::BaseCommandMgr::processCommand
isc::data::ConstElementPtr processCommand(const isc::data::ConstElementPtr &cmd)
Triggers command processing.
Definition: base_command_mgr.cc:114