SMACC2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
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 ()
 
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

ISmaccStateownerState
 
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 43 of file smacc_state_reactor.hpp.

Constructor & Destructor Documentation

◆ StateReactor()

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{}

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 67 of file smacc_state_reactor_impl.hpp.

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

References callback(), and eventCallbacks_.

Here is the call graph for this function:

◆ createEventCallback() [2/2]

template<typename T , typename TClass >
void smacc2::StateReactor::createEventCallback ( void(TClass::*)(T *)  callback,
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 T * evptr = (T *)msg;
62 (object->*callback)(evptr);
63 };
64}

References callback(), and eventCallbacks_.

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

Here is the call graph for this function:
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()
Definition: smacc_state.hpp:34

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 97 of file smacc_state_reactor.hpp.

98 {
99 //the state machine uses this method to notify this state reactor some event happened.
100 auto tid = &(typeid(TEvent));
101 if (std::find(eventTypes.begin(), eventTypes.end(), tid) != eventTypes.end())
102 {
103 this->onEventNotified(tid);
104 this->update();
105
106 if (eventCallbacks_.count(tid))
107 {
108 eventCallbacks_[tid]((void *)ev);
109 }
110 }
111 }
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:

◆ 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 RCLCPP_INFO_STREAM(
44 this->getLogger(), "[State Reactor Base] postingfn posting event: " << demangleSymbol<TEv>());
45 auto * ev = new TEv();
47 };
48}
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
virtual ISmaccStateMachine & getStateMachine()=0
std::function< void()> postEventFn
rclcpp::Logger getLogger()

References getLogger(), smacc2::ISmaccState::getStateMachine(), 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::SrConditional< TEv >, smacc2::state_reactors::SrAllEventsGo, 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 49 of file smacc_state_reactor.hpp.

Referenced by createEventCallback(), and notifyEvent().

◆ eventTypes

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

◆ ISmaccStateMachine

friend smacc2::StateReactor::ISmaccStateMachine
private

Definition at line 94 of file smacc_state_reactor.hpp.

◆ ownerState

ISmaccState* smacc2::StateReactor::ownerState

Definition at line 46 of file smacc_state_reactor.hpp.

Referenced by getLogger(), getNode(), initialize(), postEvent(), and setOutputEvent().

◆ postEventFn

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

Definition at line 47 of file smacc_state_reactor.hpp.

Referenced by setOutputEvent(), and update().


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