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.
Function Documentation