switch to process different MqTypeE void MyServiceCall(MqSP const msgque) { // the 'Freiburg' object MqSendSP const send = msgque->send; // get the MqSendS object MqSendSTART(send); // init the MqSendS buffer object MqSend2(send,int2_value); // 1. argument: a MQ_INT2 value MqSendV(send,"num:%x",num); // 2. argument: a vararg string value MqSendB(send,mypicture,size); // 3. argument: a binary picture of size length // call service "SRV1" and wait maximum 60 seconds for the results MqErrorCheck(MqSendEND_AND_WAIT(send,"SRV1",60)); // ... get the results MqErrorCheck(MqRead?(msgque->read, ???)); ... }
2: answer a service call
static MqErrorE Ot_WAR1(MqSP const msgque, MQ_PTR data) { MqSendSP const send = msgque->send; // get the MqSendS object MqSendSP const read = msgque->read; // get the MqReadS object MqSendSTART(send); // init the MqSendS buffer object MqErrorCheck(MqRead2(read,&myInt2)); // read a MQ_INT2 value MqErrorCheck(MqReadC(read,&myStr)); // read a MQ_STR value MqErrorCheck(MqReadU(read,&myPic)); // read a MqBufferS object to store the picture data // ... do some processing MqSend_RET_OK(send); // everything OK just set return-status to 'O' return MqSendEND_RETR(send,NULL); // send the package as an answer of a previous service-call error: // something is wrong, error back return MqSendRETURN(send, MQ_ERROR_PROC_FMT, __func__); }
MqSend_LST_START(send); // start a LST item MqSendX(send,X); // first LST item MqSendY(send,Y); // second LST item // ... do additional MqSend? MqSend_LST_END(send); // finish a LST item
MqSend_RET_START(send, 'W', 10); // start a RET (W)arning item list with error-code 10 MqSendX(send,X); // first warning message MqSendY(send,Y); // second warning message // ... do additional MqSend? MqSend_RET_END(send); // finish a RET item list
MqErrorE MqSendOK (register MqSendS * const send) { MqSendSTART (send); MqSendC (send, "OK"); MqSend_RET_OK (send); MqErrorCheck (MqSendEND_RETR (send, NULL)); return MQ_OK; error: return MqErrorSAppendV (MQ_ERROR_S, MQ_ERROR_PROC_FMT, __func__); }
MqErrorE MqSendRETURN (register MqSendS * const send, const char *const fmt, const char *const proc) { register MqErrorSP error = send->msgque->error; MqSendSTART (send); switch (MqErrorGetStatus (error)) { case MQ_OK: MqSend_RET_OK (send); break; case MQ_ERROR: if (fmt) MqErrorSAppendV (error, fmt, proc); MqSend_RET_START (send, 'E', MqErrorGetNum (error)); MqSendU (send, MqErrorGetText (error)); MqSend_RET_END (send); break; case MQ_WARNING: if (fmt) MqErrorSAppendV (error, fmt, proc); MqSend_RET_START (send, 'W', MqErrorGetNum (error)); MqSendU (send, MqErrorGetText (error)); MqSend_RET_END (send); break; case MQ_CONTINUE: MqPanicV (error, __func__, -1, "expect status ERROR or WARNING but got %s", MqLogStatus (MqErrorGetStatus (error))); } MqErrorCheck (MqSendEND_RETR (send, NULL)); return MQ_OK; error: return MqErrorSAppendV (MQ_ERROR_S, MQ_ERROR_PROC_FMT, __func__); }
MqOptionUP option; // this have to be filled with the values enum {BOOL, DBLE, INT, STR}; // index of the options // the array have to be sorted in the Name member (e.g. "--bool", ...) const static MqOptionS Flag[OPTT_LEN] = { { "--bool", BOOL, B, {.B 0} } , { "--dble", DBLE, D, {.D 0.0} } , { "--int", INT, I, {.I 0} } , { "--str", STR, S, {.S MqBufferInitFromString("hallo")}} , }; static MqOptionUP defopt = NULL; // first time, build 'default' if (!defopt) defopt = MqOptDefault(msgque->error, Flag, OPTT_LEN); // parse the current Msgque packet for options and fill // the option array. if no options are available option = defopt. MqErrorCheck(MqOptGet(msgque, Flag, OPTT_LEN, defopt, &option)); ... MqSendSTART(send); MqSend2(send, option[BOOL].B); // get the 'boolean' option MqSend4(send, option[INT].I); // get the 'MQ_INT4' option MqSendD(send, option[DBLE].D); // get the 'MQ_FLT8' option MqSendC(send, option[STR].S.data); // get the string option MqSend_RET_OK(send); // if options were parsed ... free the option array if (option!=defopt) MqOptFree(msgque->error, Flag, OPTT_LEN, &option); return MqSendEND_RETR(send,NULL);
MqStatCtxSP point1 = MqStatCtxCreate(msgque, "point1", 0); MqStatCtxSP all = MqStatCtxCreate(msgque, "all", 0); MqStatSP itemTimer; // define the timer MqErrorCheck(MqStatCreate(msgque,&itemTimer)); // create the timer for (...) { // just a big loop MqStatInit(itemTimer); // init the timer // ... do some work // measure the average time between 'point1' and MqStatInit MqStatCtxCalc(point1, itemTimer); // ... do some work // measure the average time between 'all' and MqStatInit MqStatCtxCalc(all , itemTimer); } MqStatCtxPrint(point1); // print the average time between 'point1' and MqStatInit MqStatCtxPrint(all); // print the average time between 'all' and MqStatInit MqStatDelete(&itemTimer); // cleanup MqStatCtxDelete(&point1); // cleanup MqStatCtxDelete(&all); // cleanup
void eventQueue(ContextSP const context) { MqEventS *event = (MqEventS*) ckalloc(sizeof(MqEventS)); event->header.proc = eventProcess; event->context = context; Tcl_QueueEvent((Tcl_Event*)event, TCL_QUEUE_TAIL); } void tclEventCheck(ClientData clientData, int flags) { if (!(flags & TCL_FILE_EVENTS)) return; struct timeval tv = {0L, 0L}; MqEventCheck(NULL, MQ_SELECT_RECV, &tv, eventQueue); }
static int eventProcess(Tcl_Event * evPtr, int flags) { if (!(flags & TCL_FILE_EVENTS)) return 0; MqSP const msgque = (((MqEventS*)evPtr)->context)->msgque; // check if event evPtr has disappeared until queuing 'eventQueue' MqErrorCheck(MqProcessEvent(msgque, MQ_TIMEOUT, !MQ_WAIT)); return 1; error: TclErrorGetResult (msgque); Tcl_BackgroundError (msgque->myCtx->interp); return 1; }
1.3.8-20040928