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{
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
83{
84private:
85 std::vector<StateReactorCallbackFunctor> callbacks_;
86
87public:
88 StateReactorHandler(rclcpp::Node::SharedPtr nh) : nh_(nh) {}
89
90 void configureStateReactor(std::shared_ptr<smacc2::StateReactor> sr);
91
92 template <typename TEv>
93 void addInputEvent();
94
95 template <typename TEv>
96 void setOutputEvent();
97
98 rclcpp::Node::SharedPtr getNode();
99
100 std::shared_ptr<smacc2::introspection::SmaccStateReactorInfo> srInfo_;
101
102private:
103 rclcpp::Node::SharedPtr nh_;
104};
105
106//-------------------------------------------------------------
107// contains metainformation about some specific state reactor in the statechart
109{
110 std::shared_ptr<SmaccStateInfo> ownerState;
111 std::function<void(smacc2::ISmaccState *)> factoryFunction;
112
113 //const std::type_info *stateReactorType;
114 std::shared_ptr<TypeInfo> stateReactorType;
115 std::shared_ptr<TypeInfo> outputEventType;
116 std::shared_ptr<TypeInfo> objectTagType;
117 std::vector<std::shared_ptr<SmaccEventInfo>> sourceEventTypes;
118 std::shared_ptr<StateReactorHandler> srh;
119};
120
121//-------------------------------------------------------------
123{
124 std::function<void(std::shared_ptr<smacc2::SmaccEventGenerator>)> fn;
125};
126
128{
129private:
130 std::vector<EventGeneratorCallbackFunctor> callbacks_;
131
132public:
133 void configureEventGenerator(std::shared_ptr<smacc2::SmaccEventGenerator> eg);
134
135 template <typename TEv>
137
138 std::shared_ptr<smacc2::introspection::SmaccEventGeneratorInfo> egInfo_;
139};
140
141// contains metainformation about some specific event generator in the statechart
143{
144 std::shared_ptr<SmaccStateInfo> ownerState;
145 std::function<void(smacc2::ISmaccState *)> factoryFunction;
146
147 // const std::type_info *eventGeneratorType;
148 std::shared_ptr<TypeInfo> eventGeneratorType;
149 std::shared_ptr<TypeInfo> outputEventType;
150 std::shared_ptr<TypeInfo> objectTagType;
151 std::vector<std::shared_ptr<SmaccEventInfo>> sourceEventTypes;
152 std::shared_ptr<EventGeneratorHandler> egh;
153};
154//-----------------------------------------------------------------------
156{
157 SUPERSTATE = 2,
158 STATE = 1,
160};
161//-----------------------------------------------------------------------
162class SmaccStateInfo : public std::enable_shared_from_this<SmaccStateInfo>
163{
164public:
165 typedef std::shared_ptr<SmaccStateInfo> Ptr;
166
167 static std::map<const std::type_info *, std::vector<ClientBehaviorInfoEntry>> staticBehaviorInfo;
168 static std::map<const std::type_info *, std::vector<std::shared_ptr<SmaccStateReactorInfo>>>
170 static std::map<const std::type_info *, std::vector<std::shared_ptr<SmaccEventGeneratorInfo>>>
172
174 std::string fullStateName;
176
177 std::shared_ptr<SmaccStateMachineInfo> stateMachine_;
178 std::shared_ptr<SmaccStateInfo> parentState_;
179 std::vector<SmaccTransitionInfo> transitions_;
180
181 std::vector<std::shared_ptr<SmaccStateInfo>> children_;
183 const std::type_info * tid_;
184
186 const std::type_info * tid, std::shared_ptr<SmaccStateInfo> parentState,
187 std::shared_ptr<SmaccStateMachineInfo> stateMachineInfo);
188
190
191 inline int depth() const { return depth_; }
192
193 void getAncestors(std::list<const SmaccStateInfo *> & ancestorsList) const;
194
195 std::string getFullPath();
196
197 template <typename StateType>
198 std::shared_ptr<SmaccStateInfo> createChildState();
199
200 template <typename EvType>
202 std::shared_ptr<SmaccStateInfo> & dstState, std::string transitionTag,
203 std::string transitionType, bool history, TypeInfo::Ptr transitionTypeInfo);
204
205 // template <typename EvSource, template <typename> typename EvType>
206 // void declareTransition(std::shared_ptr<SmaccStateInfo> &dstState, std::string transitionTag, std::string transitionType, bool history);
207
208 const std::string & toShortName() const;
209
210 std::string getDemangledFullName() const;
211 rclcpp::Node::SharedPtr getNode();
212 inline rclcpp::Logger getLogger() { return getNode()->get_logger(); }
213};
214} // namespace introspection
215} // 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