rFSMTools
rFSM Tools
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
rfsm::StateMachine Class Reference

The rfsm::StateMachine class. More...

#include <rfsm.h>

+ Inheritance diagram for rfsm::StateMachine:

Public Member Functions

 StateMachine (bool verbose=false)
 StateMachine load and execute a rFSM state machine written in LUA. More...
 
virtual ~StateMachine ()
 ~StateMachine More...
 
const std::string getFileName ()
 getFileName More...
 
bool load (const std::string &filename)
 loads and initializes a rFSM state machine More...
 
bool run ()
 run calls rfsm.run() More...
 
bool step (unsigned int n=1)
 step calls rfs.step(n) More...
 
bool sendEvent (const std::string &event)
 sendEvent calls rfsm.send_events(event) More...
 
bool sendEvents (unsigned int n,...)
 sendEvents calls rfsm.send_events(...) More...
 
bool doString (const std::string &command)
 doString execute a generic lua command More...
 
bool doFile (const std::string &filename)
 doFile execute a lua file More...
 
void addLuaPackagePath (const std::string &path)
 addLuaPackagePath add a new path to lua package.path More...
 
void close ()
 closes the state machine if it is already loaded More...
 
bool setStateCallback (const std::string &state, rfsm::StateCallback &callback)
 setStateCallback set an StateCallback object for a given state More...
 
const std::string getCurrentState ()
 getCurrentState returns the current activated state More...
 
const std::vector< std::string > & getEventsList ()
 getEventsList retrieves all available events in the state machine More...
 
bool getEventQueue (std::vector< std::string > &equeue)
 getEventQueue gets the current events in the rFSM event queue More...
 
const rfsm::StateGraphgetStateGraph ()
 getStateGraph return the rFSM state graph More...
 
bool enablePreStepHook ()
 enablePreStepHook enables the pre-step hook function of the rFSM. More...
 
bool enablePostStepHook ()
 enablePostStepHook enables the post-step hook function of the rFSM. More...
 
bool catchPrintOutput ()
 catchPrintOutput redirect the output of the lua 'print()' function to rfsm::StateMachine::onInfo() More...
 
virtual void onPreStep ()
 if pre-step hook function of rFSM is enabled this callback is called before stepping the state machine. More...
 
virtual void onPostStep ()
 if post-step hook function of rFSM is enabled this callback is called after stepping the state machine. More...
 
virtual void onWarning (const std::string message)
 this is called on every warning message generated from rFSM in verbose mode (i.e. More...
 
virtual void onError (const std::string message)
 this is called on every error message generated from rFSM More...
 
virtual void onInfo (const std::string message)
 this is called on every info message generated from rFSM in verbose mode (i.e. More...
 

Private Member Functions

virtual void onTrace (const std::string &message)
 onTrace is called on lua traceback More...
 

Private Attributes

Private *const mPriv
 
bool verbose
 

Detailed Description

The rfsm::StateMachine class.

Definition at line 122 of file rfsm.h.

Constructor & Destructor Documentation

rfsm::StateMachine::StateMachine ( bool  verbose = false)

StateMachine load and execute a rFSM state machine written in LUA.

Parameters
verboseenable verbosity if it is true.
virtual rfsm::StateMachine::~StateMachine ( )
virtual

~StateMachine

Member Function Documentation

void rfsm::StateMachine::addLuaPackagePath ( const std::string &  path)

addLuaPackagePath add a new path to lua package.path

Parameters
pathto a folder containg lua packages
bool rfsm::StateMachine::catchPrintOutput ( )

catchPrintOutput redirect the output of the lua 'print()' function to rfsm::StateMachine::onInfo()

Returns
true on success
Note
This should be called before running/stepping the state machine
void rfsm::StateMachine::close ( )

closes the state machine if it is already loaded

bool rfsm::StateMachine::doFile ( const std::string &  filename)

doFile execute a lua file

Parameters
filenamelua file name to execute
Returns
true on success
bool rfsm::StateMachine::doString ( const std::string &  command)

doString execute a generic lua command

Parameters
commanda string containg a valid lua command
Returns
true on success
bool rfsm::StateMachine::enablePostStepHook ( )

enablePostStepHook enables the post-step hook function of the rFSM.

If it is enabled, then onPostStep() callback will be called after stepping the state machine.

Returns
true on success
Note
This should be called before running/stepping the state machine
bool rfsm::StateMachine::enablePreStepHook ( )

enablePreStepHook enables the pre-step hook function of the rFSM.

If it is enabled, then onPreStep() callback will be called before stepping the state machine.

Returns
true on success
Note
This should be called before running/stepping the state machine
const std::string rfsm::StateMachine::getCurrentState ( )

getCurrentState returns the current activated state

Returns
the name of current active state
bool rfsm::StateMachine::getEventQueue ( std::vector< std::string > &  equeue)

getEventQueue gets the current events in the rFSM event queue

Parameters
equeuea vector of string to be filled with the current events
Returns
true on success
const std::vector<std::string>& rfsm::StateMachine::getEventsList ( )

getEventsList retrieves all available events in the state machine

Returns
a list of all available events
const std::string rfsm::StateMachine::getFileName ( )

getFileName

Returns
the loaded rFSM state machine's name
const rfsm::StateGraph& rfsm::StateMachine::getStateGraph ( )

getStateGraph return the rFSM state graph

Returns
rFSM state graph
bool rfsm::StateMachine::load ( const std::string &  filename)

loads and initializes a rFSM state machine

Parameters
filenamerFSM state machine file name
Returns
true on success
virtual void rfsm::StateMachine::onError ( const std::string  message)
virtual

this is called on every error message generated from rFSM

Parameters
messagethe error message
virtual void rfsm::StateMachine::onInfo ( const std::string  message)
virtual

this is called on every info message generated from rFSM in verbose mode (i.e.

StateMachine(bool verbose=true) )

Parameters
messagethe info message
virtual void rfsm::StateMachine::onPostStep ( )
virtual

if post-step hook function of rFSM is enabled this callback is called after stepping the state machine.

virtual void rfsm::StateMachine::onPreStep ( )
virtual

if pre-step hook function of rFSM is enabled this callback is called before stepping the state machine.

virtual void rfsm::StateMachine::onTrace ( const std::string &  message)
privatevirtual

onTrace is called on lua traceback

Parameters
messagethe trace message

Reimplemented from rfsm::LuaTraceCallback.

virtual void rfsm::StateMachine::onWarning ( const std::string  message)
virtual

this is called on every warning message generated from rFSM in verbose mode (i.e.

StateMachine(bool verbose=true) )

Parameters
messagethe warning message
bool rfsm::StateMachine::run ( )

run calls rfsm.run()

Returns
true on success
bool rfsm::StateMachine::sendEvent ( const std::string &  event)

sendEvent calls rfsm.send_events(event)

Parameters
eventa single event to be send to the state machine
Returns
true on success
bool rfsm::StateMachine::sendEvents ( unsigned int  n,
  ... 
)

sendEvents calls rfsm.send_events(...)

Parameters
nnumber of events to be send
...then events given as separate params (e.g. sendEvents(2, "e1", "e2"))
Returns
true on success
bool rfsm::StateMachine::setStateCallback ( const std::string &  state,
rfsm::StateCallback callback 
)

setStateCallback set an StateCallback object for a given state

Parameters
statethe name of the state (should corespond the state name in rFSM)
callbackan object of StateCallback class
Returns
true on success
bool rfsm::StateMachine::step ( unsigned int  n = 1)

step calls rfs.step(n)

Parameters
nnumber the steps to taken (defaule is 1)
Returns
true on success

Member Data Documentation

Private* const rfsm::StateMachine::mPriv
private

Definition at line 305 of file rfsm.h.

bool rfsm::StateMachine::verbose
private

Definition at line 307 of file rfsm.h.


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