I'm looking to implement a statechart (aka "hierarchical state machine")
package.
This requires that my data convey hierarchy as well as specifics about each
state; how it responds to various events, etc. As a very trivial example,
that data looks something like this:
State(TrafficSignalRoot) {
Entry(DoPOST) // call DoPOST() on entry to perform power on self test
Default(Red) // default transition into Red sub state first state is Red
Idle(CheckForError) // call CheckForError() on Idle event poll for a
FAILURE event
Terminate(FAILURE) // exit all states on FAILURE event machine exits on
FAILURE event
Exit(EnableRedFlashMode) // call EnableRedFlashMode() on exit to switch to
Flash Mode
// red light state, a substate of TrafficSignalRoot
State(Red) {
Entry(RedOn) // call RedOn() on Entry
Exit(RedOff) // call RedOff() on Exit
Transition(5.0,Green) // transition to Green state on a "5 second timer"
event
}
// green light state, a substate of TrafficSignalRoot
State(Green) {
Entry(GreenOn) // call GreenOn() on Entry
Exit(GreenOff) // call GreenOff() on Exit
Transition(5,Yellow) // transition to Yellow state on a "5 second timer"
event
}
// yellow light state, a substate of TrafficSignalRoot
State(Yellow) {
Entry(YellowOn) // call YellowOn() on Entry
Exit(YellowOff) // call YellowOff() on Exit
Transition(1.5,Red) // transition to Red state on a "1.5 second timer" event
}
}
Translated to Go, I'm thinking this data may work as a nested literal
structure. But, I'm not sure I even know where to start to pull that off.
And further, I definitely have no idea if that's a nice path to choose. So,
I'm looking for your advice on how to approach this.
Any and all ideas and comments are very welcome. Thank you in advance for
your time and consideration!
--Steve
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.