Closed yabbasi31415 closed 4 years ago
State transitions should only be triggered by events, not by simply writing to a member variable. This is a key principle of fsmlite's design.
@tkem the motivation behind adding a setter function is that we want to use a single state machine for multiple objects. Each object stores it's last known state in a data base; and whenever needed, it can fetch that state, feed it into the state machine and continue with the state transitions.
@yabbasi31415: So you kind-of want to create/initialize a new state machine for each object with a given state, but want to re-use a state machine instance (to preserve memory or for whatever reasons)? What about this (using the player
state machine from the tests):
player p;
assert(p.current_state() == player::Empty);
p = player(player::Playing);
assert(p.current_state() == player::Playing);
IMHO this is somewhat cleaner and more explicit than setting "just" the state, especially if your derived FSM also introduces other member variables that need to be taken care of.
Added a setter function to the fsm class to set the current state asynchronously in the user application code.