13#include <smacc_msgs/SmaccState.h>
14#include <smacc_msgs/SmaccTransition.h>
15#include <smacc_msgs/SmaccOrthogonal.h>
16#include <smacc_msgs/SmaccStateReactor.h>
17#include <smacc_msgs/SmaccEventGenerator.h>
21namespace introspection
26 std::map<std::string, std::shared_ptr<SmaccStateInfo>>
states;
30 template <
typename InitialStateType>
33 template <
typename StateType>
34 std::shared_ptr<SmaccStateInfo>
createState(std::shared_ptr<SmaccStateInfo> parentState);
36 template <
typename StateType>
39 auto typeNameStr =
typeid(StateType).name();
41 return states.count(typeNameStr) > 0;
44 template <
typename StateType>
47 if (this->containsState<StateType>())
49 return states[
typeid(StateType).name()];
54 template <
typename StateType>
55 void addState(std::shared_ptr<StateType> &state);
83 template <
template <
typename,
typename,
typename>
typename TTransition,
typename TevSource,
template <
typename>
typename EvType,
typename Tag,
typename DestinyState>
84 void operator()(TTransition<EvType<TevSource>, DestinyState, Tag>);
86 template <
template <
typename,
typename>
typename TTransition,
typename TevSource,
template <
typename>
typename EvType,
typename DestinyState>
87 void operator()(TTransition<EvType<TevSource>, DestinyState>);
94template <
typename InitialStateType>
97 static void walkStates(std::shared_ptr<SmaccStateInfo> ¤tState,
bool rootInitialNode);
104 using type_t =
typename T::type;
110typename disable_if<boost::mpl::is_sequence<T>>::type
118typename enable_if<boost::mpl::is_sequence<T>>::type
121 using boost::mpl::_1;
122 using wrappedList =
typename boost::mpl::transform<T, add_type_wrapper<_1>>::type;
123 boost::mpl::for_each<wrappedList>(
AddSubState(parentState));
129typename enable_if<boost::mpl::is_sequence<T>>::type
133 ROS_INFO_STREAM(
"State %s Walker has transition list");
134 using boost::mpl::_1;
135 using wrappedList =
typename boost::mpl::transform<T, add_type_wrapper<_1>>::type;
136 boost::mpl::for_each<wrappedList>(
AddTransition(sourceState));
139template <
typename Ev,
typename Dst,
typename Tag>
142 auto transitionTypeInfo = TypeInfo::getTypeInfoFromType<smacc::Transition<Ev, boost::statechart::deep_history<Dst>, Tag>>();
147template <
typename Ev,
typename Dst,
typename Tag>
150 auto transitionTypeInfo = TypeInfo::getTypeInfoFromType<smacc::Transition<Ev, Dst, Tag>>();
154template <
typename Ev,
typename Dst,
typename Tag>
157 ROS_INFO(
"State %s Walker transition: %s", sourceState->toShortName().c_str(),
demangleSymbol(
typeid(Ev).name()).c_str());
158 std::string transitionTag;
159 std::string transitionType;
163 transitionTag = demangleSymbol<Tag>();
164 transitionType = getTransitionType<Tag>();
165 ROS_DEBUG_STREAM(
"TRANSITION TYPE:" << transitionType);
170 automaticTransitionTag<Ev>(transitionTag);
171 automaticTransitionType<Ev>(transitionType);
174 ROS_INFO_STREAM(
"Transition tag: " << transitionTag);
176 if (!sourceState->stateMachine_->containsState<Dst>())
178 auto realparentState = sourceState->stateMachine_->getState<
typename Dst::TContext>();
179 auto siblingnode = sourceState->stateMachine_->createState<Dst>(realparentState);
183 sourceState->declareTransition<Ev>(siblingnode, transitionTag, transitionType, history, transitionTypeInfo);
190 auto siblingnode = sourceState->stateMachine_->getState<Dst>();
191 sourceState->declareTransition<Ev>(siblingnode, transitionTag, transitionType, history, transitionTypeInfo);
196template <
typename EvType>
199 auto evtype = demangledTypeName<EvType>();
207 if (transitionTag !=
"")
215 transitionInfo.
eventInfo = std::make_shared<SmaccEventInfo>(transitionTypeInfo->templateParameters.front());
217 EventLabel<EvType>(transitionInfo.
eventInfo->label);
218 ROS_DEBUG_STREAM(
"LABEL: " << transitionInfo.
eventInfo->label);
250template <
typename Ev,
typename Dst>
251void processTransition(statechart::transition<Ev, Dst> *, std::shared_ptr<SmaccStateInfo> &sourceState)
256template <
typename Ev>
257void processTransition(statechart::custom_reaction<Ev> *, std::shared_ptr<SmaccStateInfo> &sourceState)
266typename disable_if<boost::mpl::is_sequence<T>>::type
299template <
template <
typename,
typename,
typename>
typename TTransition,
typename TevSource,
template <
typename>
typename EvType,
typename Tag,
typename DestinyState>
302 processTransitions<TTransition<EvType<TevSource>, DestinyState, Tag>>(
currentState_);
307template <
template <
typename,
typename>
typename TTransition,
typename TevSource,
template <
typename>
typename EvType,
typename DestinyState>
310 processTransitions<TTransition<EvType<TevSource>, DestinyState>>(
currentState_);
313template <
typename TTrans>
316 using type_t =
typename TTrans::type;
330 template <
typename C>
332 template <
typename C>
343typename std::enable_if<HasOnDefinition<T>::value,
void>::type
347 ROS_INFO_STREAM(
"EXECUTING ONDEFINITION: " <<
demangleSymbol(
typeid(T).name()));
348 T::staticConfigure();
352typename std::enable_if<!HasOnDefinition<T>::value,
void>::type
355 ROS_INFO_STREAM(
"static OnDefinition: dont exist for " <<
demangleSymbol(
typeid(T).name()));
366template <
typename InitialStateType>
370 auto currentname = demangledTypeName<InitialStateType>();
372 std::shared_ptr<SmaccStateInfo> targetState;
374 if (!rootInitialNode)
376 if (parentState->stateMachine_->containsState<InitialStateType>())
382 targetState = parentState->createChildState<InitialStateType>();
386 targetState = parentState;
389 CallOnDefinition<InitialStateType>();
391 typedef typename std::remove_pointer<
decltype(InitialStateType::smacc_inner_type)>::type InnerType;
392 processSubState<InnerType>(targetState);
395 typedef typename InitialStateType::reactions reactions;
398 processTransitions<reactions>(targetState);
403template <
typename InitialStateType>
406 auto initialState = this->createState<InitialStateType>(
nullptr);
410template <
typename StateType>
413 auto thisptr = this->shared_from_this();
414 auto *statetid = &(
typeid(StateType));
416 auto demangledName = demangledTypeName<StateType>();
417 ROS_INFO_STREAM(
"Creating State Info: " << demangledName);
419 auto state = std::make_shared<SmaccStateInfo>(statetid, parent, thisptr);
420 state->demangledStateName = demangledName;
421 state->fullStateName =
typeid(StateType).name();
422 state->stateIndex_ =
states.size();
424 if (parent !=
nullptr)
426 parent->children_.push_back(state);
434template <
typename StateType>
437 states[state->fullStateName] = state;
440template <
typename StateType>
443 auto realparentState = this->
stateMachine_->getState<
typename StateType::TContext>();
445 auto childState = this->
stateMachine_->createState<StateType>(realparentState);
447 ROS_WARN_STREAM(
"Real parent state> " << demangleSymbol<typename StateType::TContext>());
static YesType & test(decltype(&C::staticConfigure))
static NoType & test(...)
std::shared_ptr< SmaccStateInfo > createChildState()
std::shared_ptr< SmaccStateMachineInfo > stateMachine_
void declareTransition(std::shared_ptr< SmaccStateInfo > &dstState, std::string transitionTag, std::string transitionType, bool history, TypeInfo::Ptr transitionTypeInfo)
std::vector< SmaccTransitionInfo > transitions_
void buildStateMachineInfo()
std::vector< smacc_msgs::SmaccState > stateMsgs
std::shared_ptr< SmaccStateInfo > getState()
void assembleSMStructureMessage(ISmaccStateMachine *sm)
void addState(std::shared_ptr< StateType > &state)
std::shared_ptr< SmaccStateInfo > createState(std::shared_ptr< SmaccStateInfo > parentState)
std::map< std::string, std::shared_ptr< SmaccStateInfo > > states
std::shared_ptr< TypeInfo > Ptr
void processTransitionAux(smacc::Transition< Ev, Dst, Tag > *, std::shared_ptr< SmaccStateInfo > &sourceState, bool history, TypeInfo::Ptr &transitionTypeInfo)
std::enable_if< HasOnDefinition< T >::value, void >::type CallOnDefinition()
enable_if< boost::mpl::is_sequence< T > >::type processTransitions(std::shared_ptr< SmaccStateInfo > &sourceState)
void processTransition(smacc::Transition< Ev, boost::statechart::deep_history< Dst >, Tag > *, std::shared_ptr< SmaccStateInfo > &sourceState)
std::string demangleSymbol()
disable_if< boost::mpl::is_sequence< T > >::type processSubState(std::shared_ptr< SmaccStateInfo > &parentState)
std::shared_ptr< SmaccStateInfo > & parentState_
AddSubState(std::shared_ptr< SmaccStateInfo > &parentState)
void operator()(TTransition< EvType< TevSource >, DestinyState, Tag >)
std::shared_ptr< SmaccStateInfo > & currentState_
AddTransition(std::shared_ptr< SmaccStateInfo > ¤tState)
std::shared_ptr< SmaccStateInfo > destinyState
std::shared_ptr< SmaccEventInfo > eventInfo
std::string transitionType
smacc::introspection::TypeInfo::Ptr transitionTypeInfo
std::shared_ptr< SmaccStateInfo > sourceState
std::string transitionTag
static void walkStates(std::shared_ptr< SmaccStateInfo > ¤tState, bool rootInitialNode)