SMACC
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
smacc::ISmaccState Class Referenceabstract

#include <smacc_state.h>

Inheritance diagram for smacc::ISmaccState:
Inheritance graph
Collaboration diagram for smacc::ISmaccState:
Collaboration graph

Public Member Functions

virtual ISmaccStateMachinegetStateMachine ()=0
 
ISmaccStategetParentState ()
 
ros::NodeHandle & getROSNode ()
 
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< smacc::introspection::TypeInfo > &transitionTypeInfo)
 
std::vector< std::shared_ptr< StateReactor > > & getStateReactors ()
 
std::vector< std::shared_ptr< SmaccEventGenerator > > & getEventGenerators ()
 
template<typename T >
bool getParam (std::string param_name, T &param_storage)
 
template<typename T >
void setParam (std::string param_name, T param_val)
 
template<typename T >
bool param (std::string param_name, T &param_val, const T &default_val) const
 
template<typename TOrthogonal >
TOrthogonal * getOrthogonal ()
 
template<typename TEventGenerator >
TEventGenerator * getEventGenerator ()
 
template<typename TStateReactor >
TStateReactor * getStateReactor ()
 

Protected Attributes

std::vector< std::shared_ptr< StateReactor > > stateReactors_
 
std::vector< std::shared_ptr< smacc::SmaccEventGenerator > > eventGenerators_
 
ros::NodeHandle nh
 
ros::NodeHandle contextNh
 
ISmaccStateparentState_
 
const smacc::introspection::SmaccStateInfostateInfo_
 

Detailed Description

Definition at line 11 of file smacc_state.h.

Member Function Documentation

◆ configure()

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

Definition at line 48 of file smacc_state_impl.h.

49 {
50 std::string orthogonalkey = demangledTypeName<TOrthogonal>();
51 ROS_INFO("[%s] Configuring orthogonal: %s", THIS_STATE_NAME, orthogonalkey.c_str());
52
53 TOrthogonal *orthogonal = this->getOrthogonal<TOrthogonal>();
54 if (orthogonal != nullptr)
55 {
56 auto clientBehavior = std::shared_ptr<TBehavior>(new TBehavior(args...));
57 clientBehavior->currentState = this;
58 orthogonal->addClientBehavior(clientBehavior);
59 clientBehavior->template onOrthogonalAllocation<TOrthogonal, TBehavior>();
60 return clientBehavior;
61 }
62 else
63 {
64 ROS_ERROR("[%s] Skipping client behavior creation in orthogonal [%s]. It does not exist.", THIS_STATE_NAME, orthogonalkey.c_str());
65 return nullptr;
66 }
67 }
#define THIS_STATE_NAME

References THIS_STATE_NAME.

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

Here is the caller graph for this function:

◆ createEventGenerator()

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

Definition at line 120 of file smacc_state_impl.h.

121 {
122 auto eg = std::make_shared<TEventGenerator>(args...);
123 eventGenerators_.push_back(eg);
124 return eg;
125 }
std::vector< std::shared_ptr< smacc::SmaccEventGenerator > > eventGenerators_
Definition: smacc_state.h:87

References eventGenerators_.

◆ createStateReactor() [1/2]

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

Definition at line 143 of file smacc_state_impl.h.

144 {
145 auto sr = std::make_shared<TStateReactor>(args...);
146 TEventList *mock;
147 sr->initialize(this);
148 sr->template setOutputEvent<TTriggerEvent>();
149
150 using boost::mpl::_1;
151 using wrappedList = typename boost::mpl::transform<TEventList, _1>::type;
152 AddTEventType<TEventList> op(sr.get());
153 boost::mpl::for_each<wrappedList>(op);
154
155 stateReactors_.push_back(sr);
156 return sr;
157 }
std::vector< std::shared_ptr< StateReactor > > stateReactors_
Definition: smacc_state.h:86

References stateReactors_.

◆ createStateReactor() [2/2]

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

Definition at line 110 of file smacc_state_impl.h.

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

References stateReactors_.

◆ getClassName()

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

Definition at line 6 of file smacc_state.cpp.

7{
8 return demangleSymbol(typeid(*this).name());
9}
std::string demangleSymbol()
Definition: introspection.h:75

References smacc::introspection::demangleSymbol().

Referenced by smacc::ISmaccOrthogonal::initState(), and smacc::ISmaccStateMachine::propagateEventToStateReactors().

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

◆ getEventGenerator()

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

Definition at line 168 of file smacc_state_impl.h.

169 {
170 TEventGenerator* ret = nullptr;
171 for(auto& evg: this->eventGenerators_)
172 {
173 ret = dynamic_cast<TEventGenerator *>(evg.get());
174 if(ret!=nullptr)
175 break;
176 }
177 return ret;
178 }

References eventGenerators_.

◆ getEventGenerators()

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

Definition at line 62 of file smacc_state.h.

62{ return eventGenerators_; }

References eventGenerators_.

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

Here is the caller graph for this function:

◆ getGlobalSMData()

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

Definition at line 95 of file smacc_state_impl.h.

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

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

Here is the call graph for this function:

◆ getOrthogonal()

template<typename TOrthogonal >
TOrthogonal * smacc::ISmaccState::getOrthogonal

Definition at line 161 of file smacc_state_impl.h.

162 {
163 //static_assert(boost::type_traits::is_base_of<ISmaccOrthogonal,TOrthogonal>::value);
164 return this->getStateMachine().getOrthogonal<TOrthogonal>();
165 }

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

Here is the call graph for this function:

◆ getParam()

template<typename T >
bool smacc::ISmaccState::getParam ( std::string  param_name,
T &  param_storage 
)

Definition at line 24 of file smacc_state_impl.h.

25 {
26 return nh.getParam(param_name, param_storage);
27 }
ros::NodeHandle nh
Definition: smacc_state.h:89

References nh.

Referenced by cl_move_base_z::CbNavigateGlobalPosition::readStartPoseFromParameterServer().

Here is the caller graph for this function:

◆ getParentState()

ISmaccState * smacc::ISmaccState::getParentState ( )
inline

Definition at line 16 of file smacc_state.h.

16{ return parentState_; }
ISmaccState * parentState_
Definition: smacc_state.h:93

References parentState_.

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

Here is the caller graph for this function:

◆ getROSNode()

ros::NodeHandle & smacc::ISmaccState::getROSNode ( )
inline

Definition at line 18 of file smacc_state.h.

18{ return nh; }

References nh.

◆ getStateMachine()

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

◆ getStateReactor()

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

Definition at line 181 of file smacc_state_impl.h.

182 {
183 TStateReactor* ret = nullptr;
184 for(auto& sr: this->stateReactors_)
185 {
186 ret = dynamic_cast<TStateReactor *>(sr.get());
187 if(ret!=nullptr)
188 break;
189 }
190 return ret;
191 }

References stateReactors_.

◆ getStateReactors()

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

Definition at line 60 of file smacc_state.h.

60{ return stateReactors_; }

References stateReactors_.

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

Here is the caller graph for this function:

◆ notifyTransition()

template<typename TransitionType >
void smacc::ISmaccState::notifyTransition

Definition at line 219 of file smacc_state_impl.h.

220 {
221 auto transitionType = TypeInfo::getTypeInfoFromType<TransitionType>();
222 this->notifyTransitionFromTransitionTypeInfo(transitionType);
223 }
void notifyTransitionFromTransitionTypeInfo(std::shared_ptr< smacc::introspection::TypeInfo > &transitionTypeInfo)
Definition: smacc_state.cpp:11

References notifyTransitionFromTransitionTypeInfo().

Here is the call graph for this function:

◆ notifyTransitionFromTransitionTypeInfo()

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

Definition at line 11 of file smacc_state.cpp.

12{
13 ROS_INFO_STREAM("NOTIFY TRANSITION: " << transitionType->getFullName());
14
15 //auto currstateinfo = this->getStateMachine().getCurrentStateInfo();
16 auto currstateinfo = this->stateInfo_;
17
18 if (currstateinfo != nullptr)
19 {
20 //ROS_ERROR_STREAM("CURRENT STATE INFO: " << currstateinfo->fullStateName);
21 for (auto &transition : currstateinfo->transitions_)
22 {
23 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
24 //ROS_ERROR_STREAM("candidate transition: " << transitionCandidateName);
25
26 if (transitionType->getFullName() == transitionCandidateName)
27 {
28 this->getStateMachine().publishTransition(transition);
29 return;
30 }
31 }
32
33 // debug information if not found
34 ROS_ERROR_STREAM("Transition happened, from current state " << currstateinfo->getDemangledFullName() << " but there is not any transitioninfo match available to publish transition: " << transitionType->getFullName());
35 std::stringstream ss;
36
37 auto stateinfo = currstateinfo;
38
39 for (auto &transition : currstateinfo->transitions_)
40 {
41 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
42 ROS_ERROR_STREAM("- candidate transition: " << transitionCandidateName);
43 }
44
45 ROS_ERROR("Ancestors candidates: ");
46
47 std::list<const SmaccStateInfo *> ancestors;
48 stateinfo->getAncestors(ancestors);
49
50 for (auto &ancestor : ancestors)
51 {
52 ROS_ERROR_STREAM(" * Ancestor " << ancestor->getDemangledFullName() << ":");
53 for (auto &transition : ancestor->transitions_)
54 {
55 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
56 ROS_ERROR_STREAM("- candidate transition: " << transitionCandidateName);
57 if (transitionType->getFullName() == transitionCandidateName)
58 {
59 ROS_ERROR("GOTCHA");
60 }
61 }
62 }
63 }
64 else
65 {
66 ROS_ERROR_STREAM("Transition happened, but current state was not set. Transition candidates:");
67 }
68}
void publishTransition(const SmaccTransitionInfo &transitionInfo)
const smacc::introspection::SmaccStateInfo * stateInfo_
Definition: smacc_state.h:95

References getStateMachine(), smacc::ISmaccStateMachine::publishTransition(), and stateInfo_.

Referenced by notifyTransition().

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

◆ param()

template<typename T >
bool smacc::ISmaccState::param ( std::string  param_name,
T &  param_val,
const T &  default_val 
) const

Definition at line 40 of file smacc_state_impl.h.

41 {
42 return nh.param(param_name, param_val, default_val);
43 }

References nh.

Referenced by cl_move_base_z::CbAbsoluteRotate::onEntry(), cl_move_base_z::CbNavigateBackwards::onEntry(), cl_move_base_z::CbNavigateForward::onEntry(), and cl_move_base_z::CbRotate::onEntry().

Here is the caller graph for this function:

◆ postEvent() [1/2]

template<typename EventType >
void smacc::ISmaccState::postEvent

Definition at line 212 of file smacc_state_impl.h.

213 {
214 getStateMachine().postEvent<EventType>();
215 }
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)

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

Here is the call graph for this function:

◆ postEvent() [2/2]

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

Definition at line 206 of file smacc_state_impl.h.

207 {
209 }

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

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

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

◆ requiresClient()

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

Definition at line 78 of file smacc_state_impl.h.

79 {
80 const char *sname = (demangleSymbol(typeid(*this).name()).c_str());
81 storage = nullptr;
82 auto &orthogonals = this->getStateMachine().getOrthogonals();
83 for (auto &ortho : orthogonals)
84 {
85 ortho.second->requiresClient(storage);
86 if (storage != nullptr)
87 return;
88 }
89
90 ROS_ERROR("[%s] Client of type '%s' not found in any orthogonal of the current state machine. This may produce a segmentation fault if the returned reference is used.", sname, demangleSymbol<SmaccClientType>().c_str());
91 }
const std::map< std::string, std::shared_ptr< smacc::ISmaccOrthogonal > > & getOrthogonals() const

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

Here is the call graph for this function:

◆ requiresComponent()

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

Definition at line 71 of file smacc_state_impl.h.

72 {
73 this->getStateMachine().requiresComponent(storage);
74 }
void requiresComponent(SmaccComponentType *&storage)

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

Here is the call graph for this function:

◆ setGlobalSMData()

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

Definition at line 103 of file smacc_state_impl.h.

104 {
105 this->getStateMachine().setGlobalSMData(name, value);
106 }
void setGlobalSMData(std::string name, T value)

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

Here is the call graph for this function:

◆ setParam()

template<typename T >
void smacc::ISmaccState::setParam ( std::string  param_name,
param_val 
)

Definition at line 32 of file smacc_state_impl.h.

33 {
34 return nh.setParam(param_name, param_val);
35 }

References nh.

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

Here is the caller graph for this function:

Member Data Documentation

◆ contextNh

ros::NodeHandle smacc::ISmaccState::contextNh
protected

◆ eventGenerators_

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

Definition at line 87 of file smacc_state.h.

Referenced by createEventGenerator(), getEventGenerator(), and getEventGenerators().

◆ nh

ros::NodeHandle smacc::ISmaccState::nh
protected

◆ parentState_

ISmaccState* smacc::ISmaccState::parentState_
protected

◆ stateInfo_

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

◆ stateReactors_

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

Definition at line 86 of file smacc_state.h.

Referenced by createStateReactor(), getStateReactor(), and getStateReactors().


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