SMACC2
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
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 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 39 of file smacc_state_impl.hpp.

40{
41 std::string orthogonalkey = demangledTypeName<TOrthogonal>();
42 RCLCPP_INFO(
43 getLogger(), "[%s] Configuring orthogonal: %s", THIS_STATE_NAME, orthogonalkey.c_str());
44
45 TOrthogonal * orthogonal = this->getOrthogonal<TOrthogonal>();
46 if (orthogonal != nullptr)
47 {
48 auto clientBehavior = std::shared_ptr<TBehavior>(new TBehavior(args...));
49 clientBehavior->currentState = this;
50 orthogonal->addClientBehavior(clientBehavior);
51 clientBehavior->template onOrthogonalAllocation<TOrthogonal, TBehavior>();
52 return clientBehavior;
53 }
54 else
55 {
56 RCLCPP_ERROR(
57 getLogger(), "[%s] Skipping client behavior creation in orthogonal [%s]. It does not exist.",
58 THIS_STATE_NAME, orthogonalkey.c_str());
59 return nullptr;
60 }
61}
rclcpp::Logger getLogger()
Definition: smacc_state.hpp:36
#define THIS_STATE_NAME

References getLogger(), and THIS_STATE_NAME.

Referenced by smacc2::SmaccState< MostDerived, Context, InnerInitial, historyMode >::configure_orthogonal(), 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 117 of file smacc_state_impl.hpp.

118{
119 auto eg = std::make_shared<TEventGenerator>(args...);
120 eventGenerators_.push_back(eg);
121 return eg;
122}
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 156 of file smacc_state_impl.hpp.

157{
158 auto sr = std::make_shared<TStateReactor>(args...);
159 sr->initialize(this);
160 sr->template setOutputEvent<TTriggerEvent>();
161
162 using boost::mpl::_1;
163 using wrappedList = typename boost::mpl::transform<TEventList, _1>::type;
164 AddTEventTypeStateReactor<TEventList> op(sr.get());
165 boost::mpl::for_each<wrappedList>(op);
166
167 stateReactors_.push_back(sr);
168 return sr;
169}
std::vector< std::shared_ptr< StateReactor > > stateReactors_
Definition: smacc_state.hpp:99

References stateReactors_.

◆ createStateReactor() [2/2]

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

Definition at line 107 of file smacc_state_impl.hpp.

108{
109 auto sr = std::make_shared<TStateReactor>(args...);
110 //sb->initialize(this, mock);
111 //sb->setOutputEvent(typelist<TTriggerEvent>());
112 stateReactors_.push_back(sr);
113 return sr;
114}

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:

◆ getEventGenerator()

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

Definition at line 178 of file smacc_state_impl.hpp.

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

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

93{
94 return this->getStateMachine().getGlobalSMData(name, ret);
95}
bool getGlobalSMData(std::string name, T &ret)
virtual ISmaccStateMachine & getStateMachine()=0

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

Here is the call graph for this function:

◆ getLogger()

rclcpp::Logger smacc2::ISmaccState::getLogger ( )
inline

◆ getName()

virtual std::string smacc2::ISmaccState::getName ( )
pure virtual

◆ getNode()

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

Definition at line 34 of file smacc_state.hpp.

34{ return node_; }
rclcpp::Node::SharedPtr node_
Definition: smacc_state.hpp:97

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

173{
174 return this->getStateMachine().getOrthogonal<TOrthogonal>();
175}

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

Here is the call 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()

virtual ISmaccStateMachine & smacc2::ISmaccState::getStateMachine ( )
pure virtual

◆ getStateReactor()

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

Definition at line 190 of file smacc_state_impl.hpp.

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

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

228{
229 auto transitionType = TypeInfo::getTypeInfoFromType<TransitionType>();
230 this->notifyTransitionFromTransitionTypeInfo(transitionType);
231}
void notifyTransitionFromTransitionTypeInfo(std::shared_ptr< smacc2::introspection::TypeInfo > &transitionTypeInfo)
Definition: smacc_state.cpp:28

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

221{
222 getStateMachine().postEvent<EventType>();
223}
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)

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

Here is the call graph for this function:

◆ postEvent() [2/2]

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

Definition at line 214 of file smacc_state_impl.hpp.

215{
217}

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

Referenced by smacc2::SmaccEventGenerator::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 72 of file smacc_state_impl.hpp.

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

66{
67 this->getStateMachine().requiresComponent(storage);
68}
void requiresComponent(SmaccComponentType *&storage, bool throwsException=false)

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,
value 
)

Definition at line 100 of file smacc_state_impl.hpp.

101{
102 this->getStateMachine().setGlobalSMData(name, value);
103}
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_

ISmaccState* smacc2::ISmaccState::parentState_
protected

◆ stateInfo_

const smacc2::introspection::SmaccStateInfo* smacc2::ISmaccState::stateInfo_
protected

◆ stateReactors_

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

Definition at line 99 of file smacc_state.hpp.

Referenced by createStateReactor(), and getStateReactors().


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