OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
qOS::sm::state Class Reference

A state object. More...

#include <fsm.hpp>

Public Member Functions

 state ()=default
 
bool add (sm::state &s, const sm::stateCallback_t &sFcn, sm::state &init) noexcept
 Add the specified state as a child state.
 
bool add (sm::state &s, const sm::stateCallback_t &sFcn) noexcept
 Add the specified state as a child state.
 
bool install (transition *table, size_t n) noexcept
 Install a table with the outgoing transitions for this state.
 
template<size_t numberOfTransitions>
bool install (transition(&table)[numberOfTransitions]) noexcept
 Install a table with the outgoing transitions for this state.
 
bool install (transition *table, size_t nTable, timeoutStateDefinition *def, size_t nDef)
 Install both, a table with the outgoing transitions for this state and fixed timeouts for the specified state using a lookup-table.
 
template<size_t numberOfTransitions, size_t numberOfTimeoutDefs>
bool install (transition(&table)[numberOfTransitions], timeoutStateDefinition(&def)[numberOfTimeoutDefs]) noexcept
 Install both, a table with the outgoing transitions for this state and fixed timeouts for the specified state using a lookup-table.
 
bool install (timeoutStateDefinition *def, size_t n) noexcept
 Install fixed timeouts for the specified state using a lookup-table.
 
template<size_t numberOfTimeoutDefs>
bool install (timeoutStateDefinition(&def)[numberOfTimeoutDefs]) noexcept
 Install fixed timeouts for the specified state using a lookup-table.
 
void * getData (void) noexcept
 Retrieve the state data or storage-pointer.
 
void setData (void *pData) noexcept
 Set the state data or storage-pointer.
 
transitiongetTransitionTable (void) noexcept
 Retrieve a pointer to the state transition table.
 
void setCallback (const stateCallback_t sFcn) noexcept
 Set/Change the state callback.
 

Protected Member Functions

virtual sm::status activities (sm::handler_t h)
 

Detailed Description

A state object.

States are represented as instances of the state object. One important attribute of this object is the callback function, which is used to describe the behavior specific to the state. Also there is a pointer to the parent state to define nesting of the state and its place in the hierarchical topology.

So concrete state machine are built by adding an arbitrary number states and defining callback functions.

State machines are constructed by composition, therefore, the topology of a state machine is determined upon construction. In this FSM implementation, there are not distinction between composite states(states containing sub-states) and leaf states. All states are potentially composite.

The APIs stateMachine::add() and state::add() should be used to initialize the state and define its position in the topology.

Constructor & Destructor Documentation

◆ state()

qOS::sm::state::state ( )
default

Member Function Documentation

◆ activities()

virtual sm::status qOS::sm::state::activities ( sm::handler_t h)
protectedvirtual

◆ add() [1/2]

bool qOS::sm::state::add ( sm::state & s,
const sm::stateCallback_t & sFcn )
inlinenoexcept

Add the specified state as a child state.

Parameters
[in]sThe state object.
[in]sFcnThe handler function associated to the state.

Prototype:

sm::status xCallback( sm::handler_t h )
The state callback argument to handle the state-machine dynamics and provide execution information....
Definition fsm.hpp:252
status
This enumeration defines the built-in state-execution status values that can be used as return value ...
Definition fsm.hpp:193
Returns
true on success, otherwise return false.

◆ add() [2/2]

bool qOS::sm::state::add ( sm::state & s,
const sm::stateCallback_t & sFcn,
sm::state & init )
inlinenoexcept

Add the specified state as a child state.

Parameters
[in]sThe state object.
[in]sFcnThe handler function associated to the state.

Prototype:

sm::status xCallback( sm::handler_t h )
Parameters
[in]initThe first child-state to be executed if the subscribed state its a parent in an hierarchical pattern. (default transition). You can ignore this argument.
Returns
true on success, otherwise return false.

◆ getData()

void * qOS::sm::state::getData ( void )
noexcept

Retrieve the state data or storage-pointer.

Returns
The state data or storage-pointer.

◆ getTransitionTable()

transition * qOS::sm::state::getTransitionTable ( void )
noexcept

Retrieve a pointer to the state transition table.

Returns
A pointer to the state transition table if available, otherwise return nullptr.

◆ install() [1/6]

bool qOS::sm::state::install ( timeoutStateDefinition * def,
size_t n )
noexcept

Install fixed timeouts for the specified state using a lookup-table.

Attention
This feature its only available if the FSM has a signal-queue installed.
Precondition
The container state-machine must have a timeout-specification installed.
Note
The lookup table should be an array of type timeoutStateDefinition with n elements matching { time, options }.
Parameters
[in]defThe lookup table matching the requested timeout values with their respective options.
{ [Timeout value], [Options(Combined with a bitwise OR)] } 
[in]nThe number of elements inside def.
Returns
Returns true on success, otherwise returns false.

◆ install() [2/6]

template<size_t numberOfTimeoutDefs>
bool qOS::sm::state::install ( timeoutStateDefinition(&) def[numberOfTimeoutDefs])
inlinenoexcept

Install fixed timeouts for the specified state using a lookup-table.

Attention
This feature its only available if the FSM has a signal-queue installed.
Precondition
The container state-machine must have a timeout-specification installed.
Note
The lookup table should be an array of type timeoutStateDefinition with n elements matching { time, options }.
Template Parameters
numberOfTimeoutDefsThe number of elements in def
Parameters
[in]defThe lookup table matching the requested timeout values with their respective options.
{ [Timeout value], [Options(Combined with a bitwise OR)] } 
Returns
Returns true on success, otherwise returns false.

◆ install() [3/6]

bool qOS::sm::state::install ( transition * table,
size_t n )
noexcept

Install a table with the outgoing transitions for this state.

Parameters
[in]tableAn array of entries of type sm::transition_t with the outgoing transitions. Each entry relates signals, actions and the target state using the following layout:
{ [Signal], [Action/Guard], [Target state], [History Mode] } 
[in]nThe number of elements inside table.
Returns
true on success, otherwise return false.

◆ install() [4/6]

bool qOS::sm::state::install ( transition * table,
size_t nTable,
timeoutStateDefinition * def,
size_t nDef )
inline

Install both, a table with the outgoing transitions for this state and fixed timeouts for the specified state using a lookup-table.

Precondition
The container state-machine must have a timeout-specification installed.
Note
The lookup table should be an array of type timeoutStateDefinition with n elements matching { time, options }.
Parameters
[in]tableAn array of entries of type sm::transition_t with the outgoing transitions. Each entry relates signals, actions and the target state using the following layout:
{ [Signal], [Action/Guard], [Target state], [History Mode] } 
[in]nTableThe number of elements inside table.
[in]defThe lookup table matching the requested timeout values with their respective options.
{ [Timeout value], [Options(Combined with a bitwise OR)] } 
[in]nDefThe number of elements inside def.
Returns
true on success, otherwise return false.

◆ install() [5/6]

template<size_t numberOfTransitions>
bool qOS::sm::state::install ( transition(&) table[numberOfTransitions])
inlinenoexcept

Install a table with the outgoing transitions for this state.

Template Parameters
numberOfTransitionsThe array size
Parameters
[in]tableAn array of entries of type sm::transition_t with the outgoing transitions. Each entry relates signals, actions and the target state using the following layout:
{ [Signal], [Action/Guard], [Target state], [History Mode] } 
Returns
true on success, otherwise return false.

◆ install() [6/6]

template<size_t numberOfTransitions, size_t numberOfTimeoutDefs>
bool qOS::sm::state::install ( transition(&) table[numberOfTransitions],
timeoutStateDefinition(&) def[numberOfTimeoutDefs] )
inlinenoexcept

Install both, a table with the outgoing transitions for this state and fixed timeouts for the specified state using a lookup-table.

Precondition
The container state-machine must have a timeout-specification installed.
Note
The lookup table should be an array of type timeoutStateDefinition with n elements matching { time, options }.
Template Parameters
numberOfTransitionsThe number of elements in table
numberOfTimeoutDefsThe number of elements in def
Parameters
[in]tableAn array of entries of type sm::transition_t with the outgoing transitions. Each entry relates signals, actions and the target state using the following layout:
{ [Signal], [Action/Guard], [Target state], [History Mode] } 
[in]defThe lookup table matching the requested timeout values with their respective options.
{ [Timeout value], [Options(Combined with a bitwise OR)] } 
Returns
true on success, otherwise return false.

◆ setCallback()

void qOS::sm::state::setCallback ( const stateCallback_t sFcn)
noexcept

Set/Change the state callback.

Parameters
[in]sFcnThe state callback function.

◆ setData()

void qOS::sm::state::setData ( void * pData)
noexcept

Set the state data or storage-pointer.

Parameters
[in]pDataThe state data or storage-pointer.