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 ssipc_control_message_callback(T_IPC_CONN conn, T_IPC_CONN_PROCESS_CB_DATA data, T_CB_ARG arg) { T_STR string; T_STR srvnode; T_IPC_MSG msg; /* printf("ssipc_control_message_callback: %d %d\n", local.nev_rec,local.nev_proc); */ /* get first string */ TipcMsgSetCurrent(data->msg,0); TipcMsgNextStr(data->msg,&string); /* evt status request */ if(strcasecmp(string,"evt_status_poll")==0) { TipcSrvGetNode(&srvnode); msg=TipcMsgCreate(TipcMtLookup("evt_status")); TipcMsgSetDest(msg,(T_STR)"/evt_system/status"); /* must send 'unique_name' here from main program */ TipcMsgSetSender(msg,local.unique_name); TipcMsgAppendStr(msg,local.unique_name); TipcMsgAppendStr(msg,getenv("HOST")); TipcMsgAppendStr(msg,local.session); TipcMsgAppendStr(msg,srvnode); TipcMsgAppendInt4(msg,local.nev_rec); TipcMsgAppendReal8(msg,local.rate_rec); TipcMsgAppendInt4(msg,local.nev_proc); TipcMsgAppendReal8(msg,local.rate_proc); TipcMsgAppendInt4(msg,local.et_ok); TipcMsgAppendStr(msg,local.data_flow); TipcSrvMsgSend(msg,TRUE); TipcSrvFlush(); } else /* don't understand message ... ship to smartsockets interpreter */ { TutCommandParseStr(string); } return; }
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); }