modify observe example 25/58425/1
authoryoungman <yman.jung@samsung.com>
Mon, 1 Feb 2016 01:45:39 +0000 (10:45 +0900)
committeryoungman <yman.jung@samsung.com>
Mon, 1 Feb 2016 01:45:39 +0000 (10:45 +0900)
Change-Id: I0c09ef50ed4d7e6d0f34b2824fb1a082bfef784d
Signed-off-by: youngman <yman.jung@samsung.com>
lib/include/iotcon-observers.h
lib/include/iotcon-request.h

index f00def7..0a34368 100644 (file)
@@ -41,42 +41,17 @@ static iotcon_observers_h _observers;
 static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
                void *user_data)
 {
-       int ret;
-       int types;
+       int ret, observe_id;
+       iotcon_request_type_e types;
+       iotcon_observe_type_e observe_type;
+       iotcon_representation_h repr = NULL;
 
+       ...
        ret = iotcon_request_get_types(request, &types);
        if (IOTCON_ERROR_NONE != ret)
                return;
+       ...
 
-       if (IOTCON_REQUEST_OBSERVE & types) {
-               int observe_id;
-               iotcon_observe_action_e action;
-
-               ret = iotcon_request_get_observe_action(request, &action);
-               if (IOTCON_ERROR_NONE != ret)
-                       return;
-
-               ret = iotcon_request_get_observe_id(request, &observe_id);
-               if (IOTCON_ERROR_NONE != ret)
-                       return;
-
-               if (IOTCON_OBSERVE_REGISTER & action) {
-                       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 & action) {
-                       if (NULL == _observers)
-                               return;
-                       ret = iotcon_observers_remove(_observers, observe_id);
-                       if (IOTCON_ERROR_NONE != ret)
-                               return;
-               }
-       }
        if (IOTCON_REQUEST_PUT & types) {
                iotcon_state_h state = NULL;
                iotcon_representation_h repr = NULL;
@@ -102,6 +77,38 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                iotcon_state_destroy(state);
                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;
+               ...
+       }
        ...
 }
  * @endcode
index 53cece4..d0af58c 100644 (file)
@@ -40,8 +40,9 @@
 static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
                void *user_data)
 {
-       int ret;
-       int types;
+       int ret, observe_id;
+       iotcon_request_type_e types;
+       iotcon_observe_type_e observe_type;
        iotcon_options_h options = NULL;
        iotcon_query_h query = NULL;
        iotcon_representation_h repr = NULL;
@@ -87,36 +88,25 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
                        return;
                ...
        }
-       if (IOTCON_REQUEST_OBSERVE & types) {
-               int observe_id;
-               iotcon_observe_action_e action;
-               char *host_address;
-               iotcon_connectivity_type_e conn_type;
 
-               ret = iotcon_request_get_observe_action(request, &action);
-               if (IOTCON_ERROR_NONE != ret)
-                       return;
+       ret = iotcon_request_get_observe_type(request, &observe_type);
+       if (IOTCON_ERROR_NONE != ret)
+               return;
 
+       if (IOTCON_OBSERVE_REGISTER == observe_type) {
                ret = iotcon_request_get_observe_id(request, &observe_id);
                if (IOTCON_ERROR_NONE != ret)
                        return;
-
-               ret = iotcon_request_get_host_address(request, &host_address);
-               if (IOTCON_ERROR_NONE != ret)
-                       return;
-
-               ret = iotcon_request_get_connectivity_type(request, &conn_type);
+               // handle register observe
+               ...
+       } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
+               ret = iotcon_request_get_observe_id(request, &observe_id);
                if (IOTCON_ERROR_NONE != ret)
                        return;
-
-               if (IOTCON_OBSERVE_REGISTER == action) {
-                       // handle register observe
-                       ...
-               } else if (IOTCON_OBSERVE_DEREGISTER == action) {
-                       // handle deregister observe
-                       ...
-               }
+               // handle deregister observe
+               ...
        }
+       ...
 }
  * @endcode
  *