Pyrogenesis  trunk
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CFsm Class Reference

Manages states, events, actions and transitions between states. More...

#include <FSM.h>

Inheritance diagram for CFsm:
Inheritance graph
[legend]

Public Member Functions

 CFsm ()
 
virtual ~CFsm ()
 
virtual void Setup ()
 Constructs the state machine. More...
 
void Shutdown ()
 Clear event, action and condition lists and reset state machine. More...
 
void AddState (unsigned int state)
 Adds the specified state to the internal list of states. More...
 
CFsmEventAddEvent (unsigned int eventType)
 Adds the specified event to the internal list of events. More...
 
CFsmTransitionAddTransition (unsigned int state, unsigned int eventType, unsigned int nextState)
 Adds a new transistion to the state machine. More...
 
CFsmTransitionAddTransition (unsigned int state, unsigned int eventType, unsigned int nextState, void *pAction, void *pContext)
 Adds a new transition to the state machine. More...
 
CFsmTransitionGetTransition (unsigned int state, unsigned int eventType) const
 Looks up the transition given the state, event and next state to transition to. More...
 
CFsmTransitionGetEventTransition (unsigned int eventType) const
 
void SetFirstState (unsigned int firstState)
 Sets the initial state for FSM. More...
 
void SetCurrState (unsigned int state)
 Sets the current state and update the last state to the current state. More...
 
unsigned int GetCurrState () const
 
void SetNextState (unsigned int nextState)
 
unsigned int GetNextState () const
 
const StateSetGetStates () const
 
const EventMapGetEvents () const
 
const TransitionListGetTransitions () const
 
bool Update (unsigned int eventType, void *pEventData)
 Updates the FSM and retrieves next state. More...
 
bool IsValidState (unsigned int state) const
 Verifies whether the specified state is managed by the FSM. More...
 
bool IsValidEvent (unsigned int eventType) const
 Verifies whether the specified event is managed by the FSM. More...
 
virtual bool IsDone () const
 Tests whether the state machine has finished its work. More...
 

Private Member Functions

 NONCOPYABLE (CFsm)
 
bool IsFirstTime () const
 Verifies whether state machine has already been updated. More...
 

Private Attributes

bool m_Done
 
unsigned int m_FirstState
 
unsigned int m_CurrState
 
unsigned int m_NextState
 
StateSet m_States
 
EventMap m_Events
 
TransitionList m_Transitions
 

Detailed Description

Manages states, events, actions and transitions between states.

It provides an interface for advertising events and track the current state. The implementation is a Mealy state machine, so the system respond to events and execute some action.

A Mealy state machine has behaviour associated with state transitions; Mealy machines are event driven where an event triggers a state transition.

Constructor & Destructor Documentation

◆ CFsm()

CFsm::CFsm ( )

◆ ~CFsm()

CFsm::~CFsm ( )
virtual

Member Function Documentation

◆ AddEvent()

CFsmEvent * CFsm::AddEvent ( unsigned int  eventType)

Adds the specified event to the internal list of events.

Note
If an eveny with the specified ID exists, the event is not added.
Returns
a pointer to the new event.

◆ AddState()

void CFsm::AddState ( unsigned int  state)

Adds the specified state to the internal list of states.

Note
If a state with the specified ID exists, the state is not added.

◆ AddTransition() [1/2]

CFsmTransition * CFsm::AddTransition ( unsigned int  state,
unsigned int  eventType,
unsigned int  nextState 
)

Adds a new transistion to the state machine.

Returns
a pointer to the new transition.

◆ AddTransition() [2/2]

CFsmTransition * CFsm::AddTransition ( unsigned int  state,
unsigned int  eventType,
unsigned int  nextState,
void *  pAction,
void *  pContext 
)

Adds a new transition to the state machine.

Returns
a pointer to the new transition.

◆ GetCurrState()

unsigned int CFsm::GetCurrState ( ) const
inline

◆ GetEvents()

const EventMap& CFsm::GetEvents ( ) const
inline

◆ GetEventTransition()

CFsmTransition* CFsm::GetEventTransition ( unsigned int  eventType) const

◆ GetNextState()

unsigned int CFsm::GetNextState ( ) const
inline

◆ GetStates()

const StateSet& CFsm::GetStates ( ) const
inline

◆ GetTransition()

CFsmTransition * CFsm::GetTransition ( unsigned int  state,
unsigned int  eventType 
) const

Looks up the transition given the state, event and next state to transition to.

◆ GetTransitions()

const TransitionList& CFsm::GetTransitions ( ) const
inline

◆ IsDone()

bool CFsm::IsDone ( ) const
virtual

Tests whether the state machine has finished its work.

Note
This is state machine specific.

◆ IsFirstTime()

bool CFsm::IsFirstTime ( ) const
private

Verifies whether state machine has already been updated.

◆ IsValidEvent()

bool CFsm::IsValidEvent ( unsigned int  eventType) const

Verifies whether the specified event is managed by the FSM.

◆ IsValidState()

bool CFsm::IsValidState ( unsigned int  state) const

Verifies whether the specified state is managed by the FSM.

◆ NONCOPYABLE()

CFsm::NONCOPYABLE ( CFsm  )
private

◆ SetCurrState()

void CFsm::SetCurrState ( unsigned int  state)

Sets the current state and update the last state to the current state.

◆ SetFirstState()

void CFsm::SetFirstState ( unsigned int  firstState)

Sets the initial state for FSM.

◆ SetNextState()

void CFsm::SetNextState ( unsigned int  nextState)
inline

◆ Setup()

void CFsm::Setup ( )
virtual

Constructs the state machine.

This method must be overriden so that connections are constructed for the particular state machine implemented.

◆ Shutdown()

void CFsm::Shutdown ( )

Clear event, action and condition lists and reset state machine.

◆ Update()

bool CFsm::Update ( unsigned int  eventType,
void *  pEventData 
)

Updates the FSM and retrieves next state.

Returns
whether the state was changed.

Member Data Documentation

◆ m_CurrState

unsigned int CFsm::m_CurrState
private

◆ m_Done

bool CFsm::m_Done
private

◆ m_Events

EventMap CFsm::m_Events
private

◆ m_FirstState

unsigned int CFsm::m_FirstState
private

◆ m_NextState

unsigned int CFsm::m_NextState
private

◆ m_States

StateSet CFsm::m_States
private

◆ m_Transitions

TransitionList CFsm::m_Transitions
private

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