SMACC2
Loading...
Searching...
No Matches
smacc_state_info.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#pragma once
22#include <functional>
23#include <memory>
26#include <vector>
27namespace smacc2
28{
29namespace introspection
30{
31//-------------------------------------------------------------
33{
35 const std::type_info * behaviorType;
36 const std::type_info * orthogonalType;
37};
38
39//---------------------------------------------
40// contains information about an specific event in the statechart
42{
43 SmaccEventInfo(std::shared_ptr<TypeInfo> eventType);
44
45 std::string getEventTypeName();
46
47 std::string getEventSourceName();
48
49 // AKA orthogonal
50 std::string getOrthogonalName();
51
52 std::string label;
53
54 std::shared_ptr<TypeInfo> eventType;
55
56private:
57};
58
59// contains metainformation about some specific transition in the statechart
61{
63
65 int index;
66 std::shared_ptr<const SmaccStateInfo> sourceState;
67 std::shared_ptr<const SmaccStateInfo> destinyState;
68
69 std::string transitionTag;
70 std::string transitionType;
71 std::shared_ptr<SmaccEventInfo> eventInfo;
72
74};
75//---------------------------------------------
76
78{
79 std::function<void(std::shared_ptr<smacc2::StateReactor>)> fn;
80};
81
82// This object is used in a static context (when the runtime state reactor is not built yet)
84{
85private:
86 std::vector<StateReactorCallbackFunctor> callbacks_;
87
88public:
89 StateReactorHandler(rclcpp::Node::SharedPtr nh) : nh_(nh) {}
90
91 void configureStateReactor(std::shared_ptr<smacc2::StateReactor> sr);
92
93 template <typename TEv>
94 void addInputEvent();
95
96 template <typename TEv>
97 void setOutputEvent();
98
99 rclcpp::Node::SharedPtr getNode();
100
101 std::shared_ptr<smacc2::introspection::SmaccStateReactorInfo> srInfo_;
102
103private:
104 rclcpp::Node::SharedPtr nh_;
105};
106//-------------------------------------------------------------
107
108// This object is used in a static context (when the runtime client behavior is not built yet)
109template <class T>
111{
112public:
114};
115//-------------------------------------------------------------
116// contains metainformation about some specific state reactor in the statechart
118{
119 std::shared_ptr<SmaccStateInfo> ownerState;
121
122 //const std::type_info *stateReactorType;
123 std::shared_ptr<TypeInfo> stateReactorType;
124 std::shared_ptr<TypeInfo> outputEventType;
125 std::shared_ptr<TypeInfo> objectTagType;
126 std::vector<std::shared_ptr<SmaccEventInfo>> sourceEventTypes;
127 std::shared_ptr<StateReactorHandler> srh;
128};
129
130//-------------------------------------------------------------
132{
133 std::function<void(std::shared_ptr<smacc2::SmaccEventGenerator>)> fn;
134};
135
137{
138private:
139 std::vector<EventGeneratorCallbackFunctor> callbacks_;
140
141public:
142 void configureEventGenerator(std::shared_ptr<smacc2::SmaccEventGenerator> eg);
143
144 template <typename TEv>
146
147 std::shared_ptr<smacc2::introspection::SmaccEventGeneratorInfo> egInfo_;
148};
149
150// contains metainformation about some specific event generator in the statechart
152{
153 std::shared_ptr<SmaccStateInfo> ownerState;
155
156 // const std::type_info *eventGeneratorType;
157 std::shared_ptr<TypeInfo> eventGeneratorType;
158 std::shared_ptr<TypeInfo> outputEventType;
159 std::shared_ptr<TypeInfo> objectTagType;
160 std::vector<std::shared_ptr<SmaccEventInfo>> sourceEventTypes;
161 std::shared_ptr<EventGeneratorHandler> egh;
162};
163//-----------------------------------------------------------------------
165{
166 SUPERSTATE = 2,
167 STATE = 1,
169};
170//-----------------------------------------------------------------------
171class SmaccStateInfo : public std::enable_shared_from_this<SmaccStateInfo>
172{
173public:
174 typedef std::shared_ptr<SmaccStateInfo> Ptr;
175
176 static std::map<const std::type_info *, std::vector<ClientBehaviorInfoEntry>> staticBehaviorInfo;
177 static std::map<const std::type_info *, std::vector<std::shared_ptr<SmaccStateReactorInfo>>>
179 static std::map<const std::type_info *, std::vector<std::shared_ptr<SmaccEventGeneratorInfo>>>
181
183 std::string fullStateName;
185
186 std::shared_ptr<SmaccStateMachineInfo> stateMachine_;
187 std::shared_ptr<SmaccStateInfo> parentState_;
188 std::vector<SmaccTransitionInfo> transitions_;
189
190 std::vector<std::shared_ptr<SmaccStateInfo>> children_;
192 const std::type_info * tid_;
193
195 const std::type_info * tid, std::shared_ptr<SmaccStateInfo> parentState,
196 std::shared_ptr<SmaccStateMachineInfo> stateMachineInfo);
197
199
200 inline int depth() const { return depth_; }
201
202 void getAncestors(std::list<const SmaccStateInfo *> & ancestorsList) const;
203
204 std::string getFullPath();
205
206 template <typename StateType>
207 std::shared_ptr<SmaccStateInfo> createChildState();
208
209 template <typename EvType>
211 std::shared_ptr<SmaccStateInfo> & dstState, std::string transitionTag,
212 std::string transitionType, bool history, TypeInfo::Ptr transitionTypeInfo);
213
214 // template <typename EvSource, template <typename> typename EvType>
215 // void declareTransition(std::shared_ptr<SmaccStateInfo> &dstState, std::string transitionTag, std::string transitionType, bool history);
216
217 const std::string & toShortName() const;
218
219 std::string getDemangledFullName() const;
220 rclcpp::Node::SharedPtr getNode();
221 inline rclcpp::Logger getLogger() { return getNode()->get_logger(); }
222};
223} // namespace introspection
224} // namespace smacc2
std::vector< EventGeneratorCallbackFunctor > callbacks_
void configureEventGenerator(std::shared_ptr< smacc2::SmaccEventGenerator > eg)
std::shared_ptr< smacc2::introspection::SmaccEventGeneratorInfo > egInfo_
std::shared_ptr< SmaccStateInfo > createChildState()
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccStateReactorInfo > > > stateReactorsInfo
void getAncestors(std::list< const SmaccStateInfo * > &ancestorsList) const
void declareTransition(std::shared_ptr< SmaccStateInfo > &dstState, std::string transitionTag, std::string transitionType, bool history, TypeInfo::Ptr transitionTypeInfo)
const std::string & toShortName() const
std::shared_ptr< SmaccStateInfo > Ptr
std::vector< std::shared_ptr< SmaccStateInfo > > children_
std::shared_ptr< SmaccStateInfo > parentState_
std::vector< SmaccTransitionInfo > transitions_
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccEventGeneratorInfo > > > eventGeneratorsInfo
std::shared_ptr< SmaccStateMachineInfo > stateMachine_
static std::map< const std::type_info *, std::vector< ClientBehaviorInfoEntry > > staticBehaviorInfo
void configureStateReactor(std::shared_ptr< smacc2::StateReactor > sr)
std::vector< StateReactorCallbackFunctor > callbacks_
StateReactorHandler(rclcpp::Node::SharedPtr nh)
std::shared_ptr< smacc2::introspection::SmaccStateReactorInfo > srInfo_
std::shared_ptr< TypeInfo > Ptr
std::function< void(smacc2::ISmaccState *)> factoryFunction
std::function< void(std::shared_ptr< smacc2::SmaccEventGenerator >)> fn
std::shared_ptr< EventGeneratorHandler > egh
std::function< void(smacc2::ISmaccState *)> factoryFunction
std::vector< std::shared_ptr< SmaccEventInfo > > sourceEventTypes
std::shared_ptr< SmaccStateInfo > ownerState
std::shared_ptr< TypeInfo > eventType
std::function< void(smacc2::ISmaccState *)> factoryFunction
std::shared_ptr< StateReactorHandler > srh
std::vector< std::shared_ptr< SmaccEventInfo > > sourceEventTypes
std::shared_ptr< SmaccStateInfo > ownerState
std::shared_ptr< const SmaccStateInfo > destinyState
std::shared_ptr< SmaccEventInfo > eventInfo
std::shared_ptr< const SmaccStateInfo > sourceState
smacc2::introspection::TypeInfo::Ptr transitionTypeInfo
std::function< void(std::shared_ptr< smacc2::StateReactor >)> fn