Next: Specifying Events, Previous: Interface Syntax, Up: Creating an Interface [Contents][Index]
The following interface has three events defined: two in events and one out event. The direction is as seen from the component implementing this interface.
interface IMotion { in void start(); in void stop(); out void ready(); behaviour { on start, stop: {} } }
This example shows an interface with a more complex interaction protocol, where the start event is only allowed in case the interface is in state Off and the stop event is only allowed in case the interface is in state Active.
interface IMotion { in void start(); in void stop(); out void started(); out void ready(); behaviour { enum State {Off, Active}; State state = State.Off; [state.Off] { on start: { state = State.Active; started; } on stop: illegal; } [state.Active] { on start: illegal; on stop: { state = State.Off; ready; } } } }