From 169cb3baaffd283ee10e8bf8775cfaeff5ae0818 Mon Sep 17 00:00:00 2001
From: meini <meini@meini-desktop.ARBEITSGRUPPE>
Date: Wed, 25 Mar 2009 18:44:36 +0100
Subject: rc is more intelligent now & localvariables set local

---
 src/awds/config.h         |    3 +-
 src/awds/configVariable.h |   39 +----------
 src/config.cc             |  178 +++++++++++++++++++++++++--------------------
 src/testmodul.cc          |    1 -
 4 files changed, 103 insertions(+), 118 deletions(-)

diff --git a/src/awds/config.h b/src/awds/config.h
index e08e7f1b33c8c5e4f7d04ca338b5999bcf924a69..ee197a671473887d687e9a05f4491bc62ab20c6e 100644
--- a/src/awds/config.h
+++ b/src/awds/config.h
@@ -9,7 +9,6 @@ class Config
 {
 
 private:
-	ostream *shellOut;
 	ShellClient* shellClient;
 	int requestCount;
 
@@ -29,6 +28,8 @@ public:
 	//int remoteConfigAnnounce(char* name,ConfigVariableType cvt,void* thisref,variableGetHandler vgh,variableSetHandler vsh,void* value=NULL);
 	virtual int registerVar(ConfigVariable* cv);
 	int configAddCommand();
+	int remoteCall(Config* classref,std::string variableName,std::string variableValue,std::string nodeList);
+
 	static int remoteconfig_command_fn(ShellClient &sc, void *data, int argc, char **argv);
 	static int requestHandler (void *data, ReadMarshalStream*  msIn, WriteMarshalStream* msOut, const awds::NodeId& src);
 	static int responseHandler (void *data, ReadMarshalStream*  msIn, const awds::NodeId& src);
diff --git a/src/awds/configVariable.h b/src/awds/configVariable.h
index baf787cd4cf20d4aaba7b3c1f0aa53e43b28b4a6..01acd5721213ada5efad6776fb5068a08a7edbf4 100644
--- a/src/awds/configVariable.h
+++ b/src/awds/configVariable.h
@@ -37,7 +37,7 @@ class ConfigVariable
 		virtual std::string toString()=0;
 		virtual int fromString(std::string)=0;
 
-		const char* getName(){return m_name.c_str();}
+		std::string getName(){return m_name;}
 };
 
 class ConfigVariableInt : public ConfigVariable
@@ -152,43 +152,6 @@ class ConfigVariableBool : public ConfigVariable
 		}
 };
 
-class ConfigVariableFloat : public ConfigVariable
-{
-
-	typedef int (*variableSetHandler) (void* classref,const float* value);
-	typedef int (*variableGetHandler) (void* classref,float* value);
-
-	private:
-	protected:
-		variableGetHandler m_vgh;
-		variableSetHandler m_vsh;
-	public:
-		ConfigVariableFloat(const char* name,variableGetHandler vgh,variableSetHandler vsh,void* classref): ConfigVariable(name)
-		{
-			m_vgh=vgh;
-			m_vsh=vsh;
-			m_thisref=classref;
-		}
-
-		virtual std::string toString()
-		{
-			ostringstream oss;
-			float value=0;
-			int retval = m_vgh(m_thisref,&value);
-			if(retval==CONFIG_VARIABLE_SUCCESS)
-			{
-				oss << value;
-  				return oss.str();
-			}
-			return std::string("CONFIG_VARIABLE_FAILURE");
-		}
-		virtual int fromString(std::string s)
-		{
-			float mvalue=strtod(s.c_str(),NULL);
-			return m_vsh(m_thisref,&mvalue);
-		}
-};
-
 class ConfigVariableDouble : public ConfigVariable
 {
 	typedef int (*variableSetHandler) (void* classref,const double* value);
diff --git a/src/config.cc b/src/config.cc
index 0ebfd17e5a3fcd0f5774561bee816b9891a238e1..b413557b6446a1e564aa591d94c49d47281d3cf0 100644
--- a/src/config.cc
+++ b/src/config.cc
@@ -17,13 +17,13 @@ struct rcMsgReq
 	uint32_t nameLength;
 	uint32_t valLength;
 	char message[MAX_MESSAGE_SIZE];
-}__attribute__((packed));
+};
 struct rcMsgRes
 {
 	uint32_t status;
 	uint32_t length;
 	char message[MAX_MESSAGE_SIZE];
-}__attribute__((packed));
+};
 
 Config::Config()
 {
@@ -97,78 +97,100 @@ int Config::configAddCommand() {
 		       config_cmd_usage);
     return 0;
 }
+int Config::remoteCall(Config* classref,std::string nodeList,std::string variableName,std::string variableValue)
+{
+	REP_MAP_OBJ(SppManager2 *,sppManager);
+	if(!sppManager)
+	{
+		GEA.dbg() << "Config::remoteCall SppManager2 not found!"<< std::endl;
+		return -1;
+	}
+
+	struct rcMsgReq rcmo;
+	memset(rcmo.message,0,MAX_MESSAGE_SIZE);
+	rcmo.nameLength=0;
+	rcmo.valLength=0;
+	if(variableName.length()>0)
+	{
+		rcmo.nameLength = variableName.length();
+		memcpy(rcmo.message,variableName.c_str(),rcmo.nameLength);
+		rcmo.valLength = variableValue.length();
+		memcpy(rcmo.message+rcmo.nameLength,variableValue.c_str(),rcmo.valLength);
+	}
+	if(!nodeList.compare("..")) //broadcast
+	{
+		if(classref->shellClient!=NULL)
+			if(classref->shellClient->state==ShellClient::CS_Idle)
+				classref->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);
+	}
+	else
+	{
+		if(classref->shellClient)
+			if(classref->shellClient->state==ShellClient::CS_Idle)
+				classref->shellClient->block();
+		char nodes[nodeList.length()+1];
+		memset(nodes,0,nodeList.length()+1);
+		memcpy(nodes,nodeList.c_str(),nodeList.length());
+		char *p;
+		char *pch = strtok_r(nodes,",", &p);
+		gea::AbsTime t_start = gea::AbsTime(GEA.lastEventTime);
+		while (pch != NULL)
+		{
+			awds::NodeId dest;
+			REP_MAP_OBJ(awds::Routing *,awdsRouting);
+			if(awdsRouting)
+			{
+				awdsRouting->getNodeByName(dest,pch);
+				classref->requestCount++;
+				sppManager->sendRequest(dest,9876,(void*) &rcmo, Config::requestCreator, &t_start, Config::responseHandler);
+			}
+			pch = strtok_r(NULL, ",", &p);
+		}
+	}
+	return 0;
+}
 
 int Config::remoteconfig_command_fn(ShellClient &sc, void *data, int argc, char **argv)
 {
 	Config *self = static_cast<Config*>(data);
 	self->shellClient = &sc;
-	self->shellOut=sc.sockout;
-	REP_MAP_OBJ(SppManager2 *,sppManager);
-	if ( (argc >= 2) )
+	 
+	if ( (argc < 2) )
+	{
+		for(VariablesMap::iterator it =self->remoteVariables.begin();it != self->remoteVariables.end();it++)
+			*(self->shellClient->sockout) << it->first << " " << it->second->toString() << std::endl;
+	}
+	else
+	if(argc==4)
+		self->remoteCall(self,argv[1],argv[2],argv[3]);
+	else
 	{
-		struct rcMsgReq rcmo;
-		memset(rcmo.message,0,MAX_MESSAGE_SIZE);
-		if(argc>=3)//lets build the request
+		VariablesMap::iterator it = self->remoteVariables.find(argv[1]);
+		if(it!=self->remoteVariables.end())
 		{
-
-			rcmo.nameLength = strlen(argv[2]);
-			rcmo.valLength=0;
-			memcpy(rcmo.message,argv[2],rcmo.nameLength);
-
-			if(argc==4)
+			if(argc==2)
+				*self->shellClient->sockout << it->first <<" "<< it->second->toString() << std::endl;
+			else 
 			{
-				rcmo.valLength = strlen(argv[3]);
-				memcpy(rcmo.message+rcmo.nameLength,argv[3],rcmo.valLength);
+				int retval = it->second->fromString(argv[2]);
+				*self->shellClient->sockout << it->first <<" "<< it->second->toString() << std::endl;
+				return retval;
 			}
+			
 		}
 		else
 		{
-			rcmo.nameLength=0;
-			rcmo.valLength=0;
-		}
-		if(!strcmp(argv[1], "[..]")) //broadcast
-		{
-			if(self->shellClient!=NULL)
-				if(self->shellClient->state==ShellClient::CS_Idle)
-					self->shellClient->block();
-			gea::AbsTime *t_start = new gea::AbsTime(GEA.lastEventTime);
-			sppManager->sendRequestAll( 9876, (void*) &rcmo, Config::requestCreator, t_start, Config::responseHandler,t_start,Config::finishedHandler);
-		}
-		else // single nodes
-		{
-			if(self->shellClient)
-				if(self->shellClient->state==ShellClient::CS_Idle)
-					self->shellClient->block();
-			int i=0;
-			char *p;
-			char *pch = strtok_r(argv[1],"[,]", &p);
-
-			gea::AbsTime *t_start = new gea::AbsTime(GEA.lastEventTime);
-			char c='9';
-			while (pch != NULL)//we might not need to split them up but to be on the safe side...
-			{
-				
-				awds::NodeId dest;
-			
-				REP_MAP_OBJ(awds::Routing *,awdsRouting);
-				if(awdsRouting)
-				{
-					awdsRouting->getNodeByName(dest,pch);
-					//self->requests[*t_start]=i++;
-					self->requestCount++;
-					sppManager->sendRequest(dest,9876,(void*) &rcmo, Config::requestCreator, &c, Config::responseHandler);
-				}
-				pch = strtok_r(NULL, "[,]", &p);
-			}
+			if(argc==2)		
+				self->remoteCall(self,argv[1],"","");
+			else 
+				self->remoteCall(self,argv[1],argv[2],"");
 		}
-    	}
-	else
-	{
-		*sc.sockout << config_cmd_usage << endl;
-		return 0;
-    	}
+	}
 	return 0;
 }
+
  /**
   * \brief	finishedHandler
   *
@@ -200,8 +222,8 @@ void Config::finishedHandler (void *data)
   */
 int Config::responseHandler (void *data, ReadMarshalStream*  msIn, const awds::NodeId& src) 
 {
-	printf("blubb1\n");fflush(stdout);
 	REP_MAP_OBJ(Config *,config);//get but we'll check it on USE!
+	//rc 0018F3536D80
 	if(!config)
 	{
 		GEA.dbg() << "Config::responseHandler Config not found!"<< std::endl;
@@ -210,7 +232,8 @@ int Config::responseHandler (void *data, ReadMarshalStream*  msIn, const awds::N
 	if(msIn==NULL)//ouch we need this!
 	{
 		//TODO timeout?
-		config->requestCount--;
+		if(config->requestCount>0)
+			config->requestCount--;
 		if(config->shellClient)
 			if(config->shellClient->state==ShellClient::CS_Blocked)
 				config->shellClient->unblock();
@@ -221,37 +244,37 @@ int Config::responseHandler (void *data, ReadMarshalStream*  msIn, const awds::N
 	uint32_t count;
 	*msIn >> status;
 	*msIn >> count;
-	config->requestCount--;
+	if(config->requestCount>0)
+		config->requestCount--;
 	if(status)//status>0? this is a problem!!
 	{
-		*config->shellOut << "Response from " << src << ". Status>1 Obviously there was an error!" << std::endl;
-		GEA.dbg() << "Response from " << src <<". Status>1 Obviously there was an error!" << std::endl;
-		return CONFIG_VARIABLE_FAILURE;
+		*config->shellClient->sockout << "Response from " << src << ". Status>0 Obviously there was an error!" << std::endl;
+		//GEA.dbg() << "Response from " << src <<". Status>1 Obviously there was an error!" << std::endl;
+		//return CONFIG_VARIABLE_FAILURE;
 	}
 	char* retval;
-
 	if(count>0)//ah we've got a message nice, print it!
 	{
-		*config->shellOut << "Response from " << src <<": " << std::endl;
-		GEA.dbg() << "Response from " << src <<": "<< std::endl;
+		*config->shellClient->sockout << "Response from " << src <<": " << std::endl;
+		//GEA.dbg() << "Response from " << src <<": "<< std::endl;
 		for(int i=0;i<count;i++)
-		{
+		{	
 			std:string s;
 			*msIn >> s;
-			*config->shellOut << s << std::endl;
+			*config->shellClient->sockout << s << std::endl;
 			GEA.dbg() << s << std::endl;
 		}
 	}
 
 	else //no Message? well at least no error!
 	{
-		*config->shellOut << "Response from" << src <<" with no length. Strange but there was no error!" << std::endl;
-		GEA.dbg() << "Response from" << src <<" with no length. Strange but there was no error!" << std::endl;
+		*config->shellClient->sockout << "Response from" << src <<" with no length. Strange but there was no error!" << std::endl;
+		//GEA.dbg() << "Response from" << src <<" with no length. Strange but there was no error!" << std::endl;
 	}
-
 	if(config->requestCount==0)
 		if(config->shellClient)
-			config->shellClient->unblock();
+			if(config->shellClient->state==ShellClient::CS_Blocked)
+				config->shellClient->unblock();
 
 	return CONFIG_VARIABLE_SUCCESS;
 }
@@ -295,17 +318,16 @@ int Config::requestHandler (void *data, ReadMarshalStream*  msIn, WriteMarshalSt
 	{
 		uint32_t numberOfEntries = config->remoteVariables.size();
 		uint32_t status = 0;
-
 		*msOut << status;
 		*msOut << numberOfEntries;
 
 		for(VariablesMap::iterator it=config->remoteVariables.begin();it!=config->remoteVariables.end();it++)
 		{
-			*msOut << std::string(it->first);
+			*msOut << (it->first + " " + it->second->toString());
 		}
 		return CONFIG_VARIABLE_SUCCESS;
 	} else {
-		VariablesMap::iterator it = config->remoteVariables.find(name);//why the heck is THIS not working?
+		VariablesMap::iterator it = config->remoteVariables.find(name);
 		uint32_t statusOut = CONFIG_VARIABLE_FAILURE;
 		uint32_t numberOfStringsOut = 0;
 		if(it != config->remoteVariables.end())//at least this works but....
@@ -324,7 +346,7 @@ int Config::requestHandler (void *data, ReadMarshalStream*  msIn, WriteMarshalSt
 		} else {
 			if(config->shellClient)
 				*config->shellClient->sockout << "Config::requestHandler Request sorry i don't know this one: " << name << std::endl;
-			GEA.dbg() << "Config::requestHandler Request sorry i don't know this one: " << name << std::endl;
+			//GEA.dbg() << "Config::requestHandler Request sorry i don't know this one: " << name << std::endl;
 
 			*msOut << statusOut;
 			*msOut << numberOfStringsOut;
diff --git a/src/testmodul.cc b/src/testmodul.cc
index b061b50127e87d56c152633ef3dbcc6609e8489f..913dc6f5ea371b358a68ed18dbc4236276f420e6 100644
--- a/src/testmodul.cc
+++ b/src/testmodul.cc
@@ -26,7 +26,6 @@ RemoteConfigTestModule::RemoteConfigTestModule()
 
 	config->registerVar(new ConfigVariableInt("testmodul.testint",getint,setint,this));
 	config->registerVar(new ConfigVariableDouble("testmodul.testdouble",getdouble,setdouble,this));
-	config->registerVar(new ConfigVariableFloat("testmodul.testfloat",getfloat,setfloat,this));
 	config->registerVar(new ConfigVariableBool("testmodul.testbool",getbool,setbool,this));
 	config->registerVar(new ConfigVariableString("testmodul.testchar",getchar,setchar,this));
 
-- 
1.6.2.1


