Kea: base_command_mgr.h Source File

| Kea 3.2.0-git

base_command_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2017-2025 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 <functional>
13#include <map>
14#include <string>
15
16namespace isc {
17namespace config {
18
20 class InvalidCommandHandler : public Exception {
21public:
22 InvalidCommandHandler(const char* file, size_t line, const char* what) :
23 isc::Exception(file, line, what) { }
24};
25
27 class InvalidCommandName : public Exception {
28public:
29 InvalidCommandName(const char* file, size_t line, const char* what) :
30 isc::Exception(file, line, what) { }
31};
32
72 class BaseCommandMgr {
73public:
74
82 typedef std::function<isc::data::ConstElementPtr (const std::string& name,
83 const isc::data::ConstElementPtr& params)> CommandHandler;
84
95 typedef std::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
123 virtual isc::data::ConstElementPtr
124 processCommand(const isc::data::ConstElementPtr& cmd);
125
130 void registerCommand(const std::string& cmd, CommandHandler handler);
131
142 void registerExtendedCommand(const std::string& cmd,
143 ExtendedCommandHandler handler);
144
148 void deregisterCommand(const std::string& cmd);
149
154 void deregisterAll();
155
159 // representation of the structure.
163 static std::string getHash(const isc::data::ConstElementPtr& config);
164
165protected:
166
182 virtual isc::data::ConstElementPtr
183 handleCommand(const std::string& cmd_name,
184 const isc::data::ConstElementPtr& params,
185 const isc::data::ConstElementPtr& original_cmd);
186
187 struct HandlersPair {
188 CommandHandler handler;
189 ExtendedCommandHandler extended_handler;
190 };
191
193 typedef std::map<std::string, HandlersPair> HandlerContainer;
194
196 HandlerContainer handlers_;
197
198private:
199
210 isc::data::ConstElementPtr
211 listCommandsHandler(const std::string& name,
212 const isc::data::ConstElementPtr& params);
213};
214
215} // end of namespace isc::config
216} // end of namespace isc
217
218#endif
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
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::handlers_
HandlerContainer handlers_
Container for command handlers.
Definition base_command_mgr.h:196
isc::config::BaseCommandMgr::processCommand
virtual isc::data::ConstElementPtr processCommand(const isc::data::ConstElementPtr &cmd)
Triggers command processing.
Definition base_command_mgr.cc:119
isc::config::BaseCommandMgr::CommandHandler
std::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::registerCommand
void registerCommand(const std::string &cmd, CommandHandler handler)
Registers specified command handler for a given command.
Definition base_command_mgr.cc:53
isc::config::BaseCommandMgr::BaseCommandMgr
BaseCommandMgr()
Constructor.
Definition base_command_mgr.cc:47
isc::config::BaseCommandMgr::getHash
static std::string getHash(const isc::data::ConstElementPtr &config)
returns a hash of a given Element structure
Definition base_command_mgr.cc:193
isc::config::BaseCommandMgr::deregisterAll
void deregisterAll()
Auxiliary method that removes all installed commands.
Definition base_command_mgr.cc:109
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:72
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:164
isc::config::BaseCommandMgr::~BaseCommandMgr
virtual ~BaseCommandMgr()
Destructor.
Definition base_command_mgr.h:106
isc::config::BaseCommandMgr::ExtendedCommandHandler
std::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::HandlerContainer
std::map< std::string, HandlersPair > HandlerContainer
Type of the container for command handlers.
Definition base_command_mgr.h:193
isc::config::BaseCommandMgr::deregisterCommand
void deregisterCommand(const std::string &cmd)
Deregisters specified command handler.
Definition base_command_mgr.cc:92
isc::config::InvalidCommandHandler::InvalidCommandHandler
InvalidCommandHandler(const char *file, size_t line, const char *what)
Definition base_command_mgr.h:22
isc::config::InvalidCommandName::InvalidCommandName
InvalidCommandName(const char *file, size_t line, const char *what)
Definition base_command_mgr.h:29
data.h
exceptions.h
isc::config
Definition command_interpreter.cc:23
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
isc::config::BaseCommandMgr::HandlersPair
Definition base_command_mgr.h:187
isc::config::BaseCommandMgr::HandlersPair::handler
CommandHandler handler
Definition base_command_mgr.h:188
isc::config::BaseCommandMgr::HandlersPair::extended_handler
ExtendedCommandHandler extended_handler
Definition base_command_mgr.h:189