Sending Events to a Storyboard Application

Storyboard events contain string based names and a variable data field.  For this reason the event data must be serialized into a buffer for communication.  The Storyboard IO API provides the functions needed to both serialize your data and send the event.  The event you wish to send must first be serialized via a call to gre_io_serialize().  This will allocated a serialized data buffer for your event.  The event can then be sent via the gre_io_send() function.  Once the event has been sent the buffer can be reused or freed via a call to gre_io_free_buffer().

[Note]Note

Serialized buffers can be reused multiple times. The gre_io_serialize_buffer() function will resize or reallocate the buffer if the data being serialized is larger than the existing buffer. This is designed to cut down on repetitive memory allocation and deallocation churn.

Data parameters must be sent in order of descending alignment requirements. Example: 4u1 4u1 2u1 1s0 is good, 2u1 4u1 4u1 1s0 is not


gre_io_t                    *send_handle;
gre_io_serialized_data_t    *nbuffer = NULL;
const char                  *event_data = "my event data"

/*
 * Connect to a channel to send messages.
 */
send_handle = gre_io_open("my_channel", GRE_IO_TYPE_WRONLY);
if(send_handle == NULL) {
    printf("Can't open send handle [%s]\n", argv[1]);
    return 0;
}

/*
 * Send a named event containing no data payload
 */
nbuffer = gre_io_serialize(nbuffer, NULL,
             "my_event_name",
             NULL,
             NULL,
             0);

gre_io_send(send_handle, nbuffer);

/*
 * Send a named event with an additional string payload
 */
nbuffer = gre_io_serialize(nbuffer, NULL,
             "my_event_name",
             "1s0 data",
             event_data,
             strlen(event_data)+1);

gre_io_send(send_handle, nbuffer);