From 89120d5f429f0b1fff66a1232cc47076fd438828 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 23 Apr 2019 15:48:16 +0900 Subject: [PATCH] Fix a wrong implementation The aul_comp_context_cb function type is changed. Change-Id: I65db9de942d673a36188c992ca4b93da9f2a9411 Signed-off-by: Hwankyu Jhun --- include/aul_comp_context.h | 2 +- src/aul_comp_context.c | 279 +++++++++++++++++++++------------------------ tool/compmgr_tool.c | 4 +- 3 files changed, 137 insertions(+), 148 deletions(-) diff --git a/include/aul_comp_context.h b/include/aul_comp_context.h index b12514c..c0c9668 100644 --- a/include/aul_comp_context.h +++ b/include/aul_comp_context.h @@ -42,7 +42,7 @@ typedef struct aul_comp_context_s *aul_comp_context_h; * otherwise @ false to break out of the loop * @see aul_comp_context_foreach() */ -typedef void (*aul_comp_context_cb)(aul_comp_context_h handle, void *user_data); +typedef bool (*aul_comp_context_cb)(aul_comp_context_h handle, void *user_data); /** * @brief Retrieves all running components context. diff --git a/src/aul_comp_context.c b/src/aul_comp_context.c index 9cf6912..5045bf6 100644 --- a/src/aul_comp_context.c +++ b/src/aul_comp_context.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -39,19 +40,121 @@ struct aul_comp_context_s { bool is_sub_comp; }; -struct cb_data_s { - aul_comp_context_cb callback; - void *user_data; -}; +static void __destroy_comp_context(gpointer data) +{ + struct aul_comp_context_s *context; + + context = (struct aul_comp_context_s *)data; + if (!context) + return; + + if (context->comp_id) + free(context->comp_id); + if (context->instance_id) + free(context->instance_id); + if (context->app_id) + free(context->app_id); + if (context->type) + free(context->type); + free(context); +} + +static struct aul_comp_context_s *__create_comp_context(bundle *b) +{ + struct aul_comp_context_s *context; + const char *val; + + context = calloc(1, sizeof(struct aul_comp_context_s)); + if (!context) { + _E("Out of memory"); + return NULL; + } + + val = bundle_get_val(b, AUL_K_PID); + if (!val) { + _E("Failed to get process ID"); + goto err; + } + context->pid = atoi(val); + + val = bundle_get_val(b, AUL_K_STATUS); + if (!val) { + _E("Failed to get component status"); + goto err; + } + context->status = atoi(val); + + val = bundle_get_val(b, AUL_K_IS_SUB_COMP); + if (!val) { + _E("Failed to get the flag for checking sub comp"); + goto err; + } + context->status = atoi(val); + + val = bundle_get_val(b, AUL_K_COMPONENT_ID); + if (!val) { + _E("Failed to get component ID"); + goto err; + } + + context->comp_id = strdup(val); + if (!context->comp_id) { + _E("Failed to duplicate component ID"); + goto err; + } + + val = bundle_get_val(b, AUL_K_INSTANCE_ID); + if (!val) { + _E("Failed to get instance ID"); + goto err; + } + + context->instance_id = strdup(val); + if (!context->instance_id) { + _E("Failed to duplicate instance ID"); + goto err; + } + + val = bundle_get_val(b, AUL_K_APPID); + if (!val) { + _E("Failed to get application ID"); + goto err; + } + + context->app_id = strdup(val); + if (!context->app_id) { + _E("Failed to duplicate application ID"); + goto err; + } + + val = bundle_get_val(b, AUL_K_COMPONENT_TYPE); + if (!val) { + _E("Failed to get component type"); + goto err; + } + + context->type = strdup(val); + if (!context->type) { + _E("Failed to duplicate component type"); + goto err; + } + + return context; + +err: + if (context) + __destroy_comp_context(context); + + return NULL; +} static void __running_context_cb(app_pkt_t *pkt, void *user_data) { - struct cb_data_s *cb_data = (struct cb_data_s *)user_data; - struct aul_comp_context_s context = { 0, }; + GList **list = (GList **)user_data; + struct aul_comp_context_s *context; bundle *b = NULL; - const char *val; - if (!pkt || !cb_data) { + if (!pkt) { _E("Invalid parameter"); return; } @@ -67,43 +170,22 @@ static void __running_context_cb(app_pkt_t *pkt, void *user_data) if (!b) return; - val = bundle_get_val(b, AUL_K_PID); - if (!val) { - bundle_free(b); - return; - } - context.pid = atoi(val); - - val = bundle_get_val(b, AUL_K_STATUS); - if (!val) { - bundle_free(b); - return; - } - context.status = atoi(val); - - val = bundle_get_val(b, AUL_K_IS_SUB_COMP); - if (!val) { + context = __create_comp_context(b); + if (!context) { bundle_free(b); return; } - context.is_sub_comp = atoi(val); - - bundle_get_str(b, AUL_K_COMPONENT_ID, &context.comp_id); - bundle_get_str(b, AUL_K_INSTANCE_ID, &context.instance_id); - bundle_get_str(b, AUL_K_APPID, &context.app_id); - bundle_get_str(b, AUL_K_COMPONENT_TYPE, &context.type); - - cb_data->callback(&context, cb_data->user_data); bundle_free(b); + + *list = g_list_append(*list, context); } API int aul_comp_context_foreach(aul_comp_context_cb callback, void *user_data) { - struct cb_data_s cb_data = { - callback, - user_data - }; + struct aul_comp_context_s *context; + GList *list = NULL; + GList *iter; char buf[32]; bundle *b; int ret; @@ -129,9 +211,22 @@ API int aul_comp_context_foreach(aul_comp_context_cb callback, if (fd < 0) return aul_error_convert(fd); - ret = aul_sock_recv_pkt_with_cb(fd, __running_context_cb, &cb_data); - if (ret < 0) + ret = aul_sock_recv_pkt_with_cb(fd, __running_context_cb, &list); + if (ret < 0) { + g_list_free_full(list, __destroy_comp_context); return aul_error_convert(ret); + } + + iter = list; + while (iter) { + context = (struct aul_comp_context_s *)iter->data; + iter = g_list_next(iter); + + if (!callback(context, user_data)) + break; + } + + g_list_free_full(list, __destroy_comp_context); return AUL_R_OK; } @@ -227,114 +322,6 @@ API int aul_comp_context_is_sub_comp(aul_comp_context_h context, return AUL_R_OK; } -static void __destroy_comp_context(aul_comp_context_h handle) -{ - struct aul_comp_context_s *context; - - context = (struct aul_comp_context_s *)handle; - if (!context) - return; - - if (context->comp_id) - free(context->comp_id); - if (context->instance_id) - free(context->instance_id); - if (context->app_id) - free(context->app_id); - if (context->type) - free(context->type); - free(context); -} - -static struct aul_comp_context_s *__create_comp_context(bundle *b) -{ - struct aul_comp_context_s *context; - const char *val; - - context = calloc(1, sizeof(struct aul_comp_context_s)); - if (!context) { - _E("Out of memory"); - return NULL; - } - - val = bundle_get_val(b, AUL_K_PID); - if (!val) { - _E("Failed to get process ID"); - goto err; - } - context->pid = atoi(val); - - val = bundle_get_val(b, AUL_K_STATUS); - if (!val) { - _E("Failed to get component status"); - goto err; - } - context->status = atoi(val); - - val = bundle_get_val(b, AUL_K_IS_SUB_COMP); - if (!val) { - _E("Failed to get the flag for checking sub comp"); - goto err; - } - context->status = atoi(val); - - val = bundle_get_val(b, AUL_K_COMPONENT_ID); - if (!val) { - _E("Failed to get component ID"); - goto err; - } - - context->comp_id = strdup(val); - if (!context->comp_id) { - _E("Failed to duplicate component ID"); - goto err; - } - - val = bundle_get_val(b, AUL_K_INSTANCE_ID); - if (!val) { - _E("Failed to get instance ID"); - goto err; - } - - context->instance_id = strdup(val); - if (!context->instance_id) { - _E("Failed to duplicate instance ID"); - goto err; - } - - val = bundle_get_val(b, AUL_K_APPID); - if (!val) { - _E("Failed to get application ID"); - goto err; - } - - context->app_id = strdup(val); - if (!context->app_id) { - _E("Failed to duplicate application ID"); - goto err; - } - - val = bundle_get_val(b, AUL_K_COMPONENT_TYPE); - if (!val) { - _E("Failed to get component type"); - goto err; - } - - context->type = strdup(val); - if (!context->type) { - _E("Failed to duplicate component type"); - goto err; - } - - return context; - -err: - if (context) - __destroy_comp_context(context); - - return NULL; -} - API int aul_comp_context_create(const char *comp_id, aul_comp_context_h *handle) { return aul_comp_context_create_usr(comp_id, getuid(), handle); diff --git a/tool/compmgr_tool.c b/tool/compmgr_tool.c index d413f57..e4a824d 100644 --- a/tool/compmgr_tool.c +++ b/tool/compmgr_tool.c @@ -317,7 +317,7 @@ static const char *__get_status_string(int status) } } -static void __comp_context_cb(aul_comp_context_h handle, void *user_data) +static bool __comp_context_cb(aul_comp_context_h handle, void *user_data) { int *member_count = (int *)user_data; const char *app_id = NULL; @@ -346,6 +346,8 @@ static void __comp_context_cb(aul_comp_context_h handle, void *user_data) printf(" - Process ID : %d\n", pid); printf(" - Status : %s\n", __get_status_string(status)); printf(" - Sub Component : %s\n", is_sub_comp ? "true" : "false"); + + return true; } static int __cmd_running_list_run(void *data) -- 2.7.4