本文整理汇总了C++中MessageManager::GetMsg方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageManager::GetMsg方法的具体用法?C++ MessageManager::GetMsg怎么用?C++ MessageManager::GetMsg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageManager
的用法示例。
在下文中一共展示了MessageManager::GetMsg方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Listener
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: main
int main(int argc, char ** argv)
{
unsigned long result = 0;
int length = 0;
int miss_count = 0;
int num_toget = 0;
char buf[BUFSIZE];
SDMReady heartbeat;
MessageManager mm;
SDMComponent_ID tm;
//Set monitor process address
heartbeat.source.setSensorID(0);
heartbeat.source.setAddress(inet_addr("127.0.0.1"));
heartbeat.source.setPort(PORT_TM_MONITOR);
//Set TM address
tm.setAddress(inet_addr("127.0.0.1"));
tm.setPort(PORT_TM);
tm.setSensorID(0);
signal(SIGINT, SigIntHandler);
tm_handle = StartTM(argv);
mm.Async_Init_Both(PORT_TM_MONITOR);
/* If spawn was successful */
if (tm_handle != NULL)
{
/* Allow the TM to get started up */
sleep(HEARTBEAT_INTERVAL);
while (1)
{
//Send heartbeats via UDP
heartbeat.SendTo(tm);
length = heartbeat.Marshal(buf);
sleep(HEARTBEAT_INTERVAL);
//If Task Manager quit
if (!GetExitCodeProcess(tm_handle,&result))
printf(" Monitor: Invalid handle for retrieving exit code.\n");
/* If the TaskManager has quit for some reason */
if (result != STILL_ACTIVE)
{
printf(" Monitor: TM failed, restarting...\n");
tm_handle = StartTM(argv);
if (tm_handle != NULL)
{
/* Allow the TM to restart */
sleep(HEARTBEAT_INTERVAL);
/* Start over at while */
continue;
}
/* Error re-starting TM */
else
{
printf(" Monitor: Could not restart the TM.\n");
return -1;
}
}
/* The TM is still running, check for responses to heartbeat messages */
else if (mm.IsReady())
{
//Should respond with one message
num_toget = 1;
while (mm.IsReady())
{
num_toget--;
/* Message is discarded, we only care that one was received */
mm.GetMsg(buf);
}
if (num_toget > 0)
miss_count++;
else
miss_count = 0;
}
/* The TM is still running, but no responses were received */
else
{
//If no messages were received
miss_count++;
if (miss_count == NUM_HEARTBEAT_TRIES)
{
printf(" Monitor: TM unresponsive, restarting...\n");
/* If the Terminate fails and the TM is already dead */
if (!TerminateProcess(tm_handle,0))
{
/* Get its return value */
GetExitCodeProcess(tm_handle,&result);
}
/* Restart the TM */
tm_handle = StartTM(argv);
/* Success restarting */
if (tm_handle != NULL)
{
/* Allow TM to get started */
sleep(HEARTBEAT_INTERVAL);
/* Start over at while loop */
continue;
}
//.........这里部分代码省略.........
示例3: Listener
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;
}