Tizen Native API
3.0
|
IoTCon Representation provides API to manage representation.
Required Header
#include <iotcon.h>
Overview
The IoTCon Representation API provides data type of resp_repr handling.
A resp_repr is a payload of a request or a response.
It has uri_path, list of resource interfaces, list of resource types and its attributes.
Attributes have capabilities to store and retrieve integer, boolean, double, string, byte string, list, null, resp_repr.
A list is a container that includes number of data of same type.
It has capabilities to store and retrieve integer, boolean, double, string, byte string, list, null, resp_repr. Example :
#include <iotcon.h> ... { int ret; iotcon_representation_h repr; iotcon_resource_types_h types; iotcon_list_h bright_step_list; ret = iotcon_representation_create(&resp_repr); if (IOTCON_ERROR_NONE != ret) { return; } ret = iotcon_representation_set_uri_path(resp_repr, "/a/light"); if (IOTCON_ERROR_NONE != ret) { iotcon_representation_destroy(resp_repr); return; } ret = iotcon_resource_types_create(&types); if (IOTCON_ERROR_NONE != ret) { iotcon_representation_destroy(resp_repr); return; } ret = iotcon_resource_types_add(types, "core.light"); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_representation_set_resource_types(resp_repr, types); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_representation_set_resource_interfaces(resp_repr, IOTCON_INTERFACE_LINK); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_attributes_add_str(resp_repr, "type", "lamp"); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_attributes_add_str(resp_repr, "where", "desk"); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_attributes_add_double(resp_repr, "default_bright", 200.0); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_attributes_add_str(resp_repr, "unit", "lux"); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_attributes_add_bool(resp_repr, "bright_step", true); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_list_create(IOTCON_TYPE_DOUBLE, &bright_step_list); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_list_add_double(bright_step_list, 100.0, -1); if (IOTCON_ERROR_NONE != ret) { iotcon_list_destroy(bright_step_list); iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_list_add_double(bright_step_list, 200.0, -1); if (IOTCON_ERROR_NONE != ret) { iotcon_list_destroy(bright_step_list); iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_list_add_double(bright_step_list, 300.0, -1); if (IOTCON_ERROR_NONE != ret) { iotcon_list_destroy(bright_step_list); iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_list_add_double(bright_step_list, 400.0, -1); if (IOTCON_ERROR_NONE != ret) { iotcon_list_destroy(bright_step_list); iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_list_add_double(bright_step_list, 500.0, -1); if (IOTCON_ERROR_NONE != ret) { iotcon_list_destroy(bright_step_list); iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } ret = iotcon_attributes_add_list(resp_repr, "bright_step_list", bright_step_list); if (IOTCON_ERROR_NONE != ret) { iotcon_list_destroy(bright_step_list); iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); return; } iotcon_list_destroy(bright_step_list); iotcon_resource_types_destroy(types); iotcon_representation_destroy(resp_repr); }
Related Features
This API is related with the following features:
- http://tizen.org/feature/iot.ocf
It is recommended to design feature related codes in your application for reliability.
You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.
To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature Element.
Functions | |
int | iotcon_representation_create (iotcon_representation_h *repr) |
Creates a new Representation handle. | |
int | iotcon_representation_destroy (iotcon_representation_h repr) |
Destroys a Representation. | |
int | iotcon_representation_clone (const iotcon_representation_h src, iotcon_representation_h *dest) |
Clones from the source Representation. | |
int | iotcon_representation_set_uri_path (iotcon_representation_h repr, const char *uri_path) |
Appends resource type name. | |
int | iotcon_representation_get_uri_path (iotcon_representation_h repr, char **uri_path) |
Gets a URI path from the Representation. | |
int | iotcon_representation_set_resource_types (iotcon_representation_h repr, iotcon_resource_types_h types) |
Sets resource type list to the Representation. | |
int | iotcon_representation_get_resource_types (iotcon_representation_h repr, iotcon_resource_types_h *types) |
Gets list of resource type from the Representation. | |
int | iotcon_representation_set_resource_interfaces (iotcon_representation_h repr, iotcon_resource_interfaces_h ifaces) |
Sets list of resource interfaces to the Representation. | |
int | iotcon_representation_get_resource_interfaces (iotcon_representation_h repr, iotcon_resource_interfaces_h *ifaces) |
Gets list of resource interfaces from the Representation. | |
int | iotcon_representation_set_attributes (iotcon_representation_h repr, iotcon_attributes_h attributes) |
Sets a new attributes handle into the Representation. | |
int | iotcon_representation_get_attributes (iotcon_representation_h repr, iotcon_attributes_h *attributes) |
Gets the attributes handle in the Representation. | |
int | iotcon_representation_add_child (iotcon_representation_h parent, iotcon_representation_h child) |
Adds a new child Representation on to the end of the parent Representation. | |
int | iotcon_representation_remove_child (iotcon_representation_h parent, iotcon_representation_h child) |
Removes a child Representation from parent Representation without freeing. | |
int | iotcon_representation_foreach_children (iotcon_representation_h parent, iotcon_children_cb cb, void *user_data) |
Calls a function for each child Representation of parent. | |
int | iotcon_representation_get_child_count (iotcon_representation_h parent, unsigned int *count) |
Gets the number of child Representations in the parent Representation. | |
int | iotcon_representation_get_nth_child (iotcon_representation_h parent, int pos, iotcon_representation_h *child) |
Gets the child Representation at the given position. | |
Typedefs | |
typedef bool(* | iotcon_children_cb )(iotcon_representation_h child, void *user_data) |
Specifies the type of function passed to iotcon_representation_foreach_children(). |
Typedef Documentation
typedef bool(* iotcon_children_cb)(iotcon_representation_h child, void *user_data) |
Specifies the type of function passed to iotcon_representation_foreach_children().
- Since :
- 3.0
- Parameters:
-
[in] child The child Representation handle [in] user_data The user data to pass to the function
- Returns:
true
to continue with the next iteration of the loop, otherwisefalse
to break out of the loop IOTCON_FUNC_CONTINUE and IOTCON_FUNC_STOP are more friendly values for the return
- Precondition:
- iotcon_representation_foreach_children() will invoke this callback function.
Function Documentation
int iotcon_representation_add_child | ( | iotcon_representation_h | parent, |
iotcon_representation_h | child | ||
) |
Adds a new child Representation on to the end of the parent Representation.
Duplicated child Representation is allowed to append.
- Since :
- 3.0
- Parameters:
-
[in] parent The parent Representation handle [in] child The child Representation handle
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
int iotcon_representation_clone | ( | const iotcon_representation_h | src, |
iotcon_representation_h * | dest | ||
) |
Clones from the source Representation.
Makes a deep copy of a source Representation.
- Since :
- 3.0
- Remarks:
- You must destroy dest by calling iotcon_representation_destroy() if dest is no longer needed.
- Parameters:
-
[in] src Source of Representation to be copied [out] dest Clone of a source Representation
- Returns:
- Clone of a source Representation, otherwise NULL on failure
- Return values:
-
iotcon_representation_h Success NULL Failure
int iotcon_representation_create | ( | iotcon_representation_h * | repr | ) |
Creates a new Representation handle.
- Since :
- 3.0
- Remarks:
- You must destroy repr by calling iotcon_representation_destroy() if repr is no longer needed.
- Parameters:
-
[out] repr A newly allocated Representation handle
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_OUT_OF_MEMORY Out of memory IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- See also:
- iotcon_representation_destroy()
int iotcon_representation_destroy | ( | iotcon_representation_h | repr | ) |
Destroys a Representation.
Releases Representation and its internal data.
- Since :
- 3.0
- Parameters:
-
[in] repr The representation handle to free
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- See also:
- iotcon_representation_create()
int iotcon_representation_foreach_children | ( | iotcon_representation_h | parent, |
iotcon_children_cb | cb, | ||
void * | user_data | ||
) |
Calls a function for each child Representation of parent.
iotcon_children_cb() will be called for each child.
- Since :
- 3.0
- Parameters:
-
[in] parent The parent Representation handle [in] cb The callback function to invoke [in] user_data The user data to pass to the function
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- Postcondition:
- iotcon_children_cb() will be called for each child.
- See also:
- iotcon_children_cb()
int iotcon_representation_get_attributes | ( | iotcon_representation_h | repr, |
iotcon_attributes_h * | attributes | ||
) |
Gets the attributes handle in the Representation.
- Since :
- 3.0
- Remarks:
- attributes must not be released using iotcon_attributes_destroy().
- Parameters:
-
[in] repr The Representation handle [in] attributes The attributes handle to get
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
int iotcon_representation_get_child_count | ( | iotcon_representation_h | parent, |
unsigned int * | count | ||
) |
Gets the number of child Representations in the parent Representation.
- Since :
- 3.0
- Parameters:
-
[in] parent The parent Representation handle [out] count The number of child Representations
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
int iotcon_representation_get_nth_child | ( | iotcon_representation_h | parent, |
int | pos, | ||
iotcon_representation_h * | child | ||
) |
Gets the child Representation at the given position.
Iterates over the parent until it reaches the pos-1 position.
- Since :
- 3.0
- Remarks:
- child must not be released using iotcon_representation_destroy().
- Parameters:
-
[in] parent The parent Representation handle [in] pos The position of the child Representation [out] child The handle to the child Representation
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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_representation_get_resource_interfaces | ( | iotcon_representation_h | repr, |
iotcon_resource_interfaces_h * | ifaces | ||
) |
Gets list of resource interfaces from the Representation.
- Since :
- 3.0
- Remarks:
- ifaces must not be released using iotcon_resource_interfaces_destroy().
- Parameters:
-
[in] repr The Representation handle [out] ifaces The list of resource interfaces to get
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
int iotcon_representation_get_resource_types | ( | iotcon_representation_h | repr, |
iotcon_resource_types_h * | types | ||
) |
Gets list of resource type from the Representation.
- Since :
- 3.0
- Remarks:
- types must not be released using iotcon_resource_types_destroy().
- Parameters:
-
[in] repr The Representation handle [out] types The list of resource types to get
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
int iotcon_representation_get_uri_path | ( | iotcon_representation_h | repr, |
char ** | uri_path | ||
) |
Gets a URI path from the Representation.
- Since :
- 3.0
- Remarks:
- uri_path must not be released using free().
- Parameters:
-
[in] repr The Representation handle [out] uri_path The URI path to get
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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_representation_remove_child | ( | iotcon_representation_h | parent, |
iotcon_representation_h | child | ||
) |
Removes a child Representation from parent Representation without freeing.
- Since :
- 3.0
- Parameters:
-
[in] parent The parent Representation handle [in] child The child Representation handle
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
int iotcon_representation_set_attributes | ( | iotcon_representation_h | repr, |
iotcon_attributes_h | attributes | ||
) |
Sets a new attributes handle into the Representation.
- Since :
- 3.0
- Parameters:
-
[in] repr The Representation handle [in] attributes The attributes handle to be set newly
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
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_representation_set_resource_interfaces | ( | iotcon_representation_h | repr, |
iotcon_resource_interfaces_h | ifaces | ||
) |
Sets list of resource interfaces to the Representation.
- Since :
- 3.0
- Remarks:
- Stored list is replaced with ifaces. If ifaces is NULL, stored list is set to NULL.
- Parameters:
-
[in] repr The Representation handle [in] ifaces The list of resource interfaces
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
int iotcon_representation_set_resource_types | ( | iotcon_representation_h | repr, |
iotcon_resource_types_h | types | ||
) |
Sets resource type list to the Representation.
- Since :
- 3.0
- Remarks:
- Stored list is replaced with types. If types is NULL, stored list is set to NULL.
- Parameters:
-
[in] repr The handle to the Representation [in] types The resource type list
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
int iotcon_representation_set_uri_path | ( | iotcon_representation_h | repr, |
const char * | uri_path | ||
) |
Appends resource type name.
- Since :
- 3.0
- Remarks:
- Stored string is replaced with uri_path. If uri_path is NULL, stored string is set to NULL.
- Parameters:
-
[in] repr The handle to the Representation [in] uri_path The URI of resource
- Returns:
0
on success, otherwise a negative error value
- Return values:
-
IOTCON_ERROR_NONE Successful IOTCON_ERROR_NOT_SUPPORTED Not supported IOTCON_ERROR_OUT_OF_MEMORY Out of memory IOTCON_ERROR_INVALID_PARAMETER Invalid parameter