Tizen Native API  5.5
Resource Types

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:

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]typeThe value of the resource types
[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_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]typesThe handle of the resource types
[in]typeThe 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_NONESuccessful
IOTCON_ERROR_NOT_SUPPORTEDNot supported
IOTCON_ERROR_INVALID_PARAMETERInvalid parameter
IOTCON_ERROR_ALREADYAlready done
See also:
iotcon_resource_types_create()
iotcon_resource_types_destroy()
iotcon_resource_types_remove()
iotcon_resource_types_clone()

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]srcThe origin handle of the resource types
[out]destClone of a source list of resource types
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_types_create()
iotcon_resource_types_destroy()
iotcon_resource_types_add()
iotcon_resource_types_remove()

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]typesA newly allocated list of resource types 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_types_destroy()
iotcon_resource_types_add()
iotcon_resource_types_remove()
iotcon_resource_types_clone()

Destroys a resource types handle.

Since :
3.0
Parameters:
[in]typesThe handle of the resource types
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_types_create()
iotcon_resource_types_add()
iotcon_resource_types_remove()
iotcon_resource_types_clone()

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]typesThe handle of resource types
[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_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]typesThe handle of the resource types
[in]typeThe string data to delete from the resource types
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_types_create()
iotcon_resource_types_destroy()
iotcon_resource_types_add()
iotcon_resource_types_clone()