# trigger

The asynchronous operation belongs to the family of message-based communication operations. It is used to receive a value from an incoming message port queue. When the first message in the queue matches the criteria described in the value part, the operation works exactly as described under the keyword receive, otherwise the message is discarded.

- The operation can be used on connected ports only.
- The operation has blocking semantics (except when used within an alt statement!) i.e., the TTCN3 program execution is halted until a message arrives.
- The operation examines the 1st message on the port queue, extracts this and discards the message unless it matches the receiving template
- In case of multiple connections the operation may be restricted to a certain sender.
- The received value and the address of the sender may be stored.

Related keywords:

- address
- any
- create
- from
- modifies
- receive
- sender
- system
- value

### port_reference.trigger [ ( value_part ) ] [ from address_reference ] [ -> assignment_part ];

- port_reference points out the incoming message port.

- the keywords any port may be used to indicate that messages from any port will be accepted (see the example 7).

- The trigger keyword introduces the message reception.

- value_part is one of the following: (rem.: when omitted, any message will be accepted)

  - a literal value, a constant, a variable, an expression. (see the example1)
  - a value template (see the example 2)
  - a modified template (see the example 3)

TITAN specific restriction compared to the standard: modified template is not implemented. When encountered in the TTCN-3 program, an error message will be generated.

- The optional from keyword is used when a port is connected to several entities and restriction to one communication partner is required.

- address_reference is one of the following:

  - a component reference (cf. create) or the keyword system, in case of one-to-many connections.

  - an address reference (cf. address) , when there are several entities within the system under test .

- assignment_part is one or both of the following:

  - the sender keyword followed by a variable of address or component type to store the address of the sender (see the example 5).
  - the value keyword followed by a variable of the same type as the received message to store the received value (see the example 6).

Example 1: literal value

portibus_PCO.trigger (charstring:"abl") from system;

The character string abl is accepted over the port portibus_PCO from the test system interface. The port is connected to several components.

Example 2: template

portibus_PCO.trigger (tr_MeiTemplate));

The template (tr_MeiTemplate) determines what kind of messages will be accepted.

Example 3: modified template

portibus_PCO.trigger (modifies tr_MeiTemplate := {field1 := false});

The modified template (tr_MeiTemplate) determines what kind of messages will be accepted.

Example 4: any message reception

portibus_PCO.trigger;

Any message on port portibus_PCO will be accepted.

Example 5: storing the sender address

portibus_PCO.trigger (tr_MeiTemplate)) -> sender v_address;

The address of the sender is stored in the variable v_address.

Example 6: storing the received value

portibus_PCO.trigger (tr_MeiTemplate)) -> value v_ReceivedMessage;

The received message is saved in the variable v_ReceivedMessage.

Example 7: receive on any port

any port.trigger (tr_MeiTemplate)) -> value v_ReceivedMessage;

The message matching the template tr_MeiTemplate and received on any port is saved to the variable v_ReceivedMessage.

BNF definition of trigger