From 9b63c115d2a7f29a6194efabe645eb19c9685485 Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Thu, 1 Sep 2016 11:29:31 +0900 Subject: [PATCH] Callback info handling when unregister local port Change-Id: Ibc107928c837f6cd997ab863faa781a4dcd5e344 Signed-off-by: Hyunho Kang --- src/message-port.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/src/message-port.c b/src/message-port.c index a5fa9a0..15f94be 100755 --- a/src/message-port.c +++ b/src/message-port.c @@ -78,12 +78,13 @@ } while (0) static bool _initialized = false; -static GDBusConnection *__gdbus_conn = NULL; +static GDBusConnection *__gdbus_conn; static char *__app_id; -static GHashTable *__local_port_info = NULL; -static GHashTable *__remote_app_info = NULL; -static GHashTable *__sender_appid_hash = NULL; -static GHashTable *__trusted_app_list_hash = NULL; +static GHashTable *__local_port_info; +static GHashTable *__remote_app_info; +static GHashTable *__sender_appid_hash; +static GHashTable *__trusted_app_list_hash; +static GHashTable *__callback_info_hash; static const int MAX_MESSAGE_SIZE = 16 * 1024; enum __certificate_info_type { @@ -132,8 +133,9 @@ typedef struct port_list_info { bool exist; } port_list_info_s; -static void __callback_info_free(message_port_callback_info_s *callback_info) +static void __callback_info_free(gpointer data) { + message_port_callback_info_s *callback_info = (message_port_callback_info_s *)data; GError *error = NULL; if (callback_info == NULL) return; @@ -159,6 +161,31 @@ static void __callback_info_free(message_port_callback_info_s *callback_info) free(callback_info); } +static void __callback_info_free_by_info(message_port_callback_info_s *callback_info) +{ + + GList *callback_info_list = g_hash_table_lookup(__callback_info_hash, GUINT_TO_POINTER(callback_info->local_id)); + GList *find_list; + + if (callback_info_list == NULL) + return; + + find_list = g_list_find(callback_info_list, callback_info); + if (find_list == NULL) + return; + + callback_info_list = g_list_remove_link(callback_info_list, find_list); + __callback_info_free(callback_info); +} + +static void __hash_destroy_callback_info(gpointer data) +{ + + GList *callback_list = (GList *)data; + if (callback_list != NULL) + g_list_free_full(callback_list, __callback_info_free); +} + static char *__get_encoded_name(const char *remote_app_id, const char *port_name, bool is_trusted) { @@ -663,20 +690,20 @@ static gboolean __socket_request_handler(GIOChannel *gio, if (cond == G_IO_HUP) { _LOGI("socket G_IO_HUP"); - __callback_info_free(mi); + __callback_info_free_by_info(mi); return FALSE; } else { if ((fd = g_io_channel_unix_get_fd(gio)) < 0) { _LOGE("fail to get fd from io channel"); - __callback_info_free(mi); + __callback_info_free_by_info(mi); return FALSE; } if ((pkt = __message_port_recv_raw(fd)) == NULL) { _LOGE("recv error on SOCKET"); - __callback_info_free(mi); + __callback_info_free_by_info(mi); return FALSE; } @@ -715,6 +742,7 @@ static bool send_message(GVariant *parameters, GDBusMethodInvocation *invocation message_port_local_port_info_s *mi; int local_reg_id = 0; message_port_callback_info_s *callback_info; + GList *callback_info_list = NULL; char buf[1024]; GDBusMessage *msg; @@ -812,6 +840,13 @@ static bool send_message(GVariant *parameters, GDBusMethodInvocation *invocation return -1; } + callback_info_list = g_hash_table_lookup(__callback_info_hash, GUINT_TO_POINTER(mi->local_id)); + if (callback_info_list == NULL) { + callback_info_list = g_list_append(callback_info_list, callback_info); + g_hash_table_insert(__callback_info_hash, GUINT_TO_POINTER(mi->local_id), callback_info_list); + } else { + callback_info_list = g_list_append(callback_info_list, callback_info); + } } } @@ -1222,6 +1257,11 @@ static bool __initialize(void) retvm_if(!__trusted_app_list_hash, false, "fail to create __trusted_app_list_hash"); } + if (__callback_info_hash == NULL) { + __callback_info_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __hash_destroy_callback_info); + retvm_if(!__trusted_app_list_hash, false, "fail to create __trusted_app_list_hash"); + } + if (!__dbus_init()) return false; _initialized = true; @@ -1463,6 +1503,8 @@ int messageport_unregister_local_port(int local_port_id, bool trusted_port) if (mi->is_trusted != trusted_port) return MESSAGEPORT_ERROR_INVALID_PARAMETER; + g_hash_table_remove(__callback_info_hash, GUINT_TO_POINTER(local_port_id)); + bus_name = __get_encoded_name(__app_id, mi->port_name, mi->is_trusted); if (bus_name == NULL) return MESSAGEPORT_ERROR_OUT_OF_MEMORY; -- 2.7.4