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

#include <smacc_state_reactor.hpp>

Inheritance diagram for smacc2::StateReactor:
Inheritance graph
Collaboration diagram for smacc2::StateReactor:
Collaboration graph

Public Member Functions

 StateReactor ()
 
virtual ~StateReactor ()
 
 StateReactor (const StateReactor &)=delete
 
StateReactor & operator= (const StateReactor &)=delete
 
 StateReactor (StateReactor &&)=delete
 
StateReactor & operator= (StateReactor &&)=delete
 
virtual void onInitialized ()
 
virtual void onEntry ()
 
virtual void onExit ()
 
virtual void onEventNotified (const std::type_info *eventType)
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename T , typename TClass >
void createEventCallback (void(TClass::*callback)(T *), TClass *object)
 
template<typename T >
void createEventCallback (std::function< void(T *)> callback)
 
void update ()
 
virtual bool triggers ()=0
 
template<typename TEv >
void addInputEvent ()
 
template<typename TEv >
void setOutputEvent ()
 
void initialize (ISmaccState *ownerState)
 
rclcpp::Node::SharedPtr & getNode ()
 
rclcpp::Logger getLogger ()
 

Public Attributes

ISmaccState * ownerState = nullptr
 
std::function< void()> postEventFn
 
std::vector< const std::type_info * > eventTypes
 
std::map< const std::type_info *, std::function< void(void *)> > eventCallbacks_
 

Private Member Functions

template<typename TEvent >
void notifyEvent (TEvent *ev)
 

Private Attributes

friend ISmaccStateMachine
 

Detailed Description

Definition at line 46 of file smacc_state_reactor.hpp.

Constructor & Destructor Documentation

◆ StateReactor() [1/3]

smacc2::StateReactor::StateReactor ( )

Definition at line 29 of file state_reactor.cpp.

29{}

◆ ~StateReactor()

smacc2::StateReactor::~StateReactor ( )
virtual

Definition at line 31 of file state_reactor.cpp.

31{}

◆ StateReactor() [2/3]

smacc2::StateReactor::StateReactor ( const StateReactor & )
delete

◆ StateReactor() [3/3]

smacc2::StateReactor::StateReactor ( StateReactor && )
delete

Member Function Documentation

◆ addInputEvent()

template<typename TEv >
void smacc2::StateReactor::addInputEvent ( )

Definition at line 51 of file smacc_state_reactor_impl.hpp.

52{
53 this->eventTypes.push_back(&typeid(TEv));
54}
std::vector< const std::type_info * > eventTypes

References eventTypes.

Referenced by smacc2::AddTEventTypeStateReactor< TEventList >::operator()().

Here is the caller graph for this function:

◆ createEventCallback() [1/2]

template<typename T >
void smacc2::StateReactor::createEventCallback ( std::function< void(T *)> callback)

Definition at line 68 of file smacc_state_reactor_impl.hpp.

69{
70 const auto * eventtype = &typeid(T);
71 this->eventCallbacks_[eventtype] = [=](void * msg)
72 {
73 T * evptr = static_cast<T *>(msg);
74 callback(evptr);
75 };
76}
std::map< const std::type_info *, std::function< void(void *)> > eventCallbacks_

References eventCallbacks_.

◆ createEventCallback() [2/2]

template<typename T , typename TClass >
void smacc2::StateReactor::createEventCallback ( void(TClass::* callback )(T *),
TClass * object )

Definition at line 57 of file smacc_state_reactor_impl.hpp.

58{
59 const auto * eventtype = &typeid(T);
60 this->eventCallbacks_[eventtype] = [=](void * msg)
61 {
62 T * evptr = static_cast<T *>(msg);
63 (object->*callback)(evptr);
64 };
65}

References eventCallbacks_.

Referenced by smacc2::state_reactors::SrConditional< TEv >::SrConditional().

Here is the caller graph for this function:

◆ getLogger()

rclcpp::Logger smacc2::StateReactor::getLogger ( )

◆ getNode()

rclcpp::Node::SharedPtr & smacc2::StateReactor::getNode ( )

Definition at line 56 of file state_reactor.cpp.

56{ return ownerState->getNode(); }
rclcpp::Node::SharedPtr & getNode()

References smacc2::ISmaccState::getNode(), and ownerState.

Here is the call graph for this function:

◆ initialize()

void smacc2::StateReactor::initialize ( smacc2::ISmaccState * ownerState)

Definition at line 33 of file state_reactor.cpp.

34{
35 this->ownerState = ownerState;
36 this->onInitialized();
37}
virtual void onInitialized()

References onInitialized(), and ownerState.

Here is the call graph for this function:

◆ notifyEvent()

template<typename TEvent >
void smacc2::StateReactor::notifyEvent ( TEvent * ev)
inlineprivate

Definition at line 107 of file smacc_state_reactor.hpp.

108 {
109 //the state machine uses this method to notify this state reactor some event happened.
110 auto tid = &(typeid(TEvent));
111 if (std::find(eventTypes.begin(), eventTypes.end(), tid) != eventTypes.end())
112 {
113 this->onEventNotified(tid);
114 this->update();
115
116 if (eventCallbacks_.count(tid))
117 {
118 eventCallbacks_[tid](static_cast<void *>(ev));
119 }
120 }
121 }
virtual void onEventNotified(const std::type_info *eventType)

References eventCallbacks_, eventTypes, onEventNotified(), and update().

Here is the call graph for this function:

◆ onEntry()

void smacc2::StateReactor::onEntry ( )
virtual

Definition at line 43 of file state_reactor.cpp.

43{}

◆ onEventNotified()

void smacc2::StateReactor::onEventNotified ( const std::type_info * eventType)
virtual

Reimplemented in smacc2::state_reactors::SrAllEventsGo, and smacc2::state_reactors::SrEventCountdown.

Definition at line 41 of file state_reactor.cpp.

41{}

Referenced by notifyEvent().

Here is the caller graph for this function:

◆ onExit()

void smacc2::StateReactor::onExit ( )
virtual

Definition at line 45 of file state_reactor.cpp.

45{}

◆ onInitialized()

void smacc2::StateReactor::onInitialized ( )
virtual

Reimplemented in smacc2::state_reactors::SrAllEventsGo, and smacc2::state_reactors::SrEventCountdown.

Definition at line 39 of file state_reactor.cpp.

39{}

Referenced by initialize().

Here is the caller graph for this function:

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ postEvent() [1/2]

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

Definition at line 34 of file smacc_state_reactor_impl.hpp.

35{
36 ownerState->postEvent<EventType>();
37}
void postEvent(const EventType &ev)

References ownerState, and smacc2::ISmaccState::postEvent().

Here is the call graph for this function:

◆ postEvent() [2/2]

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

Definition at line 28 of file smacc_state_reactor_impl.hpp.

29{
31}

References ownerState, and smacc2::ISmaccState::postEvent().

Here is the call graph for this function:

◆ setOutputEvent()

template<typename TEv >
void smacc2::StateReactor::setOutputEvent ( )

Definition at line 40 of file smacc_state_reactor_impl.hpp.

41{
42 this->postEventFn = [this]()
43 {
44 RCLCPP_INFO_STREAM(
45 this->getLogger(), "[State Reactor Base] postingfn posting event: " << demangleSymbol<TEv>());
47 };
48}
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
virtual ISmaccStateMachine & getStateMachine()=0
std::function< void()> postEventFn
rclcpp::Logger getLogger()
std::string demangleSymbol()
boost::intrusive_ptr< EventType > makeEvent(Args &&... args)

References smacc2::introspection::demangleSymbol(), getLogger(), smacc2::ISmaccState::getStateMachine(), smacc2::makeEvent(), ownerState, smacc2::ISmaccStateMachine::postEvent(), and postEventFn.

Here is the call graph for this function:

◆ triggers()

virtual bool smacc2::StateReactor::triggers ( )
pure virtual

Implemented in smacc2::state_reactors::SrAllEventsGo, smacc2::state_reactors::SrConditional< TEv >, and smacc2::state_reactors::SrEventCountdown.

Referenced by update().

Here is the caller graph for this function:

◆ update()

void smacc2::StateReactor::update ( )

Definition at line 47 of file state_reactor.cpp.

48{
49 if (this->triggers())
50 {
51 RCLCPP_INFO(getLogger(), "State reactor base REALLY TRIGGERS!!");
52 this->postEventFn();
53 }
54}
virtual bool triggers()=0

References getLogger(), postEventFn, and triggers().

Referenced by notifyEvent().

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

Member Data Documentation

◆ eventCallbacks_

std::map<const std::type_info *, std::function<void(void *)> > smacc2::StateReactor::eventCallbacks_

Definition at line 52 of file smacc_state_reactor.hpp.

Referenced by createEventCallback(), createEventCallback(), and notifyEvent().

◆ eventTypes

std::vector<const std::type_info *> smacc2::StateReactor::eventTypes

◆ ISmaccStateMachine

friend smacc2::StateReactor::ISmaccStateMachine
private

Definition at line 104 of file smacc_state_reactor.hpp.

◆ ownerState

ISmaccState* smacc2::StateReactor::ownerState = nullptr

◆ postEventFn

std::function<void()> smacc2::StateReactor::postEventFn

Definition at line 50 of file smacc_state_reactor.hpp.

Referenced by setOutputEvent(), and update().


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