From: Thomas Markwalder Date: Tue, 10 Jun 2014 13:19:40 +0000 (-0400) Subject: [master] Bundy version of D2Controller missing handlers X-Git-Tag: trac3434_base~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e69209caafc81041229f3d9601599f3d98fc86e;p=thirdparty%2Fkea.git [master] Bundy version of D2Controller missing handlers Added static handlers for ModuleSession configuration and command handling to BUNDY version of D2Controller that were removed from DControllerBase as per 3401 review. --- diff --git a/src/bin/d2/bundy_d2_controller.cc b/src/bin/d2/bundy_d2_controller.cc index c9ec4bed04..a3ba0b0563 100644 --- a/src/bin/d2/bundy_d2_controller.cc +++ b/src/bin/d2/bundy_d2_controller.cc @@ -189,7 +189,7 @@ D2Controller::establishSession() { config_session_ = ModuleCCSessionPtr(new isc::config::ModuleCCSession( getSpecFileName(), *cc_session_, dummyConfigHandler, - DControllerBase::commandHandler, + commandHandler, false)); // Enable configuration even processing. config_session_->start(); @@ -197,7 +197,7 @@ D2Controller::establishSession() { // We initially create ModuleCCSession() with a dummy configHandler, as // the session module is too eager to send partial configuration. // Replace the dummy config handler with the real handler. - config_session_->setConfigHandler(DControllerBase::configHandler); + config_session_->setConfigHandler(configHandler); // Call the real configHandler with the full configuration retrieved // from the config session. @@ -238,6 +238,29 @@ D2Controller::dummyConfigHandler(isc::data::ConstElementPtr) { return (isc::config::createAnswer(0, "Configuration accepted.")); } +isc::data::ConstElementPtr +D2Controller::configHandler(isc::data::ConstElementPtr new_config) { + + LOG_DEBUG(dctl_logger, DBGLVL_COMMAND, DCTL_CONFIG_UPDATE) + .arg(getController()->getAppName()).arg(new_config->str()); + + // Invoke the instance method on the controller singleton. + return (getController()->updateConfig(new_config)); +} + +// Static callback which invokes non-static handler on singleton +isc::data::ConstElementPtr +D2Controller::commandHandler(const std::string& command, + isc::data::ConstElementPtr args) { + + LOG_DEBUG(dctl_logger, DBGLVL_COMMAND, DCTL_COMMAND_RECEIVED) + .arg(getController()->getAppName()).arg(command) + .arg(args ? args->str() : "(no args)"); + + // Invoke the instance method on the controller singleton. + return (getController()->executeCommand(command, args)); +} + isc::data::ConstElementPtr D2Controller::updateConfig(isc::data::ConstElementPtr new_config) { if (!config_session_) { diff --git a/src/bin/d2/bundy_d2_controller.h b/src/bin/d2/bundy_d2_controller.h index fa042d4935..7de0599391 100644 --- a/src/bin/d2/bundy_d2_controller.h +++ b/src/bin/d2/bundy_d2_controller.h @@ -139,6 +139,32 @@ public: static isc::data::ConstElementPtr dummyConfigHandler(isc::data::ConstElementPtr new_config); + /// @brief A callback for handling all incoming configuration updates. + /// + /// As a pointer to this method is used as a callback in ASIO for + /// ModuleCCSession, it has to be static. It acts as a wrapper around + /// the virtual instance method, updateConfig. + /// + /// @param new_config textual representation of the new configuration + /// + /// @return status of the config update + static isc::data::ConstElementPtr + configHandler(isc::data::ConstElementPtr new_config); + + /// @brief A callback for handling all incoming commands. + /// + /// As a pointer to this method is used as a callback in ASIO for + /// ModuleCCSession, it has to be static. It acts as a wrapper around + /// the virtual instance method, executeCommand. + /// + /// @param command textual representation of the command + /// @param args parameters of the command. It can be NULL pointer if no + /// arguments exist for a particular command. + /// + /// @return status of the processed command + static isc::data::ConstElementPtr + commandHandler(const std::string& command, isc::data::ConstElementPtr args); + /// @brief Instance method invoked by the configuration event handler and /// which processes the actual configuration update. Provides behavioral /// path for both integrated and stand-alone modes. The current diff --git a/src/bin/d2/tests/bundy_d2_controller_unittests.cc b/src/bin/d2/tests/bundy_d2_controller_unittests.cc index e93f37d701..5035a34db7 100644 --- a/src/bin/d2/tests/bundy_d2_controller_unittests.cc +++ b/src/bin/d2/tests/bundy_d2_controller_unittests.cc @@ -139,7 +139,7 @@ TEST_F(BundyD2ControllerTest, configUpdateTests) { // Configuration should be rejected as there is no session. This is a // pretty contrived situation that shouldn't be possible other than the // handler being called directly (like this does). - answer = DControllerBase::configHandler(config_set); + answer = D2Controller::configHandler(config_set); isc::config::parseAnswer(rcode, answer); EXPECT_EQ(1, rcode); } @@ -163,13 +163,13 @@ TEST_F(BundyD2ControllerTest, executeCommandTests) { // Verify that an unknown command returns an COMMAND_INVALID response. std::string bogus_command("bogus"); - answer = DControllerBase::commandHandler(bogus_command, arg_set); + answer = D2Controller::commandHandler(bogus_command, arg_set); isc::config::parseAnswer(rcode, answer); EXPECT_EQ(COMMAND_INVALID, rcode); // Verify that shutdown command returns COMMAND_SUCCESS response. //answer = executeCommand(SHUT_DOWN_COMMAND, isc::data::ElementPtr()); - answer = DControllerBase::commandHandler(SHUT_DOWN_COMMAND, arg_set); + answer = D2Controller::commandHandler(SHUT_DOWN_COMMAND, arg_set); isc::config::parseAnswer(rcode, answer); EXPECT_EQ(COMMAND_SUCCESS, rcode); }