Tizen Native API
|
IoTCon Resource Interfaces provides API to manage resource interfaces.
#include <iotcon.h>
The IoTCon Resource Interfaces API provides methods for managing handle and add, remove resource interfaces. A resource interface indicates a class or category of resources. Example :
#include <iotcon.h> static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data) { // handle request ... } static void _create_light_resource() { int ret; iotcon_resource_h resource = NULL; iotcon_resource_interfaces_h resource_ifaces = NULL; iotcon_resource_types_h resource_types = NULL; ret = iotcon_resource_types_create(&resource_types); if (IOTCON_ERROR_NONE != ret) return; ret = iotcon_resource_types_add(resource_types, "org.tizen.light"); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_types_destroy(resource_types); return; } ret = iotcon_resource_interfaces_create(&resource_ifaces); if (IOTCON_ERROR_NONE != ret) iotcon_resource_types_destroy(resource_types); return; ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_interfaces_destroy(resource_ifaces); iotcon_resource_types_destroy(resource_types); return; } ret = iotcon_resource_create("/light/1", resource_types, resource_ifaces, IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, _request_handler, NULL, &resource); if (IOTCON_ERROR_NONE != ret) { iotcon_resource_interfaces_destroy(resource_ifaces); iotcon_resource_types_destroy(resource_types); return; } iotcon_resource_interfaces_destroy(resource_ifaces); iotcon_resource_types_destroy(resource_types); }
This API is related with the following features:
Functions | |
int | iotcon_resource_interfaces_create (iotcon_resource_interfaces_h *ifaces) |
Creates a new resource interfaces handle. | |
int | iotcon_resource_interfaces_destroy (iotcon_resource_interfaces_h ifaces) |
Destroys a resource ifaces handle. | |
int | iotcon_resource_interfaces_add (iotcon_resource_interfaces_h ifaces, const char *iface) |
Inserts a resource iface into the list. | |
int | iotcon_resource_interfaces_remove (iotcon_resource_interfaces_h ifaces, const char *iface) |
Deletes a resource iface from the list. | |
int | iotcon_resource_interfaces_foreach (iotcon_resource_interfaces_h ifaces, iotcon_resource_interfaces_foreach_cb cb, void *user_data) |
Gets all of the resource ifaces of the list by invoking the callback function. | |
int | iotcon_resource_interfaces_clone (iotcon_resource_interfaces_h src, iotcon_resource_interfaces_h *dest) |
Clones the resource ifaces handle. | |
Typedefs | |
typedef bool(* | iotcon_resource_interfaces_foreach_cb )(const char *iface, void *user_data) |
Specifies the iface of function passed to iotcon_resource_interfaces_foreach(). |
typedef bool(* iotcon_resource_interfaces_foreach_cb)(const char *iface, void *user_data) |
Specifies the iface of function passed to iotcon_resource_interfaces_foreach().
[in] | iface | The value of the resource ifaces |
[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_resource_interfaces_add | ( | iotcon_resource_interfaces_h | ifaces, |
const char * | iface | ||
) |
Inserts a resource iface into the list.
[in] | ifaces | The handle of the resource ifaces |
[in] | iface | The string data to insert into the resource ifaces |
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_ALREADY | Already done |
int iotcon_resource_interfaces_clone | ( | iotcon_resource_interfaces_h | src, |
iotcon_resource_interfaces_h * | dest | ||
) |
Clones the resource ifaces handle.
Makes a deep copy of a source list of resource ifaces.
[in] | src | The origin handle of the resource ifaces |
[out] | dest | Clone of a source list of resource ifaces |
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_resource_interfaces_create | ( | iotcon_resource_interfaces_h * | ifaces | ) |
Creates a new resource interfaces handle.
[out] | ifaces | A newly allocated list of resource ifaces 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 |
Destroys a resource ifaces handle.
[in] | ifaces | The handle of the resource ifaces |
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_resource_interfaces_foreach | ( | iotcon_resource_interfaces_h | ifaces, |
iotcon_resource_interfaces_foreach_cb | cb, | ||
void * | user_data | ||
) |
Gets all of the resource ifaces of the list by invoking the callback function.
iotcon_resource_interfaces_foreach_cb() will be called for each iface.
If iotcon_resource_interfaces_foreach_cb() returns false, iteration will be stopped.
[in] | ifaces | The handle of resource ifaces |
[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_resource_interfaces_remove | ( | iotcon_resource_interfaces_h | ifaces, |
const char * | iface | ||
) |
Deletes a resource iface from the list.
[in] | ifaces | The handle of the resource ifaces |
[in] | iface | The string data to delete from the resource ifaces |
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 |