Class FSM#
Defined in File FSM.h
Inheritance Relationships#
Base Type#
public Karana::Core::LockingBase(Class LockingBase)
Class Documentation#
-
class FSM : public Karana::Core::LockingBase#
A class to implement finite state machines.
The finite state machine is implemented as a graph that connects FSMStates with FSMTransitions.
Public Functions
-
const kc::ks_ptr<FSMState> &getCurrentState() const#
Get the current state.
- Returns:
The current FSMState.
-
void setCurrentState(std::string_view name)#
Set the current state of this FSM to the state with the provided name.
- Parameters:
name – The name of the state to set the FSM to.
-
void setCurrentState(const Karana::Core::ks_ptr<FSMState> &state)#
Set the current state of this FSM to the provided state.
- Parameters:
state – The state to set the FSM to.
-
const kc::ks_ptr<FSMState> &getState(std::string_view name) const#
Get the state with the provided name.
- Parameters:
name – The name of the state to retrieve.
- Returns:
The FSMState with the provided name.
-
const kc::ks_ptr<FSMTransition> &getTransition(std::string_view parent_state, std::string_view child_state)#
Get the transition that connects the two states with the provided names.
- Parameters:
parent_state – The name of the parent of the edge.
child_state – The name of the child of the edge.
- Returns:
The transition that connects the parent and child states with the names provided.
-
std::vector<kc::ks_ptr<FSMState>> getStates() const#
Get a list of all the FSMStates in this FSM.
- Returns:
A list of all the FSMStates in this FSM.
-
void update()#
Update the FSM.
This updates the current state using the should_transition_fns of the FSMTransitions for the current state.
-
bool getTraceFSM()#
Get whether this FSM is printing trace messages or not.
- Returns:
true if trace messages are being printed, false otherwise.
-
void setTraceFSM(bool trace_fsm)#
Set whether this FSM prints trace messages or not.
- Parameters:
trace_fsm – true to set the FSM to print trace messages, false to stop printing trace messages.
-
virtual std::string dumpString(std::string_view prefix = "", const Karana::Core::Base::DumpOptions *options = nullptr) const override#
Return information about the object.
- Parameters:
prefix – A string to use as prefix for each output line
options – Struct with options to tailor the output
- Returns:
String with the information about the object.
Public Members
-
Karana::Core::CallbackRegistry<void, const kc::ks_ptr<FSMTransition>&> on_state_transition_fns#
These functions will run whenever we transition to a new state.
Public Static Functions
Protected Functions
-
virtual void _discard(Karana::Core::ks_ptr<Karana::Core::Base> &base) override#
Discard the the object. Derived classes should implement this with the logic required to discard themselves if applicable.
- Parameters:
base – - A pointer to the object to discard.
-
virtual void _makeHealthy() override#
Derived classes override this to define how to make themselves healthy.
-
const kc::ks_ptr<FSMState> &getCurrentState() const#