Callback info handling when unregister local port 78/86378/2 accepted/tizen/common/20160902.141314 accepted/tizen/ivi/20160905.042207 accepted/tizen/mobile/20160905.042117 accepted/tizen/tv/20160905.042131 accepted/tizen/wearable/20160905.042152 submit/tizen/20160902.035501
authorHyunho Kang <hhstark.kang@samsung.com>
Thu, 1 Sep 2016 02:29:31 +0000 (11:29 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Thu, 1 Sep 2016 09:05:04 +0000 (18:05 +0900)
Change-Id: Ibc107928c837f6cd997ab863faa781a4dcd5e344
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/message-port.c

index a5fa9a02cc4b9a6daea104658f2370ddbf46414a..15f94be2ee77b96d48fac00213990db7d1b5f987 100755 (executable)
 } 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;