theLink 10.0
|
List of all callback defined by ccmqmsgque
The callback have to be a interface, instance-callback or class-callback.
There a two different types of callback:
ctx.ConfigSetServerSetup(MqServerSetupICB MqServerSetupCCB MqServerSetupIF* callback = NULL)
ctx.ConfigSetServerCleanup(MqServerCleanupICB MqServerCleanupCCB MqServerCleanupIF* callback = NULL)
ctx.ConfigSetBgError(MqBgErrorICB MqBgErrorCCB MqBgErrorIF* callback = NULL)
ctx.ConfigSetEvent(MqEventICB MqEventCCB MqEventIF* callback = NULL)
ctx.ServiceCreate(MQ_TOK token, MqServiceICB MqServiceCCB MqServiceIF* callback)
ctx.SendEND_AND_CALLBACK(MQ_TOK token, MqServiceICB MqServiceCCB MqServiceIF* callback, MK_TIME_T timeout = MK_TIMEOUT_DEFAULT)
ctx.SendEND_AND_SUB(MQ_TOK token, MqServiceICB MqServiceCCB MqServiceIF* callback, MK_TIME_T timeout = MK_TIMEOUT_DEFAULT)
The callback is implemented as:
type | code | example |
---|---|---|
interface | ccmqmsgque::MqServiceIF | Filter4 |
instance-callback | ccmqmsgque::MqContextC::MqTokenICB | manfilter |
class-callback | ccmqmsgque::MqContextC::MqTokenCCB | Filter6 |
Using the signature:
Example from Callback.cc
→ using MqServiceCreate with callback
#include "LibMqMsgque_cc.hh" using namespace ccmkkernel; using namespace ccmqmsgque; using std::string; // General rules for defining a callback in ATL // -------------------------------------------- // 1. The callback must be an \e instance of a class with the interface \WNS{MqServiceIF} // 2. The callback must be an \e static-method of a class with the interface \WNS{MqServiceCCB} // 2. The callback must be an \e instance-method of a class with the interface \WNS{MqServiceICB} // attention, the "::OtherServerC" has no "::MqContextC" as "base-class" and require the "MqContextC::" prefix. class OtherServerC : public MqServiceIF { private: string wht = ""; public: OtherServerC(string _wht) { wht = _wht; } // The "otherInstanceService" require an extra argument, the "cbCtx". void Service (MqContextC *cbCtx) { cbCtx->Send("R", "C", (std::string(cbCtx->ReadSTR()) + "-" + wht + "-Other-Instance").c_str()); } // The "otherClassService" require an extra argument, the "cbCtx". static void otherClassService (MqContextC *cbCtx) { cbCtx->Send("R", "C", (std::string(cbCtx->ReadSTR()) + "-World-Other-Class").c_str()); } }; // The "procService" require an extra argument, the "cbCtx". void procService (MqContextC *cbCtx) { cbCtx->Send("R", "C", (std::string(cbCtx->ReadSTR()) + "-World-Proc").c_str()); } class CallbackC : public MqContextC, public MqServerSetupIF { friend class MqFactoryCT<CallbackC>; private: OtherServerC otherCtx{"World"}; // factory startup (constructor) CallbackC (MK_TYP const typ, MqContextC* tmpl=NULL) : MqContextC(typ,tmpl) { } // The "ownInstanceService" require no extra argument. void ownInstanceService () { Send("R", "C", (string(ReadSTR()) + "-World-Own-Instance").c_str()); } // The "ownClassService" require an extra argument, the "cbCtx". static void ownClassService (MqContextC *cbCtx) { cbCtx->Send("R", "C", (string(cbCtx->ReadSTR()) + "-World-Own-Class").c_str()); } // the "serverSetup" defines the test-services void ServerSetup () { // 1. The "otherInstanceCallback" require an extra argument, the "otherCtx". ServiceCreate("HLW1",&otherCtx); // 2. The "otherClassCallback" require no extra argument. // -> remember: use the *absolute-namespace* for the callback ServiceCreate("HLW2",OtherServerC::otherClassService); // 3. The "ownInstanceCallback" require no extra argument. ServiceCreate("HLW3",MqServiceICB(&CallbackC::ownInstanceService)); // 4. The "otherClassCallback" require no extra argument. ServiceCreate("HLW4",ownClassService); // 5. The "procCallback" require NO extra argument ServiceCreate("HLW5",procService); } }; // package-main int MK_CDECL main(int argc, MK_STRN argv[]) { MqMsgque::CcMqSetup(); // setup commandline arguments for later use MkBufferListC largs = {argc, argv}; // create "CallbackC" factory… and make it to the default. MqFactoryCT<CallbackC>::Add("CallbackC")->Default(); // inspect commandline-argument for the "factory" to choose… and create a object auto srv = MqFactoryCT<MqContextC>::GetCalled(largs)->New(); // start listen for incoming call's try { srv->LinkCreate(largs); srv->ProcessEvent (MQ_WAIT_FOREVER); } catch (const std::exception& e) { srv->ErrorCatch(e); } return srv->Exit(); }