ETL
0.04.19
|
Templatized State Machine. More...
#include <_smach.h>
Classes | |
struct | egress_exception |
struct | event |
Event base class. More... | |
class | event_def_internal |
Event definition class. More... | |
struct | pop_exception |
class | state |
State class. More... | |
class | state_base |
Public Types | |
enum | event_result { RESULT_ERROR, RESULT_OK, RESULT_ACCEPT, RESULT_REJECT, RESULT_END } |
Result type for event processing. More... | |
typedef K | event_key |
typedef M | _mutex |
typedef CON | context_type |
Public Member Functions | |
const char * | get_state_name () const |
Gets the name of the currently active state. | |
bool | set_default_state (const state_base *nextstate) |
bool | egress () |
Leaves the current state. | |
bool | enter (const state_base *nextstate) |
State entry function. | |
bool | push_state (const state_base *nextstate) |
Pushes state onto state stack. | |
void | pop_state () |
Pops state off of state stack. | |
smach (context_type *machine_context=0) | |
State Machine Constructor. | |
~smach () | |
The destructor. | |
void | set_child (smach *x) |
Sets up a child state machine. | |
int | state_depth () |
Returns the number states currently active. | |
event_result | process_event (const event_key &id) |
event_result | process_event (const event &id) |
Process an event. |
Static Public Member Functions | |
static bool | event_error (const event_result &rhs) |
Determines if a given event result is an error. |
Public Attributes | |
void * | state_context |
State Context. |
Private Attributes | |
const state_base * | curr_state |
Current state of the machine. | |
smach * | child |
Child machine. | |
context_type * | machine_context |
Machine Context. | |
const state_base * | default_state |
void * | default_context |
_mutex | mutex |
const state_base * | state_stack [SMACH_STATE_STACK_SIZE] |
State stack data. | |
void * | state_context_stack [SMACH_STATE_STACK_SIZE] |
int | states_on_stack |
Templatized State Machine.
========================================================================
A more detailed description needs to be written.
typedef CON smach< CON, K, M >::context_type |
enum smach::event_result |
|
inline |
|
inline |
The destructor.
Definition at line 520 of file _smach.h.
References smach< CON, K, M >::default_context, smach< CON, K, M >::default_state, smach< CON, K, M >::egress(), and smach< CON, K, M >::state_base::leave_state().
|
inline |
Gets the name of the currently active state.
Definition at line 304 of file _smach.h.
References smach< CON, K, M >::curr_state, smach< CON, K, M >::default_state, ETL_MUTEX_LOCK, and smach< CON, K, M >::state_base::get_name().
|
inlinestatic |
Determines if a given event result is an error.
This function allows us to quickly see if an event_result contained an error
Definition at line 320 of file _smach.h.
References smach< CON, K, M >::RESULT_ERROR.
|
inline |
Definition at line 324 of file _smach.h.
References smach< CON, K, M >::default_context, smach< CON, K, M >::default_state, smach< CON, K, M >::state_base::enter_state(), ETL_MUTEX_LOCK, smach< CON, K, M >::state_base::leave_state(), and smach< CON, K, M >::machine_context.
|
inline |
Leaves the current state.
Effectively makes the state_depth() function return zero.
Definition at line 367 of file _smach.h.
References smach< CON, K, M >::curr_state, ETL_MUTEX_LOCK, smach< CON, K, M >::state_base::leave_state(), smach< CON, K, M >::pop_state(), smach< CON, K, M >::state_context, and smach< CON, K, M >::states_on_stack.
Referenced by smach< CON, K, M >::enter(), smach< CON, K, M >::pop_state(), smach< CON, K, M >::process_event(), and smach< CON, K, M >::~smach().
|
inline |
State entry function.
Attempts to enter the given state, popping off all states on the stack in the process.
Definition at line 401 of file _smach.h.
References smach< CON, K, M >::curr_state, smach< CON, K, M >::egress(), smach< CON, K, M >::state_base::enter_state(), ETL_MUTEX_LOCK, smach< CON, K, M >::machine_context, and smach< CON, K, M >::state_context.
Referenced by smach< CON, K, M >::process_event(), and smach< CON, K, M >::push_state().
|
inline |
Pushes state onto state stack.
This allows you to enter a state without leaving your current state.
nextstate | Pointer to the state to enter |
Definition at line 444 of file _smach.h.
References smach< CON, K, M >::curr_state, smach< CON, K, M >::enter(), smach< CON, K, M >::state_base::enter_state(), ETL_MUTEX_LOCK, smach< CON, K, M >::machine_context, SMACH_STATE_STACK_SIZE, smach< CON, K, M >::state_context, smach< CON, K, M >::state_context_stack, smach< CON, K, M >::state_stack, and smach< CON, K, M >::states_on_stack.
|
inline |
Pops state off of state stack.
Decreases state depth
Definition at line 480 of file _smach.h.
References smach< CON, K, M >::curr_state, smach< CON, K, M >::egress(), ETL_MUTEX_LOCK, smach< CON, K, M >::state_base::leave_state(), smach< CON, K, M >::state_context, smach< CON, K, M >::state_context_stack, smach< CON, K, M >::state_stack, and smach< CON, K, M >::states_on_stack.
Referenced by smach< CON, K, M >::egress(), and smach< CON, K, M >::process_event().
|
inline |
Sets up a child state machine.
A child state machine runs in parallel with its parent, and gets event priority. This mechanism is useful in cases where an inherited object has its own state machine.
Definition at line 533 of file _smach.h.
References smach< CON, K, M >::child, and ETL_MUTEX_LOCK.
|
inline |
Returns the number states currently active.
Definition at line 543 of file _smach.h.
References smach< CON, K, M >::curr_state, and smach< CON, K, M >::states_on_stack.
|
inline |
Definition at line 547 of file _smach.h.
References smach< CON, K, M >::process_event().
Referenced by smach< CON, K, M >::state< T >::process_event(), and smach< CON, K, M >::process_event().
|
inline |
Process an event.
Definition at line 551 of file _smach.h.
References smach< CON, K, M >::child, smach< CON, K, M >::curr_state, smach< CON, K, M >::default_context, smach< CON, K, M >::default_state, smach< CON, K, M >::egress(), smach< CON, K, M >::enter(), ETL_MUTEX_LOCK, smach< CON, K, M >::pop_state(), smach< CON, K, M >::state_base::process_event(), smach< CON, K, M >::process_event(), smach< CON, K, M >::RESULT_ACCEPT, smach< CON, K, M >::RESULT_ERROR, smach< CON, K, M >::RESULT_OK, and smach< CON, K, M >::state_context.
|
private |
Current state of the machine.
Definition at line 279 of file _smach.h.
Referenced by smach< CON, K, M >::egress(), smach< CON, K, M >::enter(), smach< CON, K, M >::get_state_name(), smach< CON, K, M >::pop_state(), smach< CON, K, M >::process_event(), smach< CON, K, M >::push_state(), and smach< CON, K, M >::state_depth().
|
private |
Child machine.
Definition at line 280 of file _smach.h.
Referenced by smach< CON, K, M >::process_event(), and smach< CON, K, M >::set_child().
void* smach< CON, K, M >::state_context |
State Context.
Definition at line 283 of file _smach.h.
Referenced by smach< CON, K, M >::egress(), smach< CON, K, M >::enter(), smach< CON, K, M >::state< T >::leave_state(), smach< CON, K, M >::pop_state(), smach< CON, K, M >::state< T >::process_event(), smach< CON, K, M >::process_event(), and smach< CON, K, M >::push_state().
|
private |
Machine Context.
Definition at line 286 of file _smach.h.
Referenced by smach< CON, K, M >::enter(), smach< CON, K, M >::push_state(), and smach< CON, K, M >::set_default_state().
|
private |
Definition at line 288 of file _smach.h.
Referenced by smach< CON, K, M >::get_state_name(), smach< CON, K, M >::process_event(), smach< CON, K, M >::set_default_state(), and smach< CON, K, M >::~smach().
|
private |
Definition at line 289 of file _smach.h.
Referenced by smach< CON, K, M >::process_event(), smach< CON, K, M >::set_default_state(), and smach< CON, K, M >::~smach().
|
private |
State stack data.
Definition at line 296 of file _smach.h.
Referenced by smach< CON, K, M >::pop_state(), and smach< CON, K, M >::push_state().
|
private |
Definition at line 297 of file _smach.h.
Referenced by smach< CON, K, M >::pop_state(), and smach< CON, K, M >::push_state().
|
private |
Definition at line 298 of file _smach.h.
Referenced by smach< CON, K, M >::egress(), smach< CON, K, M >::pop_state(), smach< CON, K, M >::push_state(), and smach< CON, K, M >::state_depth().