Tizen Native API  9.0
Resource Interfaces

IoTCon Resource Interfaces provides API to manage resource interfaces.

Required Header

#include <iotcon.h>

Overview

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);
}

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_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 Documentation

typedef bool(* iotcon_resource_interfaces_foreach_cb)(const char *iface, void *user_data)

Specifies the iface of function passed to iotcon_resource_interfaces_foreach().

Since :
3.0
Remarks:
iface could be a value such as IOTCON_INTERFACE_DEFAULT.
Parameters:
[in]ifaceThe value of the resource ifaces
[in]user_dataThe user data to pass to the function
Returns:
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
Precondition:
iotcon_resource_interfaces_foreach() will invoke this callback function.
See also:
iotcon_resource_interfaces_foreach()

Function Documentation

int iotcon_resource_interfaces_add ( iotcon_resource_interfaces_h  ifaces,
const char *  iface 
)

Inserts a resource iface into the list.

Since :
3.0
Remarks:
iface could be a value such as IOTCON_INTERFACE_DEFAULT.
Parameters:
[in]ifacesThe handle of the resource ifaces
[in]ifaceThe string data to insert into the resource ifaces
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
IOTCON_ERROR_ALREADYAlready done
See also:
iotcon_resource_interfaces_create()
iotcon_resource_interfaces_destroy()
iotcon_resource_interfaces_remove()
iotcon_resource_interfaces_clone()

Clones the resource ifaces handle.

Makes a deep copy of a source list of resource ifaces.

Since :
3.0
Remarks:
You must destroy dest by calling iotcon_resource_interfaces_destroy() if dest is no longer needed.
Parameters:
[in]srcThe origin handle of the resource ifaces
[out]destClone of a source list of resource ifaces
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_resource_interfaces_create()
iotcon_resource_interfaces_destroy()
iotcon_resource_interfaces_add()
iotcon_resource_interfaces_remove()

Creates a new resource interfaces handle.

Since :
3.0
Remarks:
You must destroy ifaces by calling iotcon_resource_interfaces_destroy() if ifaces is no longer needed.
Parameters:
[out]ifacesA newly allocated list of resource ifaces handle
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_OUT_OF_MEMORYOut of memory
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_resource_interfaces_destroy()
iotcon_resource_interfaces_add()
iotcon_resource_interfaces_remove()
iotcon_resource_interfaces_clone()

Destroys a resource ifaces handle.

Since :
3.0
Parameters:
[in]ifacesThe handle of the resource ifaces
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
See also:
iotcon_resource_interfaces_create()
iotcon_resource_interfaces_add()
iotcon_resource_interfaces_remove()
iotcon_resource_interfaces_clone()

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.

Since :
3.0
Parameters:
[in]ifacesThe handle of resource ifaces
[in]cbThe callback function to get data
[in]user_dataThe user data to pass to the function
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
Postcondition:
iotcon_resource_interfaces_foreach() will be called for each iface.
See also:
iotcon_resource_interfaces_foreach_cb()
int iotcon_resource_interfaces_remove ( iotcon_resource_interfaces_h  ifaces,
const char *  iface 
)

Deletes a resource iface from the list.

Since :
3.0
Remarks:
iface could be a value such as IOTCON_INTERFACE_DEFAULT.
Parameters:
[in]ifacesThe handle of the resource ifaces
[in]ifaceThe string data to delete from the resource ifaces
Returns:
0 on success, otherwise a negative error value
Return values:
IOTCON_ERROR_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
IOTCON_ERROR_NO_DATANo data available
See also:
iotcon_resource_interfaces_create()
iotcon_resource_interfaces_destroy()
iotcon_resource_interfaces_add()
iotcon_resource_interfaces_clone()