ETL  0.04.19
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Attributes | List of all members
smach< CON, K, M > Class Template Reference

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_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

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 61 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 65 of file _smach.h.

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

Definition at line 66 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 67 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 75 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 509 of file _smach.h.

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

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 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().

template<typename CON , typename K = int, typename M = mutex_null>
static bool smach< CON, K, M >::event_error ( const event_result rhs)
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.

template<typename CON , typename K = int, typename M = mutex_null>
bool smach< CON, K, M >::set_default_state ( const state_base nextstate)
inline
template<typename CON , typename K = int, typename M = mutex_null>
bool smach< CON, K, M >::egress ( )
inline
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 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().

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
nextstatePointer to the state to enter
See Also
pop_state()

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.

template<typename CON , typename K = int, typename M = mutex_null>
void smach< CON, K, M >::pop_state ( )
inline
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 533 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 543 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
template<typename CON , typename K = int, typename M = mutex_null>
event_result smach< CON, K, M >::process_event ( const event id)
inline

Member Data Documentation

template<typename CON , typename K = int, typename M = mutex_null>
const state_base* smach< CON, K, M >::curr_state
private
template<typename CON , typename K = int, typename M = mutex_null>
smach* smach< CON, K, M >::child
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().

template<typename CON , typename K = int, typename M = mutex_null>
void* smach< CON, K, M >::state_context
template<typename CON , typename K = int, typename M = mutex_null>
context_type* smach< CON, K, M >::machine_context
private
template<typename CON , typename K = int, typename M = mutex_null>
const state_base* smach< CON, K, M >::default_state
private
template<typename CON , typename K = int, typename M = mutex_null>
void* smach< CON, K, M >::default_context
private
template<typename CON , typename K = int, typename M = mutex_null>
_mutex smach< CON, K, M >::mutex
private

Definition at line 292 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 296 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 297 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

The documentation for this class was generated from the following file: