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< TBehaviorconfigure (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< TStateReactorcreateStateReactor (TEvArgs... args)
 
template<typename TStateReactor , typename... TEvArgs>
std::shared_ptr< TStateReactorcreateStateReactor (TEvArgs... args)
 
template<typename TEventGenerator , typename... TEvArgs>
std::shared_ptr< TEventGeneratorcreateEventGenerator (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 >
TOrthogonalgetOrthogonal ()
 
template<typename TOrthogonal , typename TClientBehavior >
TClientBehaviorgetClientBehavior (int index=0)
 
template<typename TEventGenerator >
TEventGeneratorgetEventGenerator ()
 
template<typename TStateReactor >
TStateReactorgetStateReactor ()
 

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

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

References getLogger(), and THIS_STATE_NAME.

Here is the call graph for this function:

◆ createEventGenerator()

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

Definition at line 116 of file smacc_state_impl.hpp.

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

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

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

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().

Here is the call graph for this function:

◆ getClientBehavior()

TClientBehavior * smacc2::ISmaccState::getClientBehavior ( int  index = 0)

Definition at line 177 of file smacc_state_impl.hpp.

178{
179 return this->getStateMachine().getClientBehavior<TOrthogonal, TClientBehavior>(index);
180}
virtual ISmaccStateMachine & getStateMachine()=0

References getStateMachine().

Here is the call graph for this function:

◆ getEventGenerator()

TEventGenerator * smacc2::ISmaccState::getEventGenerator ( )

Definition at line 183 of file smacc_state_impl.hpp.

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

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

92{
93 return this->getStateMachine().getGlobalSMData(name, ret);
94}

References 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_

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

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

References getStateMachine().

Referenced by 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_.

◆ getStateMachine()

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

◆ getStateReactor()

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

Definition at line 195 of file smacc_state_impl.hpp.

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

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().

Here is the caller graph for this function:

◆ notifyTransition()

void smacc2::ISmaccState::notifyTransition ( )

Definition at line 232 of file smacc_state_impl.hpp.

233{
234 auto transitionType = TypeInfo::getTypeInfoFromType<TransitionType>();
235 this->notifyTransitionFromTransitionTypeInfo(transitionType);
236}
void notifyTransitionFromTransitionTypeInfo(std::shared_ptr< smacc2::introspection::TypeInfo > &transitionTypeInfo)

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}
const smacc2::introspection::SmaccStateInfo * stateInfo_

References getLogger(), getStateMachine(), 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 225 of file smacc_state_impl.hpp.

226{
227 getStateMachine().postEvent<EventType>();
228}

References getStateMachine().

Here is the call graph for this function:

◆ postEvent() [2/2]

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

Definition at line 219 of file smacc_state_impl.hpp.

220{
221 getStateMachine().postEvent(ev);
222}

References getStateMachine().

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

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

◆ requiresClient()

void smacc2::ISmaccState::requiresClient ( SmaccClientType *&  storage)

Definition at line 71 of file smacc_state_impl.hpp.

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

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

Here is the call graph for this function:

◆ requiresComponent()

void smacc2::ISmaccState::requiresComponent ( SmaccComponentType *&  storage)

Definition at line 64 of file smacc_state_impl.hpp.

65{
66 this->getStateMachine().requiresComponent(storage);
67}

References getStateMachine().

Here is the call graph for this function:

◆ setGlobalSMData()

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

Definition at line 99 of file smacc_state_impl.hpp.

100{
101 this->getStateMachine().setGlobalSMData(name, value);
102}

References getStateMachine().

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

Referenced by createStateReactor(), and getStateReactors().


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