We’re here to help you

Menu

Specifying Ports

A port is an instance of an interface. A component has ports to communicate with other components.

The keyword provides is used to specify that a component provides an implementation of an interface.

The keyword requires is used to specify that a component uses or requires an interface.

A component must provide an implementation for all in-events of provided and all out events of required interfaces.

Syntax

  provides Interface port;
  requires Interface port;
  requires external Interface port; (Since 2.0.0) (1)
  requires injected Interface port; (2)
1 port to a component with possibly delaying communication channel (See Using external)
2 port to a shared resource (See Using injected)

Examples

A component implementing one interface

The component Leaf implements the ISensor interface that has one in-event called event.

component Leaf
{
  provides ISensor sensor;

  behaviour
  {
    on sensor.event(): { }
  }
}

A component implementing one interface and requiring another interface

The component MessageHandler below is providing an implementation of the iMessageHandler interface and requires the iProtocolStack interface.

component MessageHandler
// MessageHandler component
// implementing the iMessageHandler interface
// and using the iProtocolStack interface
{
  provides iMessageHandler mh;
  requires iProtocolStack ps;

  behaviour
  {
    enum State {Idle, Busy};

    State state = State.Idle;

    [state.Idle]
    // initial or idle state
    {
      on mh.sendMessage():
      {
        ps.sendMessage(); //forward the message to ProtocolStack
        state = State.Busy;
      }
      on ps.messageSent(): illegal;
    }

    [state.Busy]
    // State to capture that a message is being send
    {
      on mh.sendMessage():
      {
        illegal;
      }
      on ps.messageSent():
      // the ProtocolStack has send the message, now we need to inform
      // our client and go to the Idle state so another message can
      // be processed
      {
        mh.messageSent();
        state = State.Idle;
      }
    }
  }
}

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