Browse Source

CCSession constructor now does not take a module_name argument anymore, the module name is read from the .spec file (in both python and cpp)

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@578 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
0102a47f3b

+ 1 - 1
src/bin/bind10/bind10.py

@@ -169,7 +169,7 @@ class BoB:
         time.sleep(1)
         if self.verbose:
             print("[XX] starting ccsession")
-        self.ccs = isc.config.CCSession("Boss", "bob.spec", self.config_handler, self.command_handler)
+        self.ccs = isc.config.CCSession("bob.spec", self.config_handler, self.command_handler)
         if self.verbose:
             print("[XX] ccsession started")
 

+ 1 - 1
src/bin/parkinglot/main.cc

@@ -107,7 +107,7 @@ main(int argc, char* argv[]) {
 
     // initialize command channel
     try {
-        CommandSession cs = CommandSession(PROGRAM, PARKINGLOT_SPECFILE_LOCATION, my_config_handler, my_command_handler);
+        CommandSession cs = CommandSession(PARKINGLOT_SPECFILE_LOCATION, my_config_handler, my_command_handler);
     
         // main server loop
         fd_set fds;

+ 7 - 7
src/lib/config/cpp/ccsession.cc

@@ -71,14 +71,16 @@ CommandSession::read_data_definition(const std::string& filename) {
     file.close();
 }
 
-CommandSession::CommandSession(std::string module_name,
-                               std::string spec_file_name,
+CommandSession::CommandSession(std::string spec_file_name,
                                isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config),
                                isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command)
                               ) throw (isc::cc::SessionError):
-    module_name_(module_name),
     session_(isc::cc::Session())
 {
+    read_data_definition(spec_file_name);
+    sleep(1);
+
+    module_name_ = data_definition_.getDefinition()->get("data_specification")->get("module_name")->stringValue();
     config_handler_ = config_handler;
     command_handler_ = command_handler;
 
@@ -89,18 +91,16 @@ CommandSession::CommandSession(std::string module_name,
     ElementPtr answer, env;
 
     session_.establish();
-    session_.subscribe(module_name, "*");
+    session_.subscribe(module_name_, "*");
     //session_.subscribe("Boss", "*");
     //session_.subscribe("statistics", "*");
-    read_data_definition(spec_file_name);
-    sleep(1);
     // send the data specification
     session_.group_sendmsg(data_definition_.getDefinition(), "ConfigManager");
     session_.group_recvmsg(env, answer, false);
     
     // get any stored configuration from the manager
     if (config_handler_) {
-        ElementPtr cmd = Element::createFromString("{ \"command\": [\"get_config\", {\"module_name\":\"" + module_name + "\"} ] }");
+        ElementPtr cmd = Element::createFromString("{ \"command\": [\"get_config\", {\"module_name\":\"" + module_name_ + "\"} ] }");
         session_.group_sendmsg(cmd, "ConfigManager");
         session_.group_recvmsg(env, answer, false);
         cout << "[XX] got config: " << endl << answer->str() << endl;

+ 1 - 1
src/lib/config/cpp/ccsession.h

@@ -33,7 +33,7 @@ public:
      * @param spec_file_name: The name of the file containing the data
      *                        definition.
      */
-    CommandSession(std::string module_name, std::string spec_file_name,
+    CommandSession(std::string spec_file_name,
                    isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config) = NULL,
                    isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command) = NULL
                   ) throw (isc::cc::SessionError);

+ 9 - 8
src/lib/config/python/isc/config/CCSession.py

@@ -26,17 +26,15 @@ from ISC.CC import Session
 import isc
 
 class CCSession:
-    def __init__(self, module_name, spec_file_name,
-                 config_handler, command_handler):
-        self._module_name = module_name
-        #self._spec_file_name = spec_file_name
+    def __init__(self, spec_file_name, config_handler, command_handler):
+        self._data_definition = isc.config.DataDefinition(spec_file_name)
+        self._module_name = self._data_definition.getModuleName()
+        
         self.setConfigHandler(config_handler)
         self.setCommandHandler(command_handler)
 
-        self._data_definition = isc.config.DataDefinition(spec_file_name)
-
         self._session = Session()
-        self._session.group_subscribe(module_name, "*")
+        self._session.group_subscribe(self._module_name, "*")
 
         self.__sendSpec()
         self.__getFullConfig()
@@ -49,7 +47,10 @@ class CCSession:
         """Returns the command-channel session that is used, so the
            application can use it directly"""
         return self._session
-    
+
+    def close(self):
+        self._session.close()
+
     def checkCommand(self):
         """Check whether there is a command on the channel.
            Call the command callback function if so"""

+ 3 - 0
src/lib/config/python/isc/config/DataDefinition.py

@@ -61,6 +61,9 @@ class DataDefinition:
     def getDefinition(self):
         return self._data_spec
 
+    def getModuleName(self):
+        return self._data_spec["data_specification"]["module_name"]
+
 def _check(data_spec):
     if type(data_spec) != dict:
         raise DataDefinitionError("data specification not a dict")