CALLBACK ... END CALLBACK

System Testing Test Script Language.

Purpose

The CALLBACK instruction dynamically recalls message reception and links a connection identifier value to a communication channel identifier.

Syntax

CALLBACK <message_type>: <msg> ON <commtype>: <id> [ <n> ]

END CALLBACK

<message_type> is a message type previously declared in a MESSAGE statement.

<msg> is the output parameter of <message_type> that must be initialized in the callback if a message is received.

<commtype> is the type of communication used for reading messages previously declared in a COMMTYPE statement.

<id> is the input connection parameter on which a message must be read.

Description

Callbacks are declared in the first part of the test script, before the first scenario.

<commtype> must be declared with the COMMTYPE instruction.

<message_type> must be declared with the MESSAGE instruction.

You can declare only one callback per combination of message and communication type.

Message reception in the CALLBACK statement must never be blocked. If no message is received, you must exit the block using the NO_MESSAGE instruction.

Use of both a NO_MESSAGE and MESSAGE_DATE statement is mandatory within the callback or a procedure called from a callback.

If the C <message_type> contains unions, you can define for each union the display and comparison field. The system implicitly defines a structured variable, named as ATL_ followed by the name of the <message_type>. You can specify which field to use by specifying select attribute for the union.

Freeze Mode

Freeze mode is a blocking mode in which the CALLBACK waits for a message to be received. To use freeze mode, you must use only one CALLBACK block throughout the entire WAITTIL statement, messages can be read in freeze mode. In this mode, the ATL_TIMEOUT macro specifies the maximum wait delay for a message. The value of ATL_TIMEOUT is calculated from a WTIME expression used in the WAITTIL statement. Only on WTIME must be specified in the WAITTIL statement. The ATL_TIMEOUT macro is an integer and uses the time unit defined in the Target Deployment Port. By default, the time unit is a hundredth of second.

Example

typedef enum { e_name, e_id, e_balance } client_kind_t;

typedef struct {    

client_kind_t kind;    

union {           

char name[50];           

int id;           

float balance;           

} my_union;

} client_info_t;

COMMTYPE socket IS socket_id_t

CHANNEL socket: ch

MESSAGE client_info_t: msg

CALLBACK client_info_t: info ON socket: id   

    CALL read(id, &info, sizeof(client_info_t))@@ret   

    IF (ret == 0) THEN    

        NO_MESSAGE   

    END IF   

    MESSAGE_DATE   

    VAR ATL_client_info_t.my_union.select, INIT=info.kind   

END CALLBACK

 

Related Topics

COMMTYPE, MESSAGE, WAITTIL, MESSAGE_DATE, NO MESSAGE, VIRTUAL CALLBACK