Tizen Native API
5.5
|
IoTCon Options provides API to manage options.
#include <iotcon.h>
The IoTcon options API provides methods for managing vendor specific options of coap packet.
See more about coap packet in http://tools.ietf.org/html/rfc7252. Example (Client side) :
#include <iotcon.h> ... static void _request_get_with_option(iotcon_remote_resource_h resource) { int i; int ret; unsigned short opt_id = 3000; const char *opt_val = "12345"; iotcon_options_h options = NULL; .. ret = iotcon_options_create(&options); if (IOTCON_ERROR_NONE != ret) return; ret = iotcon_options_add(options, opt_id, opt_val); if (IOTCON_ERROR_NONE != ret) { iotcon_options_destroy(options); return; } ret = iotcon_remote_resource_set_options(resource, options); if (IOTCON_ERROR_NONE != ret) { iotcon_options_destroy(options); return; } ret = iotcon_remote_resource_get(resource, NULL, _on_get, NULL); if (IOTCON_ERROR_NONE != ret) { iotcon_options_destroy(options); return; } iotcon_options_destroy(options); ... }
Example (Server side) :
#include <iotcon.h> ... static bool _options_foreach(unsigned short id, const char *data, void *user_data) { // handle options return IOTCON_FUNC_CONTINUE; } static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data) { int ret; iotcon_options_h options; ret = iotcon_request_get_options(request, &options); if (IOTCON_ERROR_NONE == ret && options) { ret = iotcon_options_foreach(options, _options_foreach, NULL); if (IOTCON_ERROR_NONE != ret) return; } ... }
This API is related with the following features:
Functions | |
int | iotcon_options_create (iotcon_options_h *options) |
Creates a new option handle. | |
int | iotcon_options_destroy (iotcon_options_h options) |
Destroys an option handle. | |
int | iotcon_options_add (iotcon_options_h options, unsigned short id, const char *data) |
Adds a new ID and a corresponding data into the options. | |
int | iotcon_options_remove (iotcon_options_h options, unsigned short id) |
Removes the ID and its associated data from the options. | |
int | iotcon_options_lookup (iotcon_options_h options, unsigned short id, char **data) |
Looks up data at the given ID from the options. | |
int | iotcon_options_foreach (iotcon_options_h options, iotcon_options_foreach_cb cb, void *user_data) |
Gets all data of the options by invoking the callback function. | |
Typedefs | |
typedef bool(* | iotcon_options_foreach_cb )(unsigned short id, const char *data, void *user_data) |
Specifies the type of function passed to iotcon_options_foreach(). |
typedef bool(* iotcon_options_foreach_cb)(unsigned short id, const char *data, void *user_data) |
Specifies the type of function passed to iotcon_options_foreach().
[in] | id | The information of the option |
[in] | data | The data of the option |
[in] | user_data | The user data to pass to the function |
true
to continue with the next iteration of the loop, otherwise false
to break out of the loop IOTCON_FUNC_CONTINUE and IOTCON_FUNC_STOP are more friendly values for the return int iotcon_options_add | ( | iotcon_options_h | options, |
unsigned short | id, | ||
const char * | data | ||
) |
Adds a new ID and a corresponding data into the options.
[in] | options | The handle of the options |
[in] | id | The ID of the option to insert |
[in] | data | The string data to insert into the options |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_OUT_OF_MEMORY | Out of memory |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
int iotcon_options_create | ( | iotcon_options_h * | options | ) |
Creates a new option handle.
[out] | options | A newly allocated option handle |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_OUT_OF_MEMORY | Out of memory |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
int iotcon_options_destroy | ( | iotcon_options_h | options | ) |
Destroys an option handle.
[in] | options | The handle of the options |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
int iotcon_options_foreach | ( | iotcon_options_h | options, |
iotcon_options_foreach_cb | cb, | ||
void * | user_data | ||
) |
Gets all data of the options by invoking the callback function.
iotcon_options_foreach_cb() will be called for each option.
If iotcon_options_foreach_cb() returns false, iteration will be stopped.
[in] | options | The handle of the options |
[in] | cb | The callback function to get data |
[in] | user_data | The user data to pass to the function |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
int iotcon_options_lookup | ( | iotcon_options_h | options, |
unsigned short | id, | ||
char ** | data | ||
) |
Looks up data at the given ID from the options.
[in] | options | The handle of the options |
[in] | id | The ID of the option to lookup |
[out] | data | Found data from options |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
int iotcon_options_remove | ( | iotcon_options_h | options, |
unsigned short | id | ||
) |
Removes the ID and its associated data from the options.
[in] | options | The handle of the options |
[in] | id | The ID of the option to delete |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |