Fix observe API (set_notify_cb -> observe_register)
authorsung.goo.kim <sung.goo.kim@samsung.com>
Thu, 12 Nov 2015 09:31:37 +0000 (18:31 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Nov 2015 05:54:46 +0000 (14:54 +0900)
Change-Id: Idc3a21e6f2e7f9553cb3cfde8c9d0bd7c54f5b66

19 files changed:
daemon/icd-dbus.c
daemon/icd-ioty-ocprocess.c
daemon/icd-ioty.c
doc/iotcon_doc.h
lib/icl-lite-resource.c
lib/icl-remote-resource-crud.c
lib/icl-remote-resource.c
lib/icl-remote-resource.h
lib/icl-request.c
lib/icl-request.h
lib/icl-resource.c
lib/icl-response.h
lib/include/iotcon-constant.h
lib/include/iotcon-remote-resource.h
lib/include/iotcon-request.h
lib/include/iotcon-resource.h
test/iotcon-test-basic-client.c
test/iotcon-test-basic-server.c
test/iotcon-test-repr-server.c

index a5f43ae5fda060c92011750c44429c27274565fb..e19a0d701bdfe2cbe81f6706efbffacaab418e33 100644 (file)
@@ -517,7 +517,7 @@ static gboolean _dbus_handle_find_resource(icDbus *object,
 static gboolean _dbus_handle_observer_start(icDbus *object,
                GDBusMethodInvocation *invocation,
                GVariant *resource,
-               gint observe_type,
+               gint observe_policy,
                GVariant *query,
                guint signal_number)
 {
@@ -525,7 +525,7 @@ static gboolean _dbus_handle_observer_start(icDbus *object,
        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");
index 1215a9c68f401c26259332562e6879184db63407..c71ecc88131338ce76797080aaf9d579bea5b74d 100644 (file)
@@ -45,9 +45,9 @@ struct icd_ioty_worker
 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;
@@ -224,7 +224,7 @@ static int _ioty_oic_action_to_ioty_action(int oic_action)
        case OC_OBSERVE_NO_OPTION:
        default:
                ERR("Invalid action (%d)", oic_action);
-               action = IOTCON_OBSERVE_NO_OPTION;
+               action = IOTCON_OBSERVE_TYPE_NONE;
        }
        return action;
 }
@@ -246,7 +246,7 @@ static int _worker_req_handler(void *context)
 {
        GVariant *value;
        char *host_address;
-       int ret, conn_type, action;
+       int ret, conn_type;
        GVariantBuilder payload_builder;
        struct icd_req_context *ctx = context;
 
@@ -266,15 +266,13 @@ static int _worker_req_handler(void *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),
@@ -341,26 +339,19 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
        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:
@@ -370,6 +361,14 @@ OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
                }
        }
 
+       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,
index 331f390829ab03283bbdca49d72d9131174f4f8a..5a231674b9815f440826e4f58fc99c54f43acc26 100644 (file)
@@ -706,7 +706,7 @@ gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
 }
 
 
-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;
@@ -733,9 +733,9 @@ OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type,
                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;
index 48a02b90198eae4b9da693f12665378a2c1058b0..18840416dc41b8d1a2d841077bb8df8d49d1a8a4 100644 (file)
 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;
@@ -237,37 +237,32 @@ static void _request_handler(iotcon_request_h request, void *user_data)
        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;
                }
        }
 }
@@ -334,7 +329,7 @@ static void _on_resopnse_observe(iotcon_remote_resource_h resource, iotcon_error
 ...
 {
        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;
index 90bb99649a2968bd99290465a7a4db065e2a4453..b494af0eaa5908e52bce1ab81a6372a4a16edcda 100644 (file)
@@ -138,7 +138,7 @@ static void _icl_lite_resource_request_handler(GDBusConnection *connection,
                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;
@@ -165,7 +165,7 @@ static void _icl_lite_resource_request_handler(GDBusConnection *connection,
        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 */
@@ -174,9 +174,8 @@ static void _icl_lite_resource_request_handler(GDBusConnection *connection,
                        &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)) {
@@ -242,7 +241,7 @@ static void _icl_lite_resource_request_handler(GDBusConnection *connection,
                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);
index d3e7a9b1dfef7a7b76ff28d095fc381a2e87861f..b41f87fe1ea06d1cf502bb99ace5209f7c5eb61f 100644 (file)
@@ -38,6 +38,12 @@ typedef struct {
        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)
@@ -54,38 +60,46 @@ 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);
        }
 
@@ -113,7 +127,6 @@ static int _icl_parse_crud_gvariant(iotcon_request_type_e request_type,
        resp->result = res;
        resp->repr = repr;
        resp->header_options = options;
-       resp->seq_number = seq_number;
 
        *response = resp;
 
@@ -372,24 +385,59 @@ static void _icl_on_observe_cb(GDBusConnection *connection,
                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)
@@ -397,7 +445,7 @@ static void _icl_on_observe_cb(GDBusConnection *connection,
 }
 
 
-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;
@@ -406,7 +454,7 @@ static void _icl_observe_conn_cleanup(icl_on_response_s *cb_container)
 
 
 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,
@@ -428,7 +476,7 @@ int icl_remote_resource_observer_start(iotcon_remote_resource_h resource,
        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);
@@ -456,22 +504,22 @@ int icl_remote_resource_observer_start(iotcon_remote_resource_h resource,
 }
 
 
-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;
@@ -482,7 +530,7 @@ API int iotcon_remote_resource_set_notify_cb(iotcon_remote_resource_h resource,
        cb_container->user_data = user_data;
 
        ret = icl_remote_resource_observer_start(resource,
-                       observe_type,
+                       observe_policy,
                        query,
                        _icl_on_observe_cb,
                        cb_container,
@@ -532,7 +580,7 @@ int icl_remote_resource_stop_observing(iotcon_remote_resource_h resource,
 }
 
 
-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;
 
index e7cd598de133e285ebafbcfcd6e4e9b0bb5f2f60..7325587339a7b2f2703b7ccc413eeddab290a99a 100644 (file)
@@ -203,7 +203,7 @@ API void iotcon_remote_resource_destroy(iotcon_remote_resource_h resource)
        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);
 
index cab7a747d24afd716f2043f98d434dd7b04438ea..8f9b4afe6e0527466998141e5e268e46bef14ef5 100644 (file)
@@ -72,7 +72,7 @@ struct icl_remote_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,
index f8a5ee81d26d1e8404168d1bdfc2e8c2558dddce..da1794d2dd282048bec24473f19376e8e0f7a298 100644 (file)
@@ -55,12 +55,13 @@ API int iotcon_request_get_representation(iotcon_request_h request,
 }
 
 
-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;
 }
@@ -90,13 +91,13 @@ API int iotcon_request_get_query(iotcon_request_h request, iotcon_query_h *query
 }
 
 
-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;
 }
index b48b428e62efbd6511b553ba8e0f2b67be28fcd6..c2cba922f2f2d6768b6f127815b138d473229494 100644 (file)
 #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;
index ec8f3efcf5de3b636eeb3e8a8632779ead25d117..d0c2760bf64cbd3aff8d126772ada79f0b512edd 100644 (file)
@@ -57,7 +57,7 @@ static void _icl_request_handler(GDBusConnection *connection,
        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,
@@ -111,15 +111,12 @@ static void _icl_request_handler(GDBusConnection *connection,
        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)
index bc07daf3b19b6e5cb6a92ae2e4e9d76bf4e68da2..6a67c9b51293d0f5ce66fddbab750f0532b99704 100644 (file)
@@ -28,7 +28,6 @@ typedef enum {
 
 
 struct icl_resource_response {
-       int seq_number;
        iotcon_options_h header_options;
        iotcon_interface_e iface;
        int result;
index 9c351b564cd2eaa5ecacd23c88c9d42657a14a65..0489f5a9385e9cb25a4d636b3011004a30657ba2 100644 (file)
@@ -236,25 +236,25 @@ typedef struct icl_state_s* iotcon_state_h;
 #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.
@@ -303,11 +303,11 @@ typedef enum {
  * @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;
 
 /**
index af5b7154186df093b6333f571651798fbfec121a..8c47ece604d9a47be120d19e8e4dd1671c0c6d2d 100644 (file)
@@ -39,7 +39,7 @@
  * @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
@@ -113,10 +113,9 @@ void iotcon_remote_resource_destroy(iotcon_remote_resource_h resource);
  */
 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.
@@ -124,28 +123,25 @@ int iotcon_remote_resource_clone(iotcon_remote_resource_h src, iotcon_remote_res
  *
  * @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
@@ -168,17 +164,17 @@ typedef void (*iotcon_remote_resource_response_cb)(iotcon_remote_resource_h reso
  * @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
@@ -194,10 +190,38 @@ int iotcon_remote_resource_set_notify_cb(iotcon_remote_resource_h resource,
  * @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.
index f67f29fd3ea06b0e97ef078d126844d768d57789..24fd2085e1e5592dbb3be715e6aa4ba388a4566f 100644 (file)
  *
  * @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,
@@ -73,10 +73,10 @@ 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,
@@ -98,23 +98,23 @@ 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
@@ -125,10 +125,10 @@ int iotcon_request_get_representation(iotcon_request_h request,
  * @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
@@ -147,9 +147,9 @@ int iotcon_request_get_types(iotcon_request_h request, int *types);
  * @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);
@@ -171,9 +171,9 @@ int iotcon_request_get_options(iotcon_request_h request, iotcon_options_h *optio
  * @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);
@@ -182,10 +182,10 @@ 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
@@ -194,13 +194,13 @@ int iotcon_request_get_query(iotcon_request_h request, iotcon_query_h *query);
  * @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
@@ -217,10 +217,10 @@ int iotcon_request_get_observe_action(iotcon_request_h 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);
 
index b0055339b18911baf5c2e7f9c0cd8498407646de..7f4335996c338e670068510502c6c769c9b162e0 100644 (file)
@@ -308,8 +308,8 @@ int iotcon_resource_unbind_child_resource(iotcon_resource_h parent,
  * @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()
index ee34db4610227949e1972369a603ea26595c2084..967604740f52c4928f06ca375cbdc34636f5fac4 100644 (file)
@@ -29,8 +29,8 @@ static GList *device_id_list;
 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;
@@ -81,7 +81,7 @@ static void _on_response_notify(iotcon_remote_resource_h resource,
        }
 
        if (5 == i++) {
-               iotcon_remote_resource_unset_notify_cb(resource);
+               iotcon_remote_resource_observe_deregister(resource);
                iotcon_remote_resource_destroy(resource);
        }
 }
@@ -424,9 +424,6 @@ static void _on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
        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;
@@ -569,11 +566,11 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re
                        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;
index b235ec7ca84d978677acd8ce221fb56cac9afffe..b8c59b080f3b13da39699b56d2dae272e06b6d76 100644 (file)
@@ -355,7 +355,7 @@ static int _request_handler_post(door_resource_s *door, iotcon_request_h request
        }
 
        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;
@@ -426,45 +426,6 @@ static int _request_handler_delete(iotcon_resource_h resource, iotcon_request_h
        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);
@@ -475,10 +436,12 @@ static bool _query_cb(const char *key, const char *value, void *user_data)
 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);
 
@@ -499,25 +462,26 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
        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) {
@@ -525,8 +489,36 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                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)
index a92415041159b5f60d3f8a3b1fc083410080771c..049b30bfbe9bd9b822cfc91b2b44fc9df4509fb3 100644 (file)
@@ -591,20 +591,21 @@ static int _room_request_handler_get(room_resource_s *room, iotcon_request_h req
 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);
@@ -616,20 +617,21 @@ static void _light_request_handler(iotcon_resource_h resource, iotcon_request_h
 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);
@@ -642,7 +644,8 @@ static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h r
                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;
@@ -657,14 +660,14 @@ static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h r
        }
        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);