Tizen Native API
3.0
|
IoTCon Resource Types provides API to manage resource types.
Required Header
#include <iotcon.h>
Overview
The IoTCon Resource Types API provides methods for managing handle and add, remove resource types. A resource type 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); }
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_resource_types_create (iotcon_resource_types_h *types) |
Creates a new resource types handle. | |
int | iotcon_resource_types_destroy (iotcon_resource_types_h types) |
Destroys a resource types handle. | |
int | iotcon_resource_types_add (iotcon_resource_types_h types, const char *type) |
Inserts a resource types into the list. | |
int | iotcon_resource_types_remove (iotcon_resource_types_h types, const char *type) |
Deletes a resource types from the list. | |
int | iotcon_resource_types_foreach (iotcon_resource_types_h types, iotcon_resource_types_foreach_cb cb, void *user_data) |
Gets all of the resource types of the list by invoking the callback function. | |
int | iotcon_resource_types_clone (iotcon_resource_types_h src, iotcon_resource_types_h *dest) |
Clones the resource types handle. | |
Typedefs | |
typedef bool(* | iotcon_resource_types_foreach_cb )(const char *type, void *user_data) |
Specifies the type of function passed to iotcon_resource_types_foreach(). |
Typedef Documentation
typedef bool(* iotcon_resource_types_foreach_cb)(const char *type, void *user_data) |
Specifies the type of function passed to iotcon_resource_types_foreach().
- Since :
- 3.0
- Parameters:
-
[in] type The value of the resource types [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_resource_types_foreach() will invoke this callback function.
- See also:
- iotcon_resource_types_foreach()
Function Documentation
int iotcon_resource_types_add | ( | iotcon_resource_types_h | types, |
const char * | type | ||
) |
Inserts a resource types into the list.
- Since :
- 3.0
- Remarks:
- The length of type should be less than or equal to 61.
The type must start with a lowercase alphabetic character, followed by a sequence of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.
Duplicate strings are not allowed.
- Parameters:
-
[in] types The handle of the resource types [in] type The string data to insert into the resource types (e.g. "org.tizen.light")
- 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_ALREADY Already done
int iotcon_resource_types_clone | ( | iotcon_resource_types_h | src, |
iotcon_resource_types_h * | dest | ||
) |
Clones the resource types handle.
Makes a deep copy of a source list of resource types.
- Since :
- 3.0
- Remarks:
- You must destroy dest by calling iotcon_resource_types_destroy() if dest is no longer needed.
- Parameters:
-
[in] src The origin handle of the resource types [out] dest Clone of a source list of resource types
- 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_resource_types_create | ( | iotcon_resource_types_h * | types | ) |
Creates a new resource types handle.
- Since :
- 3.0
- Remarks:
- You must destroy types by calling iotcon_resource_types_destroy() if types is no longer needed.
- Parameters:
-
[out] types A newly allocated list of resource types 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
int iotcon_resource_types_destroy | ( | iotcon_resource_types_h | types | ) |
Destroys a resource types handle.
- Since :
- 3.0
- Parameters:
-
[in] types The handle of the resource types
- 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_resource_types_foreach | ( | iotcon_resource_types_h | types, |
iotcon_resource_types_foreach_cb | cb, | ||
void * | user_data | ||
) |
Gets all of the resource types of the list by invoking the callback function.
iotcon_resource_types_foreach_cb() will be called for each type.
If iotcon_resource_types_foreach_cb() returns false, iteration will be stopped.
- Since :
- 3.0
- Parameters:
-
[in] types The handle of resource types [in] cb The callback function to get data [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_resource_types_foreach() will be called for each type.
- See also:
- iotcon_resource_types_foreach_cb()
int iotcon_resource_types_remove | ( | iotcon_resource_types_h | types, |
const char * | type | ||
) |
Deletes a resource types from the list.
- Since :
- 3.0
- Parameters:
-
[in] types The handle of the resource types [in] type The string data to delete from the resource types
- 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