-// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
#include <config.h>
+#include <config/command_mgr.h>
#include <d2/d2_controller.h>
#include <d2/d2_process.h>
#include <d2/parser_context.h>
#include <stdlib.h>
+using namespace isc::config;
using namespace isc::process;
namespace isc {
: DControllerBase(d2_app_name_, d2_bin_name_) {
}
+void
+D2Controller::registerCommands() {
+ // CommandMgr uses IO service to run asynchronous socket operations.
+ CommandMgr::instance().setIOService(getIOService());
+
+ // These are the commands always supported by the D2 server.
+ // Please keep the list in alphabetic order.
+ CommandMgr::instance().registerCommand("build-report",
+ boost::bind(&D2Controller::buildReportHandler, this, _1, _2));
+
+ CommandMgr::instance().registerCommand("config-get",
+ boost::bind(&D2Controller::configGetHandler, this, _1, _2));
+
+ CommandMgr::instance().registerCommand("config-test",
+ boost::bind(&D2Controller::configTestHandler, this, _1, _2));
+
+ CommandMgr::instance().registerCommand("config-write",
+ boost::bind(&D2Controller::configWriteHandler, this, _1, _2));
+
+ CommandMgr::instance().registerCommand("shutdown",
+ boost::bind(&D2Controller::shutdownHandler, this, _1, _2));
+
+ CommandMgr::instance().registerCommand("version-get",
+ boost::bind(&D2Controller::versionGetHandler, this, _1, _2));
+}
+
+void
+D2Controller::deregisterCommands() {
+ try {
+ // Close the command socket (if it exists).
+ CommandMgr::instance().closeCommandSocket();
+
+ // Deregister any registered commands (please keep in alphabetic order)
+ CommandMgr::instance().deregisterCommand("build-report");
+ CommandMgr::instance().deregisterCommand("config-get");
+ CommandMgr::instance().deregisterCommand("config-test");
+ CommandMgr::instance().deregisterCommand("config-write");
+ CommandMgr::instance().deregisterCommand("shutdown");
+ CommandMgr::instance().deregisterCommand("version-get");
+
+ } catch (...) {
+ // What to do? Simply ignore...
+ }
+}
+
+
+
isc::data::ConstElementPtr
D2Controller::parseFile(const std::string& file_name) {
isc::data::ConstElementPtr elements;
}
D2Controller::~D2Controller() {
+ deregisterCommands();
}
std::string
-// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// by convention this should match the executable name.
static const char* d2_bin_name_;
+ /// @brief Register commands.
+ void registerCommands();
+
+ /// @brief Deregister commands.
+ void deregisterCommands();
+
protected:
/// @brief Returns version info specific to D2
virtual std::string getVersionAddendum();
#include <cc/command_interpreter.h>
#include <d2/d2_log.h>
#include <d2/d2_cfg_mgr.h>
+#include <d2/d2_controller.h>
#include <d2/d2_process.h>
using namespace isc::process;
void
D2Process::run() {
LOG_INFO(d2_logger, DHCP_DDNS_STARTED).arg(VERSION);
- // Loop forever until we are allowed to shutdown.
- while (!canShutdown()) {
- try {
+ try {
+ // Now logging was initialized so commands can be registered.
+ boost::dynamic_pointer_cast<D2Controller>(D2Controller::instance())->registerCommands();
+
+ // Loop forever until we are allowed to shutdown.
+ while (!canShutdown()) {
// Check on the state of the request queue. Take any
// actions necessary regarding it.
checkQueueStatus();
isc_throw(DProcessBaseError,
"Primary IO service stopped unexpectedly");
}
- } catch (const std::exception& ex) {
- LOG_FATAL(d2_logger, DHCP_DDNS_FAILED).arg(ex.what());
- isc_throw (DProcessBaseError,
- "Process run method failed: " << ex.what());
}
+ } catch (const std::exception& ex) {
+ LOG_FATAL(d2_logger, DHCP_DDNS_FAILED).arg(ex.what());
+ boost::dynamic_pointer_cast<D2Controller>(D2Controller::instance())->deregisterCommands();
+ isc_throw (DProcessBaseError,
+ "Process run method failed: " << ex.what());
}
// @todo - if queue isn't empty, we may need to persist its contents
// this might be the place to do it, once there is a persistence mgr.
// This may also be better in checkQueueStatus.
+ boost::dynamic_pointer_cast<D2Controller>(D2Controller::instance())->deregisterCommands();
+
LOG_DEBUG(d2_logger, isc::log::DBGLVL_START_SHUT, DHCP_DDNS_RUN_EXIT);
};