Async 1.8.0
|
The base class for the top state of a state machine. More...
#include <AsyncStateMachine.h>
Public Types | |
using | Type = StateBase<StateTopBase<ContextT, TopStateT>, TopStateT> |
A type alias to simplify declaration of the top state. | |
using | StateT = TopStateT |
A type alias to access the top state type. | |
using | StateMachineT = StateMachine<ContextT, StateT> |
A type alias to simplify usage of the state machine type. | |
Public Member Functions | |
virtual | ~StateTopBase (void) |
Destructor. | |
ContextT & | ctx (void) |
Get the context object. | |
Protected Member Functions | |
template<class NewStateT > | |
void | setState (void) |
Transition to the given state. | |
void | setTimeout (int timeout_ms) |
Set a timeout after which the timeoutEvent is issued. | |
void | setTimeoutAt (struct tm &tm, int expire_offset=0) |
Set a timeout after which the timeoutAtEvent is issued. | |
void | clearTimeout (void) |
Clear a pending timeout. | |
void | clearTimeoutAt (void) |
Clear a pending absolute time timeout. | |
virtual const std::type_info & | typeId (void) const =0 |
Get the typeid for this state. | |
virtual void | initHandler (void)=0 |
Run the init functon in a state. | |
virtual void | entryHandler (StateT *from) |
Run all entry handlers in the state hierarchy, top to bottom. | |
virtual void | exitHandler (StateT *to) |
Run all exit handlers in the state hierarchy, bottom to top. | |
virtual void | timeoutEvent (void)=0 |
An event function that will be called when a timeout occurs. | |
virtual void | timeoutAtEvent (void)=0 |
Event function called when an absolute time timeout occurs. | |
The base class for the top state of a state machine.
This class should be used together with Async::StateMachine to form the top state of the state machine. The top state must use this class as its parent state. A type alias is available to simplify the syntax. E.g.
struct StateTop : Async::StateTopBase<Context, StateTop>::Type { static constexpr auto NAME = "Top"; };
The NAME constant is only needed for state transition debugging.
Full demo below.
Definition at line 513 of file AsyncStateMachine.h.
using Async::StateTopBase< ContextT, TopStateT >::StateMachineT = StateMachine<ContextT, StateT> |
A type alias to simplify usage of the state machine type.
Definition at line 529 of file AsyncStateMachine.h.
using Async::StateTopBase< ContextT, TopStateT >::StateT = TopStateT |
A type alias to access the top state type.
Definition at line 524 of file AsyncStateMachine.h.
using Async::StateTopBase< ContextT, TopStateT >::Type = StateBase<StateTopBase<ContextT, TopStateT>, TopStateT> |
A type alias to simplify declaration of the top state.
Definition at line 519 of file AsyncStateMachine.h.
|
inlinevirtual |
Destructor.
Definition at line 534 of file AsyncStateMachine.h.
|
inlineprotected |
Clear a pending timeout.
Use this function to immediately cancel a running timeout timer. See setTimeout for more information.
Definition at line 581 of file AsyncStateMachine.h.
References Async::StateMachine< ContextT, StateTopT >::clearTimeout().
|
inlineprotected |
Clear a pending absolute time timeout.
Use this function to immediately cancel a running absolute time timeout timer. See setTimeoutAt for more information.
Definition at line 589 of file AsyncStateMachine.h.
References Async::StateMachine< ContextT, StateTopT >::clearTimeoutAt().
|
inline |
Get the context object.
Definition at line 540 of file AsyncStateMachine.h.
References Async::StateMachine< ContextT, StateTopT >::ctx().
|
inlineprotectedvirtual |
Run all entry handlers in the state hierarchy, top to bottom.
from | The state that we transition from |
Definition at line 605 of file AsyncStateMachine.h.
|
inlineprotectedvirtual |
Run all exit handlers in the state hierarchy, bottom to top.
to | The state that we transition to |
Definition at line 611 of file AsyncStateMachine.h.
|
protectedpure virtual |
Run the init functon in a state.
|
inlineprotected |
Transition to the given state.
See Async::StateMachine::setState.
Definition at line 549 of file AsyncStateMachine.h.
References Async::StateMachine< ContextT, StateTopT >::setState().
|
inlineprotected |
Set a timeout after which the timeoutEvent is issued.
timeout_ms | The timeout value in milliseconds |
Use this function to set a timeout to occur after the specified number of milliseconds. The timeoutEvent will be issued after the time has expired.
Definition at line 559 of file AsyncStateMachine.h.
References Async::StateMachine< ContextT, StateTopT >::setTimeout().
|
inlineprotected |
Set a timeout after which the timeoutAtEvent is issued.
tm | The absolute time when the timeout should occur |
expire_offset | A millisecond offset for the timer expiration |
Use this function to set a timeout to occur at the specified absolute time, plus or minus the offset value. The time is specified in local time. The timeoutAtEvent will be issued after the time has expired.
Definition at line 570 of file AsyncStateMachine.h.
References Async::StateMachine< ContextT, StateTopT >::setTimeoutAt().
|
protectedpure virtual |
Event function called when an absolute time timeout occurs.
This event function will be called when an absolute time timeout, previously set up using the setTimeoutAt 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 timeoutAtEvent function implemented, will have the function called.
|
protectedpure virtual |
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.
|
protectedpure virtual |
Get the typeid for this state.