18 template <
class MostDerived,
20 class InnerInitial = mpl::list<>,
21 sc::history_mode historyMode = sc::has_deep_history>
23 MostDerived, Context, InnerInitial, historyMode>,
51#define STATE_NAME (demangleSymbol(typeid(MostDerived).name()).c_str())
55 static_assert(std::is_base_of<ISmaccState, Context>::value || std::is_base_of<ISmaccStateMachine, Context>::value,
"The context class must be a SmaccState or a SmaccStateMachine");
57 static_assert(!std::is_same<MostDerived, Context>::value,
"The context must be a different state or state machine than the current state");
65 auto &ps = this->
template context<Context>();
70 ROS_DEBUG(
"[%s] Ros node handle namespace for this state: %s",
STATE_NAME,
contextNh.getNamespace().c_str());
74 ROS_INFO(
"[%s] Creating ros NodeHandle for this state: %s",
STATE_NAME, nhname.c_str());
87 auto key =
typeid(MostDerived).name();
88 if (smInfo.states.count(key))
90 return smInfo.
states[key].get();
118 auto *derivedThis =
static_cast<MostDerived *
>(
this);
149 template <
typename T>
152 return base_type::outermost_context().getGlobalSMData(name, ret);
156 template <
typename T>
159 base_type::outermost_context().setGlobalSMData(name, value);
162 template <
typename SmaccComponentType>
165 base_type::outermost_context().requiresComponent(storage);
170 return base_type::outermost_context();
173 template <
typename TOrthogonal,
typename TBehavior>
176 configure_orthogonal_internal<TOrthogonal, TBehavior>([=](
ISmaccState *state) {
178 auto bh = state->
configure<TOrthogonal, TBehavior>();
179 initializationFunction(*bh, *(
static_cast<MostDerived *
>(state)));
183 template <
typename TOrthogonal,
typename TBehavior>
186 configure_orthogonal_internal<TOrthogonal, TBehavior>([=](
ISmaccState *state) {
188 auto bh = state->
configure<TOrthogonal, TBehavior>();
189 initializationFunction(*bh);
193 template <
typename TOrthogonal,
typename TBehavior,
typename... Args>
196 configure_orthogonal_internal<TOrthogonal, TBehavior>(
199 state->
configure<TOrthogonal, TBehavior>(args...);
228 template <
typename TStateReactor,
typename TOutputEvent,
typename TInputEventList,
typename... TArgs>
231 auto srh = std::make_shared<smacc::introspection::StateReactorHandler>();
232 auto srinfo = std::make_shared<SmaccStateReactorInfo>();
234 srinfo->stateReactorType = &
typeid(TStateReactor);
236 srh->srInfo_ = srinfo;
238 const std::type_info *tindex = &(
typeid(MostDerived));
243 srinfo->factoryFunction = [&, srh, args...](
ISmaccState *state) {
244 auto sr = state->createStateReactor<TStateReactor, TOutputEvent, TInputEventList, TArgs...>(args...);
245 srh->configureStateReactor(sr);
246 sr->initialize(state);
255 template <
typename TEventGenerator,
typename... TUArgs>
258 auto egh = std::make_shared<smacc::introspection::EventGeneratorHandler>();
259 auto eginfo = std::make_shared<SmaccEventGeneratorInfo>();
260 eginfo->eventGeneratorType = &
typeid(TEventGenerator);
262 egh->egInfo_ = eginfo;
264 const std::type_info *tindex = &(
typeid(MostDerived));
269 eginfo->factoryFunction = [&, egh, args...](
ISmaccState *state) {
270 auto eg = state->createEventGenerator<TEventGenerator>(args...);
271 egh->configureEventGenerator(eg);
272 eg->initialize(state);
273 eg->template onStateAllocation<MostDerived, TEventGenerator>();
281 template <
typename TStateReactor,
typename... TUArgs>
284 auto srh = std::make_shared<smacc::introspection::StateReactorHandler>();
285 auto srinfo = std::make_shared<SmaccStateReactorInfo>();
287 srinfo->stateReactorType = &
typeid(TStateReactor);
289 srh->srInfo_ = srinfo;
291 const std::type_info *tindex = &(
typeid(MostDerived));
296 srinfo->factoryFunction = [&, srh, args...](
ISmaccState *state) {
297 auto sr = state->createStateReactor<TStateReactor>(args...);
298 srh->configureStateReactor(sr);
299 sr->initialize(state);
310 auto *thisobject =
static_cast<MostDerived *
>(
this);
311 auto condition = boost::bind(conditionFn, thisobject);
312 bool conditionResult = condition();
317 this->postEvent<EvLoopContinue<MostDerived>>();
321 this->postEvent<EvLoopEnd<MostDerived>>();
323 ROS_INFO(
"[%s] POST THROW CONDITION",
STATE_NAME);
328 this->postEvent<EvSequenceFinished<MostDerived>>();
336 typedef typename base_type::outermost_context_base_type
355 base_type::template deep_construct_inner<inner_initial_list>(
356 pInnerContext, outermostContextBase);
367 ROS_INFO(
"[%s] State object created. Initializating...",
STATE_NAME);
368 state->entryStateInternal();
370 outermostContextBase.add(pInnerContext);
371 return pInnerContext;
375 template <
typename TOrthogonal,
typename TBehavior>
386 const std::type_info *tindex = &(
typeid(MostDerived));
400 ROS_DEBUG(
"[%s] nodehandle namespace: %s",
STATE_NAME,
nh.getNamespace().c_str());
406 ROS_INFO(
"[%s] -- STATIC STATE DESCRIPTION --",
STATE_NAME);
411 for (
auto &bhinfo : stateReactorsVector.second)
417 const std::type_info *tindex = &(
typeid(MostDerived));
425 ortho.second->initState(
this);
428 for (
auto &bhinfo : staticDefinedBehaviors)
430 ROS_INFO(
"[%s] Creating static client behavior: %s",
STATE_NAME,
demangleSymbol(bhinfo.behaviorType->name()).c_str());
431 bhinfo.factoryFunction(
this);
434 for (
auto &sr : staticDefinedStateReactors)
436 ROS_INFO(
"[%s] Creating static state reactor: %s",
STATE_NAME,
demangleSymbol(sr->stateReactorType->name()).c_str());
437 sr->factoryFunction(
this);
440 for (
auto &eg : staticDefinedEventGenerators)
442 ROS_INFO(
"[%s] Creating static event generator: %s",
STATE_NAME,
demangleSymbol(eg->eventGeneratorType->name()).c_str());
443 eg->factoryFunction(
this);
446 ROS_INFO(
"[%s] ---- END STATIC DESCRIPTION",
STATE_NAME);
449 ROS_INFO(
"[%s] State runtime configuration",
STATE_NAME);
451 auto *derivedthis =
static_cast<MostDerived *
>(
this);
464 static_cast<MostDerived *
>(
this)->
onEntry();
void notifyOnRuntimeConfigurationFinished(StateType *state)
const SmaccStateMachineInfo & getStateMachineInfo()
void notifyOnStateExitting(StateType *state)
void notifyOnRuntimeConfigured(StateType *state)
const std::map< std::string, std::shared_ptr< smacc::ISmaccOrthogonal > > & getOrthogonals() const
void notifyOnStateEntryEnd(StateType *state)
void notifyOnStateExited(StateType *state)
void notifyOnStateEntryStart(StateType *state)
void setParam(std::string param_name, T param_val)
std::shared_ptr< TBehavior > configure(Args &&... args)
ISmaccState * parentState_
ros::NodeHandle contextNh
const smacc::introspection::SmaccStateInfo * stateInfo_
void entryStateInternal()
InnerInitial * smacc_inner_type
base_type::context_ptr_type context_ptr_type
context_type::state_iterator state_iterator
static void configure_orthogonal_internal(std::function< void(ISmaccState *state)> initializationFunction)
static inner_context_ptr_type shallow_construct(const context_ptr_type &pContext, outermost_context_base_type &outermostContextBase)
void requiresComponent(SmaccComponentType *&storage)
void throwSequenceFinishedEvent()
static std::shared_ptr< smacc::introspection::StateReactorHandler > static_createStateReactor(TArgs... args)
std::string getShortName()
const smacc::introspection::SmaccStateInfo * getStateInfo()
InnerInitial LastDeepState
base_type::inner_context_ptr_type inner_context_ptr_type
Context::inner_context_type context_type
sc::simple_state< MostDerived, Context, InnerInitial, historyMode > base_type
void checkWhileLoopConditionAndThrowEvent(bool(MostDerived::*conditionFn)())
static std::shared_ptr< smacc::introspection::EventGeneratorHandler > static_createEventGenerator(TUArgs... args)
std::string getFullName()
void setGlobalSMData(std::string name, T value)
static void configure_orthogonal(Args &&... args)
static void deep_construct(const context_ptr_type &pContext, outermost_context_base_type &outermostContextBase)
static std::shared_ptr< smacc::introspection::StateReactorHandler > static_createStateReactor_aux(TUArgs... args)
base_type::outermost_context_base_type outermost_context_base_type
virtual ISmaccState * getParentState()
base_type::inner_initial_list inner_initial_list
bool getGlobalSMData(std::string name, T &ret)
static void configure_orthogonal_runtime(std::function< void(TBehavior &bh, MostDerived &)> initializationFunction)
SmaccState(my_context ctx)
static void initial_deep_construct(outermost_context_base_type &outermostContextBase)
virtual ISmaccStateMachine & getStateMachine()
static void configure_orthogonal_runtime(std::function< void(TBehavior &bh)> initializationFunction)
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccStateReactorInfo > > > stateReactorsInfo
static std::map< const std::type_info *, std::vector< ClientBehaviorInfoEntry > > staticBehaviorInfo
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccEventGeneratorInfo > > > eventGeneratorsInfo
std::map< std::string, std::shared_ptr< SmaccStateInfo > > states
auto optionalNodeHandle(boost::intrusive_ptr< T > &obj) -> ros::NodeHandle
std::string demangleSymbol()
std::string cleanShortTypeName(const std::type_info &tinfo)
void standardOnExit(TState &st, std::true_type)
base_type::context_ptr_type pContext_
my_context(typename base_type::context_ptr_type pContext)
const std::type_info * behaviorType
const std::type_info * orthogonalType
std::function< void(smacc::ISmaccState *)> factoryFunction