From 6b6a1bd69844b96271575cb72562675928ec2503 Mon Sep 17 00:00:00 2001 From: hj kim Date: Fri, 10 Feb 2023 11:04:49 +0900 Subject: [PATCH] Separate connected app list from mc_service_t Connected App list does not have to work with request list, and since it is together, it delivers unnecessary data. Change-Id: I7d8b1155d6dc400490589fadb00f0ca3819a040d --- packaging/capi-media-controller.spec | 2 +- svc/media_controller_svc.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/packaging/capi-media-controller.spec b/packaging/capi-media-controller.spec index 854c876..ef47c5f 100644 --- a/packaging/capi-media-controller.spec +++ b/packaging/capi-media-controller.spec @@ -1,6 +1,6 @@ Name: capi-media-controller Summary: A media controller library in Tizen Native API -Version: 0.2.31 +Version: 0.2.32 Release: 1 Group: Multimedia/API License: Apache-2.0 diff --git a/svc/media_controller_svc.c b/svc/media_controller_svc.c index ad079bc..ca23970 100644 --- a/svc/media_controller_svc.c +++ b/svc/media_controller_svc.c @@ -31,6 +31,7 @@ static GMainLoop *g_mc_svc_mainloop = NULL; static int g_connection_cnt = -1; +static GList *g_connected_apps; typedef struct { int client_sock; @@ -57,7 +58,6 @@ typedef struct { typedef struct { mc_manage_queue_t *request; - GList *connected_apps; } mc_service_t; static int __mc_sys_get_uid(uid_t *uid) @@ -120,6 +120,15 @@ static void __mc_destroy_connected_apps(gpointer data) g_free(_app_data); } +static void __mc_clean_connected_apps(void) +{ + if (g_connected_apps) { + g_list_free_full(g_connected_apps, __mc_destroy_connected_apps); + + g_connected_apps = NULL; + } +} + static void __mc_destroy_request_queue(mc_manage_queue_t *data) { mc_retm_if_failed(data); @@ -203,8 +212,6 @@ static void __mc_service_deinit(mc_service_t *data) if (data->request != NULL) __mc_destroy_request_queue(data->request); - if (data->connected_apps != NULL) - g_list_free_full(data->connected_apps, __mc_destroy_connected_apps); g_free(data); } @@ -518,16 +525,14 @@ static void __mc_destroy_connected_apps_after_noti(gpointer data) static int __mc_service_app_dead_handler(int pid, void *data) { - mc_service_t *_service_data = (mc_service_t *)data; GList *found_app = NULL; mc_info("Received app_dead signal (pid : %d)", pid); - mc_retvm_if(!_service_data, AUL_R_ERROR, "data is null!"); - mc_retvm_if(!_service_data->connected_apps, AUL_R_OK, "No connected application!"); + mc_retvm_if(!g_connected_apps, AUL_R_OK, "No connected application!"); - while ((found_app = g_list_find_custom(_service_data->connected_apps, (gconstpointer)GINT_TO_POINTER(pid), + while ((found_app = g_list_find_custom(g_connected_apps, (gconstpointer)GINT_TO_POINTER(pid), __mc_compare_pid)) != NULL) { - _service_data->connected_apps = g_list_remove_link(_service_data->connected_apps, found_app); + g_connected_apps = g_list_remove_link(g_connected_apps, found_app); g_list_free_full(found_app, __mc_destroy_connected_apps_after_noti); } @@ -605,7 +610,7 @@ static gboolean __mc_service_process(gpointer data) req = (mc_service_request *) g_queue_pop_head(request_queue); - msg = __process_msg(req->req_msg, &(_service_data->connected_apps)); + msg = __process_msg(req->req_msg, &g_connected_apps); if (write(req->client_sock, &msg, sizeof(msg)) != sizeof(msg)) mc_stderror("send failed"); @@ -773,13 +778,9 @@ gpointer mc_svc_thread(gpointer data) return NULL; } - /* Init data */ - __mc_service_init(&mc_service_data); - /* Register app_dead signal handler */ - if (aul_listen_app_dead_signal(__mc_service_app_dead_handler, mc_service_data) != AUL_R_OK) { + if (aul_listen_app_dead_signal(__mc_service_app_dead_handler, NULL) != AUL_R_OK) { mc_error("Failed to register app_dead signal"); - __mc_service_deinit(mc_service_data); close(sockfd); return NULL; } @@ -797,6 +798,9 @@ gpointer mc_svc_thread(gpointer data) channel = g_io_channel_unix_new(sockfd); source = g_io_create_watch(channel, G_IO_IN); + /* Init data */ + __mc_service_init(&mc_service_data); + /* Set callback to be called when socket is readable */ g_source_set_callback(source, (GSourceFunc)__mc_read_service_request_tcp_socket, mc_service_data, NULL); g_source_attach(source, context); @@ -816,6 +820,7 @@ gpointer mc_svc_thread(gpointer data) mc_error("Failed to unregister app_dead signal"); __mc_service_deinit(mc_service_data); + __mc_clean_connected_apps(); /* Free resources */ g_io_channel_shutdown(channel, FALSE, NULL); -- 2.7.4