From: Wonnam Jang Date: Fri, 24 Feb 2017 00:59:38 +0000 (+0900) Subject: Fix dbus connection free X-Git-Tag: accepted/tizen/3.0/common/20170516.153801~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Ftts.git;a=commitdiff_plain;h=776431b5cb23ecd2aa385e29dfac87cbe48b6ad5 Fix dbus connection free Change-Id: I935ce93230dd849286372ef3a5c857ace32af00d Signed-off-by: Wonnam Jang --- diff --git a/client/tts_dbus.c b/client/tts_dbus.c index e23aa59..df39b69 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -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)",