C++ TargetRTS
Loading...
Searching...
No Matches
RTInjector.h
1/*
2 * Licensed Materials - Property of HCL and/or IBM
3 * Copyright HCL Technologies Ltd. 2016, 2021. All Rights Reserved.
4 *
5 * U.S. Government Users Restricted Rights - Use, duplication or
6 * disclosure restricted by GSA ADP Schedule.
7 */
8
9#ifndef __RTInjector_h__
10#define __RTInjector_h__ included
11
12#ifdef PRAGMA
13#pragma interface
14#endif
15
16#ifndef __RTConfig_h__
17#include <RTConfig.h>
18#endif
19
20#ifndef RTUseCPP11
21#error RTInjector requires a compiler that supports C++ 11.
22#endif
23
24#include <string>
25#include <functional>
26#include <unordered_map>
27
28class RTController;
29class RTActorRef;
30class RTActor;
31class RTMutex;
32
54{
55public:
56
62
63 RTInjector();
65
71 void registerCreateFunction(const std::string& id, std::function<RTActor* (RTController *, RTActorRef *, int)> createFunc);
72
78 std::function<RTActor* (RTController *, RTActorRef *, int)> getCreateFunction(const std::string& id);
79
89 RTActor* create(RTController *rts, RTActorRef *ref, int index);
90
91 RTInjector(RTInjector const&) = delete;
92 void operator=(RTInjector const&) = delete;
93
94private:
95
96 std::unordered_map<std::string, std::function<RTActor* (RTController *, RTActorRef *, int)> > createFuncRegistry;
97#if USE_THREADS
98 RTMutex* _mutex;
99#endif
100
101};
102
103#endif // __RTInjector_h__
An instance of this class represents a capsule instance.
Definition: RTActor.h:44
Represents a capsule part.
Definition: RTActorRef.h:39
A controller manages a group of capsule instances that all run in the same physical thread (i....
Definition: RTController.h:54
Dependency injector for RT applications.
Definition: RTInjector.h:54
RTActor * create(RTController *rts, RTActorRef *ref, int index)
Create a capsule instance.
static RTInjector & getInstance()
Access the singleton injector instance (created on first access)
std::function< RTActor *(RTController *, RTActorRef *, int)> getCreateFunction(const std::string &id)
Get a create function registered for incarnating capsule instances in a capsule part.
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.