|
Interface is a named group of messages and is an analogue of an interface in object-oriented design.
Messages have names and can have associated payload for both request and reply interactions. A simple message can be defined without any payload:
interface Device is message Start; message Stop; -- ... end Device;
Above, the Start
and Stop
message does not have any payload, but both messages indicate two-way interactions, which means that their processing can be confirmed by receiver.
One-way messages are used for interactions without confirmation:
interface Device is -- ... oneway message Keep_Alive; end Device;
Messages can have payload for either request or reply direction, or both. The payload, if present, is always a single value of the user-defined type with an indication of direction:
type Time is Timestamp : Long_Long; end Time; interface Clock is message Set_Time (T : in Time); message Get_Time (T : out Time); end Clock;
Above, Set_Time
is a message that will contain the Time
record as a parameter and no payload in reply, whereas Get_Time
will have no parameters in the request, but will deliver the Time
value as a reply.
Of course, data can be transmitted in both directions as well, as can be seen in the complete package definition of the calculator example:
package Calculator is type Operands is A : Integer; B : Integer; end Operands; type Results is Sum : Integer; Difference : Integer; Product : Integer; Ratio : optional Integer; -- does not exist if B = 0 end Results; interface Operations is -- message with data tramsmitted in both directions: message Calculate (Op : in Operands; Res : out Results); end Operations; end Calculator;