summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyunho Kang <hhstark.kang@samsung.com>2016-09-27 14:31:19 +0900
committerHyunho Kang <hhstark.kang@samsung.com>2016-09-27 14:31:59 +0900
commit5879c848cf6c094cead314d184ac616e5aca9282 (patch)
tree8d29106c36ddd9700330f68e8f36dfcdf1a2a02e
parent7490bebbfd823a5d86c4ae285c3bba1555b2a6d9 (diff)
downloadmessage-port-5879c848cf6c094cead314d184ac616e5aca9282.tar.gz
message-port-5879c848cf6c094cead314d184ac616e5aca9282.tar.bz2
message-port-5879c848cf6c094cead314d184ac616e5aca9282.zip
Change-Id: I1a3635dfc0bee44799fdd7dfe2645c5767ee1521 Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
-rwxr-xr-xsrc/message-port.c56
1 files changed, 42 insertions, 14 deletions
diff --git a/src/message-port.c b/src/message-port.c
index 2e54cff..eb86b2f 100755
--- a/src/message-port.c
+++ b/src/message-port.c
@@ -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,