]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Bundy version of D2Controller missing handlers
authorThomas Markwalder <tmark@isc.org>
Tue, 10 Jun 2014 13:19:40 +0000 (09:19 -0400)
committerThomas Markwalder <tmark@isc.org>
Tue, 10 Jun 2014 13:19:40 +0000 (09:19 -0400)
Added static handlers for ModuleSession configuration and command
handling to BUNDY version of D2Controller  that were removed from
DControllerBase as per 3401 review.

src/bin/d2/bundy_d2_controller.cc
src/bin/d2/bundy_d2_controller.h
src/bin/d2/tests/bundy_d2_controller_unittests.cc

index c9ec4bed04fc2241ddb9ed86b93d922cc87cc553..a3ba0b0563fadba126c320a07cc3a24c59bc2a29 100644 (file)
@@ -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_) {
index fa042d4935076b8de33ee747cc27f910199c3474..7de0599391469709a119b31b9b9ded55d52e853e 100644 (file)
@@ -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
index e93f37d7016b194dcbc1d69360b51667d6165c74..5035a34db79575e92d0ab91461ba2127fadc18df 100644 (file)
@@ -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);
 }