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;
168 boost::mpl::for_each<wrappedList>(
AddTransition(sourceState));
171template <
typename Ev,
typename Dst,
typename Tag>
174 std::shared_ptr<SmaccStateInfo> & sourceState)
182template <
typename Ev,
typename Dst,
typename Tag>
188 globalNh_->get_logger(),
"State %s Walker transition: %s", sourceState->toShortName().c_str(),
193template <
typename Ev,
typename Dst,
typename Tag>
199 globalNh_->get_logger(),
"State %s Walker transition: %s", sourceState->toShortName().c_str(),
201 std::string transitionTag;
202 std::string transitionType;
208 RCLCPP_DEBUG_STREAM(
globalNh_->get_logger(),
"TRANSITION TYPE:" << transitionType);
217 RCLCPP_INFO_STREAM(
globalNh_->get_logger(),
"Transition tag: " << transitionTag);
219 if (!sourceState->stateMachine_->containsState<Dst>())
221 auto realparentState = sourceState->stateMachine_->getState<
typename Dst::TContext>();
222 auto siblingnode = sourceState->stateMachine_->createState<Dst>(realparentState);
226 sourceState->declareTransition<Ev>(
227 siblingnode, transitionTag, transitionType, history, transitionTypeInfo);
234 auto siblingnode = sourceState->stateMachine_->getState<Dst>();
235 sourceState->declareTransition<Ev>(
236 siblingnode, transitionTag, transitionType, history, transitionTypeInfo);
241template <
typename EvType>
243 std::shared_ptr<SmaccStateInfo> & dstState, std::string transitionTag, std::string transitionType,
254 if (transitionTag !=
"")
263 std::make_shared<SmaccEventInfo>(transitionTypeInfo->templateParameters.front());
282 template <
typename C>
284 template <
typename C>
320template <
typename Ev,
typename Dst>
322 statechart::transition<Ev, Dst> *, std::shared_ptr<SmaccStateInfo> & sourceState)
327template <
typename Ev>
329 statechart::custom_reaction<Ev> *, std::shared_ptr<SmaccStateInfo> & sourceState)
339 std::shared_ptr<SmaccStateInfo> & sourceState)
353 T::staticConfigure();
361 "static OnDefinition: dont exist for " <<
demangleSymbol(
typeid(T).name()));
395 template <
typename,
typename,
typename>
typename TTransition,
typename TevSource,
396 template <
typename>
typename EvType,
typename Tag,
typename DestinyState>
405 template <
typename,
typename>
typename TTransition,
typename TevSource,
406 template <
typename>
typename EvType,
typename DestinyState>
412template <
typename TTrans>
415 using type_t =
typename TTrans::type;
426template <
typename InitialStateType>
428 std::shared_ptr<SmaccStateInfo> & parentState,
bool rootInitialNode)
433 std::shared_ptr<SmaccStateInfo> targetState;
435 if (!rootInitialNode)
437 if (parentState->stateMachine_->containsState<InitialStateType>())
443 targetState = parentState->createChildState<InitialStateType>();
447 targetState = parentState;
453 typename std::remove_pointer<
decltype(InitialStateType::smacc_inner_type)>::type InnerType;
457 typedef typename InitialStateType::reactions reactions;
466template <
typename InitialStateType>
473template <
typename StateType>
475 std::shared_ptr<SmaccStateInfo> parent)
477 auto thisptr = this->shared_from_this();
478 auto * statetid = &(
typeid(StateType));
481 RCLCPP_INFO_STREAM(
getLogger(),
"Creating State Info: " << demangledName);
483 auto state = std::make_shared<SmaccStateInfo>(statetid, parent, thisptr);
484 state->demangledStateName = demangledName;
485 state->fullStateName =
typeid(StateType).name();
486 state->stateIndex_ =
states.size();
488 if (parent !=
nullptr)
490 parent->children_.push_back(state);
498template <
typename StateType>
501 states[state->fullStateName] = state;
504template <
typename StateType>
507 auto realparentState = this->
stateMachine_->getState<
typename StateType::TContext>();
509 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)