Tizen Native API
5.5
|
IoTCon State provides API to manage attributes.
#include <iotcon.h>
The IoTCon attributes API provides string key based hash table. Example :
#include <iotcon.h> ... static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data) { int ret; iotcon_request_type_e type; ret = iotcon_request_get_request_type(request, &type); if (IOTCON_ERROR_NONE != ret) return; if (IOTCON_REQUEST_GET == type) { iotcon_response_h response = NULL; iotcon_representation_h representation = NULL; iotcon_attributes_h attributes = NULL; ret = iotcon_response_create(request, &response); if (IOTCON_ERROR_NONE != ret) return; ret = iotcon_representation_create(&representation); if (IOTCON_ERROR_NONE != ret) { iotcon_response_destroy(response); return; } ... ret = iotcon_attributes_create(&attributes); if (IOTCON_ERROR_NONE != ret) { iotcon_representation_destroy(representation); iotcon_response_destroy(response); return; } ret = iotcon_attributes_add_bool(attributes, "power", true); if (IOTCON_ERROR_NONE != ret) { iotcon_attributes_destroy(attributes); iotcon_representation_destroy(representation); iotcon_response_destroy(response); return; } ret = itocon_attributes_add_int(attributes, "brightness", 75); if (IOTCON_ERROR_NONE != ret) { iotcon_attributes_destroy(attributes); iotcon_representation_destroy(representation); iotcon_response_destroy(response); return; } ret = iotcon_representation_set_attributes(representation, attributes); if (IOTCON_ERROR_NONE != ret) { iotcon_attributes_destroy(attributes); iotcon_representation_destroy(representation); iotcon_response_destroy(response); return; } ... ret = iotcon_response_set_representation(response, representation); if (IOTCON_ERROR_NONE != ret) { iotcon_attributes_destroy(attributes); iotcon_representation_destroy(representation); iotcon_response_destroy(response); return; } ret = iotcon_response_send(response); if (IOTCON_ERROR_NONE != ret) { iotcon_attributes_destroy(attributes); iotcon_representation_destroy(representation); iotcon_response_destroy(response); return; } iotcon_attributes_destroy(attributes); iotcon_representation_destroy(representation); iotcon_response_destroy(response); } ... }
This API is related with the following features:
Functions | |
int | iotcon_attributes_create (iotcon_attributes_h *attributes) |
Creates a new attributes handle. | |
int | iotcon_attributes_destroy (iotcon_attributes_h attributes) |
Destroys the attributes. | |
int | iotcon_attributes_clone (iotcon_attributes_h attributes, iotcon_attributes_h *attributes_clone) |
Clones the attributes handle. | |
int | iotcon_attributes_add_int (iotcon_attributes_h attributes, const char *key, int val) |
Adds a new key and integer value into the attributes. | |
int | iotcon_attributes_add_bool (iotcon_attributes_h attributes, const char *key, bool val) |
Adds a new key and boolean value into the attributes. | |
int | iotcon_attributes_add_double (iotcon_attributes_h attributes, const char *key, double val) |
Adds a new key and double value into the attributes. | |
int | iotcon_attributes_add_str (iotcon_attributes_h attributes, const char *key, char *val) |
Adds a new key and string value into the attributes. | |
int | iotcon_attributes_add_byte_str (iotcon_attributes_h attributes, const char *key, unsigned char *val, int len) |
Adds a new key and byte string value into the attributes. | |
int | iotcon_attributes_add_list (iotcon_attributes_h attributes, const char *key, iotcon_list_h list) |
Adds a new key and list value into the attributes. | |
int | iotcon_attributes_add_attributes (iotcon_attributes_h dest, const char *key, iotcon_attributes_h src) |
Adds a new key and attributes value into the attributes. | |
int | iotcon_attributes_add_null (iotcon_attributes_h attributes, const char *key) |
Adds a new key with NULL value into the attributes. | |
int | iotcon_attributes_get_int (iotcon_attributes_h attributes, const char *key, int *val) |
Gets the integer value from the given key. | |
int | iotcon_attributes_get_bool (iotcon_attributes_h attributes, const char *key, bool *val) |
Gets the boolean value from the given key. | |
int | iotcon_attributes_get_double (iotcon_attributes_h attributes, const char *key, double *val) |
Gets the double value from the given key. | |
int | iotcon_attributes_get_str (iotcon_attributes_h attributes, const char *key, char **val) |
Gets the string value from the given key. | |
int | iotcon_attributes_get_byte_str (iotcon_attributes_h attributes, const char *key, unsigned char **val, int *len) |
Gets the byte string value from the given key. | |
int | iotcon_attributes_get_list (iotcon_attributes_h attributes, const char *key, iotcon_list_h *list) |
Gets the list value from the given key. | |
int | iotcon_attributes_get_attributes (iotcon_attributes_h src, const char *key, iotcon_attributes_h *dest) |
Gets the attributes value from the given key. | |
int | iotcon_attributes_is_null (iotcon_attributes_h attributes, const char *key, bool *is_null) |
Checks whether the value of given key is NULL or not. | |
int | iotcon_attributes_remove (iotcon_attributes_h attributes, const char *key) |
Removes the key and its associated value from the attributes. | |
int | iotcon_attributes_get_type (iotcon_attributes_h attributes, const char *key, iotcon_type_e *type) |
Gets the type of a value at the given key. | |
int | iotcon_attributes_foreach (iotcon_attributes_h attributes, iotcon_attributes_cb cb, void *user_data) |
Calls a function for each element of attributes. | |
int | iotcon_attributes_get_keys_count (iotcon_attributes_h attributes, unsigned int *count) |
Gets the number of keys in the attributes. | |
Typedefs | |
typedef bool(* | iotcon_attributes_cb )(iotcon_attributes_h attributes, const char *key, void *user_data) |
Specifies the type of function passed to iotcon_attributes_foreach(). |
typedef bool(* iotcon_attributes_cb)(iotcon_attributes_h attributes, const char *key, void *user_data) |
Specifies the type of function passed to iotcon_attributes_foreach().
[in] | attributes | The attributes handle |
[in] | key | The key |
[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_attributes_add_attributes | ( | iotcon_attributes_h | dest, |
const char * | key, | ||
iotcon_attributes_h | src | ||
) |
Adds a new key and attributes value into the attributes.
If key already exists, current attributes will be replaced with new src.
[in] | dest | The attributes handle |
[in] | key | The key |
[in] | src | The attributes handle to set newly |
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_attributes_add_bool | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
bool | val | ||
) |
Adds a new key and boolean value into the attributes.
If key is already exists, current value will be replaced with new val.
[in] | attributes | The attributes handle |
[in] | key | The key |
[in] | val | The value |
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_attributes_add_byte_str | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
unsigned char * | val, | ||
int | len | ||
) |
Adds a new key and byte string value into the attributes.
If key is already exists, current value will be replaced with new val.
[in] | attributes | The attributes handle |
[in] | key | The key |
[in] | val | The value |
[in] | len | The length of val |
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_attributes_add_double | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
double | val | ||
) |
Adds a new key and double value into the attributes.
If key is already exists, current value will be replaced with new val.
[in] | attributes | The attributes handle |
[in] | key | The key |
[in] | val | The value |
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_attributes_add_int | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
int | val | ||
) |
Adds a new key and integer value into the attributes.
If key is already exists, current value will be replaced with new val.
[in] | attributes | The attributes handle |
[in] | key | The key |
[in] | val | The value |
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_attributes_add_list | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
iotcon_list_h | list | ||
) |
Adds a new key and list value into the attributes.
If key already exists, current list will be replaced with new list.
[in] | attributes | The attributes handle |
[in] | key | The key |
[in] | list | The value |
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_attributes_add_null | ( | iotcon_attributes_h | attributes, |
const char * | key | ||
) |
Adds a new key with NULL value into the attributes.
If key already exists, current value will be replaced with NULL.
[in] | attributes | The attributes handle |
[in] | key | The key to be set NULL |
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_attributes_add_str | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
char * | val | ||
) |
Adds a new key and string value into the attributes.
If key is already exists, current value will be replaced with new val.
[in] | attributes | The attributes handle |
[in] | key | The key |
[in] | val | The value |
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_attributes_clone | ( | iotcon_attributes_h | attributes, |
iotcon_attributes_h * | attributes_clone | ||
) |
Clones the attributes handle.
[in] | attributes | The attributes handle |
[out] | attributes_clone | The cloned attributes 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_attributes_create | ( | iotcon_attributes_h * | attributes | ) |
Creates a new attributes handle.
[out] | attributes | A newly allocated attributes 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_attributes_destroy | ( | iotcon_attributes_h | attributes | ) |
Destroys the attributes.
Releases attributes and its internal data.
[in] | attributes | The attributes handle to free |
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_attributes_foreach | ( | iotcon_attributes_h | attributes, |
iotcon_attributes_cb | cb, | ||
void * | user_data | ||
) |
Calls a function for each element of attributes.
iotcon_attributes_cb() will be called for each child.
[in] | attributes | The attributes handle |
[in] | cb | The callback function to invoke |
[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_attributes_get_attributes | ( | iotcon_attributes_h | src, |
const char * | key, | ||
iotcon_attributes_h * | dest | ||
) |
Gets the attributes value from the given key.
[in] | src | The attributes handle |
[in] | key | The key |
[out] | dest | The attributes value at the key |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |
IOTCON_ERROR_INVALID_TYPE | Invalid type |
int iotcon_attributes_get_bool | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
bool * | val | ||
) |
Gets the boolean value from the given key.
[in] | attributes | The attributes handle |
[in] | key | The key |
[out] | val | The boolean value |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |
IOTCON_ERROR_INVALID_TYPE | Invalid type |
int iotcon_attributes_get_byte_str | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
unsigned char ** | val, | ||
int * | len | ||
) |
Gets the byte string value from the given key.
[in] | attributes | The attributes handle |
[in] | key | The key |
[out] | val | The byte string value |
[out] | len | The length of val |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |
IOTCON_ERROR_INVALID_TYPE | Invalid type |
int iotcon_attributes_get_double | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
double * | val | ||
) |
Gets the double value from the given key.
[in] | attributes | The attributes handle |
[in] | key | The key |
[out] | val | The double value |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |
IOTCON_ERROR_INVALID_TYPE | Invalid type |
int iotcon_attributes_get_int | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
int * | val | ||
) |
Gets the integer value from the given key.
[in] | attributes | The attributes handle |
[in] | key | The key |
[out] | val | The integer value |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |
IOTCON_ERROR_INVALID_TYPE | Invalid type |
int iotcon_attributes_get_keys_count | ( | iotcon_attributes_h | attributes, |
unsigned int * | count | ||
) |
Gets the number of keys in the attributes.
[in] | attributes | The attributes handle |
[out] | count | The number of keys |
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_attributes_get_list | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
iotcon_list_h * | list | ||
) |
Gets the list value from the given key.
[in] | attributes | The attributes handle |
[in] | key | The key |
[out] | list | The list value |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |
IOTCON_ERROR_INVALID_TYPE | Invalid type |
int iotcon_attributes_get_str | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
char ** | val | ||
) |
Gets the string value from the given key.
[in] | attributes | The attributes handle |
[in] | key | The key |
[out] | val | The string value |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |
IOTCON_ERROR_INVALID_TYPE | Invalid type |
int iotcon_attributes_get_type | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
iotcon_type_e * | type | ||
) |
Gets the type of a value at the given key.
It gets the data type of value related to the key in attributes. The data type could be one of iotcon_type_e.
[in] | attributes | The attributes handle |
[in] | key | The key |
[out] | type | The data type of value related to the key in attributes handle |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |
int iotcon_attributes_is_null | ( | iotcon_attributes_h | attributes, |
const char * | key, | ||
bool * | is_null | ||
) |
Checks whether the value of given key is NULL or not.
[in] | attributes | The attributes handle |
[in] | key | The key |
[out] | is_null | true if the type of the given key is null, otherwise false |
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_attributes_remove | ( | iotcon_attributes_h | attributes, |
const char * | key | ||
) |
Removes the key and its associated value from the attributes.
[in] | attributes | The attributes handle |
[in] | key | The key |
0
on success, otherwise a negative error value IOTCON_ERROR_NONE | Successful |
IOTCON_ERROR_NOT_SUPPORTED | Not supported |
IOTCON_ERROR_INVALID_PARAMETER | Invalid parameter |
IOTCON_ERROR_NO_DATA | No data available |