Simple ports map onto an object-like C struct
with a
data()
, read()
or write()
and strerror()
function members. The data()
function takes no parameter and
returns a pointer on the current port data. Input ports may refresh
their data by invoking the read()
method, while output ports may
publish new data by invoking the write()
method. Both
read()
and write()
return 0
on success, or an
unsigned 32bits integer representing an error code. The
strerror()
method can be used to transform the error code into
a user readable error message.
Ports defined with the multiple
flag map onto a similar
struct
, with the difference that data()
, read()
and write()
methods take an additional string (const char
*
) parameter representing the port element name. Multiple output
ports have two additional open()
and close()
members
(also accepting a single string parameter) that dynamically create or
destroy ports.
For instance, the following IDL:
port in double in_port; port multiple in double multi_in_port; port out double out_port; port multiple out double multi_out_port;
would map into
typedef struct { double * (*data)(); uint32_t (*read)(void); const char * (*strerror)(uint32_t); } in_port; typedef struct { double * (*data)(const char *id); uint32_t (*read)(const char *id); const char * (*strerror)(uint32_t); } multi_in_port; typedef struct { double * (*data)(); uint32_t (*write)(void); const char * (*strerror)(uint32_t); } out_port; typedef struct { double * (*data)(const char *id); uint32_t (*write)(const char *id); uint32_t (*open)(const char *id); uint32_t (*close)(const char *id); const char * (*strerror)(uint32_t); } multi_out_port;