From e50e67990789ced797086b4b11c5390ffe97b943 Mon Sep 17 00:00:00 2001 From: youngman Date: Mon, 1 Feb 2016 10:45:39 +0900 Subject: [PATCH] modify observe example Change-Id: I0c09ef50ed4d7e6d0f34b2824fb1a082bfef784d Signed-off-by: youngman --- lib/include/iotcon-observers.h | 69 +++++++++++++++++++++++------------------- lib/include/iotcon-request.h | 38 +++++++++-------------- 2 files changed, 52 insertions(+), 55 deletions(-) diff --git a/lib/include/iotcon-observers.h b/lib/include/iotcon-observers.h index f00def7..0a34368 100644 --- a/lib/include/iotcon-observers.h +++ b/lib/include/iotcon-observers.h @@ -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 diff --git a/lib/include/iotcon-request.h b/lib/include/iotcon-request.h index 53cece4..d0af58c 100644 --- a/lib/include/iotcon-request.h +++ b/lib/include/iotcon-request.h @@ -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 * -- 2.7.4