Loading...
Searching...
No Matches
MqFactoryC_TOR_C_API

MqFactoryC - various functions to create, initialize and destroy a factoryMore...

+ Collaboration diagram for MqFactoryC_TOR_C_API:

Macros

#define MqFactoryAdd_1(fct)
 
#define MqFactoryAdd_2(fct, ident)
 

Functions

MQ_EXTERN void libmqmsgque::MqFactoryFree_RT (MK_RT const mkrt, MQ_FCT const fct)
 free internal factory memory and call libmqmsgque::MqFactoryDTorS::fFree + libmqmsgque::MqFactoryCTorS::fFree
 
MQ_EXTERN MQ_FCT libmqmsgque::MqFactoryAdd_RT (MK_RT const mkrt, MK_OBJN const error, MqFactoryCTorF const createCallF, MK_CCP const constructor, MqFactoryDataFreeF const createDataFreeF, MqFactoryDataCopyF const createDataCopyF, MqFactoryDTorF const deleteCallF, MK_CCP const destructor, MqFactoryDataFreeF const deleteDataFreeF, MqFactoryDataCopyF const deleteDataCopyF, MK_STRN const ident)
 add a new MqFactoryC identified by factory-identifier and defined by factory-constructor
 
MQ_EXTERN MQ_FCT libmqmsgque::MqFactoryTypeAdd_RT (MK_RT const mkrt, MK_OBJN const error, MK_STRN const ident, MkSelfCreateF const fctCreate, MkSelfDeleteF const fctDelete, MkConstructorF const constructor, MkSelfDeleteF const selfDelete)
 add a new MqFactoryS-Object identified by a fctT
 
MQ_EXTERN MQ_FCT libmqmsgque::MqFactoryDup2_RT (MK_RT const mkrt, MQ_FCTN const fct, MK_STRN const ident)
 create a duplicate of the singleton object MqFactoryC using a new factory-identifer
 

MqFactoryDelete

MQ_EXTERN void libmqmsgque::MqFactoryDelete_RT (MK_RT const mkrt, MQ_FCT fct)
 Destructor - delete a MqFactoryC instance …
 

MqFactoryC - MqFactoryC_TOR_C_API - overload

#define MqFactoryDup2_NULL(...)
 
#define MqFactoryDup2(...)
 
#define MqFactoryAdd_NULL(...)
 
#define MqFactoryAdd(...)
 
#define MqFactoryTypeAdd_NULL(...)
 
#define MqFactoryTypeAdd(...)
 
#define MqFactoryDelete(x)
 
#define MqFactoryFree_NULL(...)
 
#define MqFactoryFree(...)
 

Detailed Description

MqFactoryC - various functions to create, initialize and destroy a factory

Macro Definition Documentation

◆ MqFactoryAdd

#define MqFactoryAdd ( ...)
Value:
MqFactoryAdd_RT(MK_RT_CALL __VA_ARGS__)
#define MK_RT_CALL

Definition at line 1042 of file msgque_overload_mq.h.

◆ MqFactoryAdd_1

#define MqFactoryAdd_1 ( fct)
Value:
MqFactoryAdd(MK_ERROR_PANIC,fct,NULL, NULL, NULL, NULL, NULL, NULL, NULL, #fct)
#define MK_ERROR_PANIC
#define MqFactoryAdd(...)

Definition at line 3484 of file LibMqMsgque_mq.h.

◆ MqFactoryAdd_2

#define MqFactoryAdd_2 ( fct,
ident )
Value:
MqFactoryAdd(MK_ERROR_PANIC,fct,NULL, NULL, NULL, NULL, NULL, NULL, NULL, ident)

Definition at line 3485 of file LibMqMsgque_mq.h.

◆ MqFactoryAdd_NULL

#define MqFactoryAdd_NULL ( ...)
Value:
MqFactoryAdd_RT(MK_RT_CALL_NULL __VA_ARGS__)
#define MK_RT_CALL_NULL

Definition at line 1041 of file msgque_overload_mq.h.

◆ MqFactoryDelete

#define MqFactoryDelete ( x)
Value:
MkObjectDeleteToNull(MqFactoryDelete_RT,x)
#define MkObjectDeleteToNull(fct, x)

Definition at line 1047 of file msgque_overload_mq.h.

◆ MqFactoryDup2

#define MqFactoryDup2 ( ...)
Value:
MqFactoryDup2_RT(MK_RT_CALL __VA_ARGS__)

Definition at line 1038 of file msgque_overload_mq.h.

◆ MqFactoryDup2_NULL

#define MqFactoryDup2_NULL ( ...)
Value:
MqFactoryDup2_RT(MK_RT_CALL_NULL __VA_ARGS__)

Definition at line 1037 of file msgque_overload_mq.h.

◆ MqFactoryFree

#define MqFactoryFree ( ...)
Value:
MqFactoryFree_RT(MK_RT_CALL __VA_ARGS__)

Definition at line 1051 of file msgque_overload_mq.h.

◆ MqFactoryFree_NULL

#define MqFactoryFree_NULL ( ...)
Value:
MqFactoryFree_RT(MK_RT_CALL_NULL __VA_ARGS__)

Definition at line 1050 of file msgque_overload_mq.h.

◆ MqFactoryTypeAdd

#define MqFactoryTypeAdd ( ...)
Value:
MqFactoryTypeAdd_RT(MK_RT_CALL __VA_ARGS__)

Definition at line 1044 of file msgque_overload_mq.h.

◆ MqFactoryTypeAdd_NULL

#define MqFactoryTypeAdd_NULL ( ...)
Value:
MqFactoryTypeAdd_RT(MK_RT_CALL_NULL __VA_ARGS__)

Definition at line 1043 of file msgque_overload_mq.h.

Function Documentation

◆ MqFactoryAdd_RT()

MQ_EXTERN MQ_FCT libmqmsgque::MqFactoryAdd_RT ( MK_RT const mkrt,
MK_OBJN const error,
MqFactoryCTorF const createCallF,
MK_CCP const constructor,
MqFactoryDataFreeF const createDataFreeF,
MqFactoryDataCopyF const createDataCopyF,
MqFactoryDTorF const deleteCallF,
MK_CCP const destructor,
MqFactoryDataFreeF const deleteDataFreeF,
MqFactoryDataCopyF const deleteDataCopyF,
MK_STRN const ident )

add a new MqFactoryC identified by factory-identifier and defined by factory-constructor

The factory is required to get all ccmqmsgque features.

The constructor have to be a C++ [class] with superclass [MqContextC]

  1. The factory is implemented as a template with ccmqmsgque::MqFactoryCT<class>.
  2. The class have to be a sub-class of ccmqmsgque::MqContextC.
  3. The class have to provide a factory-constructor like Filter6::Filter6.
  4. The factory-constructor is required in the ccmqmsgque::MqFactoryCT::ObjectSelfCreate new function.
example: use class MyServer with public name "MyServer" as a factory-class
using namespace ccmqmsgque;
// package-item
class MyServer : public MqContextC, public IServerSetup {
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::Setup();
// setup commandline arguments for later use
MkBufferListC largs = {argc, argv};
// create "MyServer" factory… and make it to the default.
// inspect commandline-argument for the "factory" to choose… and create a object
// start listen for incoming call's
try {
srv->LinkCreate(largs);
srv->ProcessEvent (MQ_WAIT_FOREVER);
} catch (const std::exception& e) {
srv->ErrorCatch(e);
}
srv->Exit();
}

Example from Filter5.cc create a new context using factory F1; F2 or F3 read from the commandline

int MK_CDECL main (int argc, MK_STRN argv[])
{
  MqMsgque::Setup();
  // create buffer-list of the application arguments
  auto largs = MkBufferListC {argc, argv};

  // init libmqmsgque global applications starter
  MqInitSetArg0VA(argv[0],NULL);

  // add factories
  MqFactoryCT<F1>::Add("F1");
  MqFactoryCT<F2>::Add("F2");
  MqFactoryCT<F3>::Add("F3");

  // call factory using the !second! application argument,
  // first argument is the executable self
  MqContextC *filter = MqFactoryCT<MqContextC>::GetCalled(&largs)->New();
  try {
    // configure and start the server
    filter->LinkCreate (largs);

    // start event-loop and wait forever
    filter->ProcessEvent (MQ_WAIT_FOREVER);
  } catch (const exception& e) {

    // set the libmqmsgque error form the c++ error
    filter->ErrorCatch(e);
  }
  filter->Exit();
}
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]error(C-API) flag to signal how to report an error. valid values are: MK_ERROR_PANIC, MK_ERROR_PRINT, MK_ERROR_IGNORE or an other MqContextC
[in]identthe factory-identifier, if MK_NULL or EMPTY the class-name is used. The ident is the public identifier (name) of the factory and is used in logging-output (MqLog...) , name-resolution (MqFactoryGet...) and an first parameter in the executable-call: myserver ident ....
[in]createCallF(C-API) object constructor function
[in]constructorobject (class) constructor data
[in]createDataFreeF(C-API) object constructor data free function
[in]createDataCopyF(C-API) object copy-constructor data free function
[in]deleteCallF(C-API) object destructor function
[in]destructorobject (class) destructor data
[in]deleteDataFreeF(C-API) object destructor data free function
[in]deleteDataCopyF(C-API) object copy-constructor data free function
Returns
the new MqFactoryC or MK_NULL on error
See also
MqFactoryTypeAdd

◆ MqFactoryDelete_RT()

MQ_EXTERN void libmqmsgque::MqFactoryDelete_RT ( MK_RT const mkrt,
MQ_FCT fct )

Destructor - delete a MqFactoryC instance …

The factory-delete is more a pseudo-delete because a factory is always in-duty:

  1. The context has a link to a factory (MqSetupS::factory) → this link is not protected by the refCount.
    1. The factory-delete will modify the environment of an existing context.
  2. The factory is a singelton (like a type) → there are very "few" factories at all.
  3. The factory is shared between threads → a modification would risk a race-condition.
    1. the factory can not be modify after creation
See also
MkRefDecr MqFactoryFree

◆ MqFactoryDup2_RT()

MQ_EXTERN MQ_FCT libmqmsgque::MqFactoryDup2_RT ( MK_RT const mkrt,
MQ_FCTN const fct,
MK_STRN const ident )

create a duplicate of the singleton object MqFactoryC using a new factory-identifer

◆ MqFactoryFree_RT()

MQ_EXTERN void libmqmsgque::MqFactoryFree_RT ( MK_RT const mkrt,
MQ_FCT const fct )

free internal factory memory and call libmqmsgque::MqFactoryDTorS::fFree + libmqmsgque::MqFactoryCTorS::fFree

Attention
Use this function with caution. The factory provide the destructor capability to a context object… using the libmqmsgque::MqSetupS::factory link… freeing the factory internal data… can cause damage.
See also
libmqmsgque::MqFactoryDelete

◆ MqFactoryTypeAdd_RT()

MQ_EXTERN MQ_FCT libmqmsgque::MqFactoryTypeAdd_RT ( MK_RT const mkrt,
MK_OBJN const error,
MK_STRN const ident,
MkSelfCreateF const fctCreate,
MkSelfDeleteF const fctDelete,
MkConstructorF const constructor,
MkSelfDeleteF const selfDelete )

add a new MqFactoryS-Object identified by a fctT

This factory is used for template based factories like in C++.

  • MqFactoryCT<Server>::Add("server")->Default(); A template create for every new class Server a new factory object. Both, the new Server and the new factory require own functions for self create.

Example from MqFactoryC_cc.hh create the self constructor/destructor

static MK_OBJ ObjectSelfCreate (MK_RT_ARGS MK_TYP const type, MK_PTR const tmpl, MK_PTR const lnk) {
T* self = NULL;
try {
//printV("type=%p, tmpl=%p", type, tmpl)
//MkRuntimeC::Debug();
// !! attention !! if the constructor has a BUG the destructor is called and the "c++ obj" becomes unusable
self = new T(type, static_cast<MqContextC*>(tmpl));
if (self) self->Init();
} catch (const std::exception& ex) {
//MkRuntimeC::Debug();
}
//self->DbgLogC();
return self?self->hdl:NULL;
}
static void ObjectSelfDelete (MK_RT_ARGS MK_PTR selfP, MK_PTR env) {
T* self = static_cast<T*>(selfP);
//self->DbgLogC();
delete self;
}
return new MqFactoryCT<T>(obj);
}
static void FactorySelfDelete (MK_RT_ARGS MK_PTR selfptr, MK_PTR env) {
delete static_cast<MqFactoryCT<T>*>(selfptr);
}
See also
MqFactoryAdd