|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
9 #ifndef YARP_MANAGER_FSM
10 #define YARP_MANAGER_FSM
35 if(szName) { strName = szName; }
42 const char*
getName() {
return strName.c_str(); }
45 return ((strName == alt.strName)); }
83 eventSink = pEventSink;
84 if(szName) { strName = szName; }
90 return strName.c_str(); }
102 typedef std::map<FSM::StateBase*, std::map<FSM::Event*, FSM::StateBase*> >
MyStateMap;
103 typedef std::map<FSM::StateBase*, std::map<FSM::Event*, FSM::StateBase*> >::iterator
MyStateItr;
114 currentTimeStamp = 0.0;
124 catch (std::exception& )
126 std::cerr<<
"Exception in currentState(): Initial state is not set!"<<std::endl;
132 if(!state) { state = pState; }
139 transitions[source][event] = target;
141 catch (std::exception& typevar)
143 std::cerr<<
"Exception in addTransition(): "<<typevar.what()<<std::endl;
163 std::cerr<<
"Initial state is not set!"<<std::endl;
175 currentTimeStamp =
event->getTimeStamp();
178 it = transitions.find(state);
179 if(it==transitions.end())
181 std::cerr<<
"No transition is registered from state "<<state->
getName()<<std::endl;
186 std::map<Event*, StateBase*> row = transitions[state];
187 std::map<Event*, StateBase*>::iterator itr2 = row.find(event);
188 if(itr2 == row.end())
190 std::cerr<<
"No transition is registered for event ";
191 std::cerr<<
event->getName()<<
" ("<<
event->getTimeStamp()<<
")";
192 std::cerr<<
" from state "<<state->
getName()<<std::endl;
209 double currentTimeStamp;
214 #endif // __YARP_MANAGER_FSM__
StateBase * currentState()
A class for thread synchronization and mutual exclusion.
void castEvent(Event *event) override
void wait()
Decrement the counter, even if we must wait to do that.
void setInitState(StateBase *pState)
std::map< FSM::StateBase *, std::map< FSM::Event *, FSM::StateBase * > >::iterator MyStateItr
void post()
Increment the counter.
virtual void onTransition(StateBase *previous, Event *event, StateBase *current)
Callback onTransition represents the change in the states.
Event(const char *szName)
~StateMachineBase() override=default
virtual ~IEventSink()=default
std::map< FSM::StateBase *, std::map< FSM::Event *, FSM::StateBase * > > MyStateMap
void setTimeStamp(double t)
virtual ~StateBase()=default
void addTransition(StateBase *source, Event *event, StateBase *target)
void castEvent(Event *event)
virtual void onEventMissed(StateBase *state, Event *event)
StateBase(IEventSink *pEventSink, const char *szName=nullptr)
bool operator==(const Event &alt) const
virtual void castEvent(Event *event)=0