OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
fsm.hpp
1#ifndef QOS_CPP_FSM
2#define QOS_CPP_FSM
3
4#include "include/types.hpp"
5#include "include/timer.hpp"
6#include "include/queue.hpp"
7
8namespace qOS {
9
10
16 class stateMachine;
17
21 namespace sm {
22
27 class state;
28
29 using signalIDType = uint32_t;
30
41 SIGNAL_START = 0xFFFFFFFFUL,
47 SIGNAL_EXIT = 0xFFFFFFFEUL,
53 SIGNAL_ENTRY = 0xFFFFFFFDUL,
57 SIGNAL_NONE = 0xFFFFFFFCUL,
59 TM_MAX = 0xFFFFFFFBUL,
60 TM_MIN = TM_MAX - ( Q_FSM_MAX_TIMEOUTS - 1 ),
62 #if ( 0 == Q_FSM_MAX_TIMEOUTS )
63 #warning "FSM has no defined internal timeouts"
64 #elif ( 1 == Q_FSM_MAX_TIMEOUTS )
65 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
66 #elif ( 2 == Q_FSM_MAX_TIMEOUTS )
67 SIGNAL_TIMEOUT0= 0xFFFFFFFBUL,
68 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
69 #elif ( 3 == Q_FSM_MAX_TIMEOUTS )
73 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
77 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
81 SIGNAL_TIMEOUT2 = 0xFFFFFFF9UL,
82 #elif ( 4 == Q_FSM_MAX_TIMEOUTS )
83 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
84 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
85 SIGNAL_TIMEOUT2 = 0xFFFFFFF9UL,
86 SIGNAL_TIMEOUT3 = 0xFFFFFFF8UL,
87 #elif ( 5 == Q_FSM_MAX_TIMEOUTS )
88 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
89 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
90 SIGNAL_TIMEOUT2 = 0xFFFFFFF9UL,
91 SIGNAL_TIMEOUT3 = 0xFFFFFFF8UL,
92 SIGNAL_TIMEOUT4 = 0xFFFFFFF7UL,
93 #elif ( 6 == Q_FSM_MAX_TIMEOUTS )
94 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
95 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
96 SIGNAL_TIMEOUT2 = 0xFFFFFFF9UL,
97 SIGNAL_TIMEOUT3 = 0xFFFFFFF8UL,
98 SIGNAL_TIMEOUT4 = 0xFFFFFFF7UL,
99 SIGNAL_TIMEOUT5 = 0xFFFFFFF6UL,
100 #elif ( 7 == Q_FSM_MAX_TIMEOUTS )
101 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
102 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
103 SIGNAL_TIMEOUT2 = 0xFFFFFFF9UL,
104 SIGNAL_TIMEOUT3 = 0xFFFFFFF8UL,
105 SIGNAL_TIMEOUT4 = 0xFFFFFFF7UL,
106 SIGNAL_TIMEOUT5 = 0xFFFFFFF6UL,
107 SIGNAL_TIMEOUT6 = 0xFFFFFFF5UL,
108 #elif ( 8 == Q_FSM_MAX_TIMEOUTS )
109 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
110 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
111 SIGNAL_TIMEOUT2 = 0xFFFFFFF9UL,
112 SIGNAL_TIMEOUT3 = 0xFFFFFFF8UL,
113 SIGNAL_TIMEOUT4 = 0xFFFFFFF7UL,
114 SIGNAL_TIMEOUT5 = 0xFFFFFFF6UL,
115 SIGNAL_TIMEOUT6 = 0xFFFFFFF5UL,
116 SIGNAL_TIMEOUT7 = 0xFFFFFFF4UL,
117 #elif ( 9 == Q_FSM_MAX_TIMEOUTS )
118 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
119 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
120 SIGNAL_TIMEOUT2 = 0xFFFFFFF9UL,
121 SIGNAL_TIMEOUT3 = 0xFFFFFFF8UL,
122 SIGNAL_TIMEOUT4 = 0xFFFFFFF7UL,
123 SIGNAL_TIMEOUT5 = 0xFFFFFFF6UL,
124 SIGNAL_TIMEOUT6 = 0xFFFFFFF5UL,
125 SIGNAL_TIMEOUT7 = 0xFFFFFFF4UL,
126 SIGNAL_TIMEOUT8 = 0xFFFFFFF3UL,
127 #elif ( 10 == Q_FSM_MAX_TIMEOUTS )
128 SIGNAL_TIMEOUT0 = 0xFFFFFFFBUL,
129 SIGNAL_TIMEOUT1 = 0xFFFFFFFAUL,
130 SIGNAL_TIMEOUT2 = 0xFFFFFFF9UL,
131 SIGNAL_TIMEOUT3 = 0xFFFFFFF8UL,
132 SIGNAL_TIMEOUT4 = 0xFFFFFFF7UL,
133 SIGNAL_TIMEOUT5 = 0xFFFFFFF6UL,
134 SIGNAL_TIMEOUT6 = 0xFFFFFFF5UL,
135 SIGNAL_TIMEOUT7 = 0xFFFFFFF4UL,
136 SIGNAL_TIMEOUT8 = 0xFFFFFFF3UL,
137 SIGNAL_TIMEOUT9 = 0xFFFFFFF2UL,
138 #elif ( Q_FSM_MAX_TIMEOUTS > 10 )
139 #error "Max FSM allowed timeout should not be greater that 10"
140 #endif
142 MIN_SIGNAL = 0x0UL,
143 MAX_SIGNAL = TM_MIN - 1
145 };
146
147
148
155 {
156 return static_cast<signalID>( signalID::TM_MAX - static_cast<signalID>( Q_FSM_MAX_TIMEOUTS - 1 ) + static_cast<signalID>( iTm ) );
157 }
158
164 constexpr signalID SIGNAL_USER( uint32_t s )
165 {
166 /*cstat -MISRAC++2008-5-0-3*/
167 return ( s < signalID::MAX_SIGNAL ) ? static_cast<signalID>( s ) : signalID::MAX_SIGNAL;
168 /*cstat +MISRAC++2008-5-0-3*/
169 }
170
174 struct signal_t {
176 void *data{ nullptr };
177 };
178
182 template <size_t numberOfSignals>
183 struct signalQueue {
185 signal_t qStack[ numberOfSignals ]; // skipcq: CXX-W2066
186 };
187
188
193 enum status : int16_t {
199 BEFORE_ANY = -32767,
204 ABSENT = -32766,
209 FAILURE = -32765,
213 SUCCESS = -32764,
220 };
221
244
245 #ifdef DOXYGEN
252 class handler_t final {
253 protected:
255 state *StartState{ nullptr };
256 state *NextState{ nullptr };
257 stateMachine* Machine{ nullptr };
258 state *State{ nullptr };
259 historyMode TransitionHistory{ historyMode::NO_HISTORY };
260 status Status{ SUCCESS };
262 _Handler( _Handler const& ) = delete; /* not copyable*/
263 void operator=( _Handler const& ) = delete; /* not assignable*/
265 public:
267 _Handler() = default;
269 void *SignalData{ nullptr };
270 void *Data{ nullptr };
271 void *StateData{ nullptr };
278 inline void nextState( state &s, historyMode m = historyMode::NO_HISTORY ) noexcept
279 {
280 NextState = &s;
281 TransitionHistory = m;
282 }
292 inline void startState( state &s ) noexcept
293 {
294 StartState = &s;
295 }
307 bool timeoutSet( const index_t i, const qOS::duration_t t ) noexcept;
318 bool timeoutStop( const index_t i ) noexcept;
323 inline state& thisState( void ) noexcept
324 {
325 return *State;
326 }
332 inline stateMachine& thisMachine( void ) noexcept
333 {
334 return *Machine;
335 }
340 inline signalID signal( void ) const noexcept
341 {
342 return Signal;
343 }
349 inline status lastStatus( void ) const noexcept
350 {
351 return Status;
352 }
353 friend class qOS::sm::state;
354 };
355 #endif
356
358 class stateHandler {
359 protected:
360 state *StartState{ nullptr };
361 state *NextState{ nullptr };
362 stateMachine* Machine{ nullptr };
363 state *State{ nullptr };
364 historyMode TransitionHistory{ historyMode::NO_HISTORY };
365 status Status{ SUCCESS };
366 signalID Signal{ signalID::SIGNAL_NONE };
367 stateHandler( stateHandler const& ) = delete; /* not copyable*/
368 void operator=( stateHandler const& ) = delete; /* not assignable*/
369 public:
370 stateHandler() = default;
371 virtual ~stateHandler() {}
372 void *SignalData{ nullptr };
373 void *Data{ nullptr };
374 void *StateData{ nullptr };
375 inline void nextState( state &s, historyMode m = historyMode::NO_HISTORY ) noexcept
376 {
377 NextState = &s;
378 TransitionHistory = m;
379 }
380 inline void startState( state &s ) noexcept
381 {
382 StartState = &s;
383 }
384 inline state& thisState( void ) noexcept
385 {
386 return *State;
387 }
388 inline stateMachine& thisMachine( void ) noexcept
389 {
390 return *Machine;
391 }
392 inline signalID signal( void ) const noexcept
393 {
394 return Signal;
395 }
396 inline status lastStatus( void ) const noexcept
397 {
398 return Status;
399 }
400 friend class qOS::sm::state;
401 };
402 using handler_t = stateHandler&;
427
446 using surroundingCallback_t = void (*)( handler_t );
447
465 using signalAction_t = bool (*)( handler_t );
466
470 using timeoutSpecOption_t = uint32_t;
471
480
485 struct transition final {
488 signalAction_t guard{ nullptr };
489 state *nextState{ nullptr };
491 void *signalData{ nullptr };
493 transition() = default;
494 /*cstat -MISRAC++2008-7-1-2*/
495 transition( signalID iSignal, signalAction_t sGuard, state &next, historyMode mHistory = historyMode::NO_HISTORY, void *sigData = nullptr ) :
496 xSignal(iSignal),
497 guard(sGuard),
498 nextState(&next),
499 history(mHistory),
500 signalData(sigData) {}
501 transition( signalID iSignal, state &next, historyMode mHistory = historyMode::NO_HISTORY, void *sigData = nullptr ) :
502 xSignal(iSignal),
503 guard(nullptr),
504 nextState(&next),
505 history(mHistory),
506 signalData(sigData) {}
507 transition( signalIDType iSignal, signalAction_t sGuard, state &next, uint8_t mHistory = 0U, void *sigData = nullptr ) :
508 xSignal( static_cast<signalID>( iSignal ) ),
509 guard(sGuard),
510 nextState(&next),
511 history( static_cast<historyMode>(mHistory) ),
512 signalData(sigData) {}
513 /*cstat +MISRAC++2008-7-1-2*/
514 transition( signalIDType iSignal, state &next, uint8_t mHistory = 0U, void *sigData = nullptr ) :
515 xSignal( static_cast<signalID>( iSignal ) ),
516 guard(nullptr),
517 nextState(&next),
518 history( static_cast<historyMode>(mHistory) ),
519 signalData(sigData) {}
520 };
521
542 class state {
543 private:
544 state *parent{ nullptr };
545 state *lastRunningChild{ nullptr };
546 state *initState{ nullptr };
547 stateCallback_t sCallback{ nullptr};
548 timeoutStateDefinition *tdef{ nullptr };
549 transition *tTable{ nullptr };
550 void *sData{ nullptr };
551 size_t tEntries{ 0U };
552 size_t nTm{ 0U };
553 stateHandler *pHandler{ nullptr };
554 void sweepTransitionTable( stateHandler &h ) const noexcept;
555 state( state const& ) = delete;
556 void operator=( state const& ) = delete;
557 bool subscribe( sm::state *s, const sm::stateCallback_t &sFcn, sm::state *init ) noexcept;
558 void topSelf( const sm::stateCallback_t &topFcn, sm::state *init ) noexcept;
559 protected:
561 public:
562 state() = default;
564 virtual ~state() {}
577 inline bool add( sm::state &s, const sm::stateCallback_t &sFcn, sm::state &init ) noexcept
578 {
579 return subscribe( &s, sFcn, &init );
580 }
589 inline bool add( sm::state &s, const sm::stateCallback_t &sFcn ) noexcept
590 {
591 return subscribe( &s, sFcn, nullptr );
592 }
603 bool install( transition *table, size_t n ) noexcept;
614 template <size_t numberOfTransitions>
615 bool install( transition (&table)[ numberOfTransitions ] ) noexcept // skipcq : CXX-W2066
616 {
617 return install( table, numberOfTransitions );
618 }
637 inline bool install( transition *table, size_t nTable, timeoutStateDefinition *def, size_t nDef )
638 {
639 int ret = 1;
640 /*cstat -MISRAC++2008-5-0-21 -CERT-EXP46-C */
641 ret &= install( table, nTable ); // skipcq: CXX-W2065
642 ret &= install( def, nDef ); // skipcq: CXX-W2065
643 /*cstat +MISRAC++2008-5-0-21 +CERT-EXP46-C */
644 return ( 0 != ret );
645 }
664 template <size_t numberOfTransitions, size_t numberOfTimeoutDefs>
665 bool install( transition (&table)[ numberOfTransitions ], timeoutStateDefinition (&def)[ numberOfTimeoutDefs ] ) noexcept // skipcq : CXX-W2066
666 {
667 return install( table, numberOfTransitions, def, numberOfTimeoutDefs );
668 }
683 bool install( timeoutStateDefinition *def, size_t n ) noexcept;
698 template <size_t numberOfTimeoutDefs>
699 bool install( timeoutStateDefinition (&def)[ numberOfTimeoutDefs ] ) noexcept // skipcq : CXX-W2066
700 {
701 return install( def, numberOfTimeoutDefs );
702 }
707 void* getData( void ) noexcept;
712 void setData( void *pData ) noexcept;
723 void setCallback( const stateCallback_t sFcn ) noexcept;
724 friend class qOS::stateMachine;
725 };
726
732 uint32_t isPeriodic{ 0U };
733 timer timeout[ Q_FSM_MAX_TIMEOUTS ]; // skipcq: CXX-W2066
734 friend class qOS::stateMachine;
735 };
736
738 enum psReqStatus{
739 PS_SIGNAL_NOT_FOUND,
740 PS_SUBSCRIBER_NOT_FOUND,
741 PS_SUBSCRIBER_FOUND,
742 PS_SIGNAL_SLOTS_FULL,
743 PS_SUBSCRIBER_SLOTS_FULL
744 };
745
746 struct psIndex_t {
747 psReqStatus status;
748 size_t sig_slot;
749 size_t sub_slot;
750 };
796 {
797 return ( 0x00FFFFFFUL & static_cast<timeoutSpecOption_t>( i ) );
798 }
806 {
807 return ( 0x00FFFFFFUL & static_cast<timeoutSpecOption_t>( i ) );
808 }
810 }
811
822 class stateMachine : protected sm::stateHandler {
823 private:
824 sm::state *current{ nullptr };
825 sm::state *next{ nullptr };
826 sm::state *source{ nullptr };
827 queue *sQueue{ nullptr };
828 sm::timeoutSpec *timeSpec{ nullptr };
829 sm::surroundingCallback_t surrounding{ nullptr };
830 sm::state top;
831 sm::signal_t signalNot;
832 void *owner{ nullptr };
833 void *mData{ nullptr };
834 bool internalSignalSend( sm::signalID sig, void *sData, bool isUrgent ) noexcept;
835 void timeoutCheckSignals( void ) noexcept;
836 void timeoutPerformSpecifiedActions( sm::state * const s, sm::signalID sig ) noexcept;
837 void transition( sm::state *target, sm::historyMode mHistory ) noexcept;
838 uint8_t levelsToLCA( sm::state *target ) const noexcept;
839 void exitUpToLCA( uint8_t lca ) noexcept;
840 void prepareHandler( sm::signal_t sig, sm::state *s ) noexcept;
841 sm::status invokeStateActivities( sm::state * const s ) noexcept;
842 sm::state* stateOnExit( sm::state *s ) noexcept;
843 void stateOnEntry( sm::state *s ) noexcept;
844 sm::state* stateOnStart( sm::state *s ) noexcept;
845 sm::status stateOnSignal( sm::state *s, sm::signal_t sig ) noexcept;
846 void tracePathAndRetraceEntry( sm::state **trace ) noexcept;
847 void traceOnStart( sm::state **entryPath ) noexcept;
848 sm::signal_t checkForSignals( sm::signal_t sig ) noexcept;
849 stateMachine( stateMachine const& ) = delete;
850 void operator=( stateMachine const& ) = delete;
851 bool smSetup( sm::stateCallback_t topFcn, sm::state *init, const sm::surroundingCallback_t sFcn, void* pData ) noexcept;
852
853 /*cstat -MISRAC++2008-8-5-2*/
854 static sm::signalID psSignals[ Q_FSM_PS_SIGNALS_MAX ]; // skipcq: CXX-W2009, CXX-W2066
855 /*cstat +MISRAC++2008-8-5-2*/
856 static stateMachine* psSubs[ Q_FSM_PS_SIGNALS_MAX ][ Q_FSM_PS_SUB_PER_SIGNAL_MAX ]; // skipcq: CXX-W2009, CXX-W2066
857 static const sm::timeoutSpecOption_t OPT_INDEX_MASK;
858 public:
859 stateMachine() = default;
861 virtual ~stateMachine() {}
875 inline bool setup( const sm::stateCallback_t &topFcn, sm::state &init, sm::surroundingCallback_t sFcn = nullptr, void* pData = nullptr) noexcept
876 {
877 return smSetup( topFcn, &init, sFcn, pData );
878 }
890 inline bool add( sm::state &s, const sm::stateCallback_t &sFcn, sm::state &init ) noexcept
891 {
892 return top.subscribe( &s, sFcn, &init );
893 }
903 inline bool add( sm::state &s, const sm::stateCallback_t &sFcn ) noexcept
904 {
905 return top.subscribe( &s, sFcn, nullptr );
906 }
918 bool install( queue& q ) noexcept;
919
926 template <size_t numberOfSignals>
928 {
929 sq.q.setup( sq.qStack, sizeof(sm::signal_t), numberOfSignals );
930 return install( sq.q );
931 }
951 bool sendSignal( sm::signalID sig, void *sData = nullptr, bool isUrgent = false ) noexcept;
952 bool sendSignal( sm::signalIDType sig, void *sData = nullptr, bool isUrgent = false ) noexcept
953 {
954 return sendSignal( static_cast<sm::signalID>( sig ), sData, isUrgent );
955 }
968 bool install( sm::timeoutSpec &ts ) noexcept;
980 bool timeoutSet( const index_t xTimeout, const qOS::duration_t t ) noexcept;
991 bool timeoutStop( const index_t xTimeout ) noexcept;
996 const sm::state& getTop( void ) const noexcept;
1001 sm::state * const & getCurrent( void ) const noexcept;
1007 queue * const & getQueue( void ) const noexcept;
1013 sm::timeoutSpec * const & getTimeSpec( void ) const noexcept;
1018 void * const & getData( void ) const noexcept;
1023 void setSurrounding( const sm::surroundingCallback_t &sFcn ) noexcept;
1034 bool run( sm::signal_t sig ) noexcept;
1035 friend class core;
1036 };
1038 namespace sm {
1051 private:
1052 sm::signalID psSignals[ Q_FSM_PS_SIGNALS_MAX ] = { sm::signalID::SIGNAL_START }; // skipcq: CXX-W2009, CXX-W2066
1053 stateMachine* psSubs[ Q_FSM_PS_SIGNALS_MAX ][ Q_FSM_PS_SUB_PER_SIGNAL_MAX ]; // skipcq: CXX-W2009, CXX-W2066
1054 sm::psIndex_t getSubscriptionStatus( stateMachine &m, sm::signalID s ) const noexcept;
1055 void unsubscribeAll( void ) noexcept;
1056 public:
1059 virtual ~signalPublisher() {}
1069 {
1070 return subscribeToSignal( m, static_cast<sm::signalID>( s ) );
1071 }
1080 {
1081 return unsubscribeFromSignal( m, static_cast<sm::signalID>( s ) );
1082 }
1105 bool sendSignal( sm::signalID sig, void *sData = nullptr, bool isUrgent = false ) noexcept;
1106 bool sendSignal( sm::signalIDType sig, void *sData = nullptr, bool isUrgent = false ) noexcept
1107 {
1108 return sendSignal( static_cast<sm::signalID>( sig ), sData, isUrgent );
1109 }
1110 };
1112 }
1113}
1114
1115
1116
1117#endif /*QOS_CPP_FSM*/
The class to interface the OS.
Definition kernel.hpp:83
A Queue object.
Definition queue.hpp:44
The state callback argument to handle the state-machine dynamics and provide execution information....
Definition fsm.hpp:252
void nextState(state &s, historyMode m=historyMode::NO_HISTORY) noexcept
Produce a transition to the desired state.
Definition fsm.hpp:278
stateMachine & thisMachine(void) noexcept
Gets a reference to the state machine in which this state is contained.
Definition fsm.hpp:332
signalID signal(void) const noexcept
Get the Signal ID currently being evaluated for this state.
Definition fsm.hpp:340
state & thisState(void) noexcept
Get a reference to state being evaluated.
Definition fsm.hpp:323
void * Data
Definition fsm.hpp:270
bool timeoutSet(const index_t i, const qOS::duration_t t) noexcept
Set the time for the selected built-in timeout inside the target FSM.
status lastStatus(void) const noexcept
The last state return status.
Definition fsm.hpp:349
void * SignalData
Definition fsm.hpp:269
void startState(state &s) noexcept
Set the nested initial state ( sub-state ). This The application writer should change this field to s...
Definition fsm.hpp:292
bool timeoutStop(const index_t i) noexcept
Stop the time count for the selected built-in timeout.
void * StateData
Definition fsm.hpp:271
An object to subscribe FSM(Finite State Machine) objects to specific user-defined signals.
Definition fsm.hpp:1050
bool subscribeToSignal(stateMachine &m, sm::signalIDType s) noexcept
Definition fsm.hpp:1068
bool unsubscribeFromSignal(stateMachine &m, sm::signalIDType s) noexcept
Definition fsm.hpp:1079
bool sendSignal(sm::signalID sig, void *sData=nullptr, bool isUrgent=false) noexcept
Sends a signal to all its subscribers.
bool subscribeToSignal(stateMachine &m, sm::signalID s) noexcept
Subscribe state machine to a particular signal.
bool unsubscribeFromSignal(stateMachine &m, sm::signalID s) noexcept
Unsubscribe state machine from a particular signal.
A state object.
Definition fsm.hpp:542
virtual sm::status activities(sm::handler_t h)
bool install(transition *table, size_t n) noexcept
Install a table with the outgoing transitions for this state.
transition * getTransitionTable(void) noexcept
Retrieve a pointer to the state transition table.
bool install(timeoutStateDefinition *def, size_t n) noexcept
Install fixed timeouts for the specified state using a lookup-table.
bool add(sm::state &s, const sm::stateCallback_t &sFcn, sm::state &init) noexcept
Add the specified state as a child state.
Definition fsm.hpp:577
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 specifi...
Definition fsm.hpp:665
bool install(transition(&table)[numberOfTransitions]) noexcept
Install a table with the outgoing transitions for this state.
Definition fsm.hpp:615
bool install(timeoutStateDefinition(&def)[numberOfTimeoutDefs]) noexcept
Install fixed timeouts for the specified state using a lookup-table.
Definition fsm.hpp:699
bool add(sm::state &s, const sm::stateCallback_t &sFcn) noexcept
Add the specified state as a child state.
Definition fsm.hpp:589
void * getData(void) noexcept
Retrieve the state data or storage-pointer.
void setCallback(const stateCallback_t sFcn) noexcept
Set/Change the state callback.
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 specifi...
Definition fsm.hpp:637
state()=default
void setData(void *pData) noexcept
Set the state data or storage-pointer.
A FSM Timeout-specification object.
Definition fsm.hpp:731
A FSM(Finite State Machine) object.
Definition fsm.hpp:822
sm::timeoutSpec *const & getTimeSpec(void) const noexcept
Get a pointer to the installed timeout specification if available.
sm::state *const & getCurrent(void) const noexcept
Retrieve a reference to the state currently being evaluated.
const sm::state & getTop(void) const noexcept
Retrieve a reference to the Top state of.
bool install(queue &q) noexcept
Install a signal queue to the provided Finite State Machine (FSM).
queue *const & getQueue(void) const noexcept
Get a pointer to the installed queue if available.
bool add(sm::state &s, const sm::stateCallback_t &sFcn) noexcept
This function adds the specified state to the stateMachine "Top" state.
Definition fsm.hpp:903
bool timeoutStop(const index_t xTimeout) noexcept
Stop the time count for the selected built-in timeout.
stateMachine()=default
bool add(sm::state &s, const sm::stateCallback_t &sFcn, sm::state &init) noexcept
Add the specified state to the stateMachine "Top" state.
Definition fsm.hpp:890
bool sendSignal(sm::signalID sig, void *sData=nullptr, bool isUrgent=false) noexcept
Sends a signal to a state machine.
bool install(sm::timeoutSpec &ts) noexcept
Install the Timeout-specification object to target FSM and allow timed signals within states.
bool timeoutSet(const index_t xTimeout, const qOS::duration_t t) noexcept
Set the time for the selected built-in timeout inside the target FSM.
bool install(sm::signalQueue< numberOfSignals > &sq) noexcept
Install a signal queue to the provided Finite State Machine (FSM).
Definition fsm.hpp:927
void setSurrounding(const sm::surroundingCallback_t &sFcn) noexcept
Set the state-machine surrounding callback.
bool setup(const sm::stateCallback_t &topFcn, sm::state &init, sm::surroundingCallback_t sFcn=nullptr, void *pData=nullptr) noexcept
Initializes a Finite State Machine (FSM).
Definition fsm.hpp:875
bool run(sm::signal_t sig) noexcept
Execute the Finite State Machine (FSM).
void *const & getData(void) const noexcept
Retrieve the state machine data or storage-pointer.
A non-blocking Timer object.
Definition timer.hpp:26
timeCount_t duration_t
The typedef that specified an time quantity, usually expressed in milliseconds.
Definition clock.hpp:18
#define Q_FSM_PS_SIGNALS_MAX
Finite State Machine : number of signals to subscribe.
Definition config.h:82
#define Q_FSM_PS_SUB_PER_SIGNAL_MAX
Finite State Machine : subscribers per signal.
Definition config.h:88
#define Q_FSM_MAX_TIMEOUTS
Finite State Machine : number of timeouts.
Definition config.h:76
base_t state
The intrinsic type of co::position to hold a coroutine progress.
Definition coroutine.hpp:21
historyMode
This enumeration defines the possible modes to perform a transition to history.
Definition fsm.hpp:226
const timeoutSpecOption_t TIMEOUT_RST_ENTRY
This timeout-specification option its used to specify that the engine should reset the timeout when t...
const timeoutSpecOption_t TIMEOUT_PERIODIC
This timeout-specification option its used setup the timeout in periodic mode.
status(*)(handler_t) stateCallback_t
Pointer to a function that represents a state callback.
Definition fsm.hpp:426
const timeoutSpecOption_t TIMEOUT_KEEP_IF_SET
This timeout-specification option its used to specify that the engine should set the timeout only if ...
constexpr timeoutSpecOption_t TIMEOUT_INDEX(index_t i)
Timeout-specification option. Should be used only to specify which timeout signal to use.
Definition fsm.hpp:795
bool(*)(handler_t) signalAction_t
Pointer to a function that represents a signal guard/action.
Definition fsm.hpp:465
constexpr timeoutSpecOption_t TIMEOUT_USE_SIGNAL(index_t i)
Timeout-specification option. Should be used only to specify which timeout signal to use.
Definition fsm.hpp:805
uint32_t signalIDType
Definition fsm.hpp:29
void(*)(handler_t) surroundingCallback_t
Pointer to a function that represents a surrounding callback.
Definition fsm.hpp:446
const timeoutSpecOption_t TIMEOUT_SET_ENTRY
This timeout-specification option its used to specify that the engine should set the timeout when the...
status
This enumeration defines the built-in state-execution status values that can be used as return value ...
Definition fsm.hpp:193
uint32_t timeoutSpecOption_t
A typedef to hold the timeout specification options.
Definition fsm.hpp:470
const timeoutSpecOption_t TIMEOUT_SET_EXIT
This timeout-specification option its used to specify that the engine should set the timeout when the...
constexpr signalID SIGNAL_USER(uint32_t s)
Function to define a user-defined signal.
Definition fsm.hpp:164
constexpr signalID SIGNAL_TIMEOUT(index_t iTm)
Built-in signal to indicate that a timeout expiration event occurs.
Definition fsm.hpp:154
const timeoutSpecOption_t TIMEOUT_RST_EXIT
This timeout-specification option its used to specify that the engine should reset the timeout when t...
signalID
The type for signal ID.
Definition fsm.hpp:34
@ SHALLOW_HISTORY
History will be kept to allow the return to only the top-most sub-state of the most recent state conf...
Definition fsm.hpp:237
@ DEEP_HISTORY
History will be kept to allow full state configuration of the most recent visit to the containing reg...
Definition fsm.hpp:242
@ NO_HISTORY
History is not preserved. Composite states will start according to their default transition.
Definition fsm.hpp:231
@ SUCCESS
To indicate that the status was successful.
Definition fsm.hpp:213
@ FAILURE
To indicate that the state had a failure or abnormal execution. It can be used to handle exceptions.
Definition fsm.hpp:209
@ BEFORE_ANY
(Only available in the surrounding callback) Indicates an execution of the surrounding callback befor...
Definition fsm.hpp:199
@ ABSENT
Not to be used at the application level. This value is reserved for use.
Definition fsm.hpp:204
@ SIGNAL_HANDLED
To indicate that the state handled the signal and therefore it is not necessary to continue propagati...
Definition fsm.hpp:219
@ SIGNAL_ENTRY
Built-in signal to indicate if the current state has just entered from another state.
Definition fsm.hpp:53
@ SIGNAL_START
Built-in signal that can be used to set a nested initial-transition (aka default transition) by using...
Definition fsm.hpp:41
@ SIGNAL_TIMEOUT2
Built-in signal to indicate that the timeout at index 2 expired.
Definition fsm.hpp:81
@ SIGNAL_TIMEOUT0
Built-in signal to indicate that the timeout at index 0 expired.
Definition fsm.hpp:73
@ SIGNAL_NONE
Built-in signal to indicate that there is not signal available.
Definition fsm.hpp:57
@ SIGNAL_EXIT
Built-in signal to indicate if the current state has just exit to another state.
Definition fsm.hpp:47
@ SIGNAL_TIMEOUT1
Built-in signal to indicate that the timeout at index 1 expired.
Definition fsm.hpp:77
STD_TYPE_SIZE_T index_t
A type to instantiate an OS index variable. Can store the maximum size of a theoretically possible ob...
Definition types.hpp:94
OS/Kernel interfaces.
Definition bytebuffer.hpp:7
The type to be used as a container variable for a signal.
Definition fsm.hpp:174
void * data
Definition fsm.hpp:176
The type of a FSM signal-queue.
Definition fsm.hpp:183
signal_t qStack[numberOfSignals]
Definition fsm.hpp:185
queue q
Definition fsm.hpp:184
This type should be used to define an item for a timeout-specification table.
Definition fsm.hpp:476
timeoutSpecOption_t options
Definition fsm.hpp:478
qOS::duration_t xTimeout
Definition fsm.hpp:477
This structure should be used to define an item for a state transition table.
Definition fsm.hpp:485
transition(signalID iSignal, signalAction_t sGuard, state &next, historyMode mHistory=historyMode::NO_HISTORY, void *sigData=nullptr)
Definition fsm.hpp:495
transition(signalIDType iSignal, state &next, uint8_t mHistory=0U, void *sigData=nullptr)
Definition fsm.hpp:514
transition(signalID iSignal, state &next, historyMode mHistory=historyMode::NO_HISTORY, void *sigData=nullptr)
Definition fsm.hpp:501
transition(signalIDType iSignal, signalAction_t sGuard, state &next, uint8_t mHistory=0U, void *sigData=nullptr)
Definition fsm.hpp:507