C++ TargetRTS
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
RTInjector Class Reference

Dependency injector for RT applications. More...

#include <RTInjector.h>

Public Member Functions

void registerCreateFunction (const std::string &id, std::function< RTActor *(RTController *, RTActorRef *, int)> createFunc)
 Register a create function to be used for incarnating capsule instances in a capsule part.
 
std::function< RTActor *(RTController *, RTActorRef *, int)> getCreateFunction (const std::string &id)
 Get a create function registered for incarnating capsule instances in a capsule part.
 
RTActorcreate (RTController *rts, RTActorRef *ref, int index)
 Create a capsule instance.
 
 RTInjector (RTInjector const &)=delete
 
void operator= (RTInjector const &)=delete
 

Static Public Member Functions

static RTInjectorgetInstance ()
 Access the singleton injector instance (created on first access)
 

Detailed Description

Dependency injector for RT applications.

At runtime a capsule instance depends on other capsule instances. Instead of hard coding such dependencies inside the capsule itself, the dependency injector approach allows to register such dependencies in a centralized location. Thereby you can configure the application by changing in that single place only.

A typical usage of this class is to access the singleton instance at application start-up (for example in the constructor of the top capsule). There you then configure the dependencies to be injected by registering create functions for capsule parts that you want to incarnate in a non-default way. Some example of customization possibilities (implemented by the create function):

Dependencies are usually not changed once registered, but if needed it's possible to do so (the implementation is thread safe).

Member Function Documentation

◆ create()

RTActor * RTInjector::create ( RTController rts,
RTActorRef ref,
int  index 
)

Create a capsule instance.

If a create function has been registered for the specified capsule part it will be used for creating the capsule instance. Otherwise nullptr will be returned, to allow the capsule instance to be created as default (if possible).

Parameters
rtsDefault controller thread to run the created capsule instance (a registered create function may override this)
refCapsule part to host the created capsule instance
indexIndex where to insert the created capsule instance in the capsule part
Returns
Created capsule instance, or nullptr in case no capsule instance was created

◆ getCreateFunction()

std::function< RTActor *(RTController *, RTActorRef *, int)> RTInjector::getCreateFunction ( const std::string &  id)

Get a create function registered for incarnating capsule instances in a capsule part.

Parameters
idQualified id string for the capsule part (e.g. "/part1:0/part2")
Returns
Registered create function, or an empty function if no create function was registered for the capsule part

◆ getInstance()

static RTInjector & RTInjector::getInstance ( )
inlinestatic

Access the singleton injector instance (created on first access)

Returns
injector instance

◆ registerCreateFunction()

void RTInjector::registerCreateFunction ( const std::string &  id,
std::function< RTActor *(RTController *, RTActorRef *, int)>  createFunc 
)

Register a create function to be used for incarnating capsule instances in a capsule part.

Parameters
idQualified id string for the capsule part (e.g. "/part1:0/part2")
createFuncCreate function to register

The documentation for this class was generated from the following file: