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;
142 std::shared_ptr<SmaccStateInfo> & parentState)
150 std::shared_ptr<SmaccStateInfo> & parentState)
152 using boost::mpl::_1;
153 using wrappedList =
typename boost::mpl::transform<T, add_type_wrapper<_1>>::type;
154 boost::mpl::for_each<wrappedList>(
AddSubState(parentState));
161 std::shared_ptr<SmaccStateInfo> & sourceState)
164 globalNh_->get_logger(),
"State %s Walker has transition list",
165 sourceState->fullStateName.c_str());
166 using boost::mpl::_1;
167 using wrappedList =
typename boost::mpl::transform<T, add_type_wrapper<_1>>::type;
169 globalNh_->get_logger(),
"[DIAG] About to call boost::mpl::for_each for state %s",
170 sourceState->fullStateName.c_str());
171 boost::mpl::for_each<wrappedList>(
AddTransition(sourceState));
173 globalNh_->get_logger(),
"[DIAG] Completed boost::mpl::for_each for state %s",
174 sourceState->fullStateName.c_str());
177template <
typename Ev,
typename Dst,
typename Tag>
180 std::shared_ptr<SmaccStateInfo> & sourceState)
183 globalNh_->get_logger(),
"[DIAG] processTransition [deep_history] START for state %s",
184 sourceState->toShortName().c_str());
188 globalNh_->get_logger(),
"[DIAG] processTransition [deep_history] got TypeInfo for state %s",
189 sourceState->toShortName().c_str());
194template <
typename Ev,
typename Dst,
typename Tag>
199 globalNh_->get_logger(),
"[DIAG] processTransition START for state %s",
200 sourceState->toShortName().c_str());
203 globalNh_->get_logger(),
"[DIAG] processTransition got TypeInfo for state %s",
204 sourceState->toShortName().c_str());
206 globalNh_->get_logger(),
"State %s Walker transition: %s", sourceState->toShortName().c_str(),
211template <
typename Ev,
typename Dst,
typename Tag>
217 globalNh_->get_logger(),
"State %s Walker transition: %s", sourceState->toShortName().c_str(),
219 std::string transitionTag;
220 std::string transitionType;
226 RCLCPP_DEBUG_STREAM(
globalNh_->get_logger(),
"TRANSITION TYPE:" << transitionType);
235 RCLCPP_INFO_STREAM(
globalNh_->get_logger(),
"Transition tag: " << transitionTag);
237 if (!sourceState->stateMachine_->containsState<Dst>())
239 auto realparentState = sourceState->stateMachine_->getState<
typename Dst::TContext>();
240 auto siblingnode = sourceState->stateMachine_->createState<Dst>(realparentState);
244 sourceState->declareTransition<Ev>(
245 siblingnode, transitionTag, transitionType, history, transitionTypeInfo);
252 auto siblingnode = sourceState->stateMachine_->getState<Dst>();
253 sourceState->declareTransition<Ev>(
254 siblingnode, transitionTag, transitionType, history, transitionTypeInfo);
259template <
typename EvType>
261 std::shared_ptr<SmaccStateInfo> & dstState, std::string transitionTag, std::string transitionType,
272 if (transitionTag !=
"")
281 std::make_shared<SmaccEventInfo>(transitionTypeInfo->templateParameters.front());
300 template <
typename C>
302 template <
typename C>
338template <
typename Ev,
typename Dst>
340 statechart::transition<Ev, Dst> *, std::shared_ptr<SmaccStateInfo> & sourceState)
345template <
typename Ev>
347 statechart::custom_reaction<Ev> *, std::shared_ptr<SmaccStateInfo> & sourceState)
357 std::shared_ptr<SmaccStateInfo> & sourceState)
360 globalNh_->get_logger(),
"[DIAG] processTransitions [single/leaf] called for state %s",
361 sourceState->fullStateName.c_str());
365 globalNh_->get_logger(),
"[DIAG] processTransitions [single/leaf] completed for state %s",
366 sourceState->fullStateName.c_str());
375 T::staticConfigure();
383 "static OnDefinition: dont exist for " <<
demangleSymbol(
typeid(T).name()));
417 template <
typename,
typename,
typename>
typename TTransition,
typename TevSource,
418 template <
typename>
typename EvType,
typename Tag,
typename DestinyState>
422 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [3-param] called for state %s",
426 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [3-param] completed for state %s",
433 template <
typename,
typename>
typename TTransition,
typename TevSource,
434 template <
typename>
typename EvType,
typename DestinyState>
438 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [2-param] called for state %s",
442 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [2-param] completed for state %s",
446template <
typename TTrans>
450 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [generic] called for state %s",
452 using type_t =
typename TTrans::type;
455 globalNh_->get_logger(),
"[DIAG] AddTransition::operator() [generic] completed for state %s",
466template <
typename InitialStateType>
468 std::shared_ptr<SmaccStateInfo> & parentState,
bool rootInitialNode)
473 std::shared_ptr<SmaccStateInfo> targetState;
475 if (!rootInitialNode)
477 if (parentState->stateMachine_->containsState<InitialStateType>())
483 targetState = parentState->createChildState<InitialStateType>();
487 targetState = parentState;
493 typename std::remove_pointer<
decltype(InitialStateType::smacc_inner_type)>::type InnerType;
497 typedef typename InitialStateType::reactions reactions;
506template <
typename InitialStateType>
513template <
typename StateType>
515 std::shared_ptr<SmaccStateInfo> parent)
517 auto thisptr = this->shared_from_this();
518 auto * statetid = &(
typeid(StateType));
521 RCLCPP_INFO_STREAM(
getLogger(),
"Creating State Info: " << demangledName);
523 auto state = std::make_shared<SmaccStateInfo>(statetid, parent, thisptr);
524 state->demangledStateName = demangledName;
525 state->fullStateName =
typeid(StateType).name();
526 state->stateIndex_ =
states.size();
528 if (parent !=
nullptr)
530 parent->children_.push_back(state);
538template <
typename StateType>
541 states[state->fullStateName] = state;
544template <
typename StateType>
547 auto realparentState = this->
stateMachine_->getState<
typename StateType::TContext>();
549 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)