Browse Source

[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.
Thomas Markwalder 11 years ago
parent
commit
8e69209caa

+ 25 - 2
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.
@@ -239,6 +239,29 @@ D2Controller::dummyConfigHandler(isc::data::ConstElementPtr) {
 }
 
 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_) {
         // That should never happen as we install config_handler

+ 26 - 0
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

+ 3 - 3
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);
 }