State-related constructs are described below.
State
A state represents a potentially active state, which can be activated by entering through a state transition and can be initial, terminal, or neither (intermediate).
There must be exactly one initial state within a state machine. A terminal state, of which multiple can exist, indicates the end of the lifecycle of the containing state machine.
State transitions are specified as always or on transitions. Always transitions, possibly guarded with expressions, are taken without events. On-event transitions drive the event-driven nature of state machines, allowing a state transition based on a received event.
Events may be generated from the state machine itself, other state machines, as well as from the environment external to CSM (for instance, an external application or device). Actions executed in a state include entry and exit actions upon entering or exiting the state. While actions are executed while the state is active. Timed actions are declared using the after keyword.
Like other constructs, a state allows for lexically declaring local, static, and persistent data. An additional type of data, static data, utilizes the capability of the state for re-entry, allowing data to retain their values between exiting and re-entering the state.
new State {
name = "Sa"
initial = true
terminal = false
entry {
new Action {...}...
}
exit {
new Action {...}...
}
while {
new Action {...}...
}
after {
new Action {...}...
}
on {
new OnTransition {...}...
}
always {
new Transition{ ... }...
}
localData = new Data {...}
persistentData = new Data {...}
staticData = new Data {...}
}
Listing 8: A State construct.
The following keywords can/must be provided:
Keyword | Description | Type | Optional |
---|---|---|---|
name | Name of the state. | string | No |
initial | Initial flag of the state. | boolean | Yes |
terminal | Terminal flag of the state. | boolean | Yes |
entry | Entry actions. | list of Action | Yes |
exit | Exit actions. | list of Action | Yes |
while | While actions. | list of Action | Yes |
after | After actions. | list of TimeoutAction | Yes |
on | On event transitions. | list of OnTransition | Yes |
always | Always transitions. | list of Transition | Yes |
localData | Local data. | Data | Yes |
persistentData | Persistent data. | Data | Yes |
staticData | Static data. | Data | Yes |
name
The name keyword specifies the name of the state and may be used for diagnostic purposes or referencing.
A state's name is referenced throughout the state machine to indicate the transition target.
The validity of a name is implementation-specific.
initial
The initial keyword specifies whether a state is the initial state of the containing state machine.
Exactly one initial state must be declared.
Initial states must not have inward transitions.
terminal
The terminal keyword specifies whether a state is a terminal state of the containing state machine. Multiple states may be declared terminal.
Terminal states must not have outward transitions.
entry / exit / while / after
The entry keyword specifies the actions executed upon entry of the state.
The exit keyword specifies the actions executed upon exiting the state.
The while keyword specifies the actions executed while in a state.
The after keyword specifies the actions executed upon a timeout.
Actions executed within a state have state scope, see dynamic extent.
An action reference must be a valid action name.
on
The on keyword specifies the transitions that can occur based on events.
The referenced event in an on-transition must be raised within the collaborative state machine.
always
The always keyword specifies the transitions that can occur regardless of raised events.
localData / persistentData / staticData
The localData, persistentData, and staticData keywords allow for lexically declaring respectively the local, persistent, and static data at the state machine level.
Static data is unique to states and is available after re-entry of a state.
Data described at the state level is accessible from the state machine and any component hierarchically below it, see dynamic extent.