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

virtual ISmaccStateMachinegetStateMachine ()=0
 
virtual std::string getName ()=0
 
ISmaccStategetParentState ()
 
rclcpp::Node::SharedPtr & getNode ()
 
rclcpp::Logger getLogger ()
 
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)
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename T >
bool getGlobalSMData (std::string name, T &ret)
 
template<typename T >
void setGlobalSMData (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_
 
ISmaccStateparentState_
 
const smacc2::introspection::SmaccStateInfostateInfo_
 

Detailed Description

Definition at line 25 of file smacc_state.hpp.

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 auto clientBehavior =
45 std::shared_ptr<TBehavior>(new TBehavior(args...)); // is there an error here? are the
46 // behavior constructor parameters right?
47 orthogonal->addClientBehavior(clientBehavior);
48 clientBehavior->template onStateOrthogonalAllocation<TOrthogonal, TBehavior>();
49 return clientBehavior;
50 }
51 else
52 {
53 RCLCPP_ERROR(
54 getLogger(), "[%s] Skipping client behavior creation in orthogonal [%s]. It does not exist.",
55 THIS_STATE_NAME, orthogonalkey.c_str());
56 return nullptr;
57 }
58}
rclcpp::Logger getLogger()
TOrthogonal * getOrthogonal()
std::string demangledTypeName()
#define THIS_STATE_NAME

References smacc2::introspection::demangledTypeName(), getLogger(), getOrthogonal(), 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 112 of file smacc_state_impl.hpp.

113{
114 auto eg = std::make_shared<TEventGenerator>(args...);
115 eventGenerators_.push_back(eg);
116 return eg;
117}
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 151 of file smacc_state_impl.hpp.

152{
153 auto sr = std::make_shared<TStateReactor>(args...);
154 sr->initialize(this);
155 sr->template setOutputEvent<TTriggerEvent>();
156
157 using boost::mpl::_1;
158 using wrappedList = typename boost::mpl::transform<TEventList, _1>::type;
159 AddTEventTypeStateReactor<TEventList> op(sr.get());
160 boost::mpl::for_each<wrappedList>(op);
161
162 stateReactors_.push_back(sr);
163 return sr;
164}
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 104 of file smacc_state_impl.hpp.

105{
106 auto sr = std::make_shared<TStateReactor>(args...);
107 stateReactors_.push_back(sr);
108 return sr;
109}

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::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 173 of file smacc_state_impl.hpp.

174{
175 return this->getStateMachine().getClientBehavior<TOrthogonal, TClientBehavior>(index);
176}
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 179 of file smacc_state_impl.hpp.

180{
181 TEventGenerator * ret = nullptr;
182 for (auto & evg : this->eventGenerators_)
183 {
184 ret = dynamic_cast<TEventGenerator *>(evg.get());
185 if (ret != nullptr) break;
186 }
187 return ret;
188}

References eventGenerators_.

◆ getEventGenerators()

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

Definition at line 82 of file smacc_state.hpp.

83 {
84 return eventGenerators_;
85 }

References eventGenerators_.

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

Here is the caller graph for this function:

◆ getGlobalSMData()

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

Definition at line 89 of file smacc_state_impl.hpp.

90{
91 return this->getStateMachine().getGlobalSMData(name, ret);
92}
bool getGlobalSMData(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 34 of file smacc_state.hpp.

34{ 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 167 of file smacc_state_impl.hpp.

168{
169 return this->getStateMachine().getOrthogonal<TOrthogonal>();
170}

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 32 of file smacc_state.hpp.

32{ 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 191 of file smacc_state_impl.hpp.

192{
193 TStateReactor * ret = nullptr;
194 for (auto & sr : this->eventGenerators_)
195 {
196 ret = dynamic_cast<TStateReactor *>(sr.get());
197 if (ret != nullptr) break;
198 }
199 return ret;
200}

References eventGenerators_.

◆ getStateReactors()

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

Definition at line 80 of file smacc_state.hpp.

80{ return stateReactors_; }

References stateReactors_.

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

Here is the caller graph for this function:

◆ notifyTransition()

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

Definition at line 218 of file smacc_state_impl.hpp.

219{
220 auto transitionType = TypeInfo::getTypeInfoFromType<TransitionType>();
221 this->notifyTransitionFromTransitionTypeInfo(transitionType);
222}
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 std::stringstream ss;
57
58 auto stateinfo = currstateinfo;
59
60 for (auto & transition : currstateinfo->transitions_)
61 {
62 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
63 RCLCPP_ERROR_STREAM(getLogger(), "- candidate transition: " << transitionCandidateName);
64 }
65
66 RCLCPP_ERROR(getLogger(), "Ancestors candidates: ");
67
68 std::list<const SmaccStateInfo *> ancestors;
69 stateinfo->getAncestors(ancestors);
70
71 for (auto & ancestor : ancestors)
72 {
73 RCLCPP_ERROR_STREAM(getLogger(), " * Ancestor " << ancestor->getDemangledFullName() << ":");
74 for (auto & transition : ancestor->transitions_)
75 {
76 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
77 RCLCPP_ERROR_STREAM(getLogger(), "- candidate transition: " << transitionCandidateName);
78 if (transitionType->getFullName() == transitionCandidateName)
79 {
80 RCLCPP_ERROR(getLogger(), "GOTCHA");
81 }
82 }
83 }
84 }
85 else
86 {
87 RCLCPP_ERROR_STREAM(
88 getLogger(), "Transition happened, but current state was not set. Transition candidates:");
89 }
90}
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:

◆ postEvent() [1/2]

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

Definition at line 211 of file smacc_state_impl.hpp.

212{
213 getStateMachine().postEvent<EventType>();
214}
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 205 of file smacc_state_impl.hpp.

206{
208}

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 69 of file smacc_state_impl.hpp.

70{
71 const char * sname = (demangleSymbol(typeid(*this).name()).c_str());
72 storage = nullptr;
73 auto & orthogonals = this->getStateMachine().getOrthogonals();
74 for (auto & ortho : orthogonals)
75 {
76 ortho.second->requiresClient(storage);
77 if (storage != nullptr) return;
78 }
79
80 RCLCPP_ERROR(
81 getLogger(),
82 "[%s] Client of type '%s' not found in any orthogonal of the current state machine. This may "
83 "produce a segmentation fault if the returned reference is used.",
84 sname, demangleSymbol<SmaccClientType>().c_str());
85}
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()

template<typename SmaccComponentType >
void smacc2::ISmaccState::requiresComponent ( SmaccComponentType *& storage)

Definition at line 62 of file smacc_state_impl.hpp.

63{
64 this->getStateMachine().requiresComponent(storage);
65}
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType)

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

Here is the call graph for this function:

◆ setGlobalSMData()

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

Definition at line 97 of file smacc_state_impl.hpp.

98{
99 this->getStateMachine().setGlobalSMData(name, value);
100}
void setGlobalSMData(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

◆ 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 105 of file smacc_state.hpp.

Referenced by createStateReactor(), and getStateReactors().


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