Exemplo n.º 1
0
void* Forwarder(void* ignored)
{
	MessageManager mm;
	SDMData dat;
	mm.Async_Init(MYPORT2);
	char buf[BUFSIZE];
	
	SDMComponent_ID Receiver;
	Receiver.setAddress(inet_addr("127.0.0.1"));
	Receiver.setPort(MYPORT);
	
	while(1)
	{
		if (mm.IsReady())
		{
			if (mm.GetMessage(buf) == SDM_Data)
			{
				SDMData received;
				long Length = received.Unmarshal(buf);
				
				printf("(Forwarder)  Received SDMData with timestamp %ld, %ld length is %ld.\n",received.GetSecondsStamp(), received.GetSubSecondsStamp(), Length);
				
				
				Length = received.Forward(Receiver);
				printf("(Forwarder)  Forwarding message length is %ld.\n", Length);
				fflush(NULL);
			}
			else
				printf("(Forwarder)  Unknown message received.\n");
		}
		sleep(1);
	}
	return NULL;
}
Exemplo n.º 2
0
int main(int argc,char** argv)
{
	MessageManager mm;
	SDMData dat;
	SDMRegInfo info;
	SDMReqReg req_reg;
	char buf[BUFSIZE];
	long length;

	//initialize consumer
	SDMInit(argc,argv);
	my_port = getPort();
	mm.Async_Init(my_port);
	signal(SIGINT, SigHandler);

	printf("%s listening on port %ld\n",argv[0],my_port);

	while(1)
	{
		if (mm.IsReady())
		{
			switch(mm.GetMessage(buf,length))
			{
			case SDM_Data:
				dat.Unmarshal(buf,length);
				DataHandler(dat,length);
				break;
			case SDM_RegInfo:
				if(info.Unmarshal(buf)!=SDM_NO_FURTHER_DATA_PROVIDER)
				{
					RegInfoHandler(info);
				}
				break;
			default:
				printf("Unexpected message\n");
			}
		}
		else
		{	//check for data and service providers
			if(consume_msgs[0].source.getSensorID() == 0)
			{
				//request info on integer data providers
				//Set variable name
				strcpy(req_reg.item_name,"Total_Messages_Recd");
				//Set the quallist can be empty
				strcpy(req_reg.quallist,"< format=\"UINT32\"/>");
				req_reg.reply = SDM_REQREG_CURRENT_FUTURE_AND_CANCELLATIONS;
				req_reg.destination.setPort(my_port);
				req_reg.id = DATA_PROVIDER;
				req_reg.Send();
				printf("Searching for new data provider\n");
				sleep(2);
			}
			usleep(1000);
		}
	}
}
Exemplo n.º 3
0
void* Listener(void * args)
{
	char buf[BUFSIZE];
	SDMSubreqst sub;
	SDMDeletesub del;
	MessageManager mm;
	mm.Async_Init(my_port);
	
	// Send one hearbeat, let the app fail
	SendHeartbeat();
	
	while(1)
	{
		if(mm.IsReady())
		{
			//SendHeartbeat();
#ifdef WIN32
			switch(mm.GetMsg(buf))
#else
			switch(mm.GetMessage(buf))
#endif
			{
			case SDM_Subreqst:
				sub.Unmarshal(buf);
				printf("Subscription Rec'd for %d\n",sub.msg_id.getInterfaceMessagePair()); fflush(NULL);
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.AddSubscription(sub);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			case SDM_Deletesub:
				printf("Cancel Rec'd\n");
				del.Unmarshal(buf);
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.RemoveSubscription(del);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			default:
				printf("Invalid Message found!\n");
				fflush(NULL);
				break;
			}
		}
		else
		{
			usleep(100000);
		}
	}
	return NULL;
}
Exemplo n.º 4
0
int main(int argc,char** argv)
{
	SDMData dat;
	

	SDMInit(argc,argv);
	my_port = getPort();
	if (my_port < 0)
	{
		printf("Error requesting port.\n");
		return -1;
	}
	mm.Async_Init(my_port);
	RegisterxTEDS();
	GetComponentID();
	CancelxTEDS();
}
Exemplo n.º 5
0
int main(int argc, char** argv)
{
	SDMInit(argc,argv);
	MessageManager mm;
	mm.Async_Init(my_port);
	signal(SIGINT,SigHandler);
	SDMReqReg request;
	SDMRegInfo info;
	char buf[BUFSIZE];
	long length;
	request.destination.setPort(my_port);
	request.id = 1;
	request.reply = SDM_REQREG_CURRENT_FUTURE_AND_CANCELLATIONS;
	printf("Sending ReqReg for Message_Count.\n");
	strcpy(request.item_name,"Message_Count");
	strcpy(request.quallist,"</>");
	request.Send();
	printf("Sending ReqReg for Enable_Logging.\n");
	strcpy(request.item_name,"Enable_Logging");
	request.Send();
	printf("Sending ReqReg for faults.\n");
	strcpy(request.item_name,"faultdata");
	request.Send();
	
	while(1)
	{
		if (mm.IsReady())
		{
			mm.GetMessage(buf,length);
			if (info.Unmarshal(buf) > 0)
			{
				printf("RegInfo received\n%s\n\n",info.msg_def);
			}
		}
		else
		{
			printf(".");
			sleep(1);
		}
	}
	
	
	request.reply = SDM_REQREG_CANCEL;
	request.Send();
	return 1;
}
Exemplo n.º 6
0
void* Sender(void* ignored)
{
	MessageManager mm;
	SDMData dat;
	for (int i = 0; i < 256; i++)
		dat.msg[i] = 0x45;
	dat.length = 256;
	mm.Async_Init(MYPORT);
	char buf[BUFSIZE];
	
	SDMComponent_ID Receiver;
	Receiver.setAddress(inet_addr("127.0.0.1"));
	Receiver.setPort(MYPORT2);
	
	while(1)
	{
		if (mm.IsReady())
		{
			if (mm.GetMessage(buf) == SDM_Data)
			{
				SDMData received;
				received.Unmarshal(buf);
				
				printf("(Sender)  Received SDMData with timestamp %ld, %ld.\n",received.GetSecondsStamp(), received.GetSubSecondsStamp());
				fflush(NULL);
				if (!DataCheck(received))
				{
					printf("(Sender)  ERROR message doesn't match!\n");
				}
			}
			else
				printf("(Sender)  Unknown message received.\n");
			
		}
		// Send the message
		printf("(Sender)  Sending message...\n");
		dat.SendTo(Receiver);
		
		sleep(1);
	}
	
	return NULL;
}
Exemplo n.º 7
0
int main(int argc,char** argv)
{
	MessageManager mm;
	SDMData dat;
	SDMRegInfo info;
	SDMReqReg req_reg;
	char buf[BUFSIZE];
	long length;
	bool infosDone = false;
	int numRecd = 0;

	//initialize consumer
	SDMInit(argc,argv);
	my_port = getPort();
	mm.Async_Init(my_port);

	printf("Consumer listening on port %ld\n",my_port);

	while(!infosDone)
	{
		if (mm.IsReady())
		{
			switch(mm.GetMessage(buf,length))
			{
			case SDM_RegInfo:
				if(info.Unmarshal(buf)!=SDM_NO_FURTHER_DATA_PROVIDER)
				{
					numRecd++;
					RegInfoHandler(info);
				}
				else
				{
					if (numRecd == 0)
					{
						printf("No log messages found.\n");
						fflush(NULL);
					}
					infosDone = true;
				}
				break;
			default:
				printf("Unexpected message\n");
			}
		}
		else
		{	//check for data and service providers
			if(data_provider.getSensorID() == 0)
			{
				//request info on integer data providers
				//Set variable name
				strcpy(req_reg.item_name,"Disable_Logging");
				//Set the quallist can be empty
				strcpy(req_reg.quallist,"< >");
				req_reg.reply = SDM_REQREG_CURRENT_AND_FUTURE;
				req_reg.destination.setPort(my_port);
				req_reg.id = DATA_PROVIDER;
				req_reg.Send();
				printf("Searching for log command...\n");
				sleep(2);
			}
			usleep(1000);
		}
	}
}
Exemplo n.º 8
0
int main(int argc,char** argv)
{
	SDMService service;
	SDMConsume con;
	MessageManager mm;
	char buf[BUFSIZE];
	char name[128];
	char ip[17];
	long port;
	SDMComponent_ID id;

	int pid = 0;
	SDMData dat;

	SDMInit(argc,argv);
	my_port = getPort();
	if (my_port < 0)
	{
		printf("Error getting port.\n");
		return -1;
	}
	mm.Async_Init(my_port);
	
	RegisterxTEDS();
	usleep(100);
	service.source.setSensorID(1);
	service.command_id = 264;
	service.destination.setPort(my_port);
	service.length = 4;
	pid = atoi(argv[3]);
	memcpy(service.data,&pid,4);
	service.Send();
	
	if (mm.BlockGetMessage(buf) != SDM_Data)
	{
		printf("Error, unknown message received.\n");
		return -1;
	}
	dat.Unmarshal(buf);
	
	pid = GET_LONG(dat.msg);
	printf("My SensorID is %d\n",pid);
	service.command_id = 262;
	memcpy(service.data,&pid,4);
	service.Send();
	
	if (mm.BlockGetMessage(buf) != SDM_Data)
	{
		printf("Error, unknown message received.\n");
		return -1;
	}
	dat.Unmarshal(buf);
	
	memset(name,0,128);
	strncpy(name,dat.msg,127);
	printf("My name is %s\n",name);
	service.command_id = 268;
	service.Send();
	
	if (mm.BlockGetMessage(buf) != SDM_Data)
	{
		printf("Error, unknown message received.\n");
		return -1;
	}
	dat.Unmarshal(buf);
	
	port = GET_LONG(dat.msg);
	strcpy(ip,&dat.msg[4]);
	printf("My port is %ld and my ip is %s\n",port,ip);
	service.command_id = 267;
	service.Send();
	service.command_id = 270;
	id.setSensorID(pid);
	id.setPort(port);
	id.setAddress(inet_addr(ip));
	id.Unmarshal(service.data,0);
	service.Send();
	
	if (mm.BlockGetMessage(buf) != SDM_Data)
	{
		printf("Error, unknown message received.\n");
		return -1;
	}
	dat.Unmarshal(buf);
	
	printf("My componentKey is %s\n",dat.msg);
	CancelxTEDS();
}
Exemplo n.º 9
0
int main(int argc,char** argv)
{
	SDMSearch s;
	SDMSearchReply reply;
	SDMData dat;
	SDMConsume con;
	int result = 0;
	char buf[BUFSIZE];
	long length;
	MessageManager mm;
	int cur = 0;
	int count = 0;
	char c;
	unsigned long SID;
		
	signal(SIGINT,SigHandler);
	SDMInit(argc,argv);
	my_port = getPort();
	if(my_port == SDM_PM_NOT_AVAILABLE)
	{
		printf("Unable to get a port from the Process Manager!\n");
		exit(0);
	}
	mm.Async_Init(my_port);
	sleep(1);
	s.destination.setPort(my_port);
	s.destination.setAddress(DataManager.getAddress());  //This application must be run on the same node as the DM
	s.reply = SDM_SEARCH_CURRENT_AND_FUTURE;
	
	printf("\nSending SDMSearch for Device orientation\n");
	memset(s.reg_expr,0,512);
	strcpy(s.reg_expr,".*?<Orientation.*?axis=\"(.*?)\".*");
	s.id = ORIENTATION_SEARCH_ID;
	s.Send();
	
	con.destination = s.destination;
	con.source.setPort(PORT_DM);
	con.source.setAddress(DataManager.getAddress());
	con.source.setSensorID(1);
	con.msg_id = 0x103;
	con.Send();
	
	con.msg_id = 0x104;
	con.Send();
	while(1)
	{
		if (mm.IsReady())
		{
			c = mm.GetMessage(buf,length);
			cur = 0;
			switch(c)
			{
				case SDM_SearchReply:
					result = reply.Unmarshal(buf);
					if(result == SDM_NO_FURTHER_DATA_PROVIDER)
						continue;
					printf("\n");
					if (reply.id == ORIENTATION_SEARCH_ID)
						printf("Reply for orientation search:\n");
					if(count != 0)
						printf("\n");
					printf("Match(es) from %lu:%lu:%d\n",reply.source.getSensorID(),reply.source.getAddress(),reply.source.getPort());
					count++;
					while(reply.captured_matches[cur]!=0)
					{
						if(strlen(reply.captured_matches+cur)<32)
							printf("Match is %s\n",reply.captured_matches+cur);
						else
							printf("Match length of %d exceeds name length restriction of 32\n",strlen(reply.captured_matches+cur));
						cur += strlen(reply.captured_matches+cur)+1;
					}
					break;
				case SDM_Data:
					result = dat.Unmarshal(buf);
					if(dat.length > 4)
					{
						memcpy(&SID,&dat.msg[1],4);
						printf("xTEDS change of type %d on SID %ld\n",dat.msg[0],SID);
					}
					else
					{
						memcpy(&SID,&dat.msg[0],4);
						printf("xTEDS modificaton of SID %ld\n",SID);
					}
					break;
				default:
					printf("Unexpected message of type %c \n",c);
			}
		}
		else
		{
			printf(".");
			sleep(1);
			fflush(NULL);
		}
	}
}
Exemplo n.º 10
0
int main (int argc, char ** argv)
{
	char buf[BUFSIZE];
	long length;
	SDMRegInfo info;
	SDMData data;
	SDMInit(argc, argv);
	int Count = 0;
	MessageManager mm;
	mm.Async_Init(my_port);
	signal(SIGINT, SigHandler);
	
	while (1)
	{
		if (mm.IsReady())
		{
			switch(mm.GetMessage(buf, length))
			{
				case SDM_RegInfo:
					if (info.Unmarshal(buf) != SDM_NO_FURTHER_DATA_PROVIDER)
					{
						RegInfoHandler(info);
					}
					break;
				case SDM_Data:
					data.Unmarshal(buf);
					DataHandler(data);
					break;
				
			}
			
		}
		else if (!providers_found)
		{
			SendRegReqs();
			sleep(1);
		}
		else
		{
			sleep(1);
			/*	if (Count++ == 10)
			{
				printf("  Starting task %s...\n", START_TASKNAME);
				SDMCommand request;
				request.source = TMID;
				request.command_id = starttask_id;
				request.destination.setPort(my_port);
				const unsigned short ZERO = 0;
				PUT_USHORT(request.data, ZERO);
				PUT_INT(request.data + 2, 0);
				const unsigned int FILENAME_OFFSET = 6;
				strcpy(request.data + FILENAME_OFFSET, START_TASKNAME);
				request.length = 27;
				request.Send();
				Count = 0;
				}*/
		}
	}
	
	
	return 0;
}
Exemplo n.º 11
0
int main (int argc, char ** argv)
{
	MessageManager mm;
	char buf[BUFSIZE];
	SDMSearchReply ReplyMsg;
	unsigned char type;
	char InfoSource[40];
	char MessageID[40];
	SDMInit(argc, argv);
	signal(SIGINT,SigHandler);
	
	myPort = getPort();
	if (myPort == SDM_PM_NOT_AVAILABLE)
	{
		myPort = 4059;
	}
	mm.Async_Init(myPort);
	
	printf("-------------------SDMSearch Tester-------------------\n");
	
	bool MenuFinished = false;
	
	while (!MenuFinished)
		MenuFinished = Menu();
		
	printf("Sending request...\n");
	Request.destination.setPort(myPort);
	Request.Send();
	
	int count = 1;
	bool Finished = false;
	if (Request.reply > SDM_SEARCH_CURRENT)
	{
		printf("Press CTRL+C to quit.\n");
		sleep(1);
	}
	while (!Finished || Request.reply > SDM_SEARCH_CURRENT)
	{
		type = mm.BlockGetMessage(buf);
		switch (type)
		{
			case SDM_SearchReply:
			{
				long length = ReplyMsg.Unmarshal(buf);
				if (length == SDM_NO_FURTHER_DATA_PROVIDER)
					Finished = true;
				else
				{
					ReplyMsg.source.IDToString(InfoSource, sizeof(InfoSource));
					printf("(%d) SearchReply received (%s):\n",count++, InfoSource);
					
					printf("\t---Captured Text Portion:---\n");
					
					bool nullFound = false;
					for (unsigned int i = 0; i < sizeof(ReplyMsg.captured_matches); i++)
					{
						if (isprint(ReplyMsg.captured_matches[i]))
						{
							printf("%c", ReplyMsg.captured_matches[i]);
							nullFound = false;
						}
						else if (ReplyMsg.captured_matches[i] == '\0')
						{
							printf("0");
							if (nullFound)
							{
								printf("\n");
								break;
							}
							nullFound = true;
						}
						
					}
				}
				break;
			}
			default:
				printf("Unexpected message (%d).\n",type);
		}
	}
	printf("End of SDMSearch messages.\n");	
	printf("-------------------SDMSearch Tester Finished-------------------\n");
	return 0;	
}
Exemplo n.º 12
0
void* Listener(void * args)
{
	char buf[BUFSIZE];
	SDMSubreqst sub;
	SDMDeletesub del;
	MessageManager mm;
	mm.Async_Init(myPort);
	while(1)
	{
		pthread_testcancel();
		if(mm.IsReady())
		{
			SendHeartbeat();
#ifdef WIN32
			switch(mm.GetMsg(buf))
#else
			switch(mm.GetMessage(buf))
#endif
			{
			case SDM_ACK:
				printf("SDMAck received\n");
				helloReply = true;
				break;
			case SDM_Register:
				printf("SDMRegister received\n");
				waitForReg = false;
				break;
			case SDM_ID:
				printf("SDMID received\n");
				myID.Unmarshal(buf);
				printf("CompID: \n");
				printf("   SensorID: %li\n", myID.destination.getSensorID());
				printf("    Address: %lx\n", myID.destination.getAddress());
				printf("       Port: %i\n", myID.destination.getPort());
				waitForID = false;					
				break;
			case SDM_Subreqst:
				sub.Unmarshal(buf);
				printf("Subscription Rec'd for %d\n",sub.msg_id.getInterfaceMessagePair());
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.AddSubscription(sub);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			case SDM_Deletesub:
				printf("Cancel Rec'd\n");
				del.Unmarshal(buf);
				pthread_mutex_lock(&subscription_mutex);
				subscriptions.RemoveSubscription(del);
				pthread_mutex_unlock(&subscription_mutex);
				break;
			default:
				printf("Invalid Message found!\n");
				break;
			}
		}
		else
		{
			usleep(100000);
		}
	}
	return NULL;
}