SMACC2
Loading...
Searching...
No Matches
smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode > Class Template Reference

#include <smacc_state_base.hpp>

Inheritance diagram for smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >:
Inheritance graph
Collaboration diagram for smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >:
Collaboration graph

Classes

struct  my_context
 

Public Types

typedef Context TContext
 
typedef Context::inner_context_type context_type
 
typedef context_type::state_iterator state_iterator
 
typedef InnerInitial LastDeepState
 
typedef base_type::outermost_context_base_type outermost_context_base_type
 
typedef base_type::inner_context_ptr_type inner_context_ptr_type
 
typedef base_type::context_ptr_type context_ptr_type
 
typedef base_type::inner_initial_list inner_initial_list
 

Public Member Functions

 SmaccState ()=delete
 
 SmaccState (my_context ctx)
 
virtual ~SmaccState ()
 
const smacc2::introspection::SmaccStateInfo * getStateInfo ()
 
std::string getName () override
 
std::string getFullName ()
 
std::string getShortName ()
 
virtual ISmaccState * getParentState ()
 
void exit ()
 
void runtimeConfigure ()
 
void onEntry ()
 
void onExit ()
 
template<typename T >
bool getGlobalSMData (const std::string &name, T &ret)
 
template<typename T >
void setGlobalSMData (const std::string &name, T value)
 
ISmaccStateMachine & getStateMachine () override
 
void checkWhileLoopConditionAndThrowEvent (bool(MostDerived::*conditionFn)())
 
void throwSequenceFinishedEvent ()
 
- Public Member Functions inherited from smacc2::ISmaccState
 ISmaccState ()=default
 
virtual ~ISmaccState ()=default
 
 ISmaccState (const ISmaccState &)=delete
 
ISmaccState & operator= (const ISmaccState &)=delete
 
 ISmaccState (ISmaccState &&)=delete
 
ISmaccState & operator= (ISmaccState &&)=delete
 
ISmaccState * getParentState ()
 
rclcpp::Node::SharedPtr & getNode ()
 
rclcpp::Logger getLogger ()
 
bool initializationFailed () const
 
virtual std::string getClassName ()
 
template<typename TOrthogonal , typename TBehavior , typename... Args>
std::shared_ptr< TBehavior > configure (Args &&... args)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (const std::string &name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename T >
bool getGlobalSMData (const std::string &name, T &ret)
 
template<typename T >
void setGlobalSMData (const std::string &name, T value)
 
template<typename TStateReactor , typename TTriggerEvent , typename TEventList , typename... TEvArgs>
std::shared_ptr< TStateReactor > createStateReactor (TEvArgs... args)
 
template<typename TStateReactor , typename... TEvArgs>
std::shared_ptr< TStateReactor > createStateReactor (TEvArgs... args)
 
template<typename TEventGenerator , typename... TEvArgs>
std::shared_ptr< TEventGenerator > createEventGenerator (TEvArgs... args)
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TransitionType >
void notifyTransition ()
 
void notifyTransitionFromTransitionTypeInfo (std::shared_ptr< smacc2::introspection::TypeInfo > &transitionTypeInfo)
 
std::vector< std::shared_ptr< StateReactor > > & getStateReactors ()
 
std::vector< std::shared_ptr< SmaccEventGenerator > > & getEventGenerators ()
 
template<typename TOrthogonal >
TOrthogonal * getOrthogonal ()
 
template<typename TOrthogonal , typename TClientBehavior >
TClientBehavior * getClientBehavior (int index=0)
 
template<typename TEventGenerator >
TEventGenerator * getEventGenerator ()
 
template<typename TStateReactor >
TStateReactor * getStateReactor ()
 

Static Public Member Functions

template<typename TOrthogonal , typename TBehavior >
static void configure_orthogonal_runtime (std::function< void(TBehavior &bh, MostDerived &)> initializationFunction)
 
template<typename TOrthogonal , typename TBehavior >
static void configure_orthogonal_runtime (std::function< void(TBehavior &bh)> initializationFunction)
 
template<typename TOrthogonal , typename TBehavior , typename... Args>
static void configure_orthogonal (Args &&... args)
 
template<typename TStateReactor , typename TOutputEvent , typename TInputEventList , typename... TArgs>
static std::shared_ptr< smacc2::introspection::StateReactorHandler > static_createStateReactor (TArgs... args)
 
template<typename TEventGenerator , typename... TUArgs>
static std::shared_ptr< smacc2::introspection::EventGeneratorHandler > static_createEventGenerator (TUArgs... args)
 
template<typename TStateReactor , typename... TUArgs>
static std::shared_ptr< smacc2::introspection::StateReactorHandler > static_createStateReactor_aux (TUArgs... args)
 
static void initial_deep_construct (outermost_context_base_type &outermostContextBase)
 
static void deep_construct (const context_ptr_type &pContext, outermost_context_base_type &outermostContextBase)
 
static inner_context_ptr_type shallow_construct (const context_ptr_type &pContext, outermost_context_base_type &outermostContextBase)
 

Public Attributes

bool finishStateThrown
 
InnerInitial * smacc_inner_type
 

Private Types

typedef sc::simple_state< MostDerived, Context, InnerInitial, historyMode > base_type
 

Private Member Functions

void entryStateInternal ()
 
void onInitializationFailure (const std::string &what)
 

Static Private Member Functions

template<typename TOrthogonal , typename TBehavior >
static void configure_orthogonal_internal (std::function< void(ISmaccState *state)> initializationFunction)
 

Additional Inherited Members

- Protected Attributes inherited from smacc2::ISmaccState
rclcpp::Node::SharedPtr node_
 
std::shared_ptr< rclcpp::Logger > logger_
 
std::vector< std::shared_ptr< StateReactor > > stateReactors_
 
std::vector< std::shared_ptr< smacc2::SmaccEventGenerator > > eventGenerators_
 
ISmaccState * parentState_ = nullptr
 
bool initializationFailed_ = false
 
const smacc2::introspection::SmaccStateInfo * stateInfo_ = nullptr
 

Detailed Description

template<class MostDerived, class Context, class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
class smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >

Definition at line 58 of file smacc_state_base.hpp.

Member Typedef Documentation

◆ base_type

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
sc::simple_state<MostDerived, Context, InnerInitial, historyMode> smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::base_type
private

Definition at line 61 of file smacc_state_base.hpp.

◆ context_ptr_type

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
base_type::context_ptr_type smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::context_ptr_type

Definition at line 362 of file smacc_state_base.hpp.

◆ context_type

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
Context::inner_context_type smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::context_type

Definition at line 65 of file smacc_state_base.hpp.

◆ inner_context_ptr_type

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
base_type::inner_context_ptr_type smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::inner_context_ptr_type

Definition at line 361 of file smacc_state_base.hpp.

◆ inner_initial_list

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
base_type::inner_initial_list smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::inner_initial_list

Definition at line 363 of file smacc_state_base.hpp.

◆ LastDeepState

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
InnerInitial smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::LastDeepState

Definition at line 68 of file smacc_state_base.hpp.

◆ outermost_context_base_type

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
base_type::outermost_context_base_type smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::outermost_context_base_type

Definition at line 360 of file smacc_state_base.hpp.

◆ state_iterator

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
context_type::state_iterator smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::state_iterator

Definition at line 66 of file smacc_state_base.hpp.

◆ TContext

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
Context smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::TContext

Definition at line 64 of file smacc_state_base.hpp.

Constructor & Destructor Documentation

◆ SmaccState() [1/2]

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::SmaccState ( )
delete

◆ SmaccState() [2/2]

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::SmaccState ( my_context ctx)
inline

Definition at line 84 of file smacc_state_base.hpp.

85 {
86 static_assert(
87 std::is_base_of<ISmaccState, Context>::value ||
88 std::is_base_of<ISmaccStateMachine, Context>::value,
89 "The context class must be a SmaccState or a SmaccStateMachine");
90 static_assert(
91 !std::is_same<MostDerived, Context>::value,
92 "The context must be a different state or state machine "
93 "than the current state");
94
95 logger_ = std::make_shared<rclcpp::Logger>(
96 rclcpp::get_logger(smacc2::utils::cleanShortTypeName(typeid(MostDerived))));
97
98 RCLCPP_INFO(getLogger(), "[%s] Creating state ", STATE_NAME);
99 this->set_context(ctx.pContext_);
100
101 node_ = this->getStateMachine().getNode();
102
103 this->stateInfo_ = getStateInfo();
104
105 // storing a reference to the parent state
106 auto & ps = this->template context<Context>();
107 parentState_ = dynamic_cast<ISmaccState *>(&ps);
108 finishStateThrown = false;
109 }
rclcpp::Node::SharedPtr getNode()
std::shared_ptr< rclcpp::Logger > logger_
rclcpp::Logger getLogger()
rclcpp::Node::SharedPtr node_
ISmaccState * parentState_
const smacc2::introspection::SmaccStateInfo * stateInfo_
ISmaccStateMachine & getStateMachine() override
const smacc2::introspection::SmaccStateInfo * getStateInfo()
std::string cleanShortTypeName()
Definition common.hpp:69
#define STATE_NAME

References smacc2::utils::cleanShortTypeName(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::finishStateThrown, smacc2::ISmaccState::getLogger(), smacc2::ISmaccStateMachine::getNode(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateInfo(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateMachine(), smacc2::ISmaccState::logger_, smacc2::ISmaccState::node_, smacc2::ISmaccState::parentState_, smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::my_context::pContext_, STATE_NAME, and smacc2::ISmaccState::stateInfo_.

Here is the call graph for this function:

◆ ~SmaccState()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
virtual smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::~SmaccState ( )
inlinevirtual

Definition at line 111 of file smacc_state_base.hpp.

111{}

Member Function Documentation

◆ checkWhileLoopConditionAndThrowEvent()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::checkWhileLoopConditionAndThrowEvent ( bool(MostDerived::* conditionFn )())
inline

Definition at line 335 of file smacc_state_base.hpp.

336 {
337 auto * thisobject = static_cast<MostDerived *>(this);
338 auto condition = boost::bind(conditionFn, thisobject);
339 bool conditionResult = condition();
340
341 // RCLCPP_INFO("LOOP EVENT CONDITION: %d", conditionResult);
342 if (conditionResult)
343 {
345 }
346 else
347 {
348 this->template postEvent<EvLoopEnd<MostDerived>>();
349 }
350 RCLCPP_INFO(getLogger(), "[%s] POST THROW CONDITION", STATE_NAME);
351 }

References smacc2::ISmaccState::getLogger(), smacc2::ISmaccState::postEvent(), and STATE_NAME.

Here is the call graph for this function:

◆ configure_orthogonal()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename TOrthogonal , typename TBehavior , typename... Args>
static void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal ( Args &&... args)
inlinestatic

Definition at line 213 of file smacc_state_base.hpp.

214 {
216 [=](ISmaccState * state) { state->configure<TOrthogonal, TBehavior>(args...); });
217 }
static void configure_orthogonal_internal(std::function< void(ISmaccState *state)> initializationFunction)

References smacc2::ISmaccState::configure(), and smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal_internal().

Here is the call graph for this function:

◆ configure_orthogonal_internal()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename TOrthogonal , typename TBehavior >
static void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal_internal ( std::function< void(ISmaccState< MostDerived, Context, InnerInitial, historyMode > *state)> initializationFunction)
inlinestaticprivate

Definition at line 397 of file smacc_state_base.hpp.

399 {
400 ClientBehaviorInfoEntry bhinfo;
401 bhinfo.factoryFunction = initializationFunction;
402
403 bhinfo.behaviorType = &(typeid(TBehavior));
404 bhinfo.orthogonalType = &(typeid(TOrthogonal));
405
406 const std::type_info * tindex = &(typeid(MostDerived));
407 if (!SmaccStateInfo::staticBehaviorInfo.count(tindex))
408 SmaccStateInfo::staticBehaviorInfo[tindex] = std::vector<ClientBehaviorInfoEntry>();
409
410 SmaccStateInfo::staticBehaviorInfo[tindex].push_back(bhinfo);
411 RCLCPP_INFO_STREAM(
412 rclcpp::get_logger("static"), "[states walking] State "
414 << "client behavior count: "
415 << SmaccStateInfo::staticBehaviorInfo[tindex].size());
416 }
static std::map< const std::type_info *, std::vector< ClientBehaviorInfoEntry > > staticBehaviorInfo

References smacc2::introspection::ClientBehaviorInfoEntry::behaviorType, smacc2::utils::cleanShortTypeName(), smacc2::introspection::ClientBehaviorInfoEntry::factoryFunction, smacc2::introspection::ClientBehaviorInfoEntry::orthogonalType, and smacc2::introspection::SmaccStateInfo::staticBehaviorInfo.

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal_runtime(), and smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal_runtime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configure_orthogonal_runtime() [1/2]

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename TOrthogonal , typename TBehavior >
static void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal_runtime ( std::function< void(TBehavior &bh)> initializationFunction)
inlinestatic

Definition at line 201 of file smacc_state_base.hpp.

203 {
205 [=](ISmaccState * state)
206 {
207 auto bh = state->configure<TOrthogonal, TBehavior>();
208 initializationFunction(*bh);
209 });
210 }

References smacc2::ISmaccState::configure(), and smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal_internal().

Here is the call graph for this function:

◆ configure_orthogonal_runtime() [2/2]

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename TOrthogonal , typename TBehavior >
static void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal_runtime ( std::function< void(TBehavior &bh, MostDerived &)> initializationFunction)
inlinestatic

Definition at line 189 of file smacc_state_base.hpp.

191 {
193 [=](ISmaccState * state)
194 {
195 auto bh = state->configure<TOrthogonal, TBehavior>();
196 initializationFunction(*bh, *(static_cast<MostDerived *>(state)));
197 });
198 }

References smacc2::ISmaccState::configure(), and smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal_internal().

Here is the call graph for this function:

◆ deep_construct()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
static void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::deep_construct ( const context_ptr_type & pContext,
outermost_context_base_type & outermostContextBase )
inlinestatic

Definition at line 371 of file smacc_state_base.hpp.

373 {
374 const inner_context_ptr_type pInnerContext(shallow_construct(pContext, outermostContextBase));
375 base_type::template deep_construct_inner<inner_initial_list>(
376 pInnerContext, outermostContextBase);
377 }
static inner_context_ptr_type shallow_construct(const context_ptr_type &pContext, outermost_context_base_type &outermostContextBase)
base_type::inner_context_ptr_type inner_context_ptr_type

References smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::shallow_construct().

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::initial_deep_construct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ entryStateInternal()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal ( )
inlineprivate

Definition at line 418 of file smacc_state_base.hpp.

419 {
420 // finally we go to the derived state onEntry Function
421
422 RCLCPP_DEBUG(getLogger(), "[%s] State object created. Initializing...", STATE_NAME);
423 this->getStateMachine().notifyOnStateEntryStart(static_cast<MostDerived *>(this));
424
425 RCLCPP_DEBUG_STREAM(
426 getLogger(), "[" << smacc2::utils::cleanShortTypeName(typeid(MostDerived)).c_str()
427 << "] creating ros subnode");
428
429 // before dynamic runtimeConfigure, we execute the staticConfigure behavior configurations
430 {
431 RCLCPP_DEBUG(getLogger(), "[%s] -- STATIC STATE DESCRIPTION --", STATE_NAME);
432
433 for (const auto & clientBehavior : SmaccStateInfo::staticBehaviorInfo)
434 {
435 RCLCPP_DEBUG(
436 getLogger(), "[%s] client behavior info: %s", STATE_NAME,
437 demangleSymbol(clientBehavior.first->name()).c_str());
438 for (auto & cbinfo : clientBehavior.second)
439 {
440 RCLCPP_DEBUG(
441 getLogger(), "[%s] client behavior: %s", STATE_NAME,
442 demangleSymbol(cbinfo.behaviorType->name()).c_str());
443 }
444 }
445
446 const std::type_info * tindex = &(typeid(MostDerived));
447 auto & staticDefinedBehaviors = SmaccStateInfo::staticBehaviorInfo[tindex];
448 auto & staticDefinedStateReactors = SmaccStateInfo::stateReactorsInfo[tindex];
449 auto & staticDefinedEventGenerators = SmaccStateInfo::eventGeneratorsInfo[tindex];
450
451 for (auto & ortho : this->getStateMachine().getOrthogonals())
452 {
453 RCLCPP_INFO(
454 getLogger(), "[%s] Initializing orthogonal: %s", STATE_NAME,
455 demangleSymbol(typeid(*ortho.second).name()).c_str());
456 ortho.second->initState(this);
457 }
458
459 RCLCPP_DEBUG_STREAM(
460 getLogger(), "Finding static client behaviors. State Database: "
461 << SmaccStateInfo::staticBehaviorInfo.size() << ". Current state "
462 << cleanShortTypeName(*tindex)
463 << " cbs: " << SmaccStateInfo::staticBehaviorInfo[tindex].size());
464 for (auto & bhinfo : staticDefinedBehaviors)
465 {
466 RCLCPP_DEBUG(
467 getLogger(), "[%s] Creating static client behavior: %s", STATE_NAME,
468 demangleSymbol(bhinfo.behaviorType->name()).c_str());
469 bhinfo.factoryFunction(this);
470 }
471
472 for (auto & sr : staticDefinedStateReactors)
473 {
474 RCLCPP_DEBUG(
475 getLogger(), "[%s] Creating static state reactor: %s", STATE_NAME,
476 sr->stateReactorType->getFullName().c_str());
477 sr->factoryFunction(this);
478 }
479
480 for (auto & eg : staticDefinedEventGenerators)
481 {
482 RCLCPP_DEBUG(
483 getLogger(), "[%s] Creating static event generator: %s", STATE_NAME,
484 eg->eventGeneratorType->getFullName().c_str());
485 eg->factoryFunction(this);
486 }
487
488 RCLCPP_DEBUG(getLogger(), "[%s] ---- END STATIC DESCRIPTION", STATE_NAME);
489 }
490
491 RCLCPP_DEBUG(getLogger(), "[%s] State runtime configuration", STATE_NAME);
492
493 auto * derivedthis = static_cast<MostDerived *>(this);
494
495 // second the orthogonals are internally configured
496 this->getStateMachine().notifyOnRuntimeConfigured(derivedthis);
497
498 // A state inside a container whose initialization failed is not initialized either; the
499 // container's failure event is already posted.
500 if (this->parentState_ != nullptr && this->parentState_->initializationFailed())
501 {
502 RCLCPP_WARN(
503 getLogger(), "[%s] not initialized: its container state failed to initialize", STATE_NAME);
504 this->initializationFailed_ = true;
505 }
506
507 // User code: an exception from runtimeConfigure or onEntry is logged and posted as
508 // EvStInitializationFailure, and the state's client behaviors are then not entered.
509 if (!this->initializationFailed_)
510 {
511 try
512 {
514 // first we runtime configure the state, where we create client behaviors
515 static_cast<MostDerived *>(this)->runtimeConfigure();
516 TRACETOOLS_TRACEPOINT(smacc2_state_onRuntimeConfigure_end, STATE_NAME);
517 }
518 catch (const std::exception & e)
519 {
520 this->onInitializationFailure(e.what());
521 }
522 catch (...)
523 {
524 this->onInitializationFailure("non-standard exception");
525 }
526 }
527
528 // Always runs: it keeps the per-state bookkeeping that the exit path undoes.
530
531 if (!this->initializationFailed_)
532 {
533 RCLCPP_DEBUG(getLogger(), "[%s] State OnEntry", STATE_NAME);
534 try
535 {
536 static_cast<MostDerived *>(this)->onEntry();
537 }
538 catch (const std::exception & e)
539 {
540 this->onInitializationFailure(e.what());
541 }
542 catch (...)
543 {
544 this->onInitializationFailure("non-standard exception");
545 }
546 }
547
548 // here orthogonals and client behaviors are entered OnEntry
549 this->getStateMachine().notifyOnStateEntryEnd(derivedthis);
550 }
void notifyOnRuntimeConfigurationFinished(StateType *state)
void notifyOnStateEntryEnd(StateType *state)
void notifyOnRuntimeConfigured(StateType *state)
void notifyOnStateEntryStart(StateType *state)
bool initializationFailed() const
void onInitializationFailure(const std::string &what)
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccStateReactorInfo > > > stateReactorsInfo
static std::map< const std::type_info *, std::vector< std::shared_ptr< SmaccEventGeneratorInfo > > > eventGeneratorsInfo
std::string demangleSymbol()
smacc2_state_onRuntimeConfigure_start
smacc2_state_onRuntimeConfigure_end

References smacc2::utils::cleanShortTypeName(), smacc2::introspection::demangleSymbol(), smacc2::introspection::SmaccStateInfo::eventGeneratorsInfo, smacc2::ISmaccState::getLogger(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateMachine(), smacc2::ISmaccState::initializationFailed(), smacc2::ISmaccState::initializationFailed_, smacc2::ISmaccStateMachine::notifyOnRuntimeConfigurationFinished(), smacc2::ISmaccStateMachine::notifyOnRuntimeConfigured(), smacc2::ISmaccStateMachine::notifyOnStateEntryEnd(), smacc2::ISmaccStateMachine::notifyOnStateEntryStart(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::onEntry(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::onInitializationFailure(), smacc2::ISmaccState::parentState_, smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::runtimeConfigure(), smacc2_state_onRuntimeConfigure_end, smacc2_state_onRuntimeConfigure_start, STATE_NAME, smacc2::introspection::SmaccStateInfo::stateReactorsInfo, and smacc2::introspection::SmaccStateInfo::staticBehaviorInfo.

Here is the call graph for this function:

◆ exit()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::exit ( )
inline

Definition at line 131 of file smacc_state_base.hpp.

132 {
133 auto * derivedThis = static_cast<MostDerived *>(this);
134 {
135 std::lock_guard<std::recursive_mutex> lock(this->getStateMachine().getMutex());
136 this->getStateMachine().notifyOnStateExiting(derivedThis);
137 try
138 {
139 TRACETOOLS_TRACEPOINT(smacc2_state_onExit_start, STATE_NAME);
140 // A state whose initialization failed was never entered, so its onExit does not run.
141 if (!this->initializationFailed_) standardOnExit(*derivedThis);
142 TRACETOOLS_TRACEPOINT(smacc2_state_onExit_end, STATE_NAME);
143 }
144 // The exit path must complete, so the exception is logged and swallowed, not propagated.
145 catch (const std::exception & e)
146 {
147 RCLCPP_ERROR(getLogger(), "[%s] exception in onExit: %s", STATE_NAME, e.what());
148 }
149 catch (...)
150 {
151 RCLCPP_ERROR(getLogger(), "[%s] non-standard exception in onExit", STATE_NAME);
152 }
153 this->getStateMachine().notifyOnStateExited(derivedThis);
154 }
155 }
void notifyOnStateExited(StateType *state)
void notifyOnStateExiting(StateType *state)
void standardOnExit(TState &st, std::true_type)
smacc2_state_onExit_end
smacc2_state_onExit_start

References smacc2::ISmaccState::getLogger(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateMachine(), smacc2::ISmaccState::initializationFailed_, smacc2::ISmaccStateMachine::notifyOnStateExited(), smacc2::ISmaccStateMachine::notifyOnStateExiting(), smacc2_state_onExit_end, smacc2_state_onExit_start, smacc2::standardOnExit(), and STATE_NAME.

Here is the call graph for this function:

◆ getFullName()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
std::string smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getFullName ( )
inline

Definition at line 124 of file smacc_state_base.hpp.

124{ return demangleSymbol(typeid(MostDerived).name()); }

References smacc2::introspection::demangleSymbol().

Here is the call graph for this function:

◆ getGlobalSMData()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename T >
bool smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getGlobalSMData ( const std::string & name,
T & ret )
inline

Definition at line 171 of file smacc_state_base.hpp.

172 {
173 return base_type::outermost_context().getGlobalSMData(name, ret);
174 }

◆ getName()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
std::string smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getName ( )
inlineoverridevirtual

Implements smacc2::ISmaccState.

Definition at line 122 of file smacc_state_base.hpp.

122{ return getShortName(); }

References smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getShortName().

Here is the call graph for this function:

◆ getParentState()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
virtual ISmaccState * smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getParentState ( )
inlinevirtual

Definition at line 128 of file smacc_state_base.hpp.

128{ return parentState_; }

References smacc2::ISmaccState::parentState_.

◆ getShortName()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
std::string smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getShortName ( )
inline

Definition at line 126 of file smacc_state_base.hpp.

126{ return smacc2::utils::cleanShortTypeName(typeid(MostDerived)); }

References smacc2::utils::cleanShortTypeName().

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStateInfo()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
const smacc2::introspection::SmaccStateInfo * smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateInfo ( )
inline

Definition at line 113 of file smacc_state_base.hpp.

114 {
115 // By reference: a plain `auto` copied the whole SmaccStateMachineInfo on every state construction.
116 const auto & smInfo = this->getStateMachine().getStateMachineInfo();
117
118 auto it = smInfo.states.find(typeid(MostDerived).name());
119 return it != smInfo.states.end() ? it->second.get() : nullptr;
120 }
const SmaccStateMachineInfo & getStateMachineInfo()
std::map< std::string, std::shared_ptr< SmaccStateInfo > > states

References smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateMachine(), smacc2::ISmaccStateMachine::getStateMachineInfo(), and smacc2::introspection::SmaccStateMachineInfo::states.

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::SmaccState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStateMachine()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
ISmaccStateMachine & smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateMachine ( )
inlineoverridevirtual

◆ initial_deep_construct()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
static void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::initial_deep_construct ( outermost_context_base_type & outermostContextBase)
inlinestatic

Definition at line 365 of file smacc_state_base.hpp.

366 {
367 deep_construct(&outermostContextBase, outermostContextBase);
368 }
static void deep_construct(const context_ptr_type &pContext, outermost_context_base_type &outermostContextBase)

References smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::deep_construct().

Here is the call graph for this function:

◆ onEntry()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::onEntry ( )
inline

Definition at line 164 of file smacc_state_base.hpp.

164{}

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().

Here is the caller graph for this function:

◆ onExit()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::onExit ( )
inline

Definition at line 168 of file smacc_state_base.hpp.

168{}

◆ onInitializationFailure()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::onInitializationFailure ( const std::string & what)
inlineprivate

Definition at line 552 of file smacc_state_base.hpp.

553 {
554 const std::string stateName = demangleSymbol(typeid(MostDerived).name());
555 RCLCPP_ERROR(
556 getLogger(),
557 "[%s] exception in state initialization: %s. Its client behaviors are not started.",
558 stateName.c_str(), what.c_str());
559 this->initializationFailed_ = true;
561 }
void postStInitializationFailure(ISmaccStateMachine *stateMachine, const std::string &stateName, const std::string &what)

References smacc2::introspection::demangleSymbol(), smacc2::ISmaccState::getLogger(), smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::getStateMachine(), smacc2::ISmaccState::initializationFailed_, and smacc2::postStInitializationFailure().

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ runtimeConfigure()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::runtimeConfigure ( )
inline

Definition at line 160 of file smacc_state_base.hpp.

160{}

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::entryStateInternal().

Here is the caller graph for this function:

◆ setGlobalSMData()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename T >
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::setGlobalSMData ( const std::string & name,
T value )
inline

Definition at line 178 of file smacc_state_base.hpp.

179 {
180 base_type::outermost_context().setGlobalSMData(name, value);
181 }

◆ shallow_construct()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
static inner_context_ptr_type smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::shallow_construct ( const context_ptr_type & pContext,
outermost_context_base_type & outermostContextBase )
inlinestatic

Definition at line 379 of file smacc_state_base.hpp.

381 {
382 // Boost.Statechart's construction protocol; owned by pInnerContext below (MISRA C++:2023 21.6.2 deviation).
383 auto state = new MostDerived(
384 SmaccState<MostDerived, Context, InnerInitial, historyMode>::my_context(pContext));
385 const inner_context_ptr_type pInnerContext(state);
386
387 TRACETOOLS_TRACEPOINT(smacc2_state_onEntry_start, STATE_NAME);
388 state->entryStateInternal();
389 TRACETOOLS_TRACEPOINT(smacc2_state_onEntry_end, STATE_NAME);
390
391 outermostContextBase.add(pInnerContext);
392 return pInnerContext;
393 }
smacc2_state_onEntry_end
smacc2_state_onEntry_start

References smacc2_state_onEntry_end, smacc2_state_onEntry_start, and STATE_NAME.

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::deep_construct().

Here is the caller graph for this function:

◆ static_createEventGenerator()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename TEventGenerator , typename... TUArgs>
static std::shared_ptr< smacc2::introspection::EventGeneratorHandler > smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::static_createEventGenerator ( TUArgs... args)
inlinestatic

Definition at line 275 of file smacc_state_base.hpp.

277 {
278 auto egh = std::make_shared<smacc2::introspection::EventGeneratorHandler>();
279 auto eginfo = std::make_shared<SmaccEventGeneratorInfo>();
280 eginfo->eventGeneratorType = TypeInfo::getTypeInfoFromType<TEventGenerator>();
281
282 eginfo->egh = egh;
283 egh->egInfo_ = eginfo;
284
285 const std::type_info * tindex = &(typeid(MostDerived)); // get identifier of the current state
286
287 if (!SmaccStateInfo::eventGeneratorsInfo.count(tindex))
289 std::vector<std::shared_ptr<SmaccEventGeneratorInfo>>();
290
291 eginfo->factoryFunction = [&, egh, args...](ISmaccState * state)
292 {
293 auto eg = state->createEventGenerator<TEventGenerator>(args...);
294 egh->configureEventGenerator(eg);
295 eg->initialize(state);
296
297 eg->template onStateOrthogonalAllocation<MostDerived, TEventGenerator>();
298 return eg;
299 };
300
301 SmaccStateInfo::eventGeneratorsInfo[tindex].push_back(eginfo);
302 return egh;
303 }
static TypeInfo::Ptr getTypeInfoFromType()

References smacc2::introspection::SmaccStateInfo::eventGeneratorsInfo, and smacc2::introspection::TypeInfo::getTypeInfoFromType().

Here is the call graph for this function:

◆ static_createStateReactor()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename TStateReactor , typename TOutputEvent , typename TInputEventList , typename... TArgs>
static std::shared_ptr< smacc2::introspection::StateReactorHandler > smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::static_createStateReactor ( TArgs... args)
inlinestatic

Definition at line 221 of file smacc_state_base.hpp.

223 {
224 auto srh = std::make_shared<smacc2::introspection::StateReactorHandler>(globalNh_);
225 auto srinfo = std::make_shared<SmaccStateReactorInfo>();
226
227 srinfo->stateReactorType = TypeInfo::getTypeInfoFromType<TStateReactor>();
228 srinfo->outputEventType = TypeInfo::getTypeInfoFromType<TOutputEvent>();
229
230 if (srinfo->outputEventType->templateParameters.size() == 2)
231 {
232 srinfo->objectTagType = srinfo->outputEventType->templateParameters[1];
233 }
234 else if (srinfo->outputEventType->templateParameters.size() == 1)
235 {
237 }
238 else
239 {
240 assert(
241 false &&
242 "state reactor output events should have one or two parameters (SourceType, ObjectTag)");
243 }
244
245 // iterate statically on all event sources
246 using boost::mpl::_1;
247 using wrappedList = typename boost::mpl::transform<TInputEventList, _1>::type;
248 AddTEventTypeStateReactorInfo<TInputEventList> op(srinfo.get());
249 boost::mpl::for_each<wrappedList>(op);
250
251 srinfo->srh = srh;
252 srh->srInfo_ = srinfo;
253
254 const std::type_info * tindex = &(typeid(MostDerived)); // get identifier of the current state
255
256 if (!SmaccStateInfo::stateReactorsInfo.count(tindex))
258 std::vector<std::shared_ptr<SmaccStateReactorInfo>>();
259
260 srinfo->factoryFunction = [&, srh, args...](ISmaccState * state)
261 {
262 auto sr =
263 state->createStateReactor<TStateReactor, TOutputEvent, TInputEventList, TArgs...>(args...);
264 srh->configureStateReactor(sr);
265 sr->initialize(state);
266 return sr;
267 };
268
269 SmaccStateInfo::stateReactorsInfo[tindex].push_back(srinfo);
270
271 return srh;
272 }
rclcpp::Node::SharedPtr globalNh_

References smacc2::introspection::TypeInfo::getTypeInfoFromType(), smacc2::introspection::globalNh_, and smacc2::introspection::SmaccStateInfo::stateReactorsInfo.

Here is the call graph for this function:

◆ static_createStateReactor_aux()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
template<typename TStateReactor , typename... TUArgs>
static std::shared_ptr< smacc2::introspection::StateReactorHandler > smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::static_createStateReactor_aux ( TUArgs... args)
inlinestatic

Definition at line 306 of file smacc_state_base.hpp.

308 {
309 auto srh = std::make_shared<smacc2::introspection::StateReactorHandler>(globalNh_);
310 auto srinfo = std::make_shared<SmaccStateReactorInfo>();
311
312 srinfo->stateReactorType = TypeInfo::getTypeInfoFromType<TStateReactor>();
313 srinfo->srh = srh;
314 srh->srInfo_ = srinfo;
315
316 const std::type_info * tindex = &(typeid(MostDerived)); // get identifier of the current state
317
318 if (!SmaccStateInfo::stateReactorsInfo.count(tindex))
320 std::vector<std::shared_ptr<SmaccStateReactorInfo>>();
321
322 srinfo->factoryFunction = [&, srh, args...](ISmaccState * state)
323 {
324 auto sr = state->createStateReactor<TStateReactor>(args...);
325 srh->configureStateReactor(sr);
326 sr->initialize(state);
327 return sr;
328 };
329
330 SmaccStateInfo::stateReactorsInfo[tindex].push_back(srinfo);
331
332 return srh;
333 }

References smacc2::introspection::TypeInfo::getTypeInfoFromType(), smacc2::introspection::globalNh_, and smacc2::introspection::SmaccStateInfo::stateReactorsInfo.

Here is the call graph for this function:

◆ throwSequenceFinishedEvent()

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
void smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::throwSequenceFinishedEvent ( )
inline

Definition at line 353 of file smacc_state_base.hpp.

References smacc2::ISmaccState::postEvent().

Here is the call graph for this function:

Member Data Documentation

◆ finishStateThrown

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
bool smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::finishStateThrown

◆ smacc_inner_type

template<class MostDerived , class Context , class InnerInitial = mpl::list<>, sc::history_mode historyMode = sc::has_deep_history>
InnerInitial* smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::smacc_inner_type

Definition at line 71 of file smacc_state_base.hpp.


The documentation for this class was generated from the following file: