SMACC2
Loading...
Searching...
No Matches
smacc_state_info.hpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft 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{
34 std::function<void(smacc2::ISmaccState *)> factoryFunction;
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;
120 std::function<void(smacc2::ISmaccState *)> factoryFunction;
121
122 std::shared_ptr<TypeInfo> stateReactorType;
123 std::shared_ptr<TypeInfo> outputEventType;
124 std::shared_ptr<TypeInfo> objectTagType;
125 std::vector<std::shared_ptr<SmaccEventInfo>> sourceEventTypes;
126 std::shared_ptr<StateReactorHandler> srh;
127};
128
129//-------------------------------------------------------------
131{
132 std::function<void(std::shared_ptr<smacc2::SmaccEventGenerator>)> fn;
133};
134
136{
137private:
138 std::vector<EventGeneratorCallbackFunctor> callbacks_;
139
140public:
141 void configureEventGenerator(std::shared_ptr<smacc2::SmaccEventGenerator> eg);
142
143 template <typename TEv>
145
146 std::shared_ptr<smacc2::introspection::SmaccEventGeneratorInfo> egInfo_;
147};
148
149// contains metainformation about some specific event generator in the statechart
151{
152 std::shared_ptr<SmaccStateInfo> ownerState;
153 std::function<void(smacc2::ISmaccState *)> factoryFunction;
154
155 std::shared_ptr<TypeInfo> eventGeneratorType;
156 std::shared_ptr<TypeInfo> outputEventType;
157 std::shared_ptr<TypeInfo> objectTagType;
158 std::vector<std::shared_ptr<SmaccEventInfo>> sourceEventTypes;
159 std::shared_ptr<EventGeneratorHandler> egh;
160};
161//-----------------------------------------------------------------------
163{
164 SUPERSTATE = 2,
165 STATE = 1,
167};
168//-----------------------------------------------------------------------
169class SmaccStateInfo : public std::enable_shared_from_this<SmaccStateInfo>
170{
171public:
172 typedef std::shared_ptr<SmaccStateInfo> Ptr;
173
174 static std::map<const std::type_info *, std::vector<ClientBehaviorInfoEntry>> staticBehaviorInfo;
175 static std::map<const std::type_info *, std::vector<std::shared_ptr<SmaccStateReactorInfo>>>
177 static std::map<const std::type_info *, std::vector<std::shared_ptr<SmaccEventGeneratorInfo>>>
179
181 std::string fullStateName;
183
184 std::shared_ptr<SmaccStateMachineInfo> stateMachine_;
185 std::shared_ptr<SmaccStateInfo> parentState_;
186 std::vector<SmaccTransitionInfo> transitions_;
187
188 std::vector<std::shared_ptr<SmaccStateInfo>> children_;
190 const std::type_info * tid_;
191
193 const std::type_info * tid, std::shared_ptr<SmaccStateInfo> parentState,
194 std::shared_ptr<SmaccStateMachineInfo> stateMachineInfo);
195
197
198 inline int depth() const { return depth_; }
199
200 void getAncestors(std::list<const SmaccStateInfo *> & ancestorsList) const;
201
202 std::string getFullPath();
203
204 template <typename StateType>
205 std::shared_ptr<SmaccStateInfo> createChildState();
206
207 template <typename EvType>
209 std::shared_ptr<SmaccStateInfo> & dstState, std::string transitionTag,
210 std::string transitionType, bool history, TypeInfo::Ptr transitionTypeInfo);
211
212 const std::string & toShortName() const;
213
214 std::string getDemangledFullName() const;
215 rclcpp::Node::SharedPtr getNode();
216 inline rclcpp::Logger getLogger() { return getNode()->get_logger(); }
217};
218} // namespace introspection
219} // 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()
SmaccStateInfo(const std::type_info *tid, std::shared_ptr< SmaccStateInfo > parentState, std::shared_ptr< SmaccStateMachineInfo > stateMachineInfo)
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
SmaccEventInfo(std::shared_ptr< TypeInfo > eventType)
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