22#include <unordered_map>
66template <
typename Context>
86 Action* pAction =
nullptr, Context* pContext =
nullptr)
126 bool Update(
unsigned int eventType,
void* pEventData)
142 if (!transitionIterator->second.action(event))
172 constexpr size_t count{std::numeric_limits<size_t>::digits / 2};
173 const size_t wideState{
static_cast<size_t>(
key.state)};
174 const size_t rotatedState{(wideState << count) | (wideState >> count)};
175 return static_cast<size_t>(
key.eventType) ^ rotatedState;
181 return lhs.state == rhs.state && lhs.eventType == rhs.eventType;
constexpr unsigned int FSM_INVALID_STATE
Definition: FSM.h:25
Represents a signal in the state machine that a change has occurred.
Definition: FSM.h:33
void * m_Param
Definition: FSM.h:52
unsigned int m_Type
Definition: FSM.h:51
unsigned int GetType() const
Definition: FSM.h:40
void * GetParamRef()
Definition: FSM.h:45
CFsmEvent(unsigned int type, void *pParam)
Definition: FSM.h:35
Manages states, events, actions and transitions between states.
Definition: FSM.h:68
unsigned int m_FirstState
Definition: FSM.h:203
void SetCurrState(unsigned int state)
Sets the current state and update the last state to the current state.
Definition: FSM.h:103
bool IsFirstTime() const
Verifies whether state machine has already been updated.
Definition: FSM.h:197
TransitionMap m_Transitions
Definition: FSM.h:206
void SetFirstState(unsigned int firstState)
Sets the initial state for FSM.
Definition: FSM.h:95
unsigned int GetCurrState() const
Definition: FSM.h:107
unsigned int GetNextState() const
Definition: FSM.h:117
void AddTransition(unsigned int state, unsigned int eventType, unsigned int nextState, Action *pAction=nullptr, Context *pContext=nullptr)
Adds a new transistion to the state machine.
Definition: FSM.h:85
bool IsDone() const
Tests whether the state machine has finished its work.
Definition: FSM.h:156
void SetNextState(unsigned int nextState)
Definition: FSM.h:112
unsigned int m_NextState
Definition: FSM.h:205
std::unordered_map< TransitionKey, const Transition, typename TransitionKey::Hash > TransitionMap
Definition: FSM.h:192
bool(Context *pContext, CFsmEvent *pEvent) Action
Definition: FSM.h:69
bool Update(unsigned int eventType, void *pEventData)
Updates the FSM and retrieves next state.
Definition: FSM.h:126
bool m_Done
Definition: FSM.h:202
unsigned int m_CurrState
Definition: FSM.h:204
Action * pFunction
Definition: FSM.h:73
bool operator()(CFsmEvent &event) const
Definition: FSM.h:76
Context * pContext
Definition: FSM.h:74
size_t operator()(const TransitionKey &key) const noexcept
Definition: FSM.h:170
UnderlyingType eventType
Definition: FSM.h:166
friend bool operator==(const TransitionKey &lhs, const TransitionKey &rhs) noexcept
Definition: FSM.h:179
unsigned int UnderlyingType
Definition: FSM.h:164
UnderlyingType state
Definition: FSM.h:165
CallbackFunction action
Definition: FSM.h:187
unsigned int nextState
Definition: FSM.h:188
pthread_key_t key
Definition: wpthread.cpp:140