static gboolean _dbus_handle_observer_start(icDbus *object,
GDBusMethodInvocation *invocation,
GVariant *resource,
- gint observe_type,
+ gint observe_policy,
GVariant *query,
guint signal_number)
{
const gchar *sender;
sender = g_dbus_method_invocation_get_sender(invocation);
- observe_h = icd_ioty_observer_start(resource, observe_type, query,
+ observe_h = icd_ioty_observer_start(resource, observe_policy, query,
signal_number, sender);
if (NULL == observe_h)
ERR("icd_ioty_observer_start() Fail");
struct icd_req_context {
unsigned int signal_number;
char *bus_name;
- int types;
+ int request_type;
int observe_id;
- int observe_action;
+ int observe_type;
OCRequestHandle request_h;
OCResourceHandle resource_h;
GVariant *payload;
case OC_OBSERVE_NO_OPTION:
default:
ERR("Invalid action (%d)", oic_action);
- action = IOTCON_OBSERVE_NO_OPTION;
+ action = IOTCON_OBSERVE_TYPE_NONE;
}
return action;
}
{
GVariant *value;
char *host_address;
- int ret, conn_type, action;
+ int ret, conn_type;
GVariantBuilder payload_builder;
struct icd_req_context *ctx = context;
return ret;
}
- action = _ioty_oic_action_to_ioty_action(ctx->observe_action);
-
value = g_variant_new("(siia(qs)a(ss)iiavxx)",
host_address,
conn_type,
- ctx->types,
+ ctx->request_type,
ctx->options,
ctx->query,
- action,
+ ctx->observe_type,
ctx->observe_id,
&payload_builder,
ICD_POINTER_TO_INT64(ctx->request_h),
if (OC_REQUEST_FLAG & flag) {
switch (request->method) {
case OC_REST_GET:
- req_ctx->types = IOTCON_REQUEST_GET;
+ req_ctx->request_type = IOTCON_REQUEST_GET;
req_ctx->payload = NULL;
-
- if (OC_OBSERVE_FLAG & flag) {
- req_ctx->types |= IOTCON_REQUEST_OBSERVE;
- /* observation info*/
- req_ctx->observe_id = request->obsInfo.obsId;
- req_ctx->observe_action = request->obsInfo.action;
- }
break;
case OC_REST_PUT:
- req_ctx->types = IOTCON_REQUEST_PUT;
+ req_ctx->request_type = IOTCON_REQUEST_PUT;
req_ctx->payload = icd_payload_to_gvariant(request->payload);
break;
case OC_REST_POST:
- req_ctx->types = IOTCON_REQUEST_POST;
+ req_ctx->request_type = IOTCON_REQUEST_POST;
req_ctx->payload = icd_payload_to_gvariant(request->payload);
break;
case OC_REST_DELETE:
- req_ctx->types = IOTCON_REQUEST_DELETE;
+ req_ctx->request_type = IOTCON_REQUEST_DELETE;
req_ctx->payload = NULL;
break;
default:
}
}
+ if (OC_OBSERVE_FLAG & flag) {
+ /* observation info*/
+ req_ctx->observe_id = request->obsInfo.obsId;
+ req_ctx->observe_type = _ioty_oic_action_to_ioty_action(request->obsInfo.action);
+ } else {
+ req_ctx->observe_type = IOTCON_OBSERVE_TYPE_NONE;
+ }
+
/* header options */
req_ctx->options = _ocprocess_parse_header_options(
request->rcvdVendorSpecificHeaderOptions,
}
-OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type,
+OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_policy,
GVariant *query, unsigned int signal_number, const char *bus_name)
{
bool is_secure;
return NULL;
}
- if (IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER == observe_type)
+ if (IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER == observe_policy)
method = OC_REST_OBSERVE;
- else if (IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER == observe_type)
+ else if (IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER == observe_policy)
method = OC_REST_OBSERVE_ALL;
else
method = OC_REST_OBSERVE_ALL;
static void _request_handler(iotcon_request_h request, void *user_data)
{
int ret;
- int types;
+ iotcon_request_type_e type;
iotcon_response_h response;
iotcon_representation_h resp_repr;
- ret = iotcon_request_get_types(request, &types);
+ ret = iotcon_request_get_request_type(request, &type);
if (IOTCON_ERROR_NONE != ret)
return;
- if (IOTCON_REQUEST_GET & types) {
+ if (IOTCON_REQUEST_GET == type) {
ret = iotcon_response_create(request, &response);
if (IOTCON_ERROR_NONE != ret)
return;
int ret;
int types;
int observe_id;
- iotcon_observe_action_e observe_action;
+ iotcon_observe_type_e observe_type;
- ret = iotcon_request_get_types(request, &types);
+ ret = iotcon_request_get_observe_type(request, &observe_type);
if (IOTCON_ERROR_NONE != ret) {
return;
}
- if (IOTCON_REQUEST_OBSERVE & types) {
- ret = iotcon_request_get_observe_action(request, &observe_action);
+ if (IOTCON_OBSERVE_REGISTER == observe_type) {
+ ret = iotcon_request_get_observe_id(request, &observe_id);
+ 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 (IOTCON_OBSERVE_REGISTER == observe_action) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- 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_action) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- return;
- }
- ret = iotcon_observers_remove(observers, observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- return;
- }
+ ret = iotcon_observers_remove(observers, observe_id);
+ if (IOTCON_ERROR_NONE != ret) {
+ return;
}
}
}
...
{
int ret;
- ret = iotcon_remote_resource_set_notify_cb(door_resource, IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER, NULL,
+ ret = iotcon_remote_resource_observe_register(door_resource, IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER, NULL,
_on_resopnse_observe, NULL);
if (IOTCON_ERROR_NONE != ret)
return;
gpointer user_data)
{
GVariant *repr_gvar;
- int ret, request_types;
+ int ret, request_type;
iotcon_representation_h repr;
iotcon_state_h recv_state = NULL;
GVariantIter *repr_iter, *state_iter;
g_variant_get(parameters, "(siia(qs)a(ss)iiavxx)",
NULL, /* host address */
NULL, /* connectivity type */
- &request_types,
+ &request_type,
NULL, /* header options */
NULL, /* query */
NULL, /* observe action */
&oic_request_h,
&oic_resource_h);
- switch (request_types) {
+ switch (request_type) {
case IOTCON_REQUEST_GET:
- case (IOTCON_REQUEST_GET | IOTCON_REQUEST_OBSERVE):
break;
case IOTCON_REQUEST_PUT:
if (FALSE == g_variant_iter_loop(repr_iter, "v", &repr_gvar)) {
return;
}
- if (IOTCON_REQUEST_PUT == request_types) {
+ if (IOTCON_REQUEST_PUT == request_type) {
ret = _icl_lite_resource_notify(resource);
if (IOTCON_ERROR_NONE != ret)
WARN("_icl_lite_resource_notify() Fail(%d)", ret);
iotcon_remote_resource_h resource;
} icl_on_response_s;
+typedef struct {
+ iotcon_remote_resource_observe_cb cb;
+ void *user_data;
+ iotcon_remote_resource_h resource;
+} icl_on_observe_s;
+
static GList *icl_crud_cb_list = NULL;
void icl_remote_resource_crud_stop(iotcon_remote_resource_h resource)
}
}
+static iotcon_options_h _icl_parse_options_iter(GVariantIter *iter)
+{
+ int ret;
+ iotcon_options_h options = NULL;
+
+ if (NULL == iter)
+ return NULL;
+
+ if (g_variant_iter_n_children(iter)) {
+ unsigned short option_id;
+ char *option_data;
+
+ ret = iotcon_options_create(&options);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_options_create() Fail(%d)", ret);
+ return NULL;
+ }
+ while (g_variant_iter_loop(iter, "(q&s)", &option_id, &option_data))
+ iotcon_options_add(options, option_id, option_data);
+ }
+ return options;
+}
+
static int _icl_parse_crud_gvariant(iotcon_request_type_e request_type,
GVariant *gvar, iotcon_response_h *response)
{
int res;
- int ret;
- int seq_number = -1;
GVariantIter *options_iter = NULL;
GVariant *repr_gvar = NULL;
iotcon_response_h resp = NULL;
iotcon_options_h options = NULL;
iotcon_representation_h repr = NULL;
- if (IOTCON_REQUEST_OBSERVE == request_type)
- g_variant_get(gvar, "(a(qs)vii)", &options_iter, &repr_gvar, &res, &seq_number);
- else if (IOTCON_REQUEST_DELETE == request_type)
+ if (IOTCON_REQUEST_DELETE == request_type)
g_variant_get(gvar, "(a(qs)i)", &options_iter, &res);
else
g_variant_get(gvar, "(a(qs)vi)", &options_iter, &repr_gvar, &res);
if (options_iter) {
- if (g_variant_iter_n_children(options_iter)) {
- unsigned short option_id;
- char *option_data;
-
- ret = iotcon_options_create(&options);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_options_create() Fail(%d)", ret);
- return ret;
- }
- while (g_variant_iter_loop(options_iter, "(q&s)", &option_id, &option_data))
- iotcon_options_add(options, option_id, option_data);
- }
+ options = _icl_parse_options_iter(options_iter);
g_variant_iter_free(options_iter);
}
resp->result = res;
resp->repr = repr;
resp->header_options = options;
- resp->seq_number = seq_number;
*response = resp;
GVariant *parameters,
gpointer user_data)
{
- int ret;
+ int res;
+ int seq_number = -1;
+ GVariantIter *options_iter = NULL;
+ GVariant *repr_gvar = NULL;
iotcon_response_h response = NULL;
- icl_on_response_s *cb_container = user_data;
+ icl_on_observe_s *cb_container = user_data;
+ iotcon_options_h options = NULL;
+ iotcon_representation_h repr = NULL;
RET_IF(NULL == cb_container);
- ret = _icl_parse_crud_gvariant(IOTCON_REQUEST_OBSERVE, parameters, &response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_parse_crud_gvariant() Fail(%d)", ret);
- if (cb_container->cb) {
- cb_container->cb(cb_container->resource, ret, IOTCON_REQUEST_OBSERVE, NULL,
- cb_container->user_data);
+ g_variant_get(parameters, "(a(qs)vii)", &options_iter, &repr_gvar, &res, &seq_number);
+
+ if (options_iter) {
+ options = _icl_parse_options_iter(options_iter);
+ g_variant_iter_free(options_iter);
+ }
+
+ if (repr_gvar) {
+ repr = icl_representation_from_gvariant(repr_gvar);
+ if (NULL == repr) {
+ ERR("icl_representation_from_gvariant() Fail");
+ if (options)
+ iotcon_options_destroy(options);
+
+ if (cb_container->cb)
+ cb_container->cb(cb_container->resource, IOTCON_ERROR_SYSTEM, -1,
+ NULL, cb_container->user_data);
+ return;
}
+ }
+
+ res = icl_dbus_convert_daemon_error(res);
+
+ response = calloc(1, sizeof(struct icl_resource_response));
+ if (NULL == response) {
+ ERR("calloc() Fail(%d)", errno);
+ if (repr)
+ iotcon_representation_destroy(repr);
+ if (options)
+ iotcon_options_destroy(options);
+
+ if (cb_container->cb)
+ cb_container->cb(cb_container->resource, IOTCON_ERROR_OUT_OF_MEMORY, -1,
+ NULL, cb_container->user_data);
return;
}
+ response->result = res;
+ response->repr = repr;
+ response->header_options = options;
if (cb_container->cb)
- cb_container->cb(cb_container->resource, IOTCON_ERROR_NONE, IOTCON_REQUEST_OBSERVE,
+ cb_container->cb(cb_container->resource, IOTCON_ERROR_NONE, seq_number,
response, cb_container->user_data);
if (response)
}
-static void _icl_observe_conn_cleanup(icl_on_response_s *cb_container)
+static void _icl_observe_conn_cleanup(icl_on_observe_s *cb_container)
{
cb_container->resource->observe_handle = 0;
cb_container->resource->observe_sub_id = 0;
int icl_remote_resource_observer_start(iotcon_remote_resource_h resource,
- iotcon_observe_type_e observe_type,
+ iotcon_observe_policy_e observe_policy,
iotcon_query_h query,
GDBusSignalCallback sig_handler,
void *cb_container,
arg_query = icl_dbus_query_to_gvariant(query);
ic_dbus_call_observer_start_sync(icl_dbus_get_object(), arg_remote_resource,
- observe_type, arg_query, signal_number, observe_handle, NULL, &error);
+ observe_policy, arg_query, signal_number, observe_handle, NULL, &error);
if (error) {
ERR("ic_dbus_call_observer_start_sync() Fail(%s)", error->message);
ret = icl_dbus_convert_dbus_error(error->code);
}
-API int iotcon_remote_resource_set_notify_cb(iotcon_remote_resource_h resource,
- iotcon_observe_type_e observe_type,
+API int iotcon_remote_resource_observe_register(iotcon_remote_resource_h resource,
+ iotcon_observe_policy_e observe_policy,
iotcon_query_h query,
- iotcon_remote_resource_response_cb cb,
+ iotcon_remote_resource_observe_cb cb,
void *user_data)
{
int ret;
unsigned int sub_id;
int64_t observe_handle;
- icl_on_response_s *cb_container;
+ icl_on_observe_s *cb_container;
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(resource->observe_handle || resource->observe_sub_id, IOTCON_ERROR_ALREADY);
- cb_container = calloc(1, sizeof(icl_on_response_s));
+ cb_container = calloc(1, sizeof(icl_on_observe_s));
if (NULL == cb_container) {
ERR("calloc() Fail(%d)", errno);
return IOTCON_ERROR_OUT_OF_MEMORY;
cb_container->user_data = user_data;
ret = icl_remote_resource_observer_start(resource,
- observe_type,
+ observe_policy,
query,
_icl_on_observe_cb,
cb_container,
}
-API int iotcon_remote_resource_unset_notify_cb(iotcon_remote_resource_h resource)
+API int iotcon_remote_resource_observe_deregister(iotcon_remote_resource_h resource)
{
int ret;
RET_IF(NULL == resource);
if (resource->observe_handle)
- iotcon_remote_resource_unset_notify_cb(resource);
+ iotcon_remote_resource_observe_deregister(resource);
icl_remote_resource_crud_stop(resource);
void icl_remote_resource_crud_stop(iotcon_remote_resource_h resource);
int icl_remote_resource_observer_start(iotcon_remote_resource_h resource,
- iotcon_observe_type_e observe_type,
+ iotcon_observe_policy_e observe_policy,
iotcon_query_h query,
GDBusSignalCallback sig_handler,
void *cb_container,
}
-API int iotcon_request_get_types(iotcon_request_h request, int *types)
+API int iotcon_request_get_request_type(iotcon_request_h request,
+ iotcon_request_type_e *type)
{
RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
- *types = request->types;
+ *type = request->type;
return IOTCON_ERROR_NONE;
}
}
-API int iotcon_request_get_observe_action(iotcon_request_h request,
- iotcon_observe_action_e *action)
+API int iotcon_request_get_observe_type(iotcon_request_h request,
+ iotcon_observe_type_e *observe_type)
{
RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == action, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == observe_type, IOTCON_ERROR_INVALID_PARAMETER);
- *action = request->observation_info.action;
+ *observe_type = request->observation_info.action;
return IOTCON_ERROR_NONE;
}
#include "iotcon-constant.h"
struct icl_observe_info {
- iotcon_observe_action_e action;
+ iotcon_observe_type_e action;
int observe_id;
};
struct icl_resource_request {
char *host_address;
iotcon_connectivity_type_e connectivity_type;
- int types;
+ iotcon_request_type_e type;
iotcon_options_h header_options;
iotcon_query_h query;
struct icl_observe_info observation_info;
g_variant_get(parameters, "(siia(qs)a(ss)iiavxx)",
&request.host_address,
&request.connectivity_type,
- &request.types,
+ &request.type,
&options,
&query,
&request.observation_info.action,
g_variant_iter_free(repr_iter);
/* for iotcon_resource_notify */
- if (IOTCON_REQUEST_OBSERVE & request.types) {
- int observe_id = request.observation_info.observe_id;
- if (IOTCON_OBSERVE_REGISTER == request.observation_info.action) {
- if (NULL == resource->observers)
- iotcon_observers_create(&resource->observers);
- iotcon_observers_add(resource->observers, observe_id);
- } else if (IOTCON_OBSERVE_DEREGISTER == request.observation_info.action) {
- iotcon_observers_remove(resource->observers, observe_id);
- }
+ if (IOTCON_OBSERVE_REGISTER == request.observation_info.action) {
+ if (NULL == resource->observers)
+ iotcon_observers_create(&resource->observers);
+ iotcon_observers_add(resource->observers, request.observation_info.observe_id);
+ } else if (IOTCON_OBSERVE_DEREGISTER == request.observation_info.action) {
+ iotcon_observers_remove(resource->observers, request.observation_info.observe_id);
}
if (cb)
struct icl_resource_response {
- int seq_number;
iotcon_options_h header_options;
iotcon_interface_e iface;
int result;
#define IOTCON_FUNC_CONTINUE true
/**
- * @brief Enumeration for action of observation.
+ * @brief Enumeration for type of observation.
*
* @since_tizen 3.0
*/
typedef enum {
IOTCON_OBSERVE_REGISTER = 0, /**< Indicates action of registering observation*/
IOTCON_OBSERVE_DEREGISTER = 1, /**< Indicates action of unregistering observation */
- IOTCON_OBSERVE_NO_OPTION = 2 /**< Indicates no option */
-} iotcon_observe_action_e;
+ IOTCON_OBSERVE_TYPE_NONE = 2, /**< Indicates no option */
+} iotcon_observe_type_e;
/**
- * @brief Enumeration for type of observation.
+ * @brief Enumeration for policy of observation.
*
* @since_tizen 3.0
*/
typedef enum {
IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER = 0, /**< Indicates observation request for most up-to-date notifications only */
IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER = 1 /**< Indicates observation request for all notifications including stale notifications */
-} iotcon_observe_type_e;
+} iotcon_observe_policy_e;
/**
* @brief Enumeration for type of interfaces which can be held in a resource.
* @since_tizen 3.0
*/
typedef enum {
- IOTCON_REQUEST_GET = (1 << 0), /**< Indicates get method of request */
- IOTCON_REQUEST_PUT = (1 << 1), /**< Indicates put method of request */
- IOTCON_REQUEST_POST = (1 << 2), /**< Indicates post method of request */
- IOTCON_REQUEST_DELETE = (1 << 3), /**< Indicates delete method of request */
- IOTCON_REQUEST_OBSERVE = (1 << 4), /**< Indicates observe method of request */
+ IOTCON_REQUEST_NONE = 0, /**< Indicates none */
+ IOTCON_REQUEST_GET = 1, /**< Indicates get method of request */
+ IOTCON_REQUEST_PUT = 2, /**< Indicates put method of request */
+ IOTCON_REQUEST_POST = 3, /**< Indicates post method of request */
+ IOTCON_REQUEST_DELETE = 4, /**< Indicates delete method of request */
} iotcon_request_type_e;
/**
* @brief Creates a new resource handle.
* @details Creates a resource proxy object so that iotcon_remote_resource_get(),
* iotcon_remote_resource_put(), iotcon_remote_resource_post(),
- * iotcon_remote_resource_delete(), iotcon_remote_resource_set_notify_cb(),
+ * iotcon_remote_resource_delete(), iotcon_remote_resource_observe_register(),
* iotcon_remote_resource_start_caching() and iotcon_remote_resource_start_monitoring()
* API can be used without discovering the object in advance.\n
* To use this API, you should provide all of the details required to correctly contact and
*/
int iotcon_remote_resource_clone(iotcon_remote_resource_h src, iotcon_remote_resource_h *dest);
-
/**
* @brief Specifies the type of response function.
- * @details The function passed to iotcon_remote_resource_set_notify_cb(),
+ * @details The function passed to iotcon_remote_resource_observe_register(),
* iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post(),
* iotcon_remote_resource_delete().
* The @a err could be one of #iotcon_error_e.
*
* @since_tizen 3.0
*
- * @param[in] resource The handle of the resource
+ * @param[in] resource The handle of the remote resource
* @param[in] err The error code
- * @param[in] request_type The request type
+ * @param[in] sequence_number The sequence number of observe
* @param[in] response The handle of the response
* @param[in] user_data The user data passed from the callback registration function
*
- * @pre The callback must be registered using iotcon_remote_resource_set_notify_cb(),
+ * @pre The callback must be registered using iotcon_remote_resource_observe_register(),
* iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post(),
* iotcon_remote_resource_delete()
*
- * @see iotcon_remote_resource_set_notify_cb()
+ * @see iotcon_remote_resource_observe_register()
*/
-typedef void (*iotcon_remote_resource_response_cb)(iotcon_remote_resource_h resource,
- iotcon_error_e err,
- iotcon_request_type_e request_type,
- iotcon_response_h response,
- void *user_data);
+typedef void (*iotcon_remote_resource_observe_cb)(iotcon_remote_resource_h resource,
+ iotcon_error_e err, int sequence_number, iotcon_response_h response, void *user_data);
/**
- * @brief Sets notify callback on the resource
+ * @brief Registers observe callback on the resource
* @details When server sends notification message, iotcon_remote_resource_response_cb() will be called.
- * The @a observe_type could be one of #iotcon_observe_type_e.
+ * The @a observe_type could be one of #iotcon_observe_policy_e.
*
* @since_tizen 3.0
* @privlevel public
* @post When the @a resource receive notification message, iotcon_remote_resource_response_cb() will be called.
*
* @see iotcon_remote_resource_response_cb()
- * @see iotcon_remote_resource_unset_notify_cb()
+ * @see iotcon_remote_resource_observe_deregister()
* @see iotcon_resource_notify()
*/
-int iotcon_remote_resource_set_notify_cb(iotcon_remote_resource_h resource,
- iotcon_observe_type_e observe_type,
+int iotcon_remote_resource_observe_register(iotcon_remote_resource_h resource,
+ iotcon_observe_policy_e observe_policy,
iotcon_query_h query,
- iotcon_remote_resource_response_cb cb,
+ iotcon_remote_resource_observe_cb cb,
void *user_data);
/**
- * @brief Unsets notify callback on the resource
+ * @brief Deregisters observe callback on the resource
*
* @since_tizen 3.0
* @privlevel public
* @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_remote_resource_response_cb()
- * @see iotcon_remote_resource_set_notify_cb()
+ * @see iotcon_remote_resource_observe_register()
* @see iotcon_resource_notify()
*/
-int iotcon_remote_resource_unset_notify_cb(iotcon_remote_resource_h resource);
+int iotcon_remote_resource_observe_deregister(iotcon_remote_resource_h resource);
+
+/**
+ * @brief Specifies the type of response function.
+ * @details The function passed to iotcon_remote_resource_observe_register(),
+ * iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post(),
+ * iotcon_remote_resource_delete().
+ * The @a err could be one of #iotcon_error_e.
+ * The @a request_type could be one of #iotcon_request_type_e.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] resource The handle of the resource
+ * @param[in] err The error code
+ * @param[in] request_type The request type
+ * @param[in] response The handle of the response
+ * @param[in] user_data The user data passed from the callback registration function
+ *
+ * @pre The callback must be registered using iotcon_remote_resource_observe_register(),
+ * iotcon_remote_resource_get(), iotcon_remote_resource_put(), iotcon_remote_resource_post(),
+ * iotcon_remote_resource_delete()
+ *
+ * @see iotcon_remote_resource_observe_register()
+ */
+typedef void (*iotcon_remote_resource_response_cb)(iotcon_remote_resource_h resource,
+ iotcon_error_e err,
+ iotcon_request_type_e request_type,
+ iotcon_response_h response,
+ void *user_data);
/**
* @brief Gets the attributes of a resource, asynchronously.
*
* @see iotcon_request_get_connectivity_type()
* @see iotcon_request_get_representation()
- * @see iotcon_request_get_types()
+ * @see iotcon_request_get_request_type()
* @see iotcon_request_get_options()
* @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_action()
+ * @see iotcon_request_get_observe_type()
* @see iotcon_request_get_observe_id()
*/
int iotcon_request_get_host_address(iotcon_request_h request,
*
* @see iotcon_request_get_host_address()
* @see iotcon_request_get_representation()
- * @see iotcon_request_get_types()
+ * @see iotcon_request_get_request_type()
* @see iotcon_request_get_options()
* @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_action()
+ * @see iotcon_request_get_observe_type()
* @see iotcon_request_get_observe_id()
*/
int iotcon_request_get_connectivity_type(iotcon_request_h request,
*
* @see iotcon_request_get_host_address()
* @see iotcon_request_get_connectivity_type()
- * @see iotcon_request_get_types()
+ * @see iotcon_request_get_request_type()
* @see iotcon_request_get_options()
* @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_action()
+ * @see iotcon_request_get_observe_type()
* @see iotcon_request_get_observe_id()
*/
int iotcon_request_get_representation(iotcon_request_h request,
iotcon_representation_h *repr);
/**
- * @brief Gets types of the request
- * @details @a types could be oring the #iotcon_request_type_e
+ * @brief Gets type of the request
+ * @details @a type could be one of the #iotcon_request_type_e
*
* @since_tizen 3.0
*
* @param[in] request The handle of the request
- * @param[out] types The types of the request.
+ * @param[out] type The types of the request.
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @see iotcon_request_get_representation()
* @see iotcon_request_get_options()
* @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_action()
+ * @see iotcon_request_get_observe_type()
* @see iotcon_request_get_observe_id()
*/
-int iotcon_request_get_types(iotcon_request_h request, int *types);
+int iotcon_request_get_request_type(iotcon_request_h request, iotcon_request_type_e *type);
/**
* @brief Gets options of the request
* @see iotcon_request_get_host_address()
* @see iotcon_request_get_connectivity_type()
* @see iotcon_request_get_representation()
- * @see iotcon_request_get_types()
+ * @see iotcon_request_get_request_type()
* @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_action()
+ * @see iotcon_request_get_observe_type()
* @see iotcon_request_get_observe_id()
*/
int iotcon_request_get_options(iotcon_request_h request, iotcon_options_h *options);
* @see iotcon_request_get_host_address()
* @see iotcon_request_get_connectivity_type()
* @see iotcon_request_get_representation()
- * @see iotcon_request_get_types()
+ * @see iotcon_request_get_request_type()
* @see iotcon_request_get_options()
- * @see iotcon_request_get_observe_action()
+ * @see iotcon_request_get_observe_type()
* @see iotcon_request_get_observe_id()
*/
int iotcon_request_get_query(iotcon_request_h request, iotcon_query_h *query);
* @brief Gets observation action of the request
*
* @since_tizen 3.0
- * @details The @a action could be one of #iotcon_observe_action_e.
+ * @details The @a observe_type could be one of #iotcon_observe_type_e.
*
* @param[in] request The handle of the request
- * @param[out] action The observation action of the request
+ * @param[out] observe_type The observation type of the request
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @see iotcon_request_get_host_address()
* @see iotcon_request_get_connectivity_type()
* @see iotcon_request_get_representation()
- * @see iotcon_request_get_types()
+ * @see iotcon_request_get_request_type()
* @see iotcon_request_get_options()
* @see iotcon_request_get_query()
* @see iotcon_request_get_observe_id()
*/
-int iotcon_request_get_observe_action(iotcon_request_h request,
- iotcon_observe_action_e *action);
+int iotcon_request_get_observe_type(iotcon_request_h request,
+ iotcon_observe_type_e *observe_type);
/**
* @brief Gets observation id of the request
* @see iotcon_request_get_host_address()
* @see iotcon_request_get_connectivity_type()
* @see iotcon_request_get_representation()
- * @see iotcon_request_get_types()
+ * @see iotcon_request_get_request_type()
* @see iotcon_request_get_options()
* @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_action()
+ * @see iotcon_request_get_observe_type()
*/
int iotcon_request_get_observe_id(iotcon_request_h request, int *observe_id);
* @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
*
* @see iotcon_remote_resource_response_cb()
- * @see iotcon_remote_resource_set_notify_cb()
- * @see iotcon_remote_resource_unset_notify_cb()
+ * @see iotcon_remote_resource_observe_register()
+ * @see iotcon_remote_resource_observe_deregister()
* @see iotcon_observers_create()
* @see iotcon_observers_destroy()
* @see iotcon_observers_add()
static void _on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
iotcon_request_type_e request_type, iotcon_response_h response, void *user_data);
-static void _on_response_notify(iotcon_remote_resource_h resource,
- iotcon_response_h response, void *user_data)
+static void _on_observe(iotcon_remote_resource_h resource, iotcon_error_e err,
+ int sequece_number, iotcon_response_h response, void *user_data)
{
int ret;
bool opened;
}
if (5 == i++) {
- iotcon_remote_resource_unset_notify_cb(resource);
+ iotcon_remote_resource_observe_deregister(resource);
iotcon_remote_resource_destroy(resource);
}
}
case IOTCON_REQUEST_DELETE:
_on_response_delete(resource, response, user_data);
break;
- case IOTCON_REQUEST_OBSERVE:
- _on_response_notify(resource, response, user_data);
- break;
default:
ERR("Invalid request type (%d)", request_type);
return;
return;
}
- /* Set NOTIFY callback */
- ret = iotcon_remote_resource_set_notify_cb(resource_clone,
- IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER, NULL, _on_response, NULL);
+ ret = iotcon_remote_resource_observe_register(resource_clone, IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER, NULL,
+ _on_observe, NULL);
+
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_set_notify_cb() Fail(%d)", ret);
+ ERR("iotcon_remote_resource_observe_register() Fail(%d)", ret);
device_id_list = g_list_remove(device_id_list, door_resource_device_id);
free(door_resource_device_id);
return;
}
new_door_handle = _create_door_resource(DOOR_RESOURCE_URI2, door->type,
- IOTCON_INTERFACE_DEFAULT, (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), NULL);
+ IOTCON_INTERFACE_DEFAULT, (IOTCON_DISCOVERABLE | IOTCON_OBSERVABLE), door);
if (NULL == new_door_handle) {
ERR("_create_door_resource() Fail");
return -1;
return 0;
}
-static int _request_handler_observe(door_resource_s *door, iotcon_request_h request)
-{
- int ret;
- int observe_id;
- iotcon_observe_action_e observe_action;
-
- ret = iotcon_request_get_observe_action(request, &observe_action);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_action() Fail(%d)", ret);
- return -1;
- }
-
- if (IOTCON_OBSERVE_REGISTER == observe_action) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_id() Fail(%d)", ret);
- return -1;
- }
- ret = iotcon_observers_add(door->observers, observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_observers_add() Fail(%d)", ret);
- return -1;
- }
- } else if (IOTCON_OBSERVE_DEREGISTER == observe_action) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_id() Fail(%d)", ret);
- return -1;
- }
- ret = iotcon_observers_remove(door->observers, observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_observers_remove() Fail(%d)", ret);
- return -1;
- }
- }
-
- return 0;
-}
-
static bool _query_cb(const char *key, const char *value, void *user_data)
{
INFO("key : %s, value : %s", key, value);
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data)
{
- int ret, types;
- char *host_address;
- iotcon_query_h query;
door_resource_s *door;
+ iotcon_query_h query;
+ int ret, observe_id;
+ iotcon_request_type_e type;
+ iotcon_observe_type_e observe_type;
+ char *host_address;
RET_IF(NULL == request);
if (query)
iotcon_query_foreach(query, _query_cb, NULL);
- ret = iotcon_request_get_types(request, &types);
+ ret = iotcon_request_get_request_type(request, &type);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_types() Fail(%d)", ret);
_send_response(request, NULL, IOTCON_RESPONSE_RESULT_ERROR);
return;
}
+
door = user_data;
- if (IOTCON_REQUEST_GET & types)
+ if (IOTCON_REQUEST_GET == type)
ret = _request_handler_get(door, request);
- else if (IOTCON_REQUEST_PUT & types)
+ else if (IOTCON_REQUEST_PUT == type)
ret = _request_handler_put(door, request);
- else if (IOTCON_REQUEST_POST & types)
+ else if (IOTCON_REQUEST_POST == type)
ret = _request_handler_post(door, request);
- else if (IOTCON_REQUEST_DELETE & types)
+ else if (IOTCON_REQUEST_DELETE == type)
ret = _request_handler_delete(resource, request);
if (0 != ret) {
return;
}
- if (IOTCON_REQUEST_OBSERVE & types)
- _request_handler_observe(door,request);
+ ret = iotcon_request_get_observe_type(request, &observe_type);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_request_get_observe_type() Fail(%d)", ret);
+ return;
+ }
+
+ if (IOTCON_OBSERVE_REGISTER == observe_type) {
+ ret = iotcon_request_get_observe_id(request, &observe_id);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_request_get_observe_id() Fail(%d)", ret);
+ return;
+ }
+
+ ret = iotcon_observers_add(door->observers, observe_id);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_observers_add() Fail(%d)", ret);
+ return;
+ }
+ } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
+ ret = iotcon_request_get_observe_id(request, &observe_id);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_request_get_observe_id() Fail(%d)", ret);
+ return;
+ }
+ ret = iotcon_observers_remove(door->observers, observe_id);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_observers_remove() Fail(%d)", ret);
+ return;
+ }
+ }
}
static gboolean _presence_timer(gpointer user_data)
static void _light_request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data)
{
- int ret, types;
+ int ret;
+ iotcon_request_type_e type;
light_resource_s *light = user_data;
int iface = IOTCON_INTERFACE_DEFAULT;
RET_IF(NULL == request);
- ret = iotcon_request_get_types(request, &types);
+ ret = iotcon_request_get_request_type(request, &type);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_types() Fail(%d)", ret);
_send_response(request, NULL, iface, IOTCON_RESPONSE_RESULT_ERROR);
return;
}
- if (IOTCON_REQUEST_GET & types) {
+ if (IOTCON_REQUEST_GET == type) {
ret = _light_request_handler_get(light, request);
if (0 != ret)
_send_response(request, NULL, iface, IOTCON_RESPONSE_RESULT_ERROR);
static void _fan_request_handler(iotcon_resource_h resource, iotcon_request_h request,
void *user_data)
{
- int ret, types;
+ int ret;
+ iotcon_request_type_e type;
fan_resource_s *fan = user_data;
int iface = IOTCON_INTERFACE_DEFAULT;
RET_IF(NULL == request);
- ret = iotcon_request_get_types(request, &types);
+ ret = iotcon_request_get_request_type(request, &type);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_types() Fail(%d)", ret);
_send_response(request, NULL, iface, IOTCON_RESPONSE_RESULT_ERROR);
return;
}
- if (IOTCON_REQUEST_GET & types) {
+ if (IOTCON_REQUEST_GET == type) {
ret = _fan_request_handler_get(fan, request);
if (0 != ret)
_send_response(request, NULL, iface, IOTCON_RESPONSE_RESULT_ERROR);
void *user_data)
{
FN_CALL;
- int ret, types;
+ int ret;
+ iotcon_request_type_e type;
char *host_address;
room_resource_s *room = user_data;
int iface = IOTCON_INTERFACE_DEFAULT;
}
INFO("host address : %s", host_address);
- ret = iotcon_request_get_types(request, &types);
+ ret = iotcon_request_get_request_type(request, &type);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_request_get_types() Fail(%d)", ret);
_send_response(request, NULL, iface, IOTCON_RESPONSE_RESULT_ERROR);
return;
}
- if (IOTCON_REQUEST_GET & types) {
+ if (IOTCON_REQUEST_GET == type) {
ret = _room_request_handler_get(room, request);
if (0 != ret)
_send_response(request, NULL, iface, IOTCON_RESPONSE_RESULT_ERROR);