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) {
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;
}
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);
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;
}
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)",