SMACC2
Loading...
Searching...
No Matches
smacc_default_events.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
23#include <functional>
24#include <string>
25
27
28#include <boost/statechart/event.hpp>
29#include <boost/statechart/state.hpp>
30
31namespace smacc2
32{
33
34namespace default_events
35{
36using namespace smacc2::introspection;
38
39//-------------- ACTION EVENTS --------------------------------------------------------
40template <typename ActionFeedback, typename TOrthogonal>
41struct EvActionFeedback : sc::event<EvActionFeedback<ActionFeedback, TOrthogonal>>
42{
44 ActionFeedback feedbackMessage;
45};
46
47template <typename TSource, typename TOrthogonal>
48struct EvActionResult : sc::event<EvActionResult<TSource, TOrthogonal>>
49{
50 typename TSource::WrappedResult resultMessage;
51};
52
53template <typename TSource, typename TOrthogonal>
54struct EvActionSucceeded : sc::event<EvActionSucceeded<TSource, TOrthogonal>>
55{
56 typename TSource::WrappedResult resultMessage;
57
58 static std::string getEventLabel()
59 {
60 // show ros message type
61 std::string label;
63 return label;
64 }
65
66 static std::string getDefaultTransitionTag() { return demangledTypeName<SUCCESS>(); }
67
68 static std::string getDefaultTransitionType() { return demangledTypeName<SUCCESS>(); }
69};
70
71template <typename TSource, typename TOrthogonal>
72struct EvActionAborted : sc::event<EvActionAborted<TSource, TOrthogonal>>
73{
74 typename TSource::WrappedResult resultMessage;
75
76 static std::string getEventLabel()
77 {
78 // show ros message type
79 std::string label;
81 return label;
82 }
83
84 static std::string getDefaultTransitionTag() { return demangledTypeName<ABORT>(); }
85
86 static std::string getDefaultTransitionType() { return demangledTypeName<ABORT>(); }
87};
88
89template <typename TSource, typename TOrthogonal>
90struct EvActionCancelled : sc::event<EvActionCancelled<TSource, TOrthogonal>>
91{
92 typename TSource::WrappedResult resultMessage;
93
94 static std::string getEventLabel()
95 {
96 // show ros message type
97 std::string label;
99 return label;
100 }
101
102 static std::string getDefaultTransitionTag() { return demangledTypeName<CANCEL>(); }
103
104 static std::string getDefaultTransitionType() { return demangledTypeName<CANCEL>(); }
105};
106
107//-------------- SERVICE EVENTS --------------------------------------------------------
108template <typename TSource, typename TOrthogonal, typename TResponse>
109struct EvServiceResponse : sc::event<EvServiceResponse<TSource, TOrthogonal, TResponse>>
110{
111 TResponse response;
112
113 static std::string getEventLabel()
114 {
115 std::string label;
116 EventLabel<TSource>(label);
117 return label;
118 }
119
120 static std::string getDefaultTransitionTag() { return demangledTypeName<SUCCESS>(); }
121
122 static std::string getDefaultTransitionType() { return demangledTypeName<SUCCESS>(); }
123};
124
125template <typename TSource, typename TOrthogonal>
126struct EvServiceRequestSent : sc::event<EvServiceRequestSent<TSource, TOrthogonal>>
127{
128 static std::string getEventLabel()
129 {
130 std::string label;
131 EventLabel<TSource>(label);
132 return label;
133 }
134};
135
136template <typename TSource, typename TOrthogonal>
137struct EvServiceFailure : sc::event<EvServiceFailure<TSource, TOrthogonal>>
138{
139 static std::string getEventLabel()
140 {
141 std::string label;
142 EventLabel<TSource>(label);
143 return label;
144 }
145
146 static std::string getDefaultTransitionTag() { return demangledTypeName<ABORT>(); }
147
148 static std::string getDefaultTransitionType() { return demangledTypeName<ABORT>(); }
149};
150
151//---------- CONTROL FLOW EVENTS ----------------------------------------------------------
152
153template <typename StateType>
154struct EvStateRequestFinish : sc::event<EvStateRequestFinish<StateType>>
155{
156};
157
158template <typename StateType>
159struct EvSequenceFinished : sc::event<EvSequenceFinished<StateType>>
160{
161};
162
163template <typename TSource>
164struct EvLoopContinue : sc::event<EvLoopContinue<TSource>>
165{
167
169};
170
171template <typename TSource>
172struct EvLoopEnd : sc::event<EvLoopEnd<TSource>>
173{
174 static std::string getDefaultTransitionTag() { return demangledTypeName<ENDLOOP>(); }
175
176 static std::string getDefaultTransitionType() { return demangledTypeName<ENDLOOP>(); }
177};
178
179//---------- CONTROL FLOW EVENTS ----------------------------------------------------------
180template <
181 typename TSource, typename TOrthogonal, typename TMessageType = typename TSource::TMessageType>
182struct EvTopicInitialMessage : sc::event<EvTopicInitialMessage<TSource, TOrthogonal, TMessageType>>
183{
184 static std::string getEventLabel()
185 {
187
188 std::string label = typeinfo->getNonTemplatedTypeName();
189 return label;
190 }
191
192 TMessageType msgData;
193};
194
195template <
196 typename TSource, typename TOrthogonal, typename TMessageType = typename TSource::TMessageType>
197struct EvTopicMessage : sc::event<EvTopicMessage<TSource, TOrthogonal, TMessageType>>
198{
199 static std::string getEventLabel()
200 {
202
203 std::string label = typeinfo->getNonTemplatedTypeName();
204 return label;
205 }
206
207 TMessageType msgData;
208};
209//-------------- STATE INITIALIZATION FAILURE --------------------------------------------------------
210// What every EvStInitializationFailure carries, whatever state it is addressed to.
212{
213 std::string stateName; // the state whose runtimeConfigure or onEntry threw
214 std::string what; // the exception's message
215 std::function<void()> escalate; // posts the failure to the next container; empty at the top
216};
217
218// Posted when a state's runtimeConfigure or onEntry throws. First addressed to the failing state;
219// if no state reacts, the state machine posts it again addressed to each container state in turn.
220template <typename TState>
221struct EvStInitializationFailure : sc::event<EvStInitializationFailure<TState>>,
223{
224};
225
226//-------------- CLIENT BEHAVIOR INITIALIZATION FAILURE ---------------------------------------------
227// Posted when a client behavior's runtimeConfigure or onEntry throws, on the state machine thread for
228// a synchronous behavior and on the behavior's own thread for an asynchronous one.
229template <typename TBehavior, typename TOrthogonal>
230struct EvCbInitializationFailure : sc::event<EvCbInitializationFailure<TBehavior, TOrthogonal>>
231{
232 std::string behaviorName;
233 std::string what; // the exception's message
234};
235
236} // namespace default_events
237} // namespace smacc2
static TypeInfo::Ptr getTypeInfoFromType()
std::enable_if< HasEventLabel< T >::value, void >::type EventLabel(std::string &label)
std::string demangledTypeName()
smacc2::client_bases::ISmaccActionClient * client