Async 1.8.0
|
Implements a hierarchial state machine. More...
#include <AsyncStateMachine.h>
Public Member Functions | |
virtual const std::type_info & | typeId (void) const override |
Get the typeid for this state. | |
virtual const char * | name (void) const |
Protected Member Functions | |
virtual void | initHandler (void) override |
Handle calling the init function on state transitions. | |
virtual void | entryHandler (typename ParentT::StateT *from) override |
Handle calling the entry function on state transitions. | |
virtual void | exitHandler (typename ParentT::StateT *to) override |
Handle calling the exit function on state transitions. | |
void | init (void) |
Called before a transition from one state to another. | |
void | entry (void) |
Called when a state is entered. | |
void | exit (void) |
virtual void | timeoutEvent (void) override |
An event function that will be called when a timeout occurs. | |
virtual void | timeoutAtEvent (void) override |
Implements a hierarchial state machine.
ParentT | The parent state |
T | The state class itself |
This class should be used together with Async::StateMachine to form a state in the state machine. All states must inherit from this class.
struct StateMyState : Async::StateBase<StateTop, StateMyState> { static constexpr auto NAME = "MyState"; };
The NAME constant is only needed for state transition debugging.
Full example below.
Definition at line 381 of file AsyncStateMachine.h.
|
inlineprotected |
Called when a state is entered.
The entry function is called when a state is entered. It is not allowed to initiate any state transitions in this function. That should be done in the init function or in event handlers.
The entry function will be called, from top to bottom, for all states in the hierarchy. States that are common to the source and the target states will not have the entry function called.
Definition at line 453 of file AsyncStateMachine.h.
Referenced by Async::StateBase< ParentT, T >::entryHandler().
|
inlineoverrideprotectedvirtual |
Handle calling the entry function on state transitions.
from | The state that we transition from |
Definition at line 408 of file AsyncStateMachine.h.
References Async::StateBase< ParentT, T >::entry().
|
inlineprotected |
@bief Called when a state is exited
The exit function is called when a state is exited. It is not allowed to initiate any state transitions in this function. That should be done in the init function or in event handlers.
The exit function will be called, from bottom to top, for all states in the hierarchy. States that are common to the source and the target states will not have the exit function called.
Definition at line 466 of file AsyncStateMachine.h.
Referenced by Async::StateBase< ParentT, T >::exitHandler().
|
inlineoverrideprotectedvirtual |
Handle calling the exit function on state transitions.
to | The state that we transition to |
Definition at line 421 of file AsyncStateMachine.h.
References Async::StateBase< ParentT, T >::exit().
|
inlineprotected |
Called before a transition from one state to another.
The init function is called before a state transition is executed so this is the place to switch to another state using the setState function. That is typically used to select a substate to activate when a state is activated.
The init function will only be called in the specific target state.
Definition at line 440 of file AsyncStateMachine.h.
Referenced by Async::StateBase< ParentT, T >::initHandler().
|
inlineoverrideprotectedvirtual |
Handle calling the init function on state transitions.
Definition at line 399 of file AsyncStateMachine.h.
References Async::StateBase< ParentT, T >::init().
|
inlinevirtual |
Definition at line 393 of file AsyncStateMachine.h.
|
inlineoverrideprotectedvirtual |
Definition at line 484 of file AsyncStateMachine.h.
|
inlineoverrideprotectedvirtual |
An event function that will be called when a timeout occurs.
This event function will be called when a timeout, previously set up using the setTimeout function, has occurred.
As all event functions this is a virtual function which work like any other virtual function in C++. The state which is furtherest down in the hierarchy, which have the timeoutEvent function implemented, will have the function called.
Definition at line 479 of file AsyncStateMachine.h.
|
inlineoverridevirtual |
Get the typeid for this state.
Definition at line 388 of file AsyncStateMachine.h.