SMACC
Loading...
Searching...
No Matches
smacc_state_reactor_impl.h
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6
7#pragma once
10
11namespace smacc
12{
13
14template <typename EventType>
15void StateReactor::postEvent(const EventType &ev)
16{
18}
19
20template <typename EventType>
22{
23 ownerState->postEvent<EventType>();
24}
25
26template <typename TEv>
28{
29 this->postEventFn = [this]() {
30 ROS_INFO_STREAM("[State Reactor Base] postingfn posting event: " << demangleSymbol<TEv>());
31 auto *ev = new TEv();
33 };
34}
35
36template <typename TEv>
38{
39 this->eventTypes.push_back(&typeid(TEv));
40}
41
42template <typename T, typename TClass>
43void StateReactor::createEventCallback(void (TClass::*callback)(T *), TClass *object)
44{
45 const auto *eventtype = &typeid(T);
46 this->eventCallbacks_[eventtype] = [=](void *msg) {
47 T *evptr = (T *)msg;
48 (object->*callback)(evptr);
49 };
50}
51
52template <typename T>
53void StateReactor::createEventCallback(std::function<void(T *)> callback)
54{
55 const auto *eventtype = &typeid(T);
56 this->eventCallbacks_[eventtype] = [=](void *msg) {
57 T *evptr = (T *)msg;
58 callback(evptr);
59 };
60}
61
62namespace introspection
63{
64
65template <typename TEv>
67{
69 functor.fn = [=](std::shared_ptr<smacc::StateReactor> sr) {
70 ROS_INFO("[%s] State Reactor adding input event: %s", demangleType(srInfo_->stateReactorType).c_str(), demangledTypeName<TEv>().c_str());
71 sr->addInputEvent<TEv>();
72 };
73
74 this->callbacks_.push_back(functor);
75
76 auto evtype = TypeInfo::getFromStdTypeInfo(typeid(TEv));
77 auto evinfo = std::make_shared<SmaccEventInfo>(evtype);
78 EventLabel<TEv>(evinfo->label);
79
80 srInfo_->sourceEventTypes.push_back(evinfo);
81}
82
83template <typename TEv>
85{
87 functor.fn = [=](std::shared_ptr<smacc::StateReactor> sr) {
88 ROS_INFO("[%s] State Reactor setting output event: %s", demangleType(srInfo_->stateReactorType).c_str(), demangledTypeName<TEv>().c_str());
89 sr->setOutputEvent<TEv>();
90 };
91
92 this->callbacks_.push_back(functor);
93}
94} // namespace introspection
95
96} // namespace smacc
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
virtual ISmaccStateMachine & getStateMachine()=0
void postEvent(const EventType &ev)
std::function< void()> postEventFn
std::map< const std::type_info *, std::function< void(void *)> > eventCallbacks_
std::vector< const std::type_info * > eventTypes
void createEventCallback(void(TClass::*callback)(T *), TClass *object)
std::vector< StateReactorCallbackFunctor > callbacks_
std::shared_ptr< smacc::introspection::SmaccStateReactorInfo > srInfo_
static TypeInfo::Ptr getFromStdTypeInfo(const std::type_info &tid)
std::string demangleType(const std::type_info *tinfo)
Definition: introspection.h:86
std::function< void(std::shared_ptr< smacc::StateReactor >)> fn