int main(int argc, char **argv) { char *mon_dg; /* decode command line */ decode_command_line(argc,argv); /* set application */ ipc_set_application(application); /* set destination */ if(destination==NULL)destination=strdup(application); /* inhibit boilerplate for brief mode */ if(brief==1)TutSetOutputFunc(ipc_output_dummy); /* connect to server */ ipc_init("","ipc test monitor"); /* define callback to add user information to status_poll_result message */ ipc_set_user_status_poll_callback(mystatuspollcallback); /* receive status_poll_result message group */ ipc_get_status_poll_group(&mon_dg); TipcSrvDgSetRecv(mon_dg,TRUE); /* define callback to handle (i.e. print) status_poll_result messages */ TipcSrvProcessCbCreate(TipcMtLookup("status_poll_result"),print_status_result,NULL); /* set alarm if polltime > 0 */ if(polltime>0) { /* declare SIGALRM handler */ signal(SIGALRM,alarm_handler); /* set alarm */ alarm(polltime); } else if (once==1) { T_IPC_MSG msg=TipcMsgCreate(TipcMtLookupByNum(T_MT_CONTROL)); TipcMsgSetDest(msg,destination); TipcMsgAppendStr(msg,"status_poll"); TipcSrvMsgSend(msg,TRUE); TipcSrvFlush(); TipcMsgDestroy(msg); } /* process messages */ if(brief==1)TutSetOutputFunc(NULL); for (;;) { TipcSrvMainLoop((double)waittime); if(once==1)break; } if(brief==1)TutSetOutputFunc(ipc_output_dummy); exit(EXIT_SUCCESS); }
/* * A little utility which can send single commands to a destination. * Special care must be taken in order not to disturb unrelated systems * by sending messages to wrong subject area. Presently the destination string * must contain /spymon somewhere for simplicity. The default values for command * and destination are 'Resume' and '/spymon/command/...' respectively. It is the * resposbility of the receiver of the messages to setup proper callbacks to handle * the messages. */ int main(int argc, char *argv[]) { T_IPC_MT mt; T_IPC_MSG msg; char commStr[20]; char dest[255]; char configFile[256]; char *configDir = 0; strcpy(commStr, "Resume"); strcpy(dest, "/spymon/command/..."); if (argc < 2) { printf("No argument specified! using default:\n"); printf("-> %s %s %s\n", argv[0], commStr, dest); } if (argc > 1) strcpy(commStr, argv[1]); if (argc > 2) strcpy(dest, argv[2]); if (!strstr(dest, "/spymon")) { printf("Can only send messaged to subject areas within /spymon\n"); exit(1); } /* Set the name of the project */ configDir = getenv("SMARTSOCKETS_CONFIG_DIR"); sprintf(configFile, "%s/vxworks.cm", configDir); TutCommandParseFile(configFile); /* Connect to RTserver */ if (!TipcSrvCreate(T_IPC_SRV_CONN_FULL)) { fprintf(stderr, "Could not connect to RTserver!\n"); exit(T_EXIT_FAILURE); } mt = TipcMtLookupByNum(T_MT_CONTROL); msg = TipcMsgCreate(mt); T_ASSERT(msg != NULL); TipcMsgSetNumFields(msg, 0); TipcMsgAppendStr(msg, commStr); TipcMsgSetDest(msg, dest); #if 0 TipcMsgPrint(msg, TutOut); #endif TipcSrvMsgSend(msg, TRUE); TipcSrvFlush(); TipcMsgDestroy(msg); /* Shutdown connection once back from the loop */ TipcSrvDestroy(T_IPC_SRV_CONN_NONE); return TRUE; }
void alarm_handler(int i) { T_IPC_MSG msg; /* create and send out status_poll control message */ msg=TipcMsgCreate(TipcMtLookupByNum(T_MT_CONTROL)); TipcMsgSetDest(msg,destination); TipcMsgAppendStr(msg,"status_poll"); TipcSrvMsgSend(msg,TRUE); TipcSrvFlush(); TipcMsgDestroy(msg); /* redeclare alarm signal handler */ signal(SIGALRM,alarm_handler); /* reset alarm */ if(once==0)alarm(polltime); }