diff options
author | sung.goo.kim <sung.goo.kim@samsung.com> | 2016-06-02 09:57:21 +0900 |
---|---|---|
committer | Sunggoo Kim <sung.goo.kim@samsung.com> | 2016-06-14 19:23:40 -0700 |
commit | 4a8c504d00e671107968e0c9b09bb62cda5d5acc (patch) | |
tree | aedbe43c7ac1e40a40eabaa2ef0dd0c5240a6905 | |
parent | 4fc23caf6ece52cfea987bc80e776ddac070f31f (diff) | |
download | iotcon-4a8c504d00e671107968e0c9b09bb62cda5d5acc.tar.gz iotcon-4a8c504d00e671107968e0c9b09bb62cda5d5acc.tar.bz2 iotcon-4a8c504d00e671107968e0c9b09bb62cda5d5acc.zip |
Modify return type of iotcon_found_resource/device_info/platform_info_cb
Change-Id: I44dc630232266f8eccb77b9a7678ac7c58d6761c
-rw-r--r-- | doc/iotcon_doc.h | 23 | ||||
-rw-r--r-- | lib/icl-ioty-ocprocess.c | 135 | ||||
-rw-r--r-- | lib/icl-ioty.c | 17 | ||||
-rw-r--r-- | lib/icl-ioty.h | 2 | ||||
-rw-r--r-- | lib/icl-types.c | 9 | ||||
-rw-r--r-- | lib/icl-types.h | 9 | ||||
-rw-r--r-- | lib/include/iotcon-client.h | 15 | ||||
-rw-r--r-- | lib/include/iotcon-remote-resource.h | 12 | ||||
-rw-r--r-- | test/iotcon-test-basic-client.c | 40 | ||||
-rw-r--r-- | test/iotcon-test-device-client.c | 41 | ||||
-rw-r--r-- | test/iotcon-test-encap-client.c | 32 | ||||
-rw-r--r-- | test/iotcon-test-iface-client.c | 30 |
12 files changed, 223 insertions, 142 deletions
diff --git a/doc/iotcon_doc.h b/doc/iotcon_doc.h index 27eeebd..07af2b1 100644 --- a/doc/iotcon_doc.h +++ b/doc/iotcon_doc.h @@ -181,7 +181,7 @@ static void _on_response_get(iotcon_remote_resource_h resource, iotcon_error_e e // handle get from response } ... -static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, +static bool _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data) { int ret; @@ -194,49 +194,50 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re iotcon_remote_resource_h resource_clone = NULL; if (IOTCON_ERROR_NONE != result) - return; + return IOTCON_FUNC_STOP; ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path); if (IOTCON_ERROR_NONE != ret) - return; + return IOTCON_FUNC_CONTINUE; ret = iotcon_remote_resource_get_device_id(resource, &device_id); if (IOTCON_ERROR_NONE != ret) - return; + return IOTCON_FUNC_CONTINUE; ret = iotcon_remote_resource_get_host_address(resource, &resource_host); if (IOTCON_ERROR_NONE != ret) - return; + return IOTCON_FUNC_CONTINUE; ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces); if (IOTCON_ERROR_NONE != ret) - return; + return IOTCON_FUNC_CONTINUE; ret = iotcon_remote_resource_get_types(resource, &resource_types); if (IOTCON_ERROR_NONE != ret) - return; + return IOTCON_FUNC_CONTINUE; ret = iotcon_query_create(&query); if (IOTCON_ERROR_NONE != ret) - return; + return IOTCON_FUNC_CONTINUE; ret = iotcon_query_add(query, "key", "value"); if (IOTCON_ERROR_NONE != ret) - return; + return IOTCON_FUNC_CONTINUE; ret = iotcon_remote_resource_clone(resource, &resource_clone); if (IOTCON_ERROR_NONE != ret) { iotcon_query_destroy(query); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_remote_resource_get(resource_clone, query, _on_response_get, NULL); if (IOTCON_ERROR_NONE != ret) { iotcon_query_destroy(query); - return; + return IOTCON_FUNC_CONTINUE; } iotcon_query_destroy(query); + return IOTCON_FUNC_CONTINUE; } ... { diff --git a/lib/icl-ioty-ocprocess.c b/lib/icl-ioty-ocprocess.c index 92df4aa..9b60d8d 100644 --- a/lib/icl-ioty-ocprocess.c +++ b/lib/icl-ioty-ocprocess.c @@ -129,26 +129,64 @@ void* icl_ioty_ocprocess_thread(void *data) return NULL; } - static gboolean _icl_ioty_ocprocess_find_idle_cb(gpointer p) { int i; - icl_find_cb_s *cb_data = p; + icl_cb_s *cb_data; + icl_find_cb_s *find_cb_data = p; + iotcon_found_resource_cb cb; + + RETV_IF(NULL == find_cb_data, G_SOURCE_REMOVE); + cb_data = find_cb_data->cb_data; + + if (cb_data && cb_data->cb) { + for (i = 0; i < find_cb_data->resource_count; i++) { + find_cb_data->resource_list[i]->is_found = true; + cb = (iotcon_found_resource_cb)cb_data->cb; + if (IOTCON_FUNC_STOP == cb(find_cb_data->resource_list[i], IOTCON_ERROR_NONE, + cb_data->user_data)) { /* Stop */ + INFO("Stop the callback"); + cb_data->cb = NULL; + + ic_utils_mutex_lock(IC_UTILS_MUTEX_IOTY); + OCCancel(cb_data->handle, OC_LOW_QOS, NULL, 0); + ic_utils_mutex_unlock(IC_UTILS_MUTEX_IOTY); + + break; + } + } + } + icl_destroy_find_cb_data(find_cb_data); + return G_SOURCE_REMOVE; +} + +static gboolean _icl_ioty_ocprocess_fail_idle_cb(gpointer p) +{ + FN_CALL; + icl_cb_s *cb_data = p; RETV_IF(NULL == cb_data, G_SOURCE_REMOVE); if (cb_data->cb) { - for (i = 0; i < cb_data->resource_count; i++) { - cb_data->resource_list[i]->is_found = true; - cb_data->cb(cb_data->resource_list[i], IOTCON_ERROR_NONE, cb_data->user_data); + switch (cb_data->op) { + case ICL_FIND_RESOURCE: + ((iotcon_found_resource_cb)cb_data->cb)(NULL, cb_data->result, cb_data->user_data); + break; + case ICL_GET_DEVICE_INFO: + ((iotcon_device_info_cb)cb_data->cb)(NULL, cb_data->result, cb_data->user_data); + break; + case ICL_GET_PLATFORM_INFO: + ((iotcon_platform_info_cb)cb_data->cb)(NULL, cb_data->result, cb_data->user_data); + break; + default: + ERR("Invalid operation(%d)", cb_data->op); + return G_SOURCE_REMOVE; } } - - icl_destroy_find_cb_data(cb_data); - return G_SOURCE_REMOVE; } + OCStackApplicationResult icl_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle, OCClientResponse *resp) { @@ -169,17 +207,16 @@ OCStackApplicationResult icl_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle (OCDiscoveryPayload*)resp->payload, &resource_list, &resource_count); if (IOTCON_ERROR_NONE != ret) { ERR("_icl_ioty_ocprocess_parse_find_payload() Fail(%d)", ret); - if (cb_data->cb) - ((iotcon_found_resource_cb)cb_data->cb)(NULL, ret, cb_data->user_data); + cb_data->result = ret; + g_idle_add(_icl_ioty_ocprocess_fail_idle_cb, cb_data); return OC_STACK_KEEP_TRANSACTION; } - cb_data->found = true; ret = icl_create_find_cb_data(cb_data, resource_list, resource_count, &find_cb_data); if (IOTCON_ERROR_NONE != ret) { ERR("icl_create_find_cb_data() Fail(%d)", ret); - if (cb_data->cb) - ((iotcon_found_resource_cb)cb_data->cb)(NULL, ret, cb_data->user_data); + cb_data->result = ret; + g_idle_add(_icl_ioty_ocprocess_fail_idle_cb, cb_data); return OC_STACK_KEEP_TRANSACTION; } @@ -192,15 +229,26 @@ OCStackApplicationResult icl_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle static gboolean _icl_ioty_ocprocess_device_info_idle_cb(gpointer p) { - icl_device_cb_s *cb_data = p; - - RETV_IF(NULL == cb_data, G_SOURCE_REMOVE); - - if (cb_data->cb) - cb_data->cb(cb_data->device_info, IOTCON_ERROR_NONE, cb_data->user_data); - - icl_destroy_device_cb_data(cb_data); + icl_cb_s *cb_data; + icl_device_cb_s *device_cb_data = p; + iotcon_device_info_cb cb; + + RETV_IF(NULL == device_cb_data, G_SOURCE_REMOVE); + cb_data = device_cb_data->cb_data; + + if (cb_data && cb_data->cb) { + cb = (iotcon_device_info_cb)cb_data->cb; + if (IOTCON_FUNC_STOP == cb(device_cb_data->device_info, IOTCON_ERROR_NONE, + cb_data->user_data)) { /* Stop */ + cb_data->cb = NULL; + + ic_utils_mutex_lock(IC_UTILS_MUTEX_IOTY); + OCCancel(cb_data->handle, OC_LOW_QOS, NULL, 0); + ic_utils_mutex_unlock(IC_UTILS_MUTEX_IOTY); + } + } + icl_destroy_device_cb_data(device_cb_data); return G_SOURCE_REMOVE; } @@ -228,17 +276,16 @@ OCStackApplicationResult icl_ioty_ocprocess_device_info_cb(void *ctx, &info); if (IOTCON_ERROR_NONE != ret) { ERR("icl_ioty_parse_oic_device_payload() Fail(%d)", ret); - if (cb_data->cb) - ((iotcon_device_info_cb)cb_data->cb)(NULL, ret, cb_data->user_data); + cb_data->result = ret; + g_idle_add(_icl_ioty_ocprocess_fail_idle_cb, cb_data); return OC_STACK_KEEP_TRANSACTION; } - cb_data->found = true; ret = icl_create_device_cb_data(cb_data, info, &device_cb_data); if (IOTCON_ERROR_NONE != ret) { ERR("icl_create_device_cb_data() Fail(%d)", ret); - if (cb_data->cb) - ((iotcon_device_info_cb)cb_data->cb)(NULL, ret, cb_data->user_data); + cb_data->result = ret; + g_idle_add(_icl_ioty_ocprocess_fail_idle_cb, cb_data); return OC_STACK_KEEP_TRANSACTION; } @@ -251,15 +298,26 @@ OCStackApplicationResult icl_ioty_ocprocess_device_info_cb(void *ctx, static gboolean _icl_ioty_ocprocess_platform_info_idle_cb(gpointer p) { - icl_platform_cb_s *cb_data = p; - - RETV_IF(NULL == cb_data, G_SOURCE_REMOVE); - - if (cb_data->cb) - cb_data->cb(cb_data->platform_info, IOTCON_ERROR_NONE, cb_data->user_data); - - icl_destroy_platform_cb_data(cb_data); + icl_cb_s *cb_data; + icl_platform_cb_s *platform_cb_data = p; + iotcon_platform_info_cb cb; + + RETV_IF(NULL == platform_cb_data, G_SOURCE_REMOVE); + cb_data = platform_cb_data->cb_data; + + if (cb_data && cb_data->cb) { + cb = (iotcon_platform_info_cb)cb_data->cb; + if (IOTCON_FUNC_STOP == cb(platform_cb_data->platform_info, IOTCON_ERROR_NONE, + cb_data->user_data)) { /* Stop */ + cb_data->cb = NULL; + + ic_utils_mutex_lock(IC_UTILS_MUTEX_IOTY); + OCCancel(cb_data->handle, OC_LOW_QOS, NULL, 0); + ic_utils_mutex_unlock(IC_UTILS_MUTEX_IOTY); + } + } + icl_destroy_platform_cb_data(platform_cb_data); return G_SOURCE_REMOVE; } @@ -287,17 +345,16 @@ OCStackApplicationResult icl_ioty_ocprocess_platform_info_cb(void *ctx, &info); if (IOTCON_ERROR_NONE != ret) { ERR("icl_ioty_parse_oic_platform_payload() Fail(%d)", ret); - if (cb_data->cb) - ((iotcon_platform_info_cb)cb_data->cb)(NULL, ret, cb_data->user_data); + cb_data->result = ret; + g_idle_add(_icl_ioty_ocprocess_fail_idle_cb, cb_data); return OC_STACK_KEEP_TRANSACTION; } - cb_data->found = true; ret = icl_create_platform_cb_data(cb_data, info, &platform_cb_data); if (IOTCON_ERROR_NONE != ret) { ERR("icl_create_platform_cb_data() Fail(%d)", ret); - if (cb_data->cb) - ((iotcon_platform_info_cb)cb_data->cb)(NULL, ret, cb_data->user_data); + cb_data->result = ret; + g_idle_add(_icl_ioty_ocprocess_fail_idle_cb, cb_data); return OC_STACK_KEEP_TRANSACTION; } diff --git a/lib/icl-ioty.c b/lib/icl-ioty.c index 0bae741..21295cc 100644 --- a/lib/icl-ioty.c +++ b/lib/icl-ioty.c @@ -149,7 +149,7 @@ static gboolean _icl_ioty_timeout(gpointer user_data) RETV_IF(NULL == cb_info, G_SOURCE_REMOVE); cb_info->timeout = 0; - if (false == cb_info->found && cb_info->cb) { + if (cb_info->cb) { switch (cb_info->op) { case ICL_FIND_RESOURCE: ((iotcon_found_resource_cb)cb_info->cb)(NULL, IOTCON_ERROR_TIMEOUT, @@ -172,6 +172,7 @@ static gboolean _icl_ioty_timeout(gpointer user_data) ic_utils_mutex_lock(IC_UTILS_MUTEX_IOTY); ret = OCCancel(cb_info->handle, OC_LOW_QOS, NULL, 0); ic_utils_mutex_unlock(IC_UTILS_MUTEX_IOTY); + if (OC_STACK_OK != ret) { ERR("OCCancel() Fail(%d)", ret); return G_SOURCE_REMOVE; @@ -180,15 +181,23 @@ static gboolean _icl_ioty_timeout(gpointer user_data) return G_SOURCE_REMOVE; } +static gboolean _icl_ioty_free_cb_data_idle_cb(gpointer p) +{ + icl_cb_s *cb_info = p; + free(cb_info); + return G_SOURCE_REMOVE; +} + static void _icl_ioty_free_cb_data(void *data) { icl_cb_s *cb_info = data; RET_IF(NULL == cb_info); - if (cb_info->timeout) + if (cb_info->timeout) { g_source_remove(cb_info->timeout); - - free(cb_info); + cb_info->timeout = 0; + } + g_idle_add(_icl_ioty_free_cb_data_idle_cb, cb_info); } int icl_ioty_find_resource(const char *host_address, diff --git a/lib/icl-ioty.h b/lib/icl-ioty.h index dd590a5..d34ccf5 100644 --- a/lib/icl-ioty.h +++ b/lib/icl-ioty.h @@ -34,7 +34,7 @@ typedef struct { icl_operation_e op; void *cb; void *user_data; - bool found; + int result; int timeout; OCDoHandle handle; } icl_cb_s; diff --git a/lib/icl-types.c b/lib/icl-types.c index 1b14523..e6929c4 100644 --- a/lib/icl-types.c +++ b/lib/icl-types.c @@ -55,8 +55,7 @@ int icl_create_find_cb_data(icl_cb_s *cb_data, return IOTCON_ERROR_OUT_OF_MEMORY; } - cd->cb = (iotcon_found_resource_cb)cb_data->cb; - cd->user_data = cb_data->user_data; + cd->cb_data = cb_data; cd->resource_list = resource_list; cd->resource_count = resource_count; @@ -94,8 +93,7 @@ int icl_create_device_cb_data(icl_cb_s *cb_data, ERR("calloc() Fail(%d)", errno); return IOTCON_ERROR_OUT_OF_MEMORY; } - cd->cb = (iotcon_device_info_cb)cb_data->cb; - cd->user_data = cb_data->user_data; + cd->cb_data = cb_data; cd->device_info = device_info; *dev_cb_data = cd; @@ -139,8 +137,7 @@ int icl_create_platform_cb_data(icl_cb_s *cb_data, ERR("calloc() Fail(%d)", errno); return IOTCON_ERROR_OUT_OF_MEMORY; } - cd->cb = (iotcon_platform_info_cb)cb_data->cb; - cd->user_data = cb_data->user_data; + cd->cb_data = cb_data; cd->platform_info = platform_info; *platform_cb_data = cd; diff --git a/lib/icl-types.h b/lib/icl-types.h index 3aaac16..b61b29b 100644 --- a/lib/icl-types.h +++ b/lib/icl-types.h @@ -23,21 +23,18 @@ #include "icl-ioty.h" typedef struct { - iotcon_found_resource_cb cb; - void *user_data; + icl_cb_s *cb_data; iotcon_remote_resource_h *resource_list; int resource_count; } icl_find_cb_s; typedef struct { - iotcon_platform_info_cb cb; - void *user_data; + icl_cb_s *cb_data; iotcon_platform_info_h platform_info; } icl_platform_cb_s; typedef struct { - iotcon_device_info_cb cb; - void *user_data; + icl_cb_s *cb_data; iotcon_device_info_h device_info; } icl_device_cb_s; diff --git a/lib/include/iotcon-client.h b/lib/include/iotcon-client.h index 7e83c62..7e8b1d6 100644 --- a/lib/include/iotcon-client.h +++ b/lib/include/iotcon-client.h @@ -336,11 +336,14 @@ int iotcon_presence_response_get_resource_type(iotcon_presence_response_h respon * @param[in] result The result code (Lesser than 0 on fail, otherwise a response result value) * @param[in] user_data The user data to pass to the function * + * @return true to continue to find resource, otherwise false to stop. \n + * #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP are more friendly values for the return. + * * @pre The callback must be registered using iotcon_find_resource() * * @see iotcon_find_resource() */ -typedef void (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource, +typedef bool (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data); /** @@ -395,12 +398,15 @@ int iotcon_find_resource(const char *host_address, * @param[in] result The result code (0 on success, other wise a negative error value) * @param[in] user_data The user data to pass to the function * + * @return true to continue to find device information, otherwise false to stop. \n + * #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP are more friendly values for the return. + * * @pre iotcon_find_device_info() will invoke this callback function. * * @see iotcon_find_device_info() * @see iotcon_device_info_get_property() */ -typedef void (*iotcon_device_info_cb)(iotcon_device_info_h device_info, +typedef bool (*iotcon_device_info_cb)(iotcon_device_info_h device_info, iotcon_error_e result, void *user_data); /** @@ -473,12 +479,15 @@ int iotcon_device_info_get_property(iotcon_device_info_h device_info, * @param[in] result The result code (0 on success, other wise a negative error value) * @param[in] user_data The user data to pass to the function * + * @return true to continue to find platform information, otherwise false to stop. \n + * #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP are more friendly values for the return. + * * @pre iotcon_find_platform_info() will invoke this callback function. * * @see iotcon_find_platform_info() * @see iotcon_platform_info_get_property() */ -typedef void (*iotcon_platform_info_cb)(iotcon_platform_info_h platform_info, +typedef bool (*iotcon_platform_info_cb)(iotcon_platform_info_h platform_info, iotcon_error_e result, void *user_data); /** diff --git a/lib/include/iotcon-remote-resource.h b/lib/include/iotcon-remote-resource.h index 62f4a5b..505a67d 100644 --- a/lib/include/iotcon-remote-resource.h +++ b/lib/include/iotcon-remote-resource.h @@ -49,31 +49,33 @@ static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err, ... } -static void _on_find(iotcon_remote_resource_h resource, iotcon_error_e result, +static bool _on_find(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data) { int ret; iotcon_remote_resource_h resource_clone = NULL; if (IOTCON_ERROR_NONE != result) - return; + return IOTCON_FUNC_STOP; if (NULL == resource) - return; + return IOTCON_FUNC_CONTINUE; // clone handle ret = iotcon_remote_resource_clone(resource, &resource_clone); if (IOTCON_ERROR_NONE != ret) - return; + return IOTCON_FUNC_CONTINUE; // request get ret = iotcon_remote_resource_get(resource_clone, NULL, _on_get, NULL); if (IOTCON_ERROR_NONE != ret) { iotcon_remote_resource_destroy(resource_clone); - return; + return IOTCON_FUNC_CONTINUE; } ... + + return IOTCON_FUNC_CONTINUE; } static void _find_light_resource() diff --git a/test/iotcon-test-basic-client.c b/test/iotcon-test-basic-client.c index 1518fed..b46afa9 100644 --- a/test/iotcon-test-basic-client.c +++ b/test/iotcon-test-basic-client.c @@ -413,7 +413,7 @@ static void _on_response(iotcon_remote_resource_h resource, iotcon_error_e err, } } -static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, +static bool _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data) { int ret; @@ -428,10 +428,10 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re iotcon_connectivity_type_e connectivity_type; iotcon_remote_resource_h resource_clone = NULL; - RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result(%d)", result); + RETVM_IF(IOTCON_ERROR_NONE != result, IOTCON_FUNC_STOP, "Invalid result(%d)", result); if (NULL == resource) - return; + return IOTCON_FUNC_CONTINUE; INFO("===== resource found ====="); @@ -439,7 +439,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_remote_resource_get_uri_path() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } /* get the device unique id. @@ -447,14 +447,14 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_remote_resource_get_device_id() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id); ret = iotcon_remote_resource_get_device_name(resource, &resource_device_name); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_remote_resource_get_device_name() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } DBG("[%s] resource device name : %s", resource_uri_path, resource_device_name); @@ -463,13 +463,13 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re if (node && TEST_STR_EQUAL == strncmp(DOOR_RESOURCE_URI_PREFIX, resource_uri_path, strlen(DOOR_RESOURCE_URI_PREFIX))) { DBG("uri_path \"%s\" already found. skip !", resource_uri_path); - return; + return IOTCON_FUNC_CONTINUE; } door_resource_device_id = strdup(resource_device_id); if (NULL == door_resource_device_id) { ERR("strdup(door_resource_device_id) Fail"); - return; + return IOTCON_FUNC_CONTINUE; } device_id_list = g_list_append(device_id_list, door_resource_device_id); @@ -480,7 +480,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_host_address() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } DBG("[%s] resource host : %s", resource_uri_path, resource_host); @@ -489,7 +489,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_connectivity_type() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* get the resource interfaces */ @@ -498,7 +498,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb, @@ -507,7 +507,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* get the resource types */ @@ -516,7 +516,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_types() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb, @@ -525,7 +525,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_resource_types_foreach() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_add_presence_cb(resource_host, connectivity_type, DOOR_RESOURCE_TYPE, @@ -534,7 +534,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_add_presence_cb() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } if (TEST_STR_EQUAL == strncmp(DOOR_RESOURCE_URI_PREFIX, resource_uri_path, @@ -546,7 +546,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_clone() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_remote_resource_observe_register(resource_clone, @@ -556,7 +556,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re 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; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_query_create(&query); @@ -564,7 +564,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_query_create() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_query_add(query, "query_key", "query_value"); @@ -573,7 +573,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re iotcon_query_destroy(query); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* send GET Request */ @@ -586,6 +586,8 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); + + return IOTCON_FUNC_CONTINUE; } int main(int argc, char **argv) diff --git a/test/iotcon-test-device-client.c b/test/iotcon-test-device-client.c index b55c28f..203b7c5 100644 --- a/test/iotcon-test-device-client.c +++ b/test/iotcon-test-device-client.c @@ -19,7 +19,7 @@ #include <iotcon.h> #include "test.h" -static void _request_device_info(iotcon_device_info_h info, iotcon_error_e result, +static bool _request_device_info(iotcon_device_info_h info, iotcon_error_e result, void *user_data) { int ret; @@ -28,31 +28,31 @@ static void _request_device_info(iotcon_device_info_h info, iotcon_error_e resul char *device_id = NULL; char *data_model_ver = NULL; - RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result (%d)", result); + RETVM_IF(IOTCON_ERROR_NONE != result, IOTCON_FUNC_STOP, "Invalid result (%d)", result); ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_NAME, &device_name); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_device_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_SPEC_VER, &spec_ver); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_device_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_ID, &device_id); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_device_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_DATA_MODEL_VER, &data_model_ver); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_device_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } INFO("Get Device Info"); @@ -60,9 +60,10 @@ static void _request_device_info(iotcon_device_info_h info, iotcon_error_e resul INFO("spec_version : %s", spec_ver); INFO("device_id : %s", device_id); INFO("data_model_version : %s", data_model_ver); + return IOTCON_FUNC_CONTINUE; } -static void _request_platform_info(iotcon_platform_info_h info, iotcon_error_e result, +static bool _request_platform_info(iotcon_platform_info_h info, iotcon_error_e result, void *user_data) { int ret; @@ -78,81 +79,81 @@ static void _request_platform_info(iotcon_platform_info_h info, iotcon_error_e r char *support_url = NULL; char *system_time = NULL; - RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result (%d)", result); + RETVM_IF(IOTCON_ERROR_NONE != result, IOTCON_FUNC_CONTINUE, "Invalid result (%d)", result); ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_ID, &platform_id); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MANUF_NAME, &manuf_name); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MANUF_URL, &manuf_url); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MODEL_NUMBER, &model_number); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_DATE_OF_MANUF, &date_of_manuf); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_PLATFORM_VER, &platform_ver); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_OS_VER, &os_ver); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_HARDWARE_VER, &hardware_ver); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_FIRMWARE_VER, &firmware_ver); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_SUPPORT_URL, &support_url); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_SYSTEM_TIME, &system_time); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_platform_info_get_property() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } INFO("Get Platform Info"); @@ -167,6 +168,8 @@ static void _request_platform_info(iotcon_platform_info_h info, iotcon_error_e r INFO("firmware_ver : %s", firmware_ver); INFO("support_url : %s", support_url); INFO("system_time : %s", system_time); + + return IOTCON_FUNC_CONTINUE; } int main(int argc, char **argv) diff --git a/test/iotcon-test-encap-client.c b/test/iotcon-test-encap-client.c index 5bda770..7403eff 100644 --- a/test/iotcon-test-encap-client.c +++ b/test/iotcon-test-encap-client.c @@ -98,7 +98,7 @@ static void _representation_changed_cb(iotcon_remote_resource_h resource, } } -static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, +static bool _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data) { int ret; @@ -110,10 +110,10 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re iotcon_resource_types_h resource_types; iotcon_remote_resource_h cloned_resource; - RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result(%d)", result); + RETVM_IF(IOTCON_ERROR_NONE != result, IOTCON_FUNC_STOP, "Invalid result(%d)", result); if (NULL == resource) - return; + return IOTCON_FUNC_CONTINUE; INFO("===== resource found ====="); @@ -121,7 +121,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_remote_resource_get_uri_path() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } /* get the device unique id. @@ -129,7 +129,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_remote_resource_get_device_id() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id); @@ -138,14 +138,14 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re door_resource_device_id = strdup(resource_device_id); if (NULL == door_resource_device_id) { ERR("strdup(door_resource_device_id) Fail"); - return; + return IOTCON_FUNC_CONTINUE; } device_id_list = g_list_append(device_id_list, door_resource_device_id); if (node) { DBG("This device(%s) is already found. skip !", door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* get the resource host address */ @@ -154,7 +154,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_host_address() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } DBG("[%s] resource host : %s", resource_uri_path, resource_host); @@ -164,7 +164,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb, @@ -173,7 +173,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* get the resource types */ @@ -182,7 +182,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_types() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb, @@ -191,7 +191,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_resource_types_foreach() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_remote_resource_clone(resource, &cloned_resource); @@ -199,7 +199,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_clone() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* Start Monitoring */ @@ -209,7 +209,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_start_monitoring() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* Start Caching */ @@ -220,11 +220,13 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re iotcon_remote_resource_stop_monitoring(resource); device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } device_id_list = g_list_remove(device_id_list, door_resource_device_id); free(door_resource_device_id); + + return IOTCON_FUNC_CONTINUE; } int main(int argc, char **argv) diff --git a/test/iotcon-test-iface-client.c b/test/iotcon-test-iface-client.c index 9bab6b2..91c57d1 100644 --- a/test/iotcon-test-iface-client.c +++ b/test/iotcon-test-iface-client.c @@ -270,7 +270,7 @@ static int _device_id_compare(const void *a, const void *b) return strcmp(a, b); } -static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, +static bool _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data) { int ret; @@ -283,10 +283,10 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re iotcon_resource_types_h resource_types; iotcon_remote_resource_h cloned_resource; - RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result(%d)", result); + RETVM_IF(IOTCON_ERROR_NONE != result, IOTCON_FUNC_STOP, "Invalid result(%d)", result); if (NULL == resource) - return; + return IOTCON_FUNC_CONTINUE; INFO("===== resource found ====="); @@ -294,21 +294,21 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_remote_resource_get_uri_path() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } /* get the resource device id */ ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_remote_resource_get_device_id() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id); ret = iotcon_remote_resource_get_device_name(resource, &resource_device_name); if (IOTCON_ERROR_NONE != ret) { ERR("iotcon_remote_resource_get_device_name() Fail(%d)", ret); - return; + return IOTCON_FUNC_CONTINUE; } DBG("[%s] resource device name : %s", resource_uri_path, resource_device_name); @@ -317,13 +317,13 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re if (node && TEST_STR_EQUAL == strncmp(ROOM_RESOURCE_URI_PREFIX, resource_uri_path, strlen(ROOM_RESOURCE_URI_PREFIX))) { DBG("uri_path \"%s\" already found. skip !", resource_uri_path); - return; + return IOTCON_FUNC_CONTINUE; } room_resource_device_id = strdup(resource_device_id); if (NULL == room_resource_device_id) { ERR("strdup(room_resource_device_id) Fail"); - return; + return IOTCON_FUNC_CONTINUE; } device_id_list = g_list_append(device_id_list, room_resource_device_id); @@ -334,7 +334,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_host_address() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, room_resource_device_id); free(room_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } DBG("[%s] resource host : %s", resource_uri_path, resource_host); @@ -344,7 +344,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, room_resource_device_id); free(room_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb, @@ -353,7 +353,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, room_resource_device_id); free(room_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* get the resource types */ @@ -362,7 +362,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_get_types() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, room_resource_device_id); free(room_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb, resource_uri_path); @@ -370,7 +370,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_resource_types_foreach() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, room_resource_device_id); free(room_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } if (TEST_STR_EQUAL == strncmp(ROOM_RESOURCE_URI_PREFIX, resource_uri_path, @@ -380,7 +380,7 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re ERR("iotcon_remote_resource_clone() Fail(%d)", ret); device_id_list = g_list_remove(device_id_list, room_resource_device_id); free(room_resource_device_id); - return; + return IOTCON_FUNC_CONTINUE; } /* send GET request */ @@ -391,6 +391,8 @@ static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e re device_id_list = g_list_remove(device_id_list, room_resource_device_id); free(room_resource_device_id); + + return IOTCON_FUNC_CONTINUE; } int main(int argc, char **argv) |