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 static RTInjector instance;
63 return instance;
64 }
65
66 RTInjector();
68
74 void registerCreateFunction(const std::string& id, std::function<RTActor* (RTController *, RTActorRef *, int)> createFunc);
75
81 std::function<RTActor* (RTController *, RTActorRef *, int)> getCreateFunction(const std::string& id);
82
92 RTActor* create(RTController *rts, RTActorRef *ref, int index);
93
94 RTInjector(RTInjector const&) = delete;
95 void operator=(RTInjector const&) = delete;
96
97private:
98
99 std::unordered_map<std::string, std::function<RTActor* (RTController *, RTActorRef *, int)> > createFuncRegistry;
100#if USE_THREADS
101 RTMutex* _mutex;
102#endif
103
104};
105
106#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)
Definition: RTInjector.h:61
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.