32#include <smacc2_msgs/msg/smacc_event_generator.hpp>
33#include <smacc2_msgs/msg/smacc_orthogonal.hpp>
34#include <smacc2_msgs/msg/smacc_state.hpp>
35#include <smacc2_msgs/msg/smacc_state_reactor.hpp>
36#include <smacc2_msgs/msg/smacc_transition.hpp>
40namespace introspection
49 std::map<std::string, std::shared_ptr<SmaccStateInfo>>
states;
51 std::vector<smacc2_msgs::msg::SmaccState>
stateMsgs;
53 template <
typename InitialStateType>
56 template <
typename StateType>
57 std::shared_ptr<SmaccStateInfo>
createState(std::shared_ptr<SmaccStateInfo> parentState);
59 template <
typename StateType>
62 auto typeNameStr =
typeid(StateType).name();
64 return states.count(typeNameStr) > 0;
67 template <
typename StateType>
72 return states[
typeid(StateType).name()];
81 template <
typename StateType>
82 void addState(std::shared_ptr<StateType> & state);
86 rclcpp::Node::SharedPtr
nh_;
110 template <
typename,
typename,
typename>
typename TTransition,
typename TevSource,
111 template <
typename>
typename EvType,
typename Tag,
typename DestinyState>
112 void operator()(TTransition<EvType<TevSource>, DestinyState, Tag>);
115 template <
typename,
typename>
typename TTransition,
typename TevSource,
116 template <
typename>
typename EvType,
typename DestinyState>
117 void operator()(TTransition<EvType<TevSource>, DestinyState>);
119 template <
typename T>
124template <
typename InitialStateType>
127 static void walkStates(std::shared_ptr<SmaccStateInfo> & currentState,
bool rootInitialNode);
134 using type_t =
typename T::type;
141 std::shared_ptr<SmaccStateInfo> & parentState)
149 std::shared_ptr<SmaccStateInfo> & parentState)
151 using boost::mpl::_1;
152 using wrappedList =
typename boost::mpl::transform<T, add_type_wrapper<_1>>::type;
153 boost::mpl::for_each<wrappedList>(
AddSubState(parentState));
160 std::shared_ptr<SmaccStateInfo> & sourceState)
163 globalNh_->get_logger(),
"State %s Walker has transition list",
164 sourceState->fullStateName.c_str());
165 using boost::mpl::_1;
166 using wrappedList =
typename boost::mpl::transform<T, add_type_wrapper<_1>>::type;
168 globalNh_->get_logger(),
"[DIAG] About to call boost::mpl::for_each for state %s",
169 sourceState->fullStateName.c_str());
170 boost::mpl::for_each<wrappedList>(
AddTransition(sourceState));
172 globalNh_->get_logger(),
"[DIAG] Completed boost::mpl::for_each for state %s",
173 sourceState->fullStateName.c_str());
176template <
typename Ev,
typename Dst,
typename Tag>
179 std::shared_ptr<SmaccStateInfo> & sourceState)
182 globalNh_->get_logger(),
"[DIAG] processTransition [deep_history] START for state %s",
183 sourceState->toShortName().c_str());
187 globalNh_->get_logger(),
"[DIAG] processTransition [deep_history] got TypeInfo for state %s",
188 sourceState->toShortName().c_str());
193template <
typename Ev,
typename Dst,
typename Tag>
198 globalNh_->get_logger(),
"[DIAG] processTransition START for state %s",
199 sourceState->toShortName().c_str());
202 globalNh_->get_logger(),
"[DIAG] processTransition got TypeInfo for state %s",
203 sourceState->toShortName().c_str());
205 globalNh_->get_logger(),
"State %s Walker transition: %s", sourceState->toShortName().c_str(),
210template <
typename Ev,
typename Dst,
typename Tag>
216 globalNh_->get_logger(),
"State %s Walker transition: %s", sourceState->toShortName().c_str(),
218 std::string transitionTag;
219 std::string transitionType;
225 RCLCPP_DEBUG_STREAM(
globalNh_->get_logger(),
"TRANSITION TYPE:" << transitionType);
234 RCLCPP_INFO_STREAM(
globalNh_->get_logger(),
"Transition tag: " << transitionTag);
236 if (!sourceState->stateMachine_->containsState<Dst>())
238 auto realparentState = sourceState->stateMachine_->getState<
typename Dst::TContext>();
239 auto siblingnode = sourceState->stateMachine_->createState<Dst>(realparentState);
242 sourceState->declareTransition<Ev>(
243 siblingnode, transitionTag, transitionType, history, transitionTypeInfo);
247 auto siblingnode = sourceState->stateMachine_->getState<Dst>();
248 sourceState->declareTransition<Ev>(
249 siblingnode, transitionTag, transitionType, history, transitionTypeInfo);
254template <
typename EvType>
256 std::shared_ptr<SmaccStateInfo> & dstState, std::string transitionTag, std::string transitionType,
267 if (transitionTag !=
"")
276 std::make_shared<SmaccEventInfo>(transitionTypeInfo->templateParameters.front());
295 template <
typename C>
297 template <
typename C>
308template <
typename Ev,
typename Dst>
310 statechart::transition<Ev, Dst> *, std::shared_ptr<SmaccStateInfo> & sourceState)
314template <
typename Ev>
316 statechart::custom_reaction<Ev> *, std::shared_ptr<SmaccStateInfo> & sourceState)
325 std::shared_ptr<SmaccStateInfo> & sourceState)
328 globalNh_->get_logger(),
"[DIAG] processTransitions [single/leaf] called for state %s",
329 sourceState->fullStateName.c_str());
333 globalNh_->get_logger(),
"[DIAG] processTransitions [single/leaf] completed for state %s",
334 sourceState->fullStateName.c_str());
343 T::staticConfigure();
351 "static OnDefinition: dont exist for " <<
demangleSymbol(
typeid(T).name()));
358 template <
typename,
typename,
typename>
typename TTransition,
typename TevSource,
359 template <
typename>
typename EvType,
typename Tag,
typename DestinyState>
363 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [3-param] called for state %s",
367 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [3-param] completed for state %s",
374 template <
typename,
typename>
typename TTransition,
typename TevSource,
375 template <
typename>
typename EvType,
typename DestinyState>
379 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [2-param] called for state %s",
383 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [2-param] completed for state %s",
387template <
typename TTrans>
391 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [generic] called for state %s",
393 using type_t =
typename TTrans::type;
396 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [generic] completed for state %s",
401template <
typename InitialStateType>
403 std::shared_ptr<SmaccStateInfo> & parentState,
bool rootInitialNode)
407 std::shared_ptr<SmaccStateInfo> targetState;
409 if (!rootInitialNode)
411 if (parentState->stateMachine_->containsState<InitialStateType>())
416 targetState = parentState->createChildState<InitialStateType>();
420 targetState = parentState;
426 typename std::remove_pointer<
decltype(InitialStateType::smacc_inner_type)>::type InnerType;
430 typedef typename InitialStateType::reactions reactions;
437template <
typename InitialStateType>
444template <
typename StateType>
446 std::shared_ptr<SmaccStateInfo> parent)
448 auto thisptr = this->shared_from_this();
449 auto * statetid = &(
typeid(StateType));
452 RCLCPP_INFO_STREAM(
getLogger(),
"Creating State Info: " << demangledName);
454 auto state = std::make_shared<SmaccStateInfo>(statetid, parent, thisptr);
455 state->demangledStateName = demangledName;
456 state->fullStateName =
typeid(StateType).name();
457 state->stateIndex_ =
states.size();
459 if (parent !=
nullptr)
461 parent->children_.push_back(state);
469template <
typename StateType>
472 states[state->fullStateName] = state;
475template <
typename StateType>
478 auto realparentState = this->
stateMachine_->getState<
typename StateType::TContext>();
480 auto childState = this->
stateMachine_->createState<StateType>(realparentState);
static YesType & test(decltype(&C::staticConfigure))
static NoType & test(...)
std::shared_ptr< SmaccStateInfo > createChildState()
void declareTransition(std::shared_ptr< SmaccStateInfo > &dstState, std::string transitionTag, std::string transitionType, bool history, TypeInfo::Ptr transitionTypeInfo)
rclcpp::Logger getLogger()
std::vector< SmaccTransitionInfo > transitions_
std::shared_ptr< SmaccStateMachineInfo > stateMachine_
rclcpp::Node::SharedPtr nh_
rclcpp::Logger getLogger()
void addState(std::shared_ptr< StateType > &state)
std::shared_ptr< SmaccStateInfo > createState(std::shared_ptr< SmaccStateInfo > parentState)
rclcpp::Node::SharedPtr getNode()
std::map< std::string, std::shared_ptr< SmaccStateInfo > > states
std::vector< smacc2_msgs::msg::SmaccState > stateMsgs
SmaccStateMachineInfo(rclcpp::Node::SharedPtr nh)
void buildStateMachineInfo()
std::shared_ptr< SmaccStateInfo > getState()
void assembleSMStructureMessage(ISmaccStateMachine *sm)
static TypeInfo::Ptr getTypeInfoFromType()
std::shared_ptr< TypeInfo > Ptr
std::enable_if< HasAutomaticTransitionType< T >::value, void >::type automaticTransitionType(std::string &transition_type)
disable_if< boost::mpl::is_sequence< T > >::type processSubState(std::shared_ptr< SmaccStateInfo > &parentState)
rclcpp::Node::SharedPtr globalNh_
std::enable_if< HasEventLabel< T >::value, void >::type EventLabel(std::string &label)
void processTransition(smacc2::Transition< Ev, boost::statechart::deep_history< Dst >, Tag > *, std::shared_ptr< SmaccStateInfo > &sourceState)
static std::string getTransitionType()
std::string demangleSymbol()
enable_if< boost::mpl::is_sequence< T > >::type processTransitions(std::shared_ptr< SmaccStateInfo > &sourceState)
void processTransitionAux(smacc2::Transition< Ev, Dst, Tag > *, std::shared_ptr< SmaccStateInfo > &sourceState, bool history, TypeInfo::Ptr &transitionTypeInfo)
std::enable_if< HasOnDefinition< T >::value, void >::type CallOnDefinition()
std::enable_if< HasAutomaticTransitionTag< T >::value, void >::type automaticTransitionTag(std::string &transition_name)
std::string demangledTypeName()
std::shared_ptr< SmaccStateInfo > & parentState_
AddSubState(std::shared_ptr< SmaccStateInfo > &parentState)
AddTransition(std::shared_ptr< SmaccStateInfo > ¤tState)
void operator()(TTransition< EvType< TevSource >, DestinyState, Tag >)
std::shared_ptr< SmaccStateInfo > & currentState_
std::shared_ptr< const SmaccStateInfo > destinyState
std::shared_ptr< SmaccEventInfo > eventInfo
std::string transitionTag
std::shared_ptr< const SmaccStateInfo > sourceState
std::string transitionType
smacc2::introspection::TypeInfo::Ptr transitionTypeInfo
static void walkStates(std::shared_ptr< SmaccStateInfo > ¤tState, bool rootInitialNode)