From 21765bc9d9ea974023a9f8c89eb5f2f3ec4afad4 Mon Sep 17 00:00:00 2001 From: "sung.goo.kim" Date: Mon, 2 Nov 2015 15:20:25 +0900 Subject: [PATCH] (ACR) Apply comments about xxx_foreach API Change-Id: I9b3f38b89d48f4a09645f8542a0b26dd8c1e23ce --- lib/icl-options.c | 2 +- lib/icl-query.c | 2 +- lib/icl-remote-resource.c | 2 +- lib/include/iotcon-constant.h | 6 +++-- lib/include/iotcon-list.h | 54 +++++++++++++++++-------------------- lib/include/iotcon-options.h | 12 ++++----- lib/include/iotcon-query.h | 12 ++++----- lib/include/iotcon-representation.h | 6 ++--- lib/include/iotcon-resource-types.h | 12 ++++----- lib/include/iotcon-state.h | 9 +++---- test/iotcon-test-basic-client.c | 2 +- test/iotcon-test-basic-server.c | 2 +- test/iotcon-test-encap-client.c | 2 +- test/iotcon-test-repr-client.c | 6 ++--- 14 files changed, 62 insertions(+), 67 deletions(-) diff --git a/lib/icl-options.c b/lib/icl-options.c index bd1ef0f..1a569d1 100644 --- a/lib/icl-options.c +++ b/lib/icl-options.c @@ -172,7 +172,7 @@ API int iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_ g_hash_table_iter_init(&iter, options->hash); while (g_hash_table_iter_next(&iter, &key, &value)) { - if (false == cb(GPOINTER_TO_UINT(key), value, user_data)) + if (IOTCON_FUNC_STOP == cb(GPOINTER_TO_UINT(key), value, user_data)) break; } diff --git a/lib/icl-query.c b/lib/icl-query.c index 75aec57..c3a6f1d 100644 --- a/lib/icl-query.c +++ b/lib/icl-query.c @@ -248,7 +248,7 @@ API int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb, g_hash_table_iter_init(&iter, query->hash); while (g_hash_table_iter_next(&iter, &key, &value)) { - if (false == cb(key, value, user_data)) + if (IOTCON_FUNC_STOP == cb(key, value, user_data)) break; } diff --git a/lib/icl-remote-resource.c b/lib/icl-remote-resource.c index 74dc44e..4206a06 100644 --- a/lib/icl-remote-resource.c +++ b/lib/icl-remote-resource.c @@ -221,7 +221,7 @@ API void iotcon_remote_resource_destroy(iotcon_remote_resource_h resource) free(resource); } -static int _icl_remote_resource_header_foreach_cb(unsigned short id, +static bool _icl_remote_resource_header_foreach_cb(unsigned short id, const char *data, void *user_data) { int ret; diff --git a/lib/include/iotcon-constant.h b/lib/include/iotcon-constant.h index fa73aa8..9738b81 100644 --- a/lib/include/iotcon-constant.h +++ b/lib/include/iotcon-constant.h @@ -16,6 +16,8 @@ #ifndef __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__ #define __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__ +#include + /** * @file iotcon-constant.h */ @@ -215,14 +217,14 @@ typedef struct icl_state_s* iotcon_state_h; * * @since_tizen 3.0 */ -#define IOTCON_FUNC_STOP 0 +#define IOTCON_FUNC_STOP false /** * @brief Use this value as the return value to continue foreach function. * * @since_tizen 3.0 */ -#define IOTCON_FUNC_CONTINUE 1 +#define IOTCON_FUNC_CONTINUE true /** * @brief Enumeration for action of observation. diff --git a/lib/include/iotcon-list.h b/lib/include/iotcon-list.h index d49d811..bf1c4d7 100644 --- a/lib/include/iotcon-list.h +++ b/lib/include/iotcon-list.h @@ -349,16 +349,15 @@ int iotcon_list_get_length(iotcon_list_h list, unsigned int *length); * @param[in] value The integer value * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_list_foreach_int() will invoke this callback function. * * @see iotcon_list_foreach_int() */ -typedef int (*iotcon_list_int_cb)(int pos, int value, void *user_data); +typedef bool (*iotcon_list_int_cb)(int pos, int value, void *user_data); /** * @brief Gets all integer values of the given list by invoking the callback function. @@ -389,16 +388,15 @@ int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_cb cb, void *use * @param[in] value The boolean value * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_list_foreach_bool() will invoke this callback function. * * @see iotcon_list_foreach_bool() */ -typedef int (*iotcon_list_bool_cb)(int pos, bool value, void *user_data); +typedef bool (*iotcon_list_bool_cb)(int pos, bool value, void *user_data); /** * @brief Gets all boolean values of the given list by invoking the callback function. @@ -429,16 +427,15 @@ int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_cb cb, void *u * @param[in] value The double value * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_list_foreach_double() will invoke this callback function. * * @see iotcon_list_foreach_double() */ -typedef int (*iotcon_list_double_cb)(int pos, double value, void *user_data); +typedef bool (*iotcon_list_double_cb)(int pos, double value, void *user_data); /** * @brief Gets all double values of the given list by invoking the callback function. @@ -470,16 +467,15 @@ int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_cb cb, * @param[in] value The string value * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_list_foreach_str() will invoke this callback function. * * @see iotcon_list_foreach_str() */ -typedef int (*iotcon_list_str_cb)(int pos, const char *value, void *user_data); +typedef bool (*iotcon_list_str_cb)(int pos, const char *value, void *user_data); /** * @brief Gets all string values of the given list by invoking the callback function. @@ -510,16 +506,15 @@ int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_cb cb, void *use * @param[in] value The list value * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_list_foreach_list() will invoke this callback function. * * @see iotcon_list_foreach_list() */ -typedef int (*iotcon_list_list_cb)(int pos, iotcon_list_h value, void *user_data); +typedef bool (*iotcon_list_list_cb)(int pos, iotcon_list_h value, void *user_data); /** * @brief Gets all sub lists of the given list by invoking the callback function. @@ -550,16 +545,15 @@ int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb, void *u * @param[in] value The state value * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_list_foreach_state() will invoke this callback function. * * @see iotcon_list_foreach_state() */ -typedef int (*iotcon_list_state_cb)(int pos, iotcon_state_h value, void *user_data); +typedef bool (*iotcon_list_state_cb)(int pos, iotcon_state_h value, void *user_data); /** * @brief Gets all state of the given list by invoking the callback function. diff --git a/lib/include/iotcon-options.h b/lib/include/iotcon-options.h index 786c0d5..e69eda4 100644 --- a/lib/include/iotcon-options.h +++ b/lib/include/iotcon-options.h @@ -16,6 +16,7 @@ #ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_OPTIONS_H__ #define __IOT_CONNECTIVITY_MANAGER_STRUCT_OPTIONS_H__ +#include #include /** @@ -147,22 +148,21 @@ int iotcon_options_lookup(iotcon_options_h options, unsigned short id, char **da * @param[in] data The data of the option * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_options_foreach() will invoke this callback function. * * @see iotcon_options_foreach() */ -typedef int (*iotcon_options_foreach_cb)(unsigned short id, const char *data, +typedef bool (*iotcon_options_foreach_cb)(unsigned short id, const char *data, void *user_data); /** * @brief Gets all datas of the options by invoking the callback function. * @details iotcon_options_foreach_cb() will be called for each option.\n - * If iotcon_options_foreach_cb() returns #IOTCON_FUNC_STOP, iteration will be stop. + * If iotcon_options_foreach_cb() returns false, iteration will be stop. * * @since_tizen 3.0 * diff --git a/lib/include/iotcon-query.h b/lib/include/iotcon-query.h index 57db776..ac9a139 100644 --- a/lib/include/iotcon-query.h +++ b/lib/include/iotcon-query.h @@ -16,6 +16,7 @@ #ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_QUERY_H__ #define __IOT_CONNECTIVITY_MANAGER_STRUCT_QUERY_H__ +#include #include /** @@ -234,22 +235,21 @@ int iotcon_query_lookup(iotcon_query_h query, const char *key, char **data); * @param[in] value The value of the query * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_query_foreach() will invoke this callback function. * * @see iotcon_query_foreach() */ -typedef int (*iotcon_query_foreach_cb)(const char *key, const char *value, +typedef bool (*iotcon_query_foreach_cb)(const char *key, const char *value, void *user_data); /** * @brief Gets all datas of the query by invoking the callback function. * @details iotcon_query_foreach_cb() will be called for each query.\n - * If iotcon_query_foreach_cb() returns #IOTCON_FUNC_STOP, iteration will be stop. + * If iotcon_query_foreach_cb() returns false, iteration will be stop. * * @since_tizen 3.0 * diff --git a/lib/include/iotcon-representation.h b/lib/include/iotcon-representation.h index 087ba02..5167799 100644 --- a/lib/include/iotcon-representation.h +++ b/lib/include/iotcon-representation.h @@ -418,9 +418,9 @@ int iotcon_representation_remove_child(iotcon_representation_h parent, * @param[in] child The child representation handle * @param[in] user_data The user data to pass to the function * - * @return 0 on success, otherwise a negative error value. - * @retval #IOTCON_FUNC_CONTINUE Continue to iterate next child representation - * @retval #IOTCON_FUNC_STOP Stop to iterate children representation + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_representation_foreach_children() will invoke this callback function. * diff --git a/lib/include/iotcon-resource-types.h b/lib/include/iotcon-resource-types.h index 21a20cc..6b156bd 100644 --- a/lib/include/iotcon-resource-types.h +++ b/lib/include/iotcon-resource-types.h @@ -16,6 +16,7 @@ #ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_TYPES_H__ #define __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_TYPES_H__ +#include #include /** @@ -123,21 +124,20 @@ int iotcon_resource_types_remove(iotcon_resource_types_h types, const char *type * @param[in] type The value of the resource types * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_STOP stop to call next function - * @retval #IOTCON_FUNC_CONTINUE continue to call next function + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_resource_types_foreach() will invoke this callback function. * * @see iotcon_resource_types_foreach() */ -typedef int (*iotcon_resource_types_foreach_cb)(const char *type, void *user_data); +typedef bool (*iotcon_resource_types_foreach_cb)(const char *type, void *user_data); /** * @brief Gets all of the resource types of the list by invoking the callback function. * @details iotcon_resource_types_foreach_cb() will be called for each type.\n - * If iotcon_resource_types_foreach_cb() returns #IOTCON_FUNC_STOP, iteration will be stop. + * If iotcon_resource_types_foreach_cb() returns false, iteration will be stop. * * @since_tizen 3.0 * diff --git a/lib/include/iotcon-state.h b/lib/include/iotcon-state.h index e8ddcd9..164f80a 100644 --- a/lib/include/iotcon-state.h +++ b/lib/include/iotcon-state.h @@ -351,16 +351,15 @@ int iotcon_state_get_type(iotcon_state_h state, const char *key, int *type); * @param[in] key The key * @param[in] user_data The user data to pass to the function * - * @return #IOTCON_FUNC_CONTINUE to continue with the next function of the loop, - * otherwise #IOTCON_FUNC_STOP to break out of the loop - * @retval #IOTCON_FUNC_CONTINUE Continue to iterate next key - * @retval #IOTCON_FUNC_STOP Stop to iterate key + * @return true to continue with the next iteration of the loop, + * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP + * are more friendly values for the return. * * @pre iotcon_state_foreach() will invoke this callback function. * * @see iotcon_state_foreach() */ -typedef int (*iotcon_state_cb)(iotcon_state_h state, const char *key, void *user_data); +typedef bool (*iotcon_state_cb)(iotcon_state_h state, const char *key, void *user_data); /** * @brief Calls a function for each element of state. diff --git a/test/iotcon-test-basic-client.c b/test/iotcon-test-basic-client.c index c8964d0..9a46524 100644 --- a/test/iotcon-test-basic-client.c +++ b/test/iotcon-test-basic-client.c @@ -288,7 +288,7 @@ static void _on_get(iotcon_remote_resource_h resource, iotcon_representation_destroy(send_repr); } -static int _get_res_type_cb(const char *string, void *user_data) +static bool _get_res_type_cb(const char *string, void *user_data) { char *resource_uri_path = user_data; diff --git a/test/iotcon-test-basic-server.c b/test/iotcon-test-basic-server.c index f17a836..e6a7c43 100644 --- a/test/iotcon-test-basic-server.c +++ b/test/iotcon-test-basic-server.c @@ -405,7 +405,7 @@ static void _request_handler_delete(iotcon_resource_h resource, iotcon_representation_destroy(resp_repr); } -static int _query_cb(const char *key, const char *value, void *user_data) +static bool _query_cb(const char *key, const char *value, void *user_data) { INFO("key : %s, value : %s", key, value); diff --git a/test/iotcon-test-encap-client.c b/test/iotcon-test-encap-client.c index bb9b4a1..41dbc7f 100644 --- a/test/iotcon-test-encap-client.c +++ b/test/iotcon-test-encap-client.c @@ -23,7 +23,7 @@ static char *door_resource_device_id; static GList *device_id_list; -static int _get_res_type_cb(const char *string, void *user_data) +static bool _get_res_type_cb(const char *string, void *user_data) { char *resource_uri_path = user_data; diff --git a/test/iotcon-test-repr-client.c b/test/iotcon-test-repr-client.c index a505e98..6c3a3ad 100644 --- a/test/iotcon-test-repr-client.c +++ b/test/iotcon-test-repr-client.c @@ -24,9 +24,9 @@ static GList *device_id_list; static const char* const room_uri_path = "/a/room"; -static int _get_int_list_cb(int pos, const int value, void *user_data) +static bool _get_int_list_cb(int pos, const int value, void *user_data) { - DBG("%d°C", value); + DBG("%d", value); return IOTCON_FUNC_CONTINUE; } @@ -236,7 +236,7 @@ static void _on_get_1st(iotcon_remote_resource_h resource, iotcon_query_destroy(query_params); } -static int _get_res_type_fn(const char *string, void *user_data) +static bool _get_res_type_fn(const char *string, void *user_data) { char *resource_uri_path = user_data; -- 2.7.4