HSM provides the framework for Hierarchical State Machine implementations.
- Introduction to Hierarchical State Machines
- Yet Another Hierarchical State Machine
- State Diagram
- gohsm Object Model: go_state_machine_framework.png
Included in this framework are the following components:
-
StateMachine: Machine that controls the event processing
-
State: Interface that must be implemented by all States in the StateMachine
-
Transition: Interface that is implemented by each of the different types of transitions:
-
ExternalTransition: Transition from current state to a different state. On execution the following takes place:
- OnExit is called on the current state and all parent states up to the parent state that owns the new state (or the parent state is nil)
- action() associated with the the transition is called
- OnEnter() is called on the new state which may call OnEnter() for a sub-state. The final new current state is returned by the OnEnter() call
-
InternalTransition: Transition within the current state. On execution the following takes place:
- action() associated with the the transition is called
-
EndTransition: Transition from current state that terminates the state machine. On execution the following takes place:
- OnExit is called on the current state and all parent states until there are no more parent states
- action() associated with the the transition is called
-
-
Event: An event represents something that has happened (login, logout, newCall, networkChange, etc.) that might drive a change in the state machine
- Define the set of events that will be processed.
- Define all of the states that are possible. For each state, implement the methods required by the State interface
- Create the state machine, and hand it the starting state
- Call Run on the state machine
Two sample HSMs have been implemented in the example/ directory.