From 6211c57e0e913b51469aff69208cbdae2099ae24 Mon Sep 17 00:00:00 2001
From: Georg Lukas <georg@op-co.de>
Date: Tue, 31 Mar 2009 02:16:04 +0200
Subject: refactoring of config init

---
 src/awds/config.h |    2 +-
 src/config.cc     |   19 ++++++++++++-------
 src/testmodul.cc  |   18 ++++--------------
 3 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/src/awds/config.h b/src/awds/config.h
index b99bb74c4656701d9c2f330642d62a81dbe9009f..b198c4fb54a8f7104f87576e4bf521a5adeecf41 100644
--- a/src/awds/config.h
+++ b/src/awds/config.h
@@ -50,7 +50,7 @@ public:
   */
 
 	virtual int registerVar(ConfigVariable* cv);
-	int configAddCommand();
+	int init();
 private:
 	int remoteCall(std::string variableName,std::string variableValue,std::string nodeList);
 
diff --git a/src/config.cc b/src/config.cc
index 84676f35cf32ce15738c455ea52b05e883867b04..137d1dc851e10113a56360dc75c90138b3b0f762 100644
--- a/src/config.cc
+++ b/src/config.cc
@@ -12,6 +12,8 @@ using namespace awds;
 
 #define MAX_MESSAGE_SIZE 2048
 
+#define SPP_CONFIG_ID 9876
+
 struct rcMsgReq
 {
 	uint32_t nameLength;
@@ -64,20 +66,23 @@ static const char *config_cmd_usage =
     " with <module>		the module containing the configuration variable\n"
     " with <value>		the value to be assigned to the variable\n";
 
-int Config::configAddCommand() {
-
-    ObjRepository& rep = ObjRepository::instance();
+int Config::init() {
 
-    Shell *shell = static_cast<Shell *>(rep.getObj("shell"));
+    REP_MAP_OBJ(Shell *, shell);
+    REP_MAP_OBJ(SppManager *, sppman);
 
-    if (!shell)
+    if (!shell || !sppman)
 	return -1;
 
     shell->add_command("rc", remoteconfig_command_fn, this,
 		       "remote manipulation of all configurations",
 		       config_cmd_usage);
+
+
+    sppman->registerHandler(SPP_CONFIG_ID, 0, Config::requestHandler);
     return 0;
 }
+
 int Config::remoteCall(std::string nodeList,std::string variableName,std::string variableValue)
 {
 	REP_MAP_OBJ(SppManager2 *,sppManager);
@@ -104,7 +109,7 @@ int Config::remoteCall(std::string nodeList,std::string variableName,std::string
 			if(shellClient->state==ShellClient::CS_Idle)
 				shellClient->block();
 		gea::AbsTime t_start = gea::AbsTime(GEA.lastEventTime);
-		sppManager->sendRequestAll( 9876, (void*) &rcmo, Config::requestCreator, &t_start, Config::responseHandler,&t_start,Config::finishedHandler);
+		sppManager->sendRequestAll( SPP_CONFIG_ID, (void*) &rcmo, Config::requestCreator, &t_start, Config::responseHandler,&t_start,Config::finishedHandler);
 	}
 	else
 	{
@@ -126,7 +131,7 @@ int Config::remoteCall(std::string nodeList,std::string variableName,std::string
 				if(awdsRouting->getNodeByName(dest,pch))
 				{
 					requestCount++;
-					sppManager->sendRequest(dest,9876,(void*) &rcmo, Config::requestCreator, &t_start, Config::responseHandler);
+					sppManager->sendRequest(dest,SPP_CONFIG_ID,(void*) &rcmo, Config::requestCreator, &t_start, Config::responseHandler);
 				}
 				else
 					*(shellClient->sockout) << "Unknown Node: " << pch << std::endl;
diff --git a/src/testmodul.cc b/src/testmodul.cc
index 913dc6f5ea371b358a68ed18dbc4236276f420e6..7df5afd7923aaf0e698bc8cbda17e2863d32b00c 100644
--- a/src/testmodul.cc
+++ b/src/testmodul.cc
@@ -93,21 +93,11 @@ int RemoteConfigTestModule::remoteconfigTestModule_command_fn(ShellClient &sc, v
 GEA_MAIN(argc, argv)
 {
 
-
 	Config *config = new Config();
+	if (config->init() != 0)
+		return -1;
+
 	REP_INSERT_OBJ(Config *, config, config);
-	REP_MAP_OBJ(SppManager *,sppManager);
-	if (!sppManager)
-	{
-		GEA.dbg() << "SppManager not found :( " << endl;
-	}
-	else
-	if (argc == 1)
-	{
-		sppManager->registerHandler(9876, 0, Config::requestHandler);
-		GEA.dbg() << "Handler registered with SPP" << endl;
-	}
-	config->configAddCommand();
 
 	RemoteConfigTestModule *remoteConfigTest = new RemoteConfigTestModule();
 	REP_INSERT_OBJ(RemoteConfigTestModule *, remoteConfigTest, remoteConfigTest);
@@ -116,4 +106,4 @@ GEA_MAIN(argc, argv)
 			GEA.dbg() << "RemoteConfigTest Module not found :( " << endl;
 	}
 	else remoteConfigTest->addRemoteConfigTestModulCmd();
-}
\ No newline at end of file
+}
-- 
1.6.2.1


