コード例 #1
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;
}
コード例 #2
0
ファイル: producer.cpp プロジェクト: NKSG/vn-sdm
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;
}