theLink 10.0
|
List of all callback defined by libmqmsgque
The servive-callback have to be a function-pointer of type MqServiceCallbackF (MqTokenF)
There a two different types of callback:
(runtime) void MqConfigSetServerSetup(MQ_CTX const ctx, MqServiceCallbackF fCall, MK_CBP callback)
(runtime) void MqConfigSetServerCleanup(MQ_CTX const ctx, MqServiceCallbackF fCall, MK_CBP callback)
(runtime) void MqConfigSetBgError(MQ_CTX const ctx, MqServiceCallbackF fCall, MK_CBP callback)
(runtime) void MqConfigSetEvent(MQ_CTX const ctx, MqServiceCallbackF fCall, MK_CBP callback)
(runtime) enum MkErrorE MqServiceCreate(MQ_CTX const ctx, MQ_TOK const token, MqServiceCallbackF const fCall, MK_CBP callback)
(runtime) enum MkErrorE MqSendEND_AND_CALLBACK(MQ_CTX const ctx, MQ_TOK const token, MqServiceCallbackF const fCall, MK_CBP callback, MK_TIME_T const timeout)
(runtime) enum MkErrorE MqSendEND_AND_SUB(MQ_CTX const ctx, MQ_TOK const token, MqServiceCallbackF const fCall, MK_CBP callback, MK_TIME_T timeout)
Callback used to call a service
Callback used to free a service
Callback used to copy a service
Example from Callback.c
→ using MqServiceCreate with callback
#include "common.h" mk_inline MK_STRN MyConcat2C(MK_STRN s1, MK_STRN s2) { static MkThreadLocal MK_STRB tmpS[256]; snprintf(tmpS,256,"%s%s",s1,s2); return tmpS; } // General rules for defining a callback in ATL // -------------------------------------------- // The \e servive-callback have to be a \e function-pointer of type \RCNs{ServiceCallbackF} (\RCNs{TokenF}) // ============================================================================= // OtherServerC // The "otherInstanceService" require an extra argument, the "mqctx". enum MkErrorE otherInstanceService (MQ_SERVICE_CALL_ARGS) { return MqSend(mqctx,"R", "C", MyConcat2C(MqReadSTR_e(mqctx),"-World-Other-Instance")); error: return MqSendRETURN (mqctx); } // The "otherClassService" require an extra argument, the "mqctx". static enum MkErrorE otherClassService (MQ_SERVICE_CALL_ARGS) { return MqSend(mqctx,"R", "C", MyConcat2C(MqReadSTR_e(mqctx),"-World-Other-Class")); error: return MqSendRETURN (mqctx); } // ============================================================================= // The "procService" require an extra argument, the "mqctx". enum MkErrorE procService (MQ_SERVICE_CALL_ARGS) { return MqSend(mqctx,"R", "C", MyConcat2C(MqReadSTR_e(mqctx),"-World-Proc")); error: return MqSendRETURN (mqctx); } // ============================================================================= // CallbackC // The "ownInstanceService" require no extra argument. enum MkErrorE ownInstanceService (MQ_SERVICE_CALL_ARGS) { return MqSend(mqctx,"R", "C", MyConcat2C(MqReadSTR_e(mqctx),"-World-Own-Instance")); error: return MqSendRETURN (mqctx); } // The "ownClassService" require an extra argument, the "mqctx". static enum MkErrorE ownClassService (MQ_SERVICE_CALL_ARGS) { return MqSend(mqctx,"R", "C", MyConcat2C(MqReadSTR_e(mqctx), "-World-Own-Class")); error: return MqSendRETURN (mqctx); } // the "serverSetup" defines the test-services static enum MkErrorE ServerSetup (MQ_SERVICE_CALL_ARGS) { // 1. The "otherInstanceCallback" require an extra argument, the "otherCtx". MqServiceCreate_E(mqctx,"HLW1",otherInstanceService,NULL,NULL,NULL); // 2. The "otherClassCallback" require no extra argument. // -> remember: use the *absolute-namespace* for the callback MqServiceCreate_E(mqctx,"HLW2",otherClassService,NULL,NULL,NULL); // 3. The "ownInstanceCallback" require no extra argument. MqServiceCreate_E(mqctx,"HLW3",ownInstanceService,NULL,NULL,NULL); // 4. The "otherClassCallback" require no extra argument. MqServiceCreate_E(mqctx,"HLW4",ownClassService,NULL,NULL,NULL); // 5. The "procCallback" require NO extra argument MqServiceCreate_E(mqctx,"HLW5",procService,NULL,NULL,NULL); return MK_OK; error: return MkErrorStack_1X(mqctx); } // package-item enum MkErrorE CallbackCSetup ( MQ_CALLBACK_FACTORY_CTOR_ARGS ) { MQ_CTX const mqctx = *contextP = MqContextCreate(NULL,tmpl); MqConfigSetServerSetup (mqctx, ServerSetup, NULL, NULL, NULL); return MK_OK; } // package-main int main (int argc, MK_STRN argv[]) { AllRtSetup_NULL; // setup commandline arguments for later use MK_BFL largv = MkBufferListCreateVC(argc, argv); MQ_CTX mqctx = NULL; // create "MyServer" factory… and make it to the default. MqFactoryDefault( MqFactoryAdd_2(CallbackCSetup, "CallbackC")); // inspect commandline-argument for the "factory" to choose… and create a object MqFactoryNew_E (MqFactoryGetCalledL(largv), NULL, &mqctx); // start listen for incoming call's MqLinkCreate_E (mqctx, largv); MqCheckForLeftOverArguments_E (mqctx, largv); MqProcessEvent_E (mqctx,MQ_WAIT_FOREVER,MK_TIMEOUT_DEFAULT); error: MkBufferListDelete(largv); MqExit_1(mqctx); }