Tizen Native API  6.5
Request

IoTCon Request provides API to manage client's request.

Required Header

#include <iotcon.h>

Overview

The IoTCon Request API provides methods for managing request handle. Example :

#include <iotcon.h>
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
        void *user_data)
{
    int ret, observe_id;
    iotcon_request_type_e type;
    iotcon_observe_type_e observe_type;
    iotcon_options_h options = NULL;
    iotcon_query_h query = NULL;
    iotcon_representation_h repr = NULL;

    ret = iotcon_request_get_options(request, &options);
    if (IOTCON_ERROR_NONE == ret && options) {
        // handle options
        ...
    }

    ret = iotcon_request_get_query(request, &query);
    if (IOTCON_ERROR_NONE == ret && query) {
        // handle query
        ...
    }

    ret = iotcon_request_get_request_type(request, &type);
    if (IOTCON_ERROR_NONE != ret)
        return;

    if (IOTCON_REQUEST_GET == type) {
        // handle get
        ...
    }
    if (IOTCON_REQUEST_PUT == type) {
        // handle put
        ret = iotcon_request_get_representation(request, &repr);
        if (IOTCON_ERROR_NONE != ret)
            return;
        ...
    }
    if (IOTCON_REQUEST_POST == type) {
        // handle post
        ret = iotcon_request_get_representation(request, &repr);
        if (IOTCON_ERROR_NONE != ret)
            return;
        ...
    }
    if (IOTCON_REQUEST_DELETE == type) {
        // handle delete
        ret = iotcon_request_get_representation(request, &repr);
        if (IOTCON_ERROR_NONE != ret)
            return;
        ...
    }

    ret = iotcon_request_get_observe_type(request, &observe_type);
    if (IOTCON_ERROR_NONE != ret)
        return;

    if (IOTCON_OBSERVE_REGISTER == observe_type) {
        ret = iotcon_request_get_observe_id(request, &observe_id);
        if (IOTCON_ERROR_NONE != ret)
            return;
        // handle register observe
        ...
    } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
        ret = iotcon_request_get_observe_id(request, &observe_id);
        if (IOTCON_ERROR_NONE != ret)
            return;
        // handle deregister observe
        ...
    }
    ...
}

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_request_get_host_address (iotcon_request_h request, char **host_address)
 Gets host address of the request.
int iotcon_request_get_connectivity_type (iotcon_request_h request, iotcon_connectivity_type_e *connectivity_type)
 Gets connectivity type of the request.
int iotcon_request_get_representation (iotcon_request_h request, iotcon_representation_h *repr)
 Gets a representation of the request.
int iotcon_request_get_request_type (iotcon_request_h request, iotcon_request_type_e *type)
 Gets type of the request.
int iotcon_request_get_options (iotcon_request_h request, iotcon_options_h *options)
 Gets options of the request.
int iotcon_request_get_query (iotcon_request_h request, iotcon_query_h *query)
 Gets query of the request.
int iotcon_request_get_observe_type (iotcon_request_h request, iotcon_observe_type_e *observe_type)
 Gets observation action of the request.
int iotcon_request_get_observe_id (iotcon_request_h request, int *observe_id)
 Gets observation ID of the request.

Function Documentation

Gets connectivity type of the request.

Since :
3.0
Parameters:
[in]requestThe handle of the request
[out]connectivity_typeThe connectivity type of the request
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_request_get_host_address()
iotcon_request_get_representation()
iotcon_request_get_request_type()
iotcon_request_get_options()
iotcon_request_get_query()
iotcon_request_get_observe_type()
iotcon_request_get_observe_id()
int iotcon_request_get_host_address ( iotcon_request_h  request,
char **  host_address 
)

Gets host address of the request.

Since :
3.0
Remarks:
host_address must not be released using free().
Parameters:
[in]requestThe handle of the request
[out]host_addressThe host address of the request
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_request_get_connectivity_type()
iotcon_request_get_representation()
iotcon_request_get_request_type()
iotcon_request_get_options()
iotcon_request_get_query()
iotcon_request_get_observe_type()
iotcon_request_get_observe_id()
int iotcon_request_get_observe_id ( iotcon_request_h  request,
int *  observe_id 
)

Gets observation ID of the request.

Since :
3.0
Parameters:
[in]requestThe handle of the request
[out]observe_idThe ID of the observer
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_request_get_host_address()
iotcon_request_get_connectivity_type()
iotcon_request_get_representation()
iotcon_request_get_request_type()
iotcon_request_get_options()
iotcon_request_get_query()
iotcon_request_get_observe_type()

Gets observation action of the request.

The observe_type could be one of iotcon_observe_type_e.

Since :
3.0
Parameters:
[in]requestThe handle of the request
[out]observe_typeThe observation type of the request
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_request_get_host_address()
iotcon_request_get_connectivity_type()
iotcon_request_get_representation()
iotcon_request_get_request_type()
iotcon_request_get_options()
iotcon_request_get_query()
iotcon_request_get_observe_id()

Gets options of the request.

Since :
3.0
Remarks:
options must not be released using iotcon_options_destroy().
Parameters:
[in]requestThe handle of the request
[out]optionsThe options of the request
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_request_get_host_address()
iotcon_request_get_connectivity_type()
iotcon_request_get_representation()
iotcon_request_get_request_type()
iotcon_request_get_query()
iotcon_request_get_observe_type()
iotcon_request_get_observe_id()

Gets query of the request.

Since :
3.0
Remarks:
query must not be released using iotcon_query_destroy().
Parameters:
[in]requestThe handle of the request
[out]queryThe query of the request
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_request_get_host_address()
iotcon_request_get_connectivity_type()
iotcon_request_get_representation()
iotcon_request_get_request_type()
iotcon_request_get_options()
iotcon_request_get_observe_type()
iotcon_request_get_observe_id()

Gets a representation of the request.

Since :
3.0
Remarks:
repr must not be released using iotcon_representation_destroy().
Parameters:
[in]requestThe handle of the request
[out]reprThe representation of the request
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_request_get_host_address()
iotcon_request_get_connectivity_type()
iotcon_request_get_request_type()
iotcon_request_get_options()
iotcon_request_get_query()
iotcon_request_get_observe_type()
iotcon_request_get_observe_id()

Gets type of the request.

type could be one of the iotcon_request_type_e.

Since :
3.0
Parameters:
[in]requestThe handle of the request
[out]typeThe types of the request
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_request_get_host_address()
iotcon_request_get_connectivity_type()
iotcon_request_get_representation()
iotcon_request_get_options()
iotcon_request_get_query()
iotcon_request_get_observe_type()
iotcon_request_get_observe_id()