#include <stdlib.h>
#include "returncodes.h"
#include "swi_dset.h"
General functionalities. | |
#define | SWI_AV_ERROR 1 |
Defines whether the library displays error traces (on stdout) to help debugging errors. | |
#define | SWI_AV_INFO 1 |
#define | SWI_AV_CX_SYNC UINT_MAX |
Value to be used to request synchronous connection to server using swi_av_ConnectToServer. | |
typedef struct swi_av_Asset | swi_av_Asset_t |
An Asset is the AirVantage Application Services object used to send data to the AirVantage Application Services server. | |
rc_ReturnCode_t | swi_av_Init () |
Initializes the Airvantage library. | |
rc_ReturnCode_t | swi_av_Destroy () |
Destroys the Airvantage library. | |
rc_ReturnCode_t | swi_av_ConnectToServer (unsigned int latency) |
Forces a connection to the server. | |
rc_ReturnCode_t | swi_av_TriggerPolicy (const char *policyPtr) |
Forces data attached to a given policy to be sent or consolidated immediately. | |
rc_ReturnCode_t | swi_av_asset_Create (swi_av_Asset_t **asset, const char *assetIdPtr) |
Creates and returns a new asset instance. | |
rc_ReturnCode_t | swi_av_asset_Start (swi_av_Asset_t *asset) |
Starts a newly created asset. | |
rc_ReturnCode_t | swi_av_asset_Destroy (swi_av_Asset_t *asset) |
Closes an asset instance, releasing the associated resources. | |
Data Sending Simple API | |
enum | swi_av_timestamp { SWI_AV_TSTAMP_NO = 0, SWI_AV_TSTAMP_AUTO = 1 } |
Specific values for timestamps. More... | |
typedef enum swi_av_timestamp | swi_av_timestamp_t |
Specific values for timestamps. | |
rc_ReturnCode_t | swi_av_asset_PushString (swi_av_Asset_t *asset, const char *pathPtr, const char *policyPtr, uint32_t timestamp, const char *valuePtr) |
Pushes a string value to the agent. | |
rc_ReturnCode_t | swi_av_asset_PushInteger (swi_av_Asset_t *asset, const char *pathPtr, const char *policyPtr, uint32_t timestamp, int64_t value) |
Pushes an integer value to the agent. | |
rc_ReturnCode_t | swi_av_asset_PushFloat (swi_av_Asset_t *asset, const char *pathPtr, const char *policyPtr, uint32_t timestamp, double value) |
Pushes a float value to the agent. | |
Data Sending Advanced API | |
enum | swi_av_Table_Storage_t { STORAGE_RAM = 0, STORAGE_FLASH } |
Specific values for storage. More... | |
typedef struct swi_av_Table | swi_av_Table_t |
A Table is the Airvantage objects handling staging database tables, to buffer, consolidate and send structured data. | |
rc_ReturnCode_t | swi_av_table_Create (swi_av_Asset_t *asset, swi_av_Table_t **table, const char *pathPtr, size_t numColumns, const char **columnNamesPtr, const char *policyPtr, swi_av_Table_Storage_t persisted, int purge) |
Creates a table, the Airvantage objects handling staging database tables, to buffer, consolidate and send structured data. | |
rc_ReturnCode_t | swi_av_table_Destroy (swi_av_Table_t *table) |
Destroys table instance, releasing associated resources. | |
rc_ReturnCode_t | swi_av_table_PushFloat (swi_av_Table_t *table, double value) |
Pushes a float value in the current row of the table. | |
rc_ReturnCode_t | swi_av_table_PushInteger (swi_av_Table_t *table, int value) |
Pushes an integer value in the current row of the table. | |
rc_ReturnCode_t | swi_av_table_PushString (swi_av_Table_t *table, const char *value) |
Pushes a string value in the current row of the table. | |
rc_ReturnCode_t | swi_av_table_PushRow (swi_av_Table_t *table) |
Pushes the current row of the database to the Agent. | |
Data Reception | |
typedef void(* | swi_av_DataWriteCB )(swi_av_Asset_t *asset, const char *pathPtr, swi_dset_Iterator_t *data, int ack_id, void *userDataPtr) |
DataWrite callback to receive data coming from the server. | |
rc_ReturnCode_t | swi_av_RegisterDataWrite (swi_av_Asset_t *asset, swi_av_DataWriteCB cb, void *userDataPtr) |
Registers a callback to receive DataWrite notifications. | |
rc_ReturnCode_t | swi_av_Acknowledge (int ackId, int status, const char *errMsgPtr, const char *policyPtr, int persisted) |
Acknowledges a server message received with an acknowledgment ticket id. | |
Asset Update | |
Using those APIs and types, the application can receive update request, coming with update files from update package sent by AirVantage Services platform. | |
typedef rc_ReturnCode_t(* | swi_av_updateNotificationCB )(swi_av_Asset_t *asset, const char *componentNamePtr, const char *versionPtr, const char *updateFilePathPtr, swi_dset_Iterator_t *customParams, void *userDataPtr) |
asset update notification callback. | |
rc_ReturnCode_t | swi_av_RegisterUpdateNotification (swi_av_Asset_t *asset, swi_av_updateNotificationCB cb, void *userDataPtr) |
Registers the hook function to be called when the asset receives a software update request from the AirVantage services platform. | |
rc_ReturnCode_t | swi_av_SendUpdateResult (swi_av_Asset_t *asset, const char *componentNamePtr, int updateResult) |
Sends the result of the software update request previously received by an asset. |
Using this API, an application can work with Sierra Wireless AirVantage Services Platform to:
This module relies on Mihini's Agent process, which is responsible for queuing data, managing the flush timers and sending the data to the remote AirVantage server. Many of the APIs in this module relay the data to the Agent; the Agent then manages the data as described.
Two methods are supported for sending data to the AirVantage servers:
#define SWI_AV_ERROR 1 |
Defines whether the library displays error traces (on stdout) to help debugging errors.
Using 0 for this setting will ensure no printing is done by the libra
typedef struct swi_av_Asset swi_av_Asset_t |
An Asset is the AirVantage Application Services object used to send data to the AirVantage Application Services server.
Instances of this object must be created through swi_av_asset_Create.
typedef void(* swi_av_DataWriteCB)(swi_av_Asset_t *asset,const char *pathPtr,swi_dset_Iterator_t *data,int ack_id,void *userDataPtr) |
DataWrite callback to receive data coming from the server.
No automatic acknowledge of received data will be done, so application that wants the server to receive acknowledge needs to call swi_av_Acknowledge function.
String parameters given to this function will be released when the callback returns.
asset | [IN] the asset receiving the data | |
pathPtr | [IN] the path targeted by the data sent by the server. | |
data | [IN] the data iterator containing the received data. The data contained in the iterator will be automatically released when the callback returns. | |
ack_id | [IN] the id to be used to acknowledge the received data. If ack_id=0 then there is no need to acknowledge. | |
userDataPtr | [IN] the user data given at callback registration. |
typedef struct swi_av_Table swi_av_Table_t |
A Table is the Airvantage objects handling staging database tables, to buffer, consolidate and send structured data.
Instances of this object must be created through swi_av_table_Create.
typedef enum swi_av_timestamp swi_av_timestamp_t |
Specific values for timestamps.
Timestamps values 0 and 1 (in second since Unix Epoch) are reserved for those special timestamp requests.
typedef rc_ReturnCode_t(* swi_av_updateNotificationCB)(swi_av_Asset_t *asset,const char *componentNamePtr,const char *versionPtr,const char *updateFilePathPtr,swi_dset_Iterator_t *customParams,void *userDataPtr) |
asset update notification callback.
The callback will be called when the associated asset is responsible to manage a software update request coming from AirVantage services platform.
The application must call swi_av_SendUpdateResult explicitly to send update result, otherwise no result is sent, retry mechanism will be started and eventually the update status will be set to failed.
String parameters will be released when the callback returns.
asset | [IN] the asset receiving the update notification | |
componentNamePtr | [IN] is the identifier of the component to update, (the component name is a path in dotted notation) the name is defined in update package manifest file, here it is provided without the assetid at the beginning. | |
versionPtr | [IN] is the version of the component to install. Version can be empty string (but not NULL!) to specify de-installation request, non empty string for regular update/install of software component. | |
updateFilePathPtr | [IN] absolute path to local file to use on the device to do the update, can be empty string when version is empty too. The file will be automatically deleted when the update process ends, so once swi_av_SendUpdateResult has been called, or all retries have been done for a single component update, the file existence on file system is not guaranteed anymore. | |
customParams | [IN] application specifics parameters, defined in update package, can be NULL if no custom parameter was defined. To be processed using swi_dset_Iterator_t API, embedded data in the iterator will be automatically released when this callback returns. | |
userDataPtr | [IN] the user data given at callback registration |
enum swi_av_timestamp |
Specific values for timestamps.
Timestamps values 0 and 1 (in second since Unix Epoch) are reserved for those special timestamp requests.
rc_ReturnCode_t swi_av_Acknowledge | ( | int | ackId, | |
int | status, | |||
const char * | errMsgPtr, | |||
const char * | policyPtr, | |||
int | persisted | |||
) |
Acknowledges a server message received with an acknowledgment ticket id.
No automatic acknowledge will be done, so application that wants the server to receive acknowledge needs to call this function.
RC_BAD_PARAMETER if the requested policy name is not found.
ackId | [IN] the id to acknowledge, as given to the data reception callback. |
status | [IN] status of the acknowledge: 0 means success, other values mean error |
errMsgPtr | [IN] an optional error message string |
policyPtr | [IN] optional triggering policy to send the acknowledgment, defaults to "now". |
persisted | [IN] boolean, if true, the ACK message will be persisted in flash by the agent, and kept even if a reboot occurs before the policy is triggered. |
rc_ReturnCode_t swi_av_asset_Create | ( | swi_av_Asset_t ** | asset, | |
const char * | assetIdPtr | |||
) |
Creates and returns a new asset instance.
The newly created asset is not started when returned, it can therefore neither send nor receive messages at this point. This intermediate, non-started asset allows to configure message/update handlers before any message/update is actually transferred to the asset.
See swi_av_asset_Start to start the newly created instance.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
RC_BAD_PARAMETER if the supplied parameters are invalid
asset | [OUT] pointer to hold the newly created asset. The AirVantage library is responsible for allocating the resources of this asset. The user is responsible of releasing resources using swi_av_asset_Destroy. |
assetIdPtr | [IN] string defining the assetId identifying the instance of this new asset. NULL and empty string values are forbidden. The assetId must be unique on the same device, otherwise asset starting will fail. |
rc_ReturnCode_t swi_av_asset_Destroy | ( | swi_av_Asset_t * | asset | ) |
Closes an asset instance, releasing the associated resources.
Once this destructor method has been called, no more message can be sent nor received by the instance and update for this asset will be automatically rejected.
RC_BAD_FORMAT if asset parameter is invalid
asset | [IN] the asset to stop |
rc_ReturnCode_t swi_av_asset_PushFloat | ( | swi_av_Asset_t * | asset, | |
const char * | pathPtr, | |||
const char * | policyPtr, | |||
uint32_t | timestamp, | |||
double | value | |||
) |
Pushes a float value to the agent.
The data are not necessarily moved forward from the agent to the server immediately: agent-to-server data transfers are managed through policies, as described in the Mihini Agent product documentation. This API is optimized for ease of use: it will internally try to reformat data in the most sensible, server-compatible way. Applications requiring a tight control over how data are structured, buffered, consolidated and reported should consider the more advanced Table API, especially it is not possible to send correlated data using this API.
String parameters can be released by user once the call has returned.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
asset | [IN] the asset used to send the data |
pathPtr | [IN] the datastore path under which data will be stored relative to the asset node, the last path segment will be used as a datastore key |
policyPtr | [IN] optional name of the policy controlling when the data must be sent to the server. If omitted, the default policy is used. |
timestamp | [IN] optional timestamp, in second since Unix Epoch, swi_av_timestamp_t values can be used to request automatic or no timestamp. |
value | [IN] float value to push |
rc_ReturnCode_t swi_av_asset_PushInteger | ( | swi_av_Asset_t * | asset, | |
const char * | pathPtr, | |||
const char * | policyPtr, | |||
uint32_t | timestamp, | |||
int64_t | value | |||
) |
Pushes an integer value to the agent.
The data are not necessarily moved forward from the agent to the server immediately: agent-to-server data transfers are managed through policies, as described in the Mihini Agent product documentation. This API is optimized for ease of use: it will internally try to reformat data in the most sensible, server-compatible way. Applications requiring a tight control over how data are structured, buffered, consolidated and reported should consider the more advanced Table API, especially it is not possible to send correlated data using this API.
String parameters can be released by user once the call has returned.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
asset | [IN] the asset used to send the data |
pathPtr | [IN] the datastore path under which data will be stored relative to the asset node, the last path segment will be used as a datastore key. |
policyPtr | [IN] optional, name of the policy controlling when the data must be sent to the server. If omitted, the default policy is used. |
timestamp | [IN] optional timestamp, in second since Unix Epoch, swi_av_timestamp_t values can be used to request automatic or no timestamp. |
value | [IN] integer value to push |
rc_ReturnCode_t swi_av_asset_PushString | ( | swi_av_Asset_t * | asset, | |
const char * | pathPtr, | |||
const char * | policyPtr, | |||
uint32_t | timestamp, | |||
const char * | valuePtr | |||
) |
Pushes a string value to the agent.
The data are not necessarily moved forward from the agent to the server immediately: agent-to-server data transfers are managed through policies, as described in the Mihini Agent product documentation. This API is optimized for ease of use: it will internally try to reformat data in the most sensible, server-compatible way. Applications requiring a tight control over how data are structured, buffered, consolidated and reported should consider the more advanced Table API, especially it is not possible to send correlated data using this API.
String parameters can be released by user once the call has returned.
RC_NOT__AVAILABLE if the Agent cannot be accessed.
asset | [IN] the asset used to send the data |
pathPtr | [IN] the datastore path under which data will be stored relative to the asset node, the last path segment will be used as a datastore key. NULL and empty string values are forbidden. |
policyPtr | [IN] optional name of the policy controlling when the data must be sent to the server. If omitted, the default policy is used. |
timestamp | [IN] optional timestamp, in second since Unix Epoch, swi_av_timestamp_t values can be used to request automatic or no timestamp. |
valuePtr | [IN] string value to push |
rc_ReturnCode_t swi_av_asset_Start | ( | swi_av_Asset_t * | asset | ) |
Starts a newly created asset.
Allows the asset instance to send and receive messages to/from the servers.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
asset | [IN] the asset to start |
rc_ReturnCode_t swi_av_ConnectToServer | ( | unsigned int | latency | ) |
Forces a connection to the server.
This connection will not flush outgoing data handled through policies, but it will poll the server for new messages addressed to assets on this gateway device.
If using SWI_AV_CX_SYNC, the connection is synchronous, i.e. once this function returns, the requested connection to the server is closed. Otherwise the connection will happen after this call returns.
Notes:
RC_NOT_AVAILABLE if the Agent cannot be accessed.
latency | [IN] latency in seconds before initiating the connection to the server, use SWI_AV_CX_SYNC to specify synchronous connection. |
rc_ReturnCode_t swi_av_Destroy | ( | ) |
Destroys the Airvantage library.
rc_ReturnCode_t swi_av_Init | ( | ) |
Initializes the Airvantage library.
A call to swi_av_Init is mandatory to enable AirVantage library APIs.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
rc_ReturnCode_t swi_av_RegisterDataWrite | ( | swi_av_Asset_t * | asset, | |
swi_av_DataWriteCB | cb, | |||
void * | userDataPtr | |||
) |
Registers a callback to receive DataWrite notifications.
The callback will be called in a new pthread.
Usage example of the datawrite callback function:
int my_datacallback(swi_av_Asset *asset, const char *path, swi_dset_Iterator* data, int ack_id, void *userData){ if(! strncmp(path, "command.setvalue", strlen("command.setvalue")) ){ int64_t cmd_value; assert(RC_OK == swi_dset_GetIntegerByName(data, "cmd_value", &cmd_value) ); setvalue(cmd_value); } else{ //unknown command printf("received data on path[%s]:\n", path); while(RC_NOT_FOUND != swi_dset_Next(data) ){ printf("data name: [%s]\n", swi_dset_GetName(data)); //... } } if(ack_id) swi_av_Acknowledge(ack_id, 0, NULL, "now", 1); return 0; } main(...){ swi_av_RegisterDataWrite(asset, my_datacallback, NULL) }
RC_BAD_FORMAT if provided asset param is invalid
asset | [IN] the asset listening to incoming data. |
cb | [IN] the callback function to register to receive the data. |
userDataPtr | [IN] user data that will be given back in callback. |
rc_ReturnCode_t swi_av_RegisterUpdateNotification | ( | swi_av_Asset_t * | asset, | |
swi_av_updateNotificationCB | cb, | |||
void * | userDataPtr | |||
) |
Registers the hook function to be called when the asset receives a software update request from the AirVantage services platform.
The callback will be called in a new pthread.
This feature targets applications that want to process their own update or applications that are responsible for updating another pieces of software, taking advantage of the integrated solution provided by AirVantage services.
If the application wants to have a deeper control of the whole update process, it needs to use the functionalities provided by swi_update.h.
RC_BAD_FORMAT if provided asset param is invalid
asset | [IN] the asset listening to update notification, can be a started or non-started asset. |
cb | [IN] the callback function to register to receive asset update notification Giving NULL as parameter will be treated as unregister of previous callback. |
userDataPtr | [IN] user data that will be given back in callback |
rc_ReturnCode_t swi_av_SendUpdateResult | ( | swi_av_Asset_t * | asset, | |
const char * | componentNamePtr, | |||
int | updateResult | |||
) |
Sends the result of the software update request previously received by an asset.
RC_BAD_PARAMETER when no update request is matching asset and component name, the update result is discarded.
asset | [IN] the asset that was targeted by the software update request. |
componentNamePtr | [IN] this must be the same value as the one that was given as argument to the swi_av_updateNotificationCB. As only one software update is possible for the same component at the same time, the couple asset+componentName fully identifies the software update request. |
updateResult | [IN] the result of the update, 200 for success, any other value means error. Values from 480 to 499 are reserved for applicative error codes,so it is highly recommended to use one (or more) of those to signify an error coming from an asset update. |
rc_ReturnCode_t swi_av_table_Create | ( | swi_av_Asset_t * | asset, | |
swi_av_Table_t ** | table, | |||
const char * | pathPtr, | |||
size_t | numColumns, | |||
const char ** | columnNamesPtr, | |||
const char * | policyPtr, | |||
swi_av_Table_Storage_t | persisted, | |||
int | purge | |||
) |
Creates a table, the Airvantage objects handling staging database tables, to buffer, consolidate and send structured data.
String parameters can be released by user once the call has returned.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
RC_BAD_FORMAT if error occurred during the payload generation (iternally used to echange data with the Agent)
asset | [IN] the asset used to send the data |
table | [OUT] pointer to hold the newly created table. The AirVantage library is responsible for allocating the resources of this table, The user is responsible of releasing the resources using swi_av_Table_Destroy. |
pathPtr | [IN] the datastore path under which data will be stored relative to the asset node |
numColumns | [IN] number of columns of the table |
columnNamesPtr | [IN] pointer to an array of strings (with numColums entries): name of each column. |
policyPtr | [IN] name of the policy controlling when the data must be sent to the server. |
persisted | [IN] value which describes how the table must be persisted, STORAGE_FLASH meaning file persistence, STORAGE_RAM meaning in ram only. |
purge | [IN] boolean value, indicates if existing table (if any) is recreated (true) or reused (false). Recreation means the table will be dropped and then created from scratch (so any data inside table will be lost). |
rc_ReturnCode_t swi_av_table_Destroy | ( | swi_av_Table_t * | table | ) |
Destroys table instance, releasing associated resources.
Partial data not pushed yet to the agent will be lost.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
RC_BAD_FORMAT if error occurred during the payload generation (iternally used to echange data with the Agent)
table | [IN] the table to destroy |
rc_ReturnCode_t swi_av_table_PushFloat | ( | swi_av_Table_t * | table, | |
double | value | |||
) |
Pushes a float value in the current row of the table.
swi_av_table_Push* functions have be called in the correct order to match the table definition created in swi_av_table_Create. Until a row is complete and sent to the Agent by invoking swi_av_table_PushRow(), data is only pushed locally in the table database.
RC_OUT_OF_RANGE maximum len for the current row has been reached, the value cannot be pushed
table | [IN] the table where to push the value |
value | [IN] the float to push |
rc_ReturnCode_t swi_av_table_PushInteger | ( | swi_av_Table_t * | table, | |
int | value | |||
) |
Pushes an integer value in the current row of the table.
swi_av_table_Push* functions have be called in the correct order to match the table definition created in swi_av_table_Create. Until a row is complete and sent to the Agent by invoking swi_av_table_PushRow(), data is only pushed locally in the table database.
RC_OUT_OF_RANGE maximum len for the current row has been reached, the value cannot be pushed
table | [IN] the table where to push the value |
value | [IN] the integer to push |
rc_ReturnCode_t swi_av_table_PushRow | ( | swi_av_Table_t * | table | ) |
Pushes the current row of the database to the Agent.
Once the current row has been pushed to the Agent, it is totally freed in the database, And the table is ready to received new pushed data using swi_av_table_Push*() functions.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
RC_BAD_FORMAT if error occurred during the payload generation (iternally used to echange data with the Agent)
table | [IN] the table where to push the value |
rc_ReturnCode_t swi_av_table_PushString | ( | swi_av_Table_t * | table, | |
const char * | value | |||
) |
Pushes a string value in the current row of the table.
swi_av_table_Push* functions have be called in the correct order to match the table definition created in swi_av_table_Create. Until a row is complete and sent to the Agent by invoking swi_av_table_PushRow(), data is only pushed locally in the table database.
RC_OUT_OF_RANGE maximum len for the current row has been reached, the value cannot be pushed
table | [IN] the table where to push the value |
value | [IN] the string to push |
rc_ReturnCode_t swi_av_TriggerPolicy | ( | const char * | policyPtr | ) |
Forces data attached to a given policy to be sent or consolidated immediately.
This only applies to data sent using simple or advanced Data Sending APIs. Data Reception and Asset Update exchanges are not modified by this function.
A connection to the server is done only if data needs to be sent as the result to this trigger operation. Put another way, if no data is attached to the triggered policy(ies), then no connection to the server is done. See swi_av_ConnectToServer for complementary function.
For a description of how policies allow to manage data reporting from the assets to the server, see Mihini Agent product documentation.
RC_BAD_PARAMETER if the requested policy name is not found.
RC_NOT_AVAILABLE if the Agent cannot be accessed.
policyPtr | [IN] name of the policy queue to be flushed. Flush all policies if policy=='*'; only flush the default policy if policy is omitted. |