This sample emulates a telephone.
If you are new to state machines, then we recommend that you familiarize yourself with the editor as well as some of the building blocks that you'll be working with.
Here is a brief description of the functionality that this diagram represents.
When the state machine begins at the Start state, the first operation is init, and it initializes the telephone.
The state machine then enters the On Hook state where it will wait for an event to happen. If the operation arrives that signals that the phone has been unplugged, then the state machine moves to the End final state. If however, the operation arrives that signals that the receiver has been taken off the hook, then the state machine moves into the In Use composite state.
The In Use composite state nests a number of states and transitions that define the dialing behaviour of the telephone. It begins with the In Use Start state, and immediately moves through the PlayDialTone action to the DialTonePlaying state. While there, it waits for the phone number to be dialed. If the digit event arrives, the AppendDigit action records the digit that has just been punched in, and the state machine moves to the Dialing state. If no digit has been dialed within a predefined period of time, then the No dialing timeout event moves the state machine to the Too long dialing final state.
There are a number of ways out of the Dialing state. If the user takes too long between entries, then the Too long dialing timeout forces a move to the Too long dialing final state. If the user enters another number, then it is recorded by the AppendDigit action, and a self-transition returns to the Dialing state to await more input. When a total of four digits have been received, the FinishedDialing condition will move the machine to the Connecting state.
The Connecting state will attempt to establish a connection with the third party. If the Busy condition evaluates to true, then a connection cannot be established, and the state machine will move to the In Use End final state. Alternatively, if the NotBusy condition is fired, then a connection is established, and the machine will move to the Talking state.
The state machine will stay in the Talking state until the call ends. There are two ways that the call can end. In the first way, the state machine will move to the Disconnected state if either of the final states in the In Use composite state are reached (The Too long dialing is reached when too much time passes between entries, and the In Use End state is reached when the call is disconnected remotely. The state machine will stay in the Disconnected state until the phone is returned to the hook).
The second way that a call can end is if the user hangs the phone up (as recorded by the onHook operation), in which case the state machine will return to the On Hook state.