SMACC2
Loading...
Searching...
No Matches
smacc2::ISmaccState Class Referenceabstract

#include <smacc_state.hpp>

Inheritance diagram for smacc2::ISmaccState:
Inheritance graph
Collaboration diagram for smacc2::ISmaccState:
Collaboration graph

Public Member Functions

 ISmaccState ()=default
 
virtual ~ISmaccState ()=default
 
 ISmaccState (const ISmaccState &)=delete
 
ISmaccState & operator= (const ISmaccState &)=delete
 
 ISmaccState (ISmaccState &&)=delete
 
ISmaccState & operator= (ISmaccState &&)=delete
 
virtual ISmaccStateMachine & getStateMachine ()=0
 
virtual std::string getName ()=0
 
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 ()
 

Protected Attributes

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

Definition at line 25 of file smacc_state.hpp.

Constructor & Destructor Documentation

◆ ISmaccState() [1/3]

smacc2::ISmaccState::ISmaccState ( )
default

◆ ~ISmaccState()

virtual smacc2::ISmaccState::~ISmaccState ( )
virtualdefault

◆ ISmaccState() [2/3]

smacc2::ISmaccState::ISmaccState ( const ISmaccState & )
delete

◆ ISmaccState() [3/3]

smacc2::ISmaccState::ISmaccState ( ISmaccState && )
delete

Member Function Documentation

◆ configure()

template<typename TOrthogonal , typename TBehavior , typename... Args>
std::shared_ptr< TBehavior > smacc2::ISmaccState::configure ( Args &&... args)

Definition at line 35 of file smacc_state_impl.hpp.

36{
37 std::string orthogonalkey = demangledTypeName<TOrthogonal>();
38 RCLCPP_INFO(
39 getLogger(), "[%s] Configuring orthogonal: %s", THIS_STATE_NAME, orthogonalkey.c_str());
40
41 TOrthogonal * orthogonal = this->getOrthogonal<TOrthogonal>();
42 if (orthogonal != nullptr)
43 {
44 // A compile error here usually means the behavior's constructor parameters do not match.
45 auto clientBehavior = std::make_shared<TBehavior>(args...);
46 orthogonal->addClientBehavior(clientBehavior);
47 clientBehavior->template onStateOrthogonalAllocation<TOrthogonal, TBehavior>();
48 // Set here and not in onStateOrthogonalAllocation, which a derived behavior may hide.
49 ISmaccClientBehavior * behavior = clientBehavior.get();
50 behavior->postInitializationFailureEventFn_ = [behavior](const std::string & what)
51 {
53 ev->behaviorName = behavior->getName();
54 ev->what = what;
55 behavior->postEvent(ev);
56 };
57 return clientBehavior;
58 }
59 else
60 {
61 RCLCPP_ERROR(
62 getLogger(), "[%s] Skipping client behavior creation in orthogonal [%s]. It does not exist.",
63 THIS_STATE_NAME, orthogonalkey.c_str());
64 return nullptr;
65 }
66}
rclcpp::Logger getLogger()
TOrthogonal * getOrthogonal()
std::string demangledTypeName()
boost::intrusive_ptr< EventType > makeEvent(Args &&... args)
#define THIS_STATE_NAME

References smacc2::introspection::demangledTypeName(), getLogger(), smacc2::ISmaccClientBehavior::getName(), getOrthogonal(), smacc2::makeEvent(), smacc2::ISmaccClientBehavior::postEvent(), smacc2::ISmaccClientBehavior::postInitializationFailureEventFn_, and THIS_STATE_NAME.

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:

◆ createEventGenerator()

template<typename TEventGenerator , typename... TEvArgs>
std::shared_ptr< TEventGenerator > smacc2::ISmaccState::createEventGenerator ( TEvArgs... args)

Definition at line 131 of file smacc_state_impl.hpp.

132{
133 auto eg = std::make_shared<TEventGenerator>(args...);
134 eventGenerators_.push_back(eg);
135 return eg;
136}
std::vector< std::shared_ptr< smacc2::SmaccEventGenerator > > eventGenerators_

References eventGenerators_.

◆ createStateReactor() [1/2]

template<typename TStateReactor , typename TTriggerEvent , typename TEventList , typename... TEvArgs>
std::shared_ptr< TStateReactor > smacc2::ISmaccState::createStateReactor ( TEvArgs... args)

Definition at line 170 of file smacc_state_impl.hpp.

171{
172 auto sr = std::make_shared<TStateReactor>(args...);
173 sr->initialize(this);
174 sr->template setOutputEvent<TTriggerEvent>();
175
176 using boost::mpl::_1;
177 using wrappedList = typename boost::mpl::transform<TEventList, _1>::type;
178 AddTEventTypeStateReactor<TEventList> op(sr.get());
179 boost::mpl::for_each<wrappedList>(op);
180
181 stateReactors_.push_back(sr);
182 return sr;
183}
std::vector< std::shared_ptr< StateReactor > > stateReactors_

References stateReactors_.

◆ createStateReactor() [2/2]

template<typename TStateReactor , typename... TEvArgs>
std::shared_ptr< TStateReactor > smacc2::ISmaccState::createStateReactor ( TEvArgs... args)

Definition at line 123 of file smacc_state_impl.hpp.

124{
125 auto sr = std::make_shared<TStateReactor>(args...);
126 stateReactors_.push_back(sr);
127 return sr;
128}

References stateReactors_.

◆ getClassName()

std::string smacc2::ISmaccState::getClassName ( )
virtual

Definition at line 26 of file smacc_state.cpp.

26{ return demangleSymbol(typeid(*this).name()); }
std::string demangleSymbol()

References smacc2::introspection::demangleSymbol().

Referenced by smacc2::ISmaccClientBehavior::getTraceStateName(), smacc2::ISmaccOrthogonal::initState(), and smacc2::ISmaccStateMachine::propagateEventToStateReactors().

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

◆ getClientBehavior()

template<typename TOrthogonal , typename TClientBehavior >
TClientBehavior * smacc2::ISmaccState::getClientBehavior ( int index = 0)

Definition at line 192 of file smacc_state_impl.hpp.

193{
194 return this->getStateMachine().getClientBehavior<TOrthogonal, TClientBehavior>(index);
195}
TClientBehavior * getClientBehavior(int index=0)
virtual ISmaccStateMachine & getStateMachine()=0

References smacc2::ISmaccStateMachine::getClientBehavior(), and getStateMachine().

Here is the call graph for this function:

◆ getEventGenerator()

template<typename TEventGenerator >
TEventGenerator * smacc2::ISmaccState::getEventGenerator ( )

Definition at line 198 of file smacc_state_impl.hpp.

199{
200 TEventGenerator * ret = nullptr;
201 for (auto & evg : this->eventGenerators_)
202 {
203 ret = dynamic_cast<TEventGenerator *>(evg.get());
204 if (ret != nullptr) break;
205 }
206 return ret;
207}

References eventGenerators_.

◆ getEventGenerators()

std::vector< std::shared_ptr< SmaccEventGenerator > > & smacc2::ISmaccState::getEventGenerators ( )
inline

Definition at line 106 of file smacc_state.hpp.

107 {
108 return eventGenerators_;
109 }

References eventGenerators_.

Referenced by smacc2::SignalDetector::findUpdatableStateElements().

Here is the caller graph for this function:

◆ getGlobalSMData()

template<typename T >
bool smacc2::ISmaccState::getGlobalSMData ( const std::string & name,
T & ret )

Definition at line 108 of file smacc_state_impl.hpp.

109{
110 return this->getStateMachine().getGlobalSMData(name, ret);
111}
bool getGlobalSMData(const std::string &name, T &ret)

References smacc2::ISmaccStateMachine::getGlobalSMData(), and getStateMachine().

Here is the call graph for this function:

◆ getLogger()

◆ getName()

◆ getNode()

rclcpp::Node::SharedPtr & smacc2::ISmaccState::getNode ( )
inline

Definition at line 44 of file smacc_state.hpp.

44{ return node_; }
rclcpp::Node::SharedPtr node_

References node_.

Referenced by smacc2::StateReactor::getNode().

Here is the caller graph for this function:

◆ getOrthogonal()

template<typename TOrthogonal >
TOrthogonal * smacc2::ISmaccState::getOrthogonal ( )

Definition at line 186 of file smacc_state_impl.hpp.

187{
188 return this->getStateMachine().getOrthogonal<TOrthogonal>();
189}

References smacc2::ISmaccStateMachine::getOrthogonal(), and getStateMachine().

Referenced by configure(), and smacc2::client_behaviors::CbSequence::then().

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

◆ getParentState()

ISmaccState * smacc2::ISmaccState::getParentState ( )
inline

Definition at line 42 of file smacc_state.hpp.

42{ return parentState_; }
ISmaccState * parentState_

References parentState_.

Referenced by smacc2::ISmaccStateMachine::propagateEventToStateReactors().

Here is the caller graph for this function:

◆ getStateMachine()

◆ getStateReactor()

template<typename TStateReactor >
TStateReactor * smacc2::ISmaccState::getStateReactor ( )

Definition at line 210 of file smacc_state_impl.hpp.

211{
212 TStateReactor * ret = nullptr;
213 for (auto & sr : this->eventGenerators_)
214 {
215 ret = dynamic_cast<TStateReactor *>(sr.get());
216 if (ret != nullptr) break;
217 }
218 return ret;
219}

References eventGenerators_.

◆ getStateReactors()

std::vector< std::shared_ptr< StateReactor > > & smacc2::ISmaccState::getStateReactors ( )
inline

Definition at line 104 of file smacc_state.hpp.

104{ return stateReactors_; }

References stateReactors_.

Referenced by smacc2::SignalDetector::findUpdatableStateElements(), and smacc2::ISmaccStateMachine::propagateEventToStateReactors().

Here is the caller graph for this function:

◆ initializationFailed()

bool smacc2::ISmaccState::initializationFailed ( ) const
inline

Definition at line 48 of file smacc_state.hpp.

References initializationFailed_.

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

Here is the caller graph for this function:

◆ notifyTransition()

template<typename TransitionType >
void smacc2::ISmaccState::notifyTransition ( )

Definition at line 237 of file smacc_state_impl.hpp.

238{
239 auto transitionType = TypeInfo::getTypeInfoFromType<TransitionType>();
240 this->notifyTransitionFromTransitionTypeInfo(transitionType);
241}
void notifyTransitionFromTransitionTypeInfo(std::shared_ptr< smacc2::introspection::TypeInfo > &transitionTypeInfo)
static TypeInfo::Ptr getTypeInfoFromType()

References smacc2::introspection::TypeInfo::getTypeInfoFromType(), and notifyTransitionFromTransitionTypeInfo().

Here is the call graph for this function:

◆ notifyTransitionFromTransitionTypeInfo()

void smacc2::ISmaccState::notifyTransitionFromTransitionTypeInfo ( std::shared_ptr< smacc2::introspection::TypeInfo > & transitionTypeInfo)

Definition at line 28 of file smacc_state.cpp.

29{
30 RCLCPP_INFO_STREAM(getLogger(), "TRANSITION RULE TRIGGERED: " << transitionType->getFullName());
31
32 auto currstateinfo = this->stateInfo_;
33
34 if (currstateinfo != nullptr)
35 {
36 //RCLCPP_ERROR_STREAM(getLogger(),"CURRENT STATE INFO: " << currstateinfo->fullStateName);
37 for (auto & transition : currstateinfo->transitions_)
38 {
39 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
40 //RCLCPP_ERROR_STREAM(getLogger(),"candidate transition: " << transitionCandidateName);
41
42 if (transitionType->getFullName() == transitionCandidateName)
43 {
44 this->getStateMachine().publishTransition(transition);
45 return;
46 }
47 }
48
49 // debug information if not found
50 RCLCPP_ERROR_STREAM(
51 getLogger(),
52 "Transition happened, from current state "
53 << currstateinfo->getDemangledFullName()
54 << " but there is not any transitioninfo match available to publish transition: "
55 << transitionType->getFullName());
56
57 auto stateinfo = currstateinfo;
58
59 for (auto & transition : currstateinfo->transitions_)
60 {
61 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
62 RCLCPP_ERROR_STREAM(getLogger(), "- candidate transition: " << transitionCandidateName);
63 }
64
65 RCLCPP_ERROR(getLogger(), "Ancestors candidates: ");
66
67 std::list<const SmaccStateInfo *> ancestors;
68 stateinfo->getAncestors(ancestors);
69
70 for (auto & ancestor : ancestors)
71 {
72 RCLCPP_ERROR_STREAM(getLogger(), " * Ancestor " << ancestor->getDemangledFullName() << ":");
73 for (auto & transition : ancestor->transitions_)
74 {
75 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
76 RCLCPP_ERROR_STREAM(getLogger(), "- candidate transition: " << transitionCandidateName);
77 if (transitionType->getFullName() == transitionCandidateName)
78 {
79 RCLCPP_ERROR(getLogger(), "GOTCHA");
80 }
81 }
82 }
83 }
84 else
85 {
86 RCLCPP_ERROR_STREAM(
87 getLogger(), "Transition happened, but current state was not set. Transition candidates:");
88 }
89}
void publishTransition(const SmaccTransitionInfo &transitionInfo)
const smacc2::introspection::SmaccStateInfo * stateInfo_

References getLogger(), getStateMachine(), smacc2::ISmaccStateMachine::publishTransition(), and stateInfo_.

Referenced by notifyTransition().

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

◆ operator=() [1/2]

ISmaccState & smacc2::ISmaccState::operator= ( const ISmaccState & )
delete

◆ operator=() [2/2]

ISmaccState & smacc2::ISmaccState::operator= ( ISmaccState && )
delete

◆ postEvent() [1/2]

template<typename EventType >
void smacc2::ISmaccState::postEvent ( )

Definition at line 230 of file smacc_state_impl.hpp.

231{
232 getStateMachine().postEvent<EventType>();
233}
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)

References getStateMachine(), and smacc2::ISmaccStateMachine::postEvent().

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

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

◆ postEvent() [2/2]

template<typename EventType >
void smacc2::ISmaccState::postEvent ( const EventType & ev)

Definition at line 224 of file smacc_state_impl.hpp.

225{
227}

References getStateMachine(), and smacc2::ISmaccStateMachine::postEvent().

Referenced by smacc2::SmaccEventGenerator::postEvent(), smacc2::SmaccEventGenerator::postEvent(), smacc2::StateReactor::postEvent(), and smacc2::StateReactor::postEvent().

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

◆ requiresClient()

template<typename SmaccClientType >
void smacc2::ISmaccState::requiresClient ( SmaccClientType *& storage)

Definition at line 85 of file smacc_state_impl.hpp.

86{
87 storage = nullptr;
88 auto & orthogonals = this->getStateMachine().getOrthogonals();
89 for (auto & ortho : orthogonals)
90 {
91 ortho.second->requiresClient(storage);
92 if (storage != nullptr) return;
93 }
94
95 // Keep the std::string alive across the log call. This used to take c_str() of the temporary
96 // returned by demangleSymbol into a const char *, which read freed memory here. The name is
97 // only needed on this path, so it is demangled here rather than on every lookup.
98 const std::string sname = demangleSymbol(typeid(*this).name());
99 RCLCPP_ERROR(
100 getLogger(),
101 "[%s] Client of type '%s' not found in any orthogonal of the current state machine. This may "
102 "produce a segmentation fault if the returned reference is used.",
103 sname.c_str(), demangleSymbol<SmaccClientType>().c_str());
104}
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & getOrthogonals() const

References smacc2::introspection::demangleSymbol(), getLogger(), smacc2::ISmaccStateMachine::getOrthogonals(), and getStateMachine().

Here is the call graph for this function:

◆ requiresComponent() [1/2]

template<typename SmaccComponentType >
void smacc2::ISmaccState::requiresComponent ( const std::string & name,
SmaccComponentType *& storage,
ComponentRequirement requirementType = ComponentRequirement::SOFT )

Definition at line 77 of file smacc_state_impl.hpp.

79{
80 this->getStateMachine().requiresComponent(name, storage, requirementType);
81}
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType, ISmaccOrthogonal *first=nullptr)

References getStateMachine(), and smacc2::ISmaccStateMachine::requiresComponent().

Here is the call graph for this function:

◆ requiresComponent() [2/2]

template<typename SmaccComponentType >
void smacc2::ISmaccState::requiresComponent ( SmaccComponentType *& storage,
ComponentRequirement requirementType = ComponentRequirement::SOFT )

Definition at line 70 of file smacc_state_impl.hpp.

72{
73 this->getStateMachine().requiresComponent(storage, requirementType);
74}

References getStateMachine(), and smacc2::ISmaccStateMachine::requiresComponent().

Here is the call graph for this function:

◆ setGlobalSMData()

template<typename T >
void smacc2::ISmaccState::setGlobalSMData ( const std::string & name,
T value )

Definition at line 116 of file smacc_state_impl.hpp.

117{
118 this->getStateMachine().setGlobalSMData(name, value);
119}
void setGlobalSMData(const std::string &name, T value)

References getStateMachine(), and smacc2::ISmaccStateMachine::setGlobalSMData().

Here is the call graph for this function:

Member Data Documentation

◆ eventGenerators_

std::vector<std::shared_ptr<smacc2::SmaccEventGenerator> > smacc2::ISmaccState::eventGenerators_
protected

◆ initializationFailed_

◆ logger_

std::shared_ptr<rclcpp::Logger> smacc2::ISmaccState::logger_
protected

◆ node_

rclcpp::Node::SharedPtr smacc2::ISmaccState::node_
protected

◆ parentState_

◆ stateInfo_

◆ stateReactors_

std::vector<std::shared_ptr<StateReactor> > smacc2::ISmaccState::stateReactors_
protected

Definition at line 129 of file smacc_state.hpp.

Referenced by createStateReactor(), and getStateReactors().


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