S2C Stream APIs. More...

Functions

zos_result_t s2c_write_stream_context_init (msgpack_context_t *context, const char *stream, uint32_t max_length)
 Initialize the streaming writing MessagePack context. More...
 
zos_result_t s2c_write_stream_context_flush (msgpack_context_t *context)
 Send a previously populated stream message to all listening nodes. More...
 
zos_result_t s2c_register_listener (const char *stream, s2c_stream_listener_t listener, void *arg)
 Register a listener for incoming stream data. More...
 
zos_result_t s2c_unregister_listener (const char *stream)
 Unregister a listener for incoming stream data. More...
 
zos_result_t s2c_request_stream_data (const char *stream)
 Request a streams current value from the cloud. More...
 

Detailed Description

S2C Stream APIs.

Function Documentation

zos_result_t s2c_register_listener ( const char *  stream,
s2c_stream_listener_t  listener,
void *  arg 
)

Register a listener for incoming stream data.

This registers a callback which is executed when the corresponding stream receives data from either the cloud or Mobile. Refer to s2c_stream_listener_t for more information on how the callback works.

Use s2c_unregister_listener() to remove the listener.

Note
The registered listener executes in the Zap event thread context.
Parameters
streamName of stream to listen for incoming data
listenerCallback to be executed when stream receives data
argOptional argument to pass to callback
Returns
zos_result_t The result of the API call
zos_result_t s2c_request_stream_data ( const char *  stream)

Request a streams current value from the cloud.

This retrieves the latest value the cloud currently has stored for the corresponding stream. This is typically used after opening a cloud connection to update the device's output components to their correct value.

Note
A cloud connection must be opened before calling this API
Parameters
streamName of the stream for which to retrieve latest value from cloud, leave NULL to request all registered streams
Returns
zos_result_t The result of the API call
zos_result_t s2c_unregister_listener ( const char *  stream)

Unregister a listener for incoming stream data.

This removes a listener registered by s2c_register_listener()

Parameters
streamName of the stream for which to remove the listener
Returns
zos_result_t The result of the API call
zos_result_t s2c_write_stream_context_flush ( msgpack_context_t context)

Send a previously populated stream message to all listening nodes.

This sends a previously populated stream message to all listening nodes.

Refer to s2c_write_stream_context_init() for details on initializing the msgpack_context_t and writing the stream message.

Parameters
contextmsgpack_context_t containing a stream's message to send to all listening nodes
Returns
zos_result_t The result of the API call
zos_result_t s2c_write_stream_context_init ( msgpack_context_t context,
const char *  stream,
uint32_t  max_length 
)

Initialize the streaming writing MessagePack context.

This prepares a msgpack_context_t context from writing a stream's message data. Once the context is initialized, the msgpack_write_xxx APIs should be used for populating the stream message data. Refer to the MessagePack Write APIs for more details about writing MessagePack data.

Once all the stream message data is written, call s2c_write_stream_context_flush() to send the stream message to all listening nodes.

Note
Set the max_length to UINT32_MAX if the total length of the stream message data is unknown. This will allocate a buffer of S2C_MAX_PACKET_SIZE
Parameters
contextA msgpack_context_t to initilize
streamthe name of the stream to write
max_lengthThe maximum length of the stream message (the actual length may be shorter)
Returns
zos_result_t The result of the API call