Пример #1
0
int main(int argc, char ** argv)
{
	SubscriptionManager sm;
	SDMSubreqst sub_msg;
	SDMSerreqst ser_msg;
	SDMDeletesub del_msg;
	
	sub_msg.msg_id.setInterface(1);
	sub_msg.msg_id.setMessage(2);
	sub_msg.destination.setAddress(inet_addr("127.0.0.1"));
	sub_msg.destination.setPort(4050);
	sm.AddSubscription(sub_msg) ? printf("First added\n") : printf("First not added\n");
	sm.AddSubscription(sub_msg) ? printf("Second added\n") : printf("Second not added\n");
	
	ser_msg.reply_id.setInterface(1);
	ser_msg.reply_id.setMessage(3);
	sub_msg.destination.setAddress(inet_addr("127.0.0.1"));
	sub_msg.destination.setPort(4050);
	sm.AddSubscription(ser_msg) ? printf("Third added\n") : printf("Third not added\n");
	sub_msg.destination.setPort(4051);
	sm.AddSubscription(ser_msg) ? printf("Fourth added\n") : printf("Fourth not added\n");
	
	sm.Publish(1,3,"A",1);
	return 0;
}
Пример #2
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;
}
Пример #3
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;
}