smach< CON, K, M > Class Template Reference

Templatized State Machine. More...

#include <_smach.h>

List of all members.

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_basecurr_state
 Current state of the machine.
smachchild
 Child machine.
context_typemachine_context
 Machine Context.
const state_basedefault_state
void * default_context
_mutex mutex
const state_basestate_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
 Event definition class. More...
struct  pop_exception
class  state
 State class. More...
class  state_base


Detailed Description

template<typename CON, typename K = int, typename M = mutex_null>
class smach< CON, K, M >

Templatized State Machine.

========================================================================

A more detailed description needs to be written.

Definition at line 60 of file _smach.h.


Member Typedef Documentation

template<typename CON, typename K = int, typename M = mutex_null>
typedef K smach< CON, K, M >::event_key

Definition at line 64 of file _smach.h.

template<typename CON, typename K = int, typename M = mutex_null>
typedef M smach< CON, K, M >::_mutex

Definition at line 65 of file _smach.h.

template<typename CON, typename K = int, typename M = mutex_null>
typedef CON smach< CON, K, M >::context_type

Definition at line 66 of file _smach.h.


Member Enumeration Documentation

template<typename CON, typename K = int, typename M = mutex_null>
enum smach::event_result

Result type for event processing.

Enumerator:
RESULT_ERROR  General error or malfunction.
RESULT_OK  Event has been processed.
RESULT_ACCEPT  The event has been explicitly accepted.
RESULT_REJECT  The event has been explicitly rejected.
RESULT_END  Not a valid result.

Definition at line 74 of file _smach.h.


Constructor & Destructor Documentation

template<typename CON, typename K = int, typename M = mutex_null>
smach< CON, K, M >::smach ( context_type machine_context = 0  )  [inline]

State Machine Constructor.

A more detailed description needs to be written

Definition at line 516 of file _smach.h.

template<typename CON, typename K = int, typename M = mutex_null>
smach< CON, K, M >::~smach (  )  [inline]

The destructor.

Definition at line 527 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().


Member Function Documentation

template<typename CON, typename K = int, typename M = mutex_null>
const char* smach< CON, K, M >::get_state_name (  )  const [inline]

Gets the name of the currently active state.

Definition at line 311 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().

template<typename CON, typename K = int, typename M = mutex_null>
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 327 of file _smach.h.

References smach< CON, K, M >::RESULT_ERROR.

template<typename CON, typename K = int, typename M = mutex_null>
bool smach< CON, K, M >::set_default_state ( const state_base nextstate  )  [inline]

Definition at line 331 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.

template<typename CON, typename K = int, typename M = mutex_null>
bool smach< CON, K, M >::egress (  )  [inline]

Leaves the current state.

Effectively makes the state_depth() function return zero.

Definition at line 374 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().

template<typename CON, typename K = int, typename M = mutex_null>
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 408 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().

template<typename CON, typename K = int, typename M = mutex_null>
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.

Parameters:
nextstate Pointer to the state to enter
See also:
pop_state()

Definition at line 451 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.

template<typename CON, typename K = int, typename M = mutex_null>
void smach< CON, K, M >::pop_state (  )  [inline]

Pops state off of state stack.

Decreases state depth

Definition at line 487 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().

template<typename CON, typename K = int, typename M = mutex_null>
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 540 of file _smach.h.

References smach< CON, K, M >::child, and ETL_MUTEX_LOCK.

template<typename CON, typename K = int, typename M = mutex_null>
int smach< CON, K, M >::state_depth (  )  [inline]

Returns the number states currently active.

Definition at line 550 of file _smach.h.

References smach< CON, K, M >::curr_state, and smach< CON, K, M >::states_on_stack.

template<typename CON, typename K = int, typename M = mutex_null>
event_result smach< CON, K, M >::process_event ( const event_key id  )  [inline]

Definition at line 554 of file _smach.h.

Referenced by smach< CON, K, M >::process_event(), and smach< CON, K, M >::state< T >::process_event().

template<typename CON, typename K = int, typename M = mutex_null>
event_result smach< CON, K, M >::process_event ( const event id  )  [inline]

Process an event.

Definition at line 558 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.


Member Data Documentation

template<typename CON, typename K = int, typename M = mutex_null>
const state_base* smach< CON, K, M >::curr_state [private]

Current state of the machine.

Definition at line 286 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().

template<typename CON, typename K = int, typename M = mutex_null>
smach* smach< CON, K, M >::child [private]

Child machine.

Definition at line 287 of file _smach.h.

Referenced by smach< CON, K, M >::process_event(), and smach< CON, K, M >::set_child().

template<typename CON, typename K = int, typename M = mutex_null>
void* smach< CON, K, M >::state_context

State Context.

Definition at line 290 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().

template<typename CON, typename K = int, typename M = mutex_null>
context_type* smach< CON, K, M >::machine_context [private]

Machine Context.

Definition at line 293 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().

template<typename CON, typename K = int, typename M = mutex_null>
const state_base* smach< CON, K, M >::default_state [private]

Definition at line 295 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().

template<typename CON, typename K = int, typename M = mutex_null>
void* smach< CON, K, M >::default_context [private]

Definition at line 296 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().

template<typename CON, typename K = int, typename M = mutex_null>
_mutex smach< CON, K, M >::mutex [private]

Definition at line 299 of file _smach.h.

template<typename CON, typename K = int, typename M = mutex_null>
const state_base* smach< CON, K, M >::state_stack[SMACH_STATE_STACK_SIZE] [private]

State stack data.

Definition at line 303 of file _smach.h.

Referenced by smach< CON, K, M >::pop_state(), and smach< CON, K, M >::push_state().

template<typename CON, typename K = int, typename M = mutex_null>
void* smach< CON, K, M >::state_context_stack[SMACH_STATE_STACK_SIZE] [private]

Definition at line 304 of file _smach.h.

Referenced by smach< CON, K, M >::pop_state(), and smach< CON, K, M >::push_state().

template<typename CON, typename K = int, typename M = mutex_null>
int smach< CON, K, M >::states_on_stack [private]

Definition at line 305 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().


The documentation for this class was generated from the following file:
Generated on Sun Oct 28 03:51:07 2007 for ETL by  doxygen 1.5.3-20071008