Esempio n. 1
0
int main(int argc, char * argv[])
{
	MOOS::MOOSAsyncCommClient C;
	MOOS::CommandLineParser P(argc,argv);


	C.AddMessageCallback("CallbackA","X",func,NULL);
	C.AddMessageCallback("CallbackB","Y",func,NULL);
	C.SetOnConnectCallBack(on_connect, &C);
	C.Run("localhost",9000,"reg_test");

	std::cerr<<"now run \"umm -p=X@2,Y@2\n\"";

	while(1)
	{
		std::cerr<<"waiting 5 seconds\n";
		MOOSPause(5000);
		std::cerr<<"unregistering for everything\n";
		C.UnRegister("*","*");
		std::cerr<<"waiting 5 seconds\n";
		MOOSPause(5000);
		std::cerr<<"registering for \"X\" and \"Y\"\n";
		C.Register("X");
		C.Register("Y");
	}



}
Esempio n. 2
0
int main(int argc, char * argv[]){

	//understand the command line
	MOOS::CommandLineParser P(argc,argv);

	std::string db_host="localhost";
	P.GetVariable("--moos_host",db_host);

	int db_port=9000;
	P.GetVariable("--moos_port",db_port);

	std::string my_name ="ex50";
	P.GetVariable("--moos_name",my_name);

	//configure the comms
	MOOS::MOOSAsyncCommClient Comms;
	Comms.SetOnConnectCallBack(OnConnect,&Comms);

	//here we add per message callbacks
	//first parameter is the channel nick-name, then the function
	//to call, then a parameter we want passed when callback is
	//invoked
	Comms.AddMessageCallback("callbackA","V1",funcA,NULL);

	//add a default handler
	Comms.AddMessageCallback("default","*",DefaultMail,NULL);

	//start the comms running
	Comms.Run(db_host,db_port,my_name);

	//for ever loop sending data
	std::vector<unsigned char> data(1000);
	for(;;){
		MOOSPause(10);
		Comms.Notify("V1",data); //for funcA
		Comms.Notify("V2","This is stuff"); //will be caught by default
	}
	return 0;
}