mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 15:35:17 +00:00
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
This commit is contained in:
@@ -169,7 +169,7 @@ class BoB:
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("[XX] starting ccsession")
|
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:
|
if self.verbose:
|
||||||
print("[XX] ccsession started")
|
print("[XX] ccsession started")
|
||||||
|
|
||||||
|
@@ -107,7 +107,7 @@ main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
// initialize command channel
|
// initialize command channel
|
||||||
try {
|
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
|
// main server loop
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
|
@@ -71,14 +71,16 @@ CommandSession::read_data_definition(const std::string& filename) {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandSession::CommandSession(std::string module_name,
|
CommandSession::CommandSession(std::string spec_file_name,
|
||||||
std::string spec_file_name,
|
|
||||||
isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config),
|
isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config),
|
||||||
isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command)
|
isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command)
|
||||||
) throw (isc::cc::SessionError):
|
) throw (isc::cc::SessionError):
|
||||||
module_name_(module_name),
|
|
||||||
session_(isc::cc::Session())
|
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;
|
config_handler_ = config_handler;
|
||||||
command_handler_ = command_handler;
|
command_handler_ = command_handler;
|
||||||
|
|
||||||
@@ -89,18 +91,16 @@ CommandSession::CommandSession(std::string module_name,
|
|||||||
ElementPtr answer, env;
|
ElementPtr answer, env;
|
||||||
|
|
||||||
session_.establish();
|
session_.establish();
|
||||||
session_.subscribe(module_name, "*");
|
session_.subscribe(module_name_, "*");
|
||||||
//session_.subscribe("Boss", "*");
|
//session_.subscribe("Boss", "*");
|
||||||
//session_.subscribe("statistics", "*");
|
//session_.subscribe("statistics", "*");
|
||||||
read_data_definition(spec_file_name);
|
|
||||||
sleep(1);
|
|
||||||
// send the data specification
|
// send the data specification
|
||||||
session_.group_sendmsg(data_definition_.getDefinition(), "ConfigManager");
|
session_.group_sendmsg(data_definition_.getDefinition(), "ConfigManager");
|
||||||
session_.group_recvmsg(env, answer, false);
|
session_.group_recvmsg(env, answer, false);
|
||||||
|
|
||||||
// get any stored configuration from the manager
|
// get any stored configuration from the manager
|
||||||
if (config_handler_) {
|
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_sendmsg(cmd, "ConfigManager");
|
||||||
session_.group_recvmsg(env, answer, false);
|
session_.group_recvmsg(env, answer, false);
|
||||||
cout << "[XX] got config: " << endl << answer->str() << endl;
|
cout << "[XX] got config: " << endl << answer->str() << endl;
|
||||||
|
@@ -33,7 +33,7 @@ public:
|
|||||||
* @param spec_file_name: The name of the file containing the data
|
* @param spec_file_name: The name of the file containing the data
|
||||||
* definition.
|
* 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(*config_handler)(isc::data::ElementPtr new_config) = NULL,
|
||||||
isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command) = NULL
|
isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command) = NULL
|
||||||
) throw (isc::cc::SessionError);
|
) throw (isc::cc::SessionError);
|
||||||
|
@@ -26,17 +26,15 @@ from ISC.CC import Session
|
|||||||
import isc
|
import isc
|
||||||
|
|
||||||
class CCSession:
|
class CCSession:
|
||||||
def __init__(self, module_name, spec_file_name,
|
def __init__(self, spec_file_name, config_handler, command_handler):
|
||||||
config_handler, command_handler):
|
self._data_definition = isc.config.DataDefinition(spec_file_name)
|
||||||
self._module_name = module_name
|
self._module_name = self._data_definition.getModuleName()
|
||||||
#self._spec_file_name = spec_file_name
|
|
||||||
self.setConfigHandler(config_handler)
|
self.setConfigHandler(config_handler)
|
||||||
self.setCommandHandler(command_handler)
|
self.setCommandHandler(command_handler)
|
||||||
|
|
||||||
self._data_definition = isc.config.DataDefinition(spec_file_name)
|
|
||||||
|
|
||||||
self._session = Session()
|
self._session = Session()
|
||||||
self._session.group_subscribe(module_name, "*")
|
self._session.group_subscribe(self._module_name, "*")
|
||||||
|
|
||||||
self.__sendSpec()
|
self.__sendSpec()
|
||||||
self.__getFullConfig()
|
self.__getFullConfig()
|
||||||
@@ -49,7 +47,10 @@ class CCSession:
|
|||||||
"""Returns the command-channel session that is used, so the
|
"""Returns the command-channel session that is used, so the
|
||||||
application can use it directly"""
|
application can use it directly"""
|
||||||
return self._session
|
return self._session
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self._session.close()
|
||||||
|
|
||||||
def checkCommand(self):
|
def checkCommand(self):
|
||||||
"""Check whether there is a command on the channel.
|
"""Check whether there is a command on the channel.
|
||||||
Call the command callback function if so"""
|
Call the command callback function if so"""
|
||||||
|
@@ -61,6 +61,9 @@ class DataDefinition:
|
|||||||
def getDefinition(self):
|
def getDefinition(self):
|
||||||
return self._data_spec
|
return self._data_spec
|
||||||
|
|
||||||
|
def getModuleName(self):
|
||||||
|
return self._data_spec["data_specification"]["module_name"]
|
||||||
|
|
||||||
def _check(data_spec):
|
def _check(data_spec):
|
||||||
if type(data_spec) != dict:
|
if type(data_spec) != dict:
|
||||||
raise DataDefinitionError("data specification not a dict")
|
raise DataDefinitionError("data specification not a dict")
|
||||||
|
Reference in New Issue
Block a user