state.h File Reference

Include file for state manager. More...

#include "..\list\list.h"
#include "state.c"

Data Structures

struct  STATE_TRAN
 Definition of a state transition. More...
struct  STATE_ACTION
 Definition of a state action. More...
struct  STATEMGR
 Definition of a state machine. More...

Defines

#define STATE_ACTIVE
 This define can be evaluated to check if this module is included and active.

Functions

STATEMGRSTATEMGR_create (var vState)
 Creates new State Manager.
void STATEMGR_remove (STATEMGR *psState)
 Removes a State Machine.
void STATEMGR_addTransition (STATEMGR *psState, var vCurState, var vNewState, void *pfCheck, void *pfSwitch)
 Add new transition to State Machine.
void STATEMGR_addState (STATEMGR *psState, var vCurState, void *pfAction, void *pfInit, void *pfDeinit)
 Add new state to State Machine.
void STATEMGR_execute (STATEMGR *psState)
 Execute cyclical actions and transition checks for State Machine.
var STATEMGR_getState (STATEMGR *psState)
 Get currently active state.


Detailed Description

Include file for state manager.


Function Documentation

void STATEMGR_addState ( STATEMGR psState,
var  vCurState,
void *  pfAction,
void *  pfInit,
void *  pfDeinit 
)

Add new state to State Machine.

A new state with init, deinit and cyclical callback functions is added. States can only be added, but not removed. Each state may only be added once. If a state is added multiple times, only the first definition will be recognized.

Parameters:
psState Pointer to affected STATEMGR
vCurState Current state
pfAction Pointer to cyclical action callback function (type void func(void)) [optional: may be set to NULL]
pfInit Pointer to initialization function (called on state entry - type void func(void)) [optional: may be set to NULL]
pfDeinit Pointer to deinitialization function (called on state exit - type void func(void)) [optional: may be set to NULL]

void STATEMGR_addTransition ( STATEMGR psState,
var  vCurState,
var  vNewState,
void *  pfCheck,
void *  pfSwitch 
)

Add new transition to State Machine.

A new state transition with check condition callback and tranistion action callback is added. Transitions can only be added, but not removed.

Parameters:
psState Pointer to affected STATEMGR
vCurState Current state
vNewState Next state
pfCheck Check condition callback function (type: var func(void) - return value 1 = true, 0 = false)
pfSwitch Pointer to transition action callback function (type void func(void)) [optional: may be set to NULL]

STATEMGR* STATEMGR_create ( var  vState  ) 

Creates new State Manager.

Use STATEMGR_addTransition and STATEMGR_addAction to configure state manager.

Parameters:
vState initial state
Returns:
Pointer to STATEMGR structure

void STATEMGR_execute ( STATEMGR psState  ) 

Execute cyclical actions and transition checks for State Machine.

Must be called cyclically.

Parameters:
psState Pointer to affected STATEMGR

var STATEMGR_getState ( STATEMGR psState  ) 

Get currently active state.

Should only be used for stopping loop functions and never for if checks.

Parameters:
psState Pointer to affected STATEMGR
Returns:
Current state

void STATEMGR_remove ( STATEMGR psState  ) 

Removes a State Machine.

Frees all memory previously allocated by the given state machine.

Parameters:
psState Pointer to affected STATEMGR


Generated on Wed Feb 10 23:23:43 2010 for Toolbox by  doxygen 1.5.9