#include <_smach.h>
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 |
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 |
========================================================================
A more detailed description needs to be written.
Definition at line 61 of file _smach.h.
typedef CON smach< CON, K, M >::context_type |
enum smach::event_result |
smach< CON, K, M >::smach | ( | context_type * | machine_context = 0 |
) | [inline] |
smach< CON, K, M >::~smach | ( | ) | [inline] |
The destructor.
Definition at line 528 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().
const char* smach< CON, K, M >::get_state_name | ( | ) | const [inline] |
Gets the name of the currently active state.
Definition at line 312 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().
static bool smach< CON, K, M >::event_error | ( | const event_result & | rhs | ) | [inline, static] |
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 328 of file _smach.h.
References smach< CON, K, M >::RESULT_ERROR.
bool smach< CON, K, M >::set_default_state | ( | const state_base * | nextstate | ) | [inline] |
Definition at line 332 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.
bool smach< CON, K, M >::egress | ( | ) | [inline] |
Leaves the current state.
Effectively makes the state_depth() function return zero.
Definition at line 375 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().
bool smach< CON, K, M >::enter | ( | const state_base * | nextstate | ) | [inline] |
State entry function.
Attempts to enter the given state, popping off all states on the stack in the process.
Definition at line 409 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().
bool smach< CON, K, M >::push_state | ( | const state_base * | nextstate | ) | [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 452 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.
void smach< CON, K, M >::pop_state | ( | ) | [inline] |
Pops state off of state stack.
Decreases state depth
Definition at line 488 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().
void smach< CON, K, M >::set_child | ( | smach< CON, K, M > * | x | ) | [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 541 of file _smach.h.
References smach< CON, K, M >::child, and ETL_MUTEX_LOCK.
int smach< CON, K, M >::state_depth | ( | ) | [inline] |
Returns the number states currently active.
Definition at line 551 of file _smach.h.
References smach< CON, K, M >::curr_state, and smach< CON, K, M >::states_on_stack.
event_result smach< CON, K, M >::process_event | ( | const event_key & | id | ) | [inline] |
Definition at line 555 of file _smach.h.
Referenced by smach< CON, K, M >::process_event(), and smach< CON, K, M >::state< T >::process_event().
event_result smach< CON, K, M >::process_event | ( | const event & | id | ) | [inline] |
Process an event.
Definition at line 559 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.
const state_base* smach< CON, K, M >::curr_state [private] |
Current state of the machine.
Definition at line 287 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().
smach* smach< CON, K, M >::child [private] |
Child machine.
Definition at line 288 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 291 of file _smach.h.
Referenced by smach< CON, K, M >::egress(), smach< CON, K, M >::enter(), smach< CON, K, M >::state< T >::get_context(), smach< CON, K, M >::state< T >::leave_state(), smach< CON, K, M >::pop_state(), smach< CON, K, M >::process_event(), smach< CON, K, M >::state< T >::process_event(), and smach< CON, K, M >::push_state().
context_type* smach< CON, K, M >::machine_context [private] |
Machine Context.
Definition at line 294 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().
const state_base* smach< CON, K, M >::default_state [private] |
Definition at line 296 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().
void* smach< CON, K, M >::default_context [private] |
Definition at line 297 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().
const state_base* smach< CON, K, M >::state_stack[SMACH_STATE_STACK_SIZE] [private] |
State stack data.
Definition at line 304 of file _smach.h.
Referenced by smach< CON, K, M >::pop_state(), and smach< CON, K, M >::push_state().
void* smach< CON, K, M >::state_context_stack[SMACH_STATE_STACK_SIZE] [private] |
Definition at line 305 of file _smach.h.
Referenced by smach< CON, K, M >::pop_state(), and smach< CON, K, M >::push_state().
int smach< CON, K, M >::states_on_stack [private] |
Definition at line 306 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().