Fix dbus connection free 43/116343/1
authorWonnam Jang <wn.jang@samsung.com>
Fri, 24 Feb 2017 00:59:38 +0000 (09:59 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Fri, 24 Feb 2017 01:00:45 +0000 (10:00 +0900)
Change-Id: I935ce93230dd849286372ef3a5c857ace32af00d
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
client/tts_dbus.c

index e23aa59..df39b69 100644 (file)
@@ -154,6 +154,20 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
        return ECORE_CALLBACK_PASS_ON;
 }
 
+static void __tts_dbus_connection_free()
+{
+       if (NULL != g_conn_listener) {
+               dbus_connection_close(g_conn_listener);
+               dbus_connection_unref(g_conn_listener);
+               g_conn_listener = NULL;
+       }
+       if (NULL != g_conn_sender) {
+               dbus_connection_close(g_conn_sender);
+               dbus_connection_unref(g_conn_sender);
+               g_conn_sender = NULL;
+       }
+}
+
 int tts_dbus_open_connection()
 {
        if (NULL != g_conn_sender && NULL != g_conn_listener) {
@@ -188,6 +202,7 @@ int tts_dbus_open_connection()
 
        if (NULL == g_conn_listener) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] fail to get dbus connection for listener");
+               __tts_dbus_connection_free();
                return TTS_ERROR_OPERATION_FAILED;
        }
 
@@ -201,6 +216,7 @@ int tts_dbus_open_connection()
        int fd = 0;
        if (true != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
                SLOG(LOG_ERROR, TAG_TTSC, "Fail to get fd from dbus");
+               __tts_dbus_connection_free();
                return TTS_ERROR_OPERATION_FAILED;
        } else {
                SLOG(LOG_DEBUG, TAG_TTSC, "Get fd from dbus : %d", fd);
@@ -209,6 +225,7 @@ int tts_dbus_open_connection()
        g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, NULL, NULL, NULL);
        if (NULL == g_dbus_fd_handler) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get fd handler from ecore");
+               __tts_dbus_connection_free();
                return TTS_ERROR_OPERATION_FAILED;
        }
 
@@ -225,20 +242,25 @@ int tts_dbus_close_connection()
                g_dbus_fd_handler = NULL;
        }
 
-       dbus_connection_close(g_conn_sender);
-       dbus_connection_close(g_conn_listener);
-
-       dbus_connection_unref(g_conn_sender);
-       dbus_connection_unref(g_conn_listener);
-
-       g_conn_sender = NULL;
-       g_conn_listener = NULL;
+       __tts_dbus_connection_free();
 
        return 0;
 }
 
 int tts_dbus_reconnect()
 {
+       if (!g_conn_sender || !g_conn_listener) {
+               tts_dbus_close_connection();
+
+               if (0 != tts_dbus_open_connection()) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to reconnect");
+                       return -1;
+               }
+
+               SLOG(LOG_DEBUG, TAG_TTSC, "[DBUS] Reconnect");
+               return 0;
+       }
+
        bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
        bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
        SLOG(LOG_DEBUG, TAG_TTSC, "[DBUS] Sender(%s) Listener(%s)",