SMACC
Loading...
Searching...
No Matches
smacc_client.h
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6#pragma once
7
8#include <smacc/common.h>
9#include <smacc/component.h>
10#include <typeinfo>
11
12namespace smacc
13{
15{
16 ComponentKey(const std::type_info *typeinfo, std::string name)
17 {
18 this->name = name;
19 this->typeinfo = typeinfo;
20 encodedKey = std::to_string((long)(void *)typeinfo) + "_" + name;
21 }
22 std::string encodedKey;
23 const std::type_info *typeinfo;
24 std::string name;
25
26 bool operator<(const ComponentKey &other) const
27 {
28 return this->encodedKey < other.encodedKey;
29 }
30 bool operator==(const ComponentKey &other) const
31 {
32 return this->encodedKey == other.encodedKey;
33 }
34};
35
37{
38public:
40 virtual ~ISmaccClient();
41
42 virtual void initialize();
43
44 // Returns a custom identifier defined by the specific plugin implementation
45 virtual std::string getName() const;
46
47 template <typename EventType>
48 void postEvent(const EventType &ev);
49
50 template <typename EventType>
51 void postEvent();
52
53 template <typename TComponent>
54 TComponent *getComponent();
55
56 template <typename TComponent>
57 TComponent *getComponent(std::string name);
58
60
62
63 template <typename TSmaccSignal, typename T>
64 void connectSignal(TSmaccSignal &signal, void (T::*callback)(), T *object);
65
66 template <typename SmaccClientType>
67 void requiresClient(SmaccClientType *&storage);
68
69 void getComponents(std::vector<std::shared_ptr<ISmaccComponent>> &components);
70
71protected:
72
73// it is called after the client initialization, provides information about the orthogonal it is located in
74 template <typename TOrthogonal, typename TSourceObject>
76
77 // components
78 std::map<ComponentKey, std::shared_ptr<smacc::ISmaccComponent>> components_;
79
80 template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
81 SmaccComponentType *createComponent(TArgs... targs);
82
83 template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
84 SmaccComponentType *createNamedComponent(std::string name, TArgs... targs);
85
86 // Assigns the owner of this resource to the given state machine parameter object
87 void setStateMachine(ISmaccStateMachine *stateMachine);
88
89 void setOrthogonal(ISmaccOrthogonal *orthogonal);
90
91private:
92 // A reference to the state machine object that owns this resource
95
96 friend class ISmaccOrthogonal;
97 friend class ISmaccComponent;
98};
99} // namespace smacc
virtual ~ISmaccClient()
Definition: client.cpp:17
void getComponents(std::vector< std::shared_ptr< ISmaccComponent > > &components)
Definition: client.cpp:26
void setStateMachine(ISmaccStateMachine *stateMachine)
Definition: client.cpp:40
void setOrthogonal(ISmaccOrthogonal *orthogonal)
Definition: client.cpp:45
ISmaccOrthogonal * orthogonal_
Definition: smacc_client.h:94
SmaccComponentType * createComponent(TArgs... targs)
void onOrthogonalAllocation()
Definition: smacc_client.h:75
void requiresClient(SmaccClientType *&storage)
virtual std::string getName() const
Definition: client.cpp:34
ISmaccStateMachine * stateMachine_
Definition: smacc_client.h:93
virtual void initialize()
Definition: client.cpp:21
std::map< ComponentKey, std::shared_ptr< smacc::ISmaccComponent > > components_
Definition: smacc_client.h:78
void connectSignal(TSmaccSignal &signal, void(T::*callback)(), T *object)
TComponent * getComponent()
virtual smacc::introspection::TypeInfo::Ptr getType()
Definition: client.cpp:50
ISmaccStateMachine * getStateMachine()
SmaccComponentType * createNamedComponent(std::string name, TArgs... targs)
std::shared_ptr< TypeInfo > Ptr
const std::type_info * typeinfo
Definition: smacc_client.h:23
bool operator<(const ComponentKey &other) const
Definition: smacc_client.h:26
std::string encodedKey
Definition: smacc_client.h:22
bool operator==(const ComponentKey &other) const
Definition: smacc_client.h:30
ComponentKey(const std::type_info *typeinfo, std::string name)
Definition: smacc_client.h:16
std::string name
Definition: smacc_client.h:24