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; }
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); } } }
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; }
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; }
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; }
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); } } }
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); } } }
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; }
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; }