Tizen Native API  7.0
Observers

IoTCon Observers provides API to manage client observing a resource.

Required Header

#include <iotcon.h>

Overview

The IoTcon overview API provides methods for managing observe ID. Example :

#include <iotcon.h>
static iotcon_observers_h _observers;
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_representation_h repr = NULL;

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

    if (IOTCON_REQUEST_PUT == type) {
        iotcon_attributes_h attributes = NULL;
        iotcon_representation_h repr = NULL;
        ...

        ret = iotcon_representation_create(&repr);
        if (IOTCON_ERROR_NONE != ret)
            return;

        ret = iotcon_attributes_create(&attributes);
        if (IOTCON_ERROR_NONE != ret) {
            iotcon_representation_destroy(repr);
            return;
        }
        ...
        ret = iotcon_resource_notify(resource, repr, _observers, IOTCON_QOS_HIGH);
        if (IOTCON_ERROR_NONE != ret) {
            iotcon_attributes_destroy(attributes);
            iotcon_representation_destroy(repr);
            return;
        }

        iotcon_attributes_destroy(attributes);
        iotcon_representation_destroy(repr);
    }

    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;

        if (NULL == _observers) {
            ret = iotcon_observers_create(&_observers);
            if (IOTCON_ERROR_NONE != ret)
                return;
        }
        ret = iotcon_observers_add(_observers, observe_id);
        if (IOTCON_ERROR_NONE != ret)
            return;
        ...
    } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
        ret = iotcon_request_get_observe_id(request, &observe_id);
        if (IOTCON_ERROR_NONE != ret)
            return;

        if (NULL == _observers)
            return;

        ret = iotcon_observers_remove(_observers, observe_id);
        if (IOTCON_ERROR_NONE != ret)
            return;
        ...
    }
    ...
}

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_observers_create (iotcon_observers_h *observers)
 Creates a new observers handle.
int iotcon_observers_destroy (iotcon_observers_h observers)
 Destroys a observers handle.
int iotcon_observers_add (iotcon_observers_h observers, int obs_id)
 Adds an observers ID into the observers handle.
int iotcon_observers_remove (iotcon_observers_h observers, int obs_id)
 Removes ID from the observers.

Function Documentation

int iotcon_observers_add ( iotcon_observers_h  observers,
int  obs_id 
)

Adds an observers ID into the observers handle.

Since :
3.0
Parameters:
[in]observersThe handle of the observers
[in]obs_idThe ID to be appended to observers
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_observers_create()
iotcon_observers_destroy()
iotcon_observers_remove()

Creates a new observers handle.

Since :
3.0
Remarks:
You must destroy observers by calling iotcon_observers_destroy() if observers is no longer needed.
Parameters:
[out]observersA newly allocated list of observers handle
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_OUT_OF_MEMORYOut of memory
See also:
iotcon_observers_destroy()
iotcon_observers_add()
iotcon_observers_remove()

Destroys a observers handle.

Since :
3.0
Parameters:
[in]observersThe handle of the observers
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_observers_create()
iotcon_observers_add()
iotcon_observers_remove()
int iotcon_observers_remove ( iotcon_observers_h  observers,
int  obs_id 
)

Removes ID from the observers.

Since :
3.0
Parameters:
[in]observersobservers The handle of the observers
[in]obs_idThe ID to be removed from observers
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_observers_create()
iotcon_observers_destroy()
iotcon_observers_add()