Fix watch on not exist name bug 98/89798/1 accepted/tizen/3.0/ivi/20161011.055307 accepted/tizen/3.0/mobile/20161015.033618 accepted/tizen/3.0/tv/20161016.005133 accepted/tizen/3.0/wearable/20161015.083515 accepted/tizen/common/20160927.152838 accepted/tizen/ivi/20160928.050352 accepted/tizen/mobile/20160928.050300 accepted/tizen/tv/20160928.050320 accepted/tizen/wearable/20160928.050337 submit/tizen/20160927.094009 submit/tizen_3.0_ivi/20161010.000005 submit/tizen_3.0_mobile/20161015.000004 submit/tizen_3.0_tv/20161015.000004 submit/tizen_3.0_wearable/20161015.000004
authorHyunho Kang <hhstark.kang@samsung.com>
Tue, 27 Sep 2016 05:31:19 +0000 (14:31 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 27 Sep 2016 05:31:59 +0000 (14:31 +0900)
Change-Id: I1a3635dfc0bee44799fdd7dfe2645c5767ee1521
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
src/message-port.c

index 2e54cff..eb86b2f 100755 (executable)
@@ -325,9 +325,19 @@ static void on_name_vanished(GDBusConnection *connection,
 {
        _LOGI("name vanished : %s", name);
        port_list_info_s *pli = (port_list_info_s *)user_data;
-       g_bus_unwatch_name(pli->watcher_id);
+       if (pli == NULL) {
+               LOGE("NULL port info");
+               return;
+       }
+
+       _LOGI("watcher_id :%d", pli->watcher_id);
+       if (pli->watcher_id > 0)
+               g_bus_unwatch_name(pli->watcher_id);
+       else
+               _LOGE("Invalid watcher_id %d", pli->watcher_id);
        pli->exist = false;
        pli->watcher_id = 0;
+
        _LOGI("name vanished socket : %d", pli->send_sock_fd);
        if (pli->send_sock_fd > 0) {
                close(pli->send_sock_fd);
@@ -407,6 +417,26 @@ out:
        return remote_app_info;
 }
 
+static void __watch_remote_port_info(port_list_info_s *port_info)
+{
+       if (port_info == NULL)
+               return;
+
+       if (port_info->watcher_id < 1) {
+               port_info->watcher_id = g_bus_watch_name_on_connection(
+                               __gdbus_conn,
+                               port_info->encoded_bus_name,
+                               G_BUS_NAME_WATCHER_FLAGS_NONE,
+                               on_name_appeared,
+                               on_name_vanished,
+                               port_info,
+                               NULL);
+       } else {
+               LOGI("Already watched port info");
+               return;
+       }
+}
+
 static int __get_remote_port_info(const char *remote_app_id, const char *remote_port, bool is_trusted,
                message_port_remote_app_info_s **mri, port_list_info_s **pli)
 {
@@ -445,17 +475,6 @@ static int __get_remote_port_info(const char *remote_app_id, const char *remote_
        } else {
                *pli = (port_list_info_s *)cb_list->data;
        }
-       if ((*pli)->watcher_id < 1) {
-               LOGI("watch remote port : %s", (*pli)->encoded_bus_name);
-               (*pli)->watcher_id = g_bus_watch_name_on_connection(
-                                       __gdbus_conn,
-                                       (*pli)->encoded_bus_name,
-                                       G_BUS_NAME_WATCHER_FLAGS_NONE,
-                                       on_name_appeared,
-                                       on_name_vanished,
-                                       *pli,
-                                       NULL);
-       }
 out:
 
        return ret_val;
@@ -960,6 +979,7 @@ static int __check_remote_port(const char *remote_app_id, const char *remote_por
                        port_info->exist = true;
                        *exist = true;
                        ret_val = MESSAGEPORT_ERROR_NONE;
+                       __watch_remote_port_info(port_info);
                }
        }
 out:
@@ -987,8 +1007,15 @@ static void __on_sender_name_vanished(GDBusConnection *connection,
        if (!remove_result)
                _LOGE("Fail to remove sender appid from hash : %s", name);
 
-       g_bus_unwatch_name(*watcher_id);
-       free(watcher_id);
+       if (watcher_id) {
+               if (*watcher_id > 0)
+                       g_bus_unwatch_name(*watcher_id);
+               else
+                       LOGE("Invalid watcher_id %d", *watcher_id);
+               free(watcher_id);
+       } else {
+               LOGE("watcher_id is NULL");
+       }
 }
 
 static bool __check_sender_validation(GVariant *parameters, const char *sender, GDBusConnection *conn)
@@ -1409,6 +1436,7 @@ static int __message_port_send_message(const char *remote_appid, const char *rem
                        goto out;
                }
        }
+       __watch_remote_port_info(port_info);
 
        if (port_info->send_sock_fd > 0) {
                ret = __message_port_send_async(port_info->send_sock_fd, message,