theLink 10.0
Loading...
Searching...
No Matches
MqMsgque_Main_CC_API

MqMsgque PACKAGE - the package-main is a single piece of code evaluated only once at application startup …

+ Collaboration diagram for MqMsgque_Main_CC_API:

MqMsgque PACKAGE - the package-main is a single piece of code evaluated only once at application startup …

Example from MyServer.cc The package-main configure the factory and start the server.

#include "LibMqMsgque_cc.hh"

using namespace ccmkkernel;
using namespace ccmqmsgque;

// package-item
class MyServer : public MqContextC, public MqServerSetupIF {
  friend class MqFactoryCT<MyServer>;
  private:
    // define the factory constructor
    MyServer(MK_TYP const typ, MqContextC* tmpl=NULL) : MqContextC(typ,tmpl) {};

  private:
    // service to serve all incoming requests for token "HLWO"
    void MyFirstService () {
      SendSTART();
      SendV("%s World", ReadSTR());
      SendRETURN();
    }

    // define a service as link between the token "HLWO" and the callback "MyFirstService"
    void ServerSetup() {
      ServiceCreate("HLWO", MqServiceICB(&MyServer::MyFirstService));
    }
};

// package-main
int MK_CDECL main(int argc, MK_STRN argv[]) {
  MqMsgque::CcMqSetup();

  // setup commandline arguments for later use
  MkBufferListC largs = {argc, argv};
  // create "MyServer" factory… and make it to the default.
  MqFactoryCT<MyServer>::Add("MyServer")->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();
}