diff --git a/src/bin/bind10/bind10.py b/src/bin/bind10/bind10.py index f36a511678..f19f183e7d 100644 --- a/src/bin/bind10/bind10.py +++ b/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") diff --git a/src/bin/parkinglot/main.cc b/src/bin/parkinglot/main.cc index 5a73c3c5c6..d32e0cebea 100644 --- a/src/bin/parkinglot/main.cc +++ b/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; diff --git a/src/lib/config/cpp/ccsession.cc b/src/lib/config/cpp/ccsession.cc index 16f5a9308b..462ef9bad6 100644 --- a/src/lib/config/cpp/ccsession.cc +++ b/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; diff --git a/src/lib/config/cpp/ccsession.h b/src/lib/config/cpp/ccsession.h index f872c6f653..1e30285651 100644 --- a/src/lib/config/cpp/ccsession.h +++ b/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); diff --git a/src/lib/config/python/isc/config/CCSession.py b/src/lib/config/python/isc/config/CCSession.py index ce04dced72..607dc2ec74 100644 --- a/src/lib/config/python/isc/config/CCSession.py +++ b/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""" diff --git a/src/lib/config/python/isc/config/DataDefinition.py b/src/lib/config/python/isc/config/DataDefinition.py index 07fa719bc5..7481a5fbef 100644 --- a/src/lib/config/python/isc/config/DataDefinition.py +++ b/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")