Kea  2.1.7-git
ca_controller.cc
Go to the documentation of this file.
1 // Copyright (C) 2016-2020 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 #include <config.h>
8 
9 #include <agent/ca_controller.h>
10 #include <agent/ca_process.h>
11 #include <agent/ca_command_mgr.h>
12 #include <agent/parser_context.h>
13 #include <cfgrpt/config_report.h>
14 #include <functional>
15 
16 using namespace isc::process;
17 namespace ph = std::placeholders;
18 
19 namespace isc {
20 namespace agent {
21 
24 const char* CtrlAgentController::agent_app_name_ = "Control-agent";
25 
27 const char* CtrlAgentController::agent_bin_name_ = "kea-ctrl-agent";
28 
30 CtrlAgentController::instance() {
31  // If the instance hasn't been created yet, create it. Note this method
32  // must use the base class singleton instance methods.
33  if (!getController()) {
34  DControllerBasePtr controller_ptr(new CtrlAgentController());
35  setController(controller_ptr);
36  }
37 
38  return (getController());
39 }
40 
42 CtrlAgentController::createProcess() {
43  // Instantiate and return an instance of the D2 application process. Note
44  // that the process is passed the controller's io_service.
45  return (new CtrlAgentProcess(getAppName().c_str(), getIOService()));
46 }
47 
49 CtrlAgentController::parseFile(const std::string& name) {
50  ParserContext parser;
51  return (parser.parseFile(name, ParserContext::PARSER_AGENT));
52 }
53 
54 void
55 CtrlAgentController::registerCommands() {
56  CtrlAgentCommandMgr::instance().registerCommand(BUILD_REPORT_COMMAND,
57  std::bind(&DControllerBase::buildReportHandler, this, ph::_1, ph::_2));
58 
59  CtrlAgentCommandMgr::instance().registerCommand(CONFIG_GET_COMMAND,
60  std::bind(&DControllerBase::configGetHandler, this, ph::_1, ph::_2));
61 
62  CtrlAgentCommandMgr::instance().registerCommand(CONFIG_RELOAD_COMMAND,
63  std::bind(&DControllerBase::configReloadHandler, this, ph::_1, ph::_2));
64 
65  CtrlAgentCommandMgr::instance().registerCommand(CONFIG_SET_COMMAND,
66  std::bind(&DControllerBase::configSetHandler, this, ph::_1, ph::_2));
67 
68  CtrlAgentCommandMgr::instance().registerCommand(CONFIG_TEST_COMMAND,
69  std::bind(&DControllerBase::configTestHandler, this, ph::_1, ph::_2));
70 
71  CtrlAgentCommandMgr::instance().registerCommand(CONFIG_WRITE_COMMAND,
72  std::bind(&DControllerBase::configWriteHandler, this, ph::_1, ph::_2));
73 
74  CtrlAgentCommandMgr::instance().registerCommand(SHUT_DOWN_COMMAND,
75  std::bind(&DControllerBase::shutdownHandler, this, ph::_1, ph::_2));
76 
77  CtrlAgentCommandMgr::instance().registerCommand(STATUS_GET_COMMAND,
78  std::bind(&DControllerBase::statusGetHandler, this, ph::_1, ph::_2));
79 
80  CtrlAgentCommandMgr::instance().registerCommand(VERSION_GET_COMMAND,
81  std::bind(&DControllerBase::versionGetHandler, this, ph::_1, ph::_2));
82 }
83 
84 void
85 CtrlAgentController::deregisterCommands() {
86  CtrlAgentCommandMgr::instance().deregisterCommand(BUILD_REPORT_COMMAND);
87  CtrlAgentCommandMgr::instance().deregisterCommand(CONFIG_GET_COMMAND);
88  CtrlAgentCommandMgr::instance().deregisterCommand(CONFIG_RELOAD_COMMAND);
89  CtrlAgentCommandMgr::instance().deregisterCommand(CONFIG_SET_COMMAND);
90  CtrlAgentCommandMgr::instance().deregisterCommand(CONFIG_TEST_COMMAND);
91  CtrlAgentCommandMgr::instance().deregisterCommand(CONFIG_WRITE_COMMAND);
92  CtrlAgentCommandMgr::instance().deregisterCommand(SHUT_DOWN_COMMAND);
93  CtrlAgentCommandMgr::instance().deregisterCommand(STATUS_GET_COMMAND);
94  CtrlAgentCommandMgr::instance().deregisterCommand(VERSION_GET_COMMAND);
95 }
96 
97 CtrlAgentController::CtrlAgentController()
98  : DControllerBase(agent_app_name_, agent_bin_name_) {
99 }
100 
101 CtrlAgentController::~CtrlAgentController() {
102 }
103 
105 CtrlAgentController::getCtrlAgentProcess() {
106  return (boost::dynamic_pointer_cast<CtrlAgentProcess>(getProcess()));
107 }
108 
109 // Refer to config_report so it will be embedded in the binary.
111 
112 } // namespace isc::agent
113 } // namespace isc
boost::shared_ptr< DControllerBase > DControllerBasePtr
Definition: d_controller.h:78
isc::data::ConstElementPtr statusGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for status-get command
isc::data::ConstElementPtr configTestHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-test command
isc::data::ConstElementPtr configReloadHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-reload command
isc::data::ConstElementPtr shutdownHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for &#39;shutdown&#39; command
boost::shared_ptr< CtrlAgentProcess > CtrlAgentProcessPtr
Defines a shared pointer to CtrlAgentProcess.
Definition: ca_process.h:150
Process Controller for Control Agent Process.
Definition: ca_controller.h:21
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
isc::data::ConstElementPtr configWriteHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-write command
Kea Control Agent Application Process.
Definition: ca_process.h:32
Defines the logger used by the top-level component of kea-lfc.
const char *const config_report[]
isc::data::ConstElementPtr configGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-get command
isc::data::ConstElementPtr configSetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-set command
Application Process Interface.
Definition: d_process.h:81
isc::data::ConstElementPtr buildReportHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for &#39;build-report&#39; command
Application Controller.
Definition: d_controller.h:104
isc::data::ConstElementPtr versionGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for version-get command
Parser context is a wrapper around flex/bison instances dedicated to Control-agent config file parser...
const char *const * ca_config_report