Messages allow communication between objects. A message has parameters
port, destination, and value. Example:
- msg(PORT_OUT, all, 4.56);
- msg(PORT_OUT, all, var1);, where var1 could be int or
float.
- msg(link, Server_Queue, vec);, where vec could be
int vec[k]; or int vec[]; for .
There are three ways to read the message body, depending on the message type:
- msg_data is always available in the message action code, and it
keeps the value of the message body (int or float). If the message sent was
of a vector type, msg_data will have the value 0. For example,
var = msg_data;
- msg_type is always available too, and indicates the type of
the message by an integer: 0 means an integer or float number, 1 means an
integer vector (INT_VEC), and 2 indicates a float vector
(FLOAT_VEC). E.g.
if ( msg_type == 1 ) { ... }
- integer vector type: the vector can be copied to a local integer vector,
through the function get_msg_data:
int vec[10];
get_msg_data(vec);
In this last case, if the sent vector is longer than the local vector, the
excess part of the sent vector will be dropped. On the other hand, if the
local vector is longer than the sent vector, the rest of the local vector
will be 0-filled.
Guilherme Dutra Gonzaga Jaime
2010-10-27