We’re here to help you

Menu

Creating an Interface

Interfaces define how components interact: the events that can be communicated and the interaction protocol.

Each event has a direction specified by the 'in' or 'out' keywords.

The interface protocol is specified in a 'behaviour' section. For each in event it specifies the actions performed.

An interface does not lead to any code being generated. It serves as a specification only.

Syntax

The 'interface' keyword is used to declare an interface, followed by the interface name.

Within the interface declaration, a list of in and out events is defined followed by a behaviour declaration.

interface IntName
{
  in type inEvent1();   // list of in events
  in type inEvent2();
  /* ... */

  out void outEvent1(); // list of out events
  out void outEvent2();
  /* ... */

  behaviour             // contract; protocol description
  { /* ... */ }
}

Examples

An interface with three events and a simple behaviour

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: {}
  }
}

An interface specifying an interaction protocol

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;
      }
    }
  }
}

If you have questions that weren’t answered by this Guide,
let our support team help you out.

Enjoy this article? Don't forget to share.
google-site-verification:google656c7703ab521151.html