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

#include <smacc_state_reactor.h>

Inheritance diagram for smacc::StateReactor:
Inheritance graph
Collaboration diagram for smacc::StateReactor:
Collaboration graph

Public Member Functions

 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)
 

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 29 of file smacc_state_reactor.h.

Constructor & Destructor Documentation

◆ StateReactor()

smacc::StateReactor::StateReactor ( )

Definition at line 7 of file state_reactor.cpp.

8{
9}

Member Function Documentation

◆ addInputEvent()

template<typename TEv >
void smacc::StateReactor::addInputEvent

Definition at line 37 of file smacc_state_reactor_impl.h.

38{
39 this->eventTypes.push_back(&typeid(TEv));
40}
std::vector< const std::type_info * > eventTypes

References eventTypes.

Referenced by smacc::AddTEventType< TEventList >::operator()().

Here is the caller graph for this function:

◆ createEventCallback() [1/2]

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

Definition at line 53 of file smacc_state_reactor_impl.h.

54{
55 const auto *eventtype = &typeid(T);
56 this->eventCallbacks_[eventtype] = [=](void *msg) {
57 T *evptr = (T *)msg;
58 callback(evptr);
59 };
60}
std::map< const std::type_info *, std::function< void(void *)> > eventCallbacks_

References eventCallbacks_.

◆ createEventCallback() [2/2]

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

Definition at line 43 of file smacc_state_reactor_impl.h.

44{
45 const auto *eventtype = &typeid(T);
46 this->eventCallbacks_[eventtype] = [=](void *msg) {
47 T *evptr = (T *)msg;
48 (object->*callback)(evptr);
49 };
50}

References eventCallbacks_.

Referenced by smacc::state_reactors::Srsr_conditional::Srsr_conditional().

Here is the caller graph for this function:

◆ initialize()

void smacc::StateReactor::initialize ( smacc::ISmaccState ownerState)

Definition at line 11 of file state_reactor.cpp.

12{
13 this->ownerState = ownerState;
14 this->onInitialized();
15}
virtual void onInitialized()

References onInitialized(), and ownerState.

Here is the call graph for this function:

◆ notifyEvent()

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

Definition at line 78 of file smacc_state_reactor.h.

79 {
80 //the state machine uses this method to notify this state reactor some event happened.
81 auto tid = &(typeid(TEvent));
82 if (std::find(eventTypes.begin(), eventTypes.end(), tid) != eventTypes.end())
83 {
84 this->onEventNotified(tid);
85 this->update();
86
87 if (eventCallbacks_.count(tid))
88 {
89 eventCallbacks_[tid]((void *)ev);
90 }
91 }
92 }
virtual void onEventNotified(const std::type_info *eventType)

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

Here is the call graph for this function:

◆ onEntry()

void smacc::StateReactor::onEntry ( )
virtual

Definition at line 25 of file state_reactor.cpp.

26{
27
28}

◆ onEventNotified()

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

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

Definition at line 21 of file state_reactor.cpp.

22{
23}

Referenced by notifyEvent().

Here is the caller graph for this function:

◆ onExit()

void smacc::StateReactor::onExit ( )
virtual

Definition at line 30 of file state_reactor.cpp.

31{
32
33}

◆ onInitialized()

void smacc::StateReactor::onInitialized ( )
virtual

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

Definition at line 17 of file state_reactor.cpp.

18{
19}

Referenced by initialize().

Here is the caller graph for this function:

◆ postEvent() [1/2]

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

Definition at line 21 of file smacc_state_reactor_impl.h.

22{
23 ownerState->postEvent<EventType>();
24}
void postEvent(const EventType &ev)

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

Here is the call graph for this function:

◆ postEvent() [2/2]

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

Definition at line 15 of file smacc_state_reactor_impl.h.

16{
18}

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

Here is the call graph for this function:

◆ setOutputEvent()

template<typename TEv >
void smacc::StateReactor::setOutputEvent

Definition at line 27 of file smacc_state_reactor_impl.h.

28{
29 this->postEventFn = [this]() {
30 ROS_INFO_STREAM("[State Reactor Base] postingfn posting event: " << demangleSymbol<TEv>());
31 auto *ev = new TEv();
33 };
34}
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
virtual ISmaccStateMachine & getStateMachine()=0
std::function< void()> postEventFn

References smacc::ISmaccState::getStateMachine(), ownerState, smacc::ISmaccStateMachine::postEvent(), and postEventFn.

Here is the call graph for this function:

◆ triggers()

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

Implemented in smacc::state_reactors::SrAllEventsGo, smacc::state_reactors::Srsr_conditional, and smacc::state_reactors::SrEventCountdown.

Referenced by update().

Here is the caller graph for this function:

◆ update()

void smacc::StateReactor::update ( )

Definition at line 35 of file state_reactor.cpp.

36{
37 if (this->triggers())
38 {
39 ROS_INFO("State reactor base REALLY TRIGGERS!!");
40 this->postEventFn();
41 }
42}
virtual bool triggers()=0

References 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 *)> > smacc::StateReactor::eventCallbacks_

Definition at line 35 of file smacc_state_reactor.h.

Referenced by createEventCallback(), and notifyEvent().

◆ eventTypes

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

◆ ISmaccStateMachine

friend smacc::StateReactor::ISmaccStateMachine
private

Definition at line 75 of file smacc_state_reactor.h.

◆ ownerState

ISmaccState* smacc::StateReactor::ownerState

Definition at line 32 of file smacc_state_reactor.h.

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

◆ postEventFn

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

Definition at line 33 of file smacc_state_reactor.h.

Referenced by setOutputEvent(), and update().


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