/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* limitations under the License.
*/
-
#include <dbus/dbus.h>
+#include <dirent.h>
+#include <dlfcn.h>
#include <Ecore.h>
+#include "tts_config_mgr.h"
#include "ttsd_main.h"
#include "ttsd_dbus_server.h"
#include "ttsd_dbus.h"
#include "ttsd_server.h"
+static DBusConnection* g_conn_sender = NULL;
+static DBusConnection* g_conn_listener = NULL;
-static DBusConnection* g_conn;
+static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
-static int g_waiting_time = 3000;
+//static int g_waiting_time = 3000;
-static char *g_service_name;
-static char *g_service_object;
-static char *g_service_interface;
+static char *g_service_name = NULL;
+static char *g_service_object = NULL;
+static char *g_service_interface = NULL;
+
+const char* __ttsd_get_error_code(ttsd_error_e err)
+{
+ switch (err) {
+ case TTSD_ERROR_NONE: return "TTS_ERROR_NONE";
+ case TTSD_ERROR_OUT_OF_MEMORY: return "TTS_ERROR_OUT_OF_MEMORY";
+ case TTSD_ERROR_IO_ERROR: return "TTS_ERROR_IO_ERROR";
+ case TTSD_ERROR_INVALID_PARAMETER: return "TTS_ERROR_INVALID_PARAMETER";
+ case TTSD_ERROR_OUT_OF_NETWORK: return "TTS_ERROR_OUT_OF_NETWORK";
+ case TTSD_ERROR_INVALID_STATE: return "TTS_ERROR_INVALID_STATE";
+ case TTSD_ERROR_INVALID_VOICE: return "TTS_ERROR_INVALID_VOICE";
+ case TTSD_ERROR_ENGINE_NOT_FOUND: return "TTS_ERROR_ENGINE_NOT_FOUND";
+ case TTSD_ERROR_TIMED_OUT: return "TTS_ERROR_TIMED_OUT";
+ case TTSD_ERROR_OPERATION_FAILED: return "TTS_ERROR_OPERATION_FAILED";
+ case TTSD_ERROR_AUDIO_POLICY_BLOCKED: return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
+ case TTSD_ERROR_NOT_SUPPORTED_FEATURE: return "TTSD_ERROR_NOT_SUPPORTED_FEATURE";
+ case TTSD_ERROR_SERVICE_RESET: return "TTSD_ERROR_SERVICE_RESET";
+ default:
+ return "Invalid error code";
+ }
+
+ return NULL;
+}
int ttsdc_send_hello(int pid, int uid)
{
- if (NULL == g_conn) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] Dbus connection is not available" );
+#if 0
+ if (NULL == g_conn_sender) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
return -1;
}
target_if_name,
TTSD_METHOD_HELLO);
- if (NULL == msg) {
- SLOG(LOG_ERROR, get_tag(), "<<<< [Dbus ERROR] Fail to create hello message : uid(%d)", uid);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, tts_tag(), "<<<< [Dbus ERROR] Fail to create hello message : uid(%d)", uid);
return -1;
} else {
- SLOG(LOG_DEBUG, get_tag(), "<<<< [Dbus] Send hello message : uid(%d)", uid);
+ SLOG(LOG_DEBUG, tts_tag(), "<<<< [Dbus] Send hello message : uid(%d)", uid);
}
dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
DBusMessage* result_msg;
int result = -1;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
+ result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
dbus_message_unref(msg);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Send error (%s)", err.message);
+ dbus_error_free(&err);
+ }
if (NULL != result_msg) {
dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, get_tag(), ">>>> [Dbus] Get arguments error (%s)", err.message);
- dbus_error_free(&err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, tts_tag(), ">>>> [Dbus] Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
result = -1;
}
dbus_message_unref(result_msg);
} else {
- SLOG(LOG_DEBUG, get_tag(), ">>>> [Dbus] Result message is NULL. Client is not available");
+ SLOG(LOG_DEBUG, tts_tag(), ">>>> [Dbus] Result message is NULL. Client is not available");
result = 0;
}
return result;
+#endif
+ return 0;
}
-int ttsdc_send_message(int pid, int uid, int data, char *method)
+int ttsdc_send_message(int pid, int uid, int data, const char *method)
{
-#if 0
- if (NULL == g_conn) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] Dbus connection is not available" );
+ if (NULL == g_conn_sender) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
return -1;
}
- char service_name[64];
- memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s%d", TTS_CLIENT_SERVICE_NAME, pid);
-
- char target_if_name[64];
- snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
-
- DBusMessage* msg;
+ DBusMessage* msg = NULL;
- /* create a message & check for errors */
- msg = dbus_message_new_method_call(
- service_name,
- TTS_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- method);
+ /* create a message */
+ msg = dbus_message_new_signal(
+ TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ TTS_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */
+ method); /* name of the signal */
- if (NULL == msg) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] Fail to create message : type(%s), uid(%d)\n", method, uid);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to create message : %s", method);
return -1;
- }
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Dbus] Send %s message : uid(%d) data(%d)", method, uid, data);
+ }
dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INT32, &data, DBUS_TYPE_INVALID);
- /* send the message and flush the connection */
- if (!dbus_connection_send(g_conn, msg, NULL)) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] <<<< send message : Out Of Memory, type(%s), ifname(%s), uid(%d), data(%d)", method, target_if_name, uid, data);
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to Send");
+ return -1;
} else {
- SLOG(LOG_DEBUG, get_tag(), "<<<< send message : type(%s), uid(%d), data(%d)", method, uid, data);
-
- dbus_connection_flush(g_conn);
+ SLOG(LOG_DEBUG, tts_tag(), "[Dbus] SUCCESS Send");
+ dbus_connection_flush(g_conn_sender);
}
dbus_message_unref(msg);
-#endif
- char send_filename[64];
- memset(send_filename, 0, 64);
- snprintf(send_filename, 64, "/%s_%d", MESSAGE_FILE_PATH, pid);
-
- FILE* fp;
- fp = fopen(send_filename, "a+");
- if (NULL == fp) {
- SLOG(LOG_ERROR, get_tag(), "[File message ERROR] Fail to open message file");
- return -1;
- }
- SLOG(LOG_DEBUG, get_tag(), "[File message] Write send file - %s, uid=%d, send_data=%d", method, uid, data);
-
- fprintf(fp, "%s %d %d\n", method, uid, data);
-
- fclose(fp);
-
return 0;
}
return ttsdc_send_message(pid, uid, uttid, TTSD_METHOD_UTTERANCE_STARTED);
}
-int ttsdc_send_utt_finish_message(int pid, int uid, int uttid)
+int ttsdc_send_utt_finish_message(int pid, int uid, int uttid)
{
return ttsdc_send_message(pid, uid, uttid, TTSD_METHOD_UTTERANCE_COMPLETED);
}
return ttsdc_send_message(pid, uid, state, TTSD_METHOD_SET_STATE);
}
-int ttsdc_send_error_message(int pid, int uid, int uttid, int reason)
+int ttsdc_send_error_message(int pid, int uid, int uttid, int reason, char* err_msg)
{
- if (NULL == g_conn) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] Dbus connection is not available" );
+ if (NULL == g_conn_sender) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
return -1;
}
- char service_name[64];
- memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s%d", TTS_CLIENT_SERVICE_NAME, pid);
-
- char target_if_name[128];
- snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
-
- DBusMessage* msg;
+ DBusMessage* msg = NULL;
- msg = dbus_message_new_method_call(
- service_name,
- TTS_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- TTSD_METHOD_ERROR);
+ /* create a message */
+ msg = dbus_message_new_signal(
+ TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ TTS_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */
+ TTSD_METHOD_ERROR); /* name of the signal */
- if (NULL == msg) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] Fail to create error message : uid(%d)\n", uid);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to create error message : uid(%d)", uid);
return -1;
}
- dbus_message_append_args( msg,
- DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &uttid,
- DBUS_TYPE_INT32, &reason,
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &uttid,
+ DBUS_TYPE_INT32, &reason,
+ DBUS_TYPE_STRING, &err_msg,
DBUS_TYPE_INVALID);
-
- if (!dbus_connection_send(g_conn, msg, NULL)) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] <<<< error message : Out Of Memory !\n");
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] <<<< error message : Out Of Memory !");
} else {
- SLOG(LOG_DEBUG, get_tag(), "<<<< Send error signal : uid(%d), reason(%d), uttid(%d)", uid, reason, uttid);
- dbus_connection_flush(g_conn);
+ SLOG(LOG_DEBUG, tts_tag(), "<<<< Send error message : uid(%d), reason(%s), uttid(%d), err_msg(%s)",
+ uid, __ttsd_get_error_code(reason), uttid, (NULL == err_msg) ? "NULL" : err_msg);
+ dbus_connection_flush(g_conn_sender);
}
dbus_message_unref(msg);
return 0;
}
-#if 0
-int ttsd_send_start_next_synthesis()
+static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
{
- if (NULL == g_conn) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] Dbus connection is not available" );
- return -1;
- }
+ if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW;
- DBusMessage* msg;
+ dbus_connection_read_write_dispatch(g_conn_listener, 50);
- msg = dbus_message_new_signal(
- g_service_object, /* object name of the signal */
- g_service_interface, /* interface name of the signal */
- TTSD_SIGNAL_NEXT_SYNTHESIS); /* name of the signal */
+ while (1) {
+ DBusMessage* msg = NULL;
+ msg = dbus_connection_pop_message(g_conn_listener);
- if (NULL == msg) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] >>>> Fail to make message for 'start next synthesis'");
- return -1;
- }
-
- if (!dbus_connection_send(g_conn, msg, NULL)) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] >>>> Fail to send message for 'start next synthesis'");
- return -1;
- }
-
- SLOG(LOG_DEBUG, get_tag(), "[Dbus] >>>> Send message for 'start next synthesis'");
-
- dbus_connection_flush(g_conn);
- dbus_message_unref(msg);
-
- return 0;
-}
-#endif
+ if (true != dbus_connection_get_is_connected(g_conn_listener)) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Connection is disconnected");
+ return ECORE_CALLBACK_RENEW;
+ }
-static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
-{
- DBusConnection* conn = (DBusConnection*)data;
+ /* loop again if we haven't read a message */
+ if (NULL == msg) {
+ return ECORE_CALLBACK_RENEW;
+ }
- if (NULL == conn) return ECORE_CALLBACK_RENEW;
+ /* client event */
+ if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_HELLO)) {
+ ttsd_dbus_server_hello(g_conn_listener, msg);
- dbus_connection_read_write_dispatch(conn, 50);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_INITIALIZE)) {
+ ttsd_dbus_server_initialize(g_conn_listener, msg);
- DBusMessage* msg = NULL;
- msg = dbus_connection_pop_message(conn);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_FINALIZE)) {
+ ttsd_dbus_server_finalize(g_conn_listener, msg);
- /* loop again if we haven't read a message */
- if (NULL == msg || NULL == conn) {
- return ECORE_CALLBACK_RENEW;
- }
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_SUPPORT_VOICES)) {
+ ttsd_dbus_server_get_support_voices(g_conn_listener, msg);
- /* client event */
- if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_HELLO))
- ttsd_dbus_server_hello(conn, msg);
-
- else if( dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_INITIALIZE) )
- ttsd_dbus_server_initialize(conn, msg);
-
- else if( dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_FINALIZE) )
- ttsd_dbus_server_finalize(conn, msg);
-
- else if( dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_SUPPORT_VOICES) )
- ttsd_dbus_server_get_support_voices(conn, msg);
-
- else if( dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_CURRENT_VOICE) )
- ttsd_dbus_server_get_current_voice(conn, msg);
-
- else if( dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_ADD_QUEUE) )
- ttsd_dbus_server_add_text(conn, msg);
-
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PLAY))
- ttsd_dbus_server_play(conn, msg);
-
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_STOP))
- ttsd_dbus_server_stop(conn, msg);
-
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PAUSE))
- ttsd_dbus_server_pause(conn, msg);
-#if 0
- /* daemon internal event*/
- else if (dbus_message_is_signal(msg, g_service_interface, TTSD_SIGNAL_NEXT_SYNTHESIS))
- ttsd_dbus_server_start_next_synthesis();
-#endif
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_CURRENT_VOICE)) {
+ ttsd_dbus_server_get_current_voice(g_conn_listener, msg);
- /* setting event */
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_HELLO))
- ttsd_dbus_server_hello(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_ADD_QUEUE)) {
+ ttsd_dbus_server_add_text(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_INITIALIZE) )
- ttsd_dbus_server_setting_initialize(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PLAY)) {
+ ttsd_dbus_server_play(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_FINALIZE) )
- ttsd_dbus_server_setting_finalize(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_STOP)) {
+ ttsd_dbus_server_stop(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_GET_ENGINE_LIST) )
- ttsd_dbus_server_setting_get_engine_list(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PAUSE)) {
+ ttsd_dbus_server_pause(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_GET_ENGINE) )
- ttsd_dbus_server_setting_get_engine(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_SET_PRIVATE_DATA)) {
+ ttsd_dbus_server_set_private_data(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_SET_ENGINE) )
- ttsd_dbus_server_setting_set_engine(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_PRIVATE_DATA)) {
+ ttsd_dbus_server_get_private_data(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_GET_VOICE_LIST) )
- ttsd_dbus_server_setting_get_voice_list(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PLAY_PCM)) {
+ ttsd_dbus_server_play_pcm(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_GET_DEFAULT_VOICE) )
- ttsd_dbus_server_setting_get_default_voice(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_STOP_PCM)) {
+ ttsd_dbus_server_stop_pcm(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_SET_DEFAULT_VOICE) )
- ttsd_dbus_server_setting_set_default_voice(conn, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_ADD_PCM)) {
+ ttsd_dbus_server_add_pcm(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_GET_DEFAULT_SPEED) )
- ttsd_dbus_server_setting_get_speed(conn, msg);
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "Message is NOT valid");
+ /* Invalid method */
+ }
+ /* free the message */
+ dbus_message_unref(msg);
+ }
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_SET_DEFAULT_SPEED) )
- ttsd_dbus_server_setting_set_speed(conn, msg);
+ return ECORE_CALLBACK_RENEW;
+}
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_GET_ENGINE_SETTING) )
- ttsd_dbus_server_setting_get_engine_setting(conn, msg);
+void __ttsd_dbus_service_free()
+{
+ if (NULL != g_service_name) {
+ free(g_service_name);
+ g_service_name = NULL;
+ }
- else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_SET_ENGINE_SETTING) )
- ttsd_dbus_server_setting_set_engine_setting(conn, msg);
-
+ if (NULL != g_service_object) {
+ free(g_service_object);
+ g_service_object = NULL;
+ }
- /* free the message */
- dbus_message_unref(msg);
+ if (NULL != g_service_interface) {
+ free(g_service_interface);
+ g_service_interface = NULL;
+ }
+}
- return ECORE_CALLBACK_RENEW;
+void __ttsd_dbus_connection_free()
+{
+ if (NULL != g_conn_listener) {
+ dbus_connection_close(g_conn_listener);
+ g_conn_listener = NULL;
+ }
+ if (NULL != g_conn_sender) {
+ dbus_connection_close(g_conn_sender);
+ g_conn_sender = NULL;
+ }
}
int ttsd_dbus_open_connection()
{
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ start dbus open connection");
DBusError err;
dbus_error_init(&err);
int ret;
- /* connect to the bus and check for errors */
- g_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ /* Create connection for sender */
+ g_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
+ dbus_error_free(&err);
+ }
+
+ if (NULL == g_conn_sender) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get dbus connection sender");
+ return -1;
+ }
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] fail dbus_bus_get : %s\n", err.message);
- dbus_error_free(&err);
+ dbus_connection_set_exit_on_disconnect(g_conn_sender, false);
+
+ /* connect to the bus and check for errors */
+ g_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
+ dbus_error_free(&err);
+ __ttsd_dbus_connection_free();
+ return -1;
}
- if (NULL == g_conn) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] fail to get dbus connection \n" );
+ if (NULL == g_conn_listener) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get dbus connection");
+ __ttsd_dbus_connection_free();
return -1;
}
+ dbus_connection_set_exit_on_disconnect(g_conn_listener, false);
+
+ __ttsd_dbus_service_free();
+
if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
- g_service_name = (char*)malloc(sizeof(char) * strlen(TTS_SR_SERVER_SERVICE_NAME) + 1);
- g_service_object = (char*)malloc(sizeof(char) * strlen(TTS_SR_SERVER_SERVICE_OBJECT_PATH) + 1);
- g_service_interface = (char*)malloc(sizeof(char) * strlen(TTS_SR_SERVER_SERVICE_INTERFACE) + 1);
+ g_service_name = (char*)calloc(strlen(TTS_SR_SERVER_SERVICE_NAME) + 1, sizeof(char));
+ g_service_object = (char*)calloc(strlen(TTS_SR_SERVER_SERVICE_OBJECT_PATH) + 1, sizeof(char));
+ g_service_interface = (char*)calloc(strlen(TTS_SR_SERVER_SERVICE_INTERFACE) + 1, sizeof(char));
+
+ if (NULL == g_service_name || NULL == g_service_object || NULL == g_service_interface) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
+ __ttsd_dbus_service_free();
+ __ttsd_dbus_connection_free();
+ return -1;
+ }
- strcpy(g_service_name, TTS_SR_SERVER_SERVICE_NAME);
- strcpy(g_service_object, TTS_SR_SERVER_SERVICE_OBJECT_PATH);
- strcpy(g_service_interface, TTS_SR_SERVER_SERVICE_INTERFACE);
+ snprintf(g_service_name, strlen(TTS_SR_SERVER_SERVICE_NAME) + 1, "%s", TTS_SR_SERVER_SERVICE_NAME);
+ snprintf(g_service_object, strlen(TTS_SR_SERVER_SERVICE_OBJECT_PATH) + 1, "%s", TTS_SR_SERVER_SERVICE_OBJECT_PATH);
+ snprintf(g_service_interface, strlen(TTS_SR_SERVER_SERVICE_INTERFACE) + 1, "%s", TTS_SR_SERVER_SERVICE_INTERFACE);
} else if (TTSD_MODE_NOTIFICATION == ttsd_get_mode()) {
- g_service_name = (char*)malloc(sizeof(char) * strlen(TTS_NOTI_SERVER_SERVICE_NAME) + 1);
- g_service_object = (char*)malloc(sizeof(char) * strlen(TTS_NOTI_SERVER_SERVICE_OBJECT_PATH) + 1);
- g_service_interface = (char*)malloc(sizeof(char) * strlen(TTS_NOTI_SERVER_SERVICE_INTERFACE) + 1);
+ g_service_name = (char*)calloc(strlen(TTS_NOTI_SERVER_SERVICE_NAME) + 1, sizeof(char));
+ g_service_object = (char*)calloc(strlen(TTS_NOTI_SERVER_SERVICE_OBJECT_PATH) + 1, sizeof(char));
+ g_service_interface = (char*)calloc(strlen(TTS_NOTI_SERVER_SERVICE_INTERFACE) + 1, sizeof(char));
+
+ if (NULL == g_service_name || NULL == g_service_object || NULL == g_service_interface) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
+ __ttsd_dbus_service_free();
+ __ttsd_dbus_connection_free();
+ return -1;
+ }
- strcpy(g_service_name, TTS_NOTI_SERVER_SERVICE_NAME);
- strcpy(g_service_object, TTS_NOTI_SERVER_SERVICE_OBJECT_PATH);
- strcpy(g_service_interface, TTS_NOTI_SERVER_SERVICE_INTERFACE);
+ snprintf(g_service_name, strlen(TTS_NOTI_SERVER_SERVICE_NAME) + 1, "%s", TTS_NOTI_SERVER_SERVICE_NAME);
+ snprintf(g_service_object, strlen(TTS_NOTI_SERVER_SERVICE_OBJECT_PATH) + 1, "%s", TTS_NOTI_SERVER_SERVICE_OBJECT_PATH);
+ snprintf(g_service_interface, strlen(TTS_NOTI_SERVER_SERVICE_INTERFACE) + 1, "%s", TTS_NOTI_SERVER_SERVICE_INTERFACE);
+ } else if (TTSD_MODE_INTERRUPT == ttsd_get_mode()) {
+ g_service_name = (char*)calloc(strlen(TTS_INTERRUPT_SERVER_SERVICE_NAME) + 1, sizeof(char));
+ g_service_object = (char*)calloc(strlen(TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH) + 1, sizeof(char));
+ g_service_interface = (char*)calloc(strlen(TTS_INTERRUPT_SERVER_SERVICE_INTERFACE) + 1, sizeof(char));
+
+ if (NULL == g_service_name || NULL == g_service_object || NULL == g_service_interface) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
+ __ttsd_dbus_service_free();
+ __ttsd_dbus_connection_free();
+ return -1;
+ }
+
+ snprintf(g_service_name, strlen(TTS_INTERRUPT_SERVER_SERVICE_NAME) + 1, "%s", TTS_INTERRUPT_SERVER_SERVICE_NAME);
+ snprintf(g_service_object, strlen(TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH) + 1, "%s", TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH);
+ snprintf(g_service_interface, strlen(TTS_INTERRUPT_SERVER_SERVICE_INTERFACE) + 1, "%s", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE);
} else {
- g_service_name = (char*)malloc(sizeof(char) * strlen(TTS_SERVER_SERVICE_NAME) + 1);
- g_service_object = (char*)malloc(sizeof(char) * strlen(TTS_SERVER_SERVICE_OBJECT_PATH) + 1);
- g_service_interface = (char*)malloc(sizeof(char) * strlen(TTS_SERVER_SERVICE_INTERFACE) + 1);
+ g_service_name = (char*)calloc(strlen(TTS_SERVER_SERVICE_NAME) + 1, sizeof(char));
+ g_service_object = (char*)calloc(strlen(TTS_SERVER_SERVICE_OBJECT_PATH) + 1, sizeof(char));
+ g_service_interface = (char*)calloc(strlen(TTS_SERVER_SERVICE_INTERFACE) + 1, sizeof(char));
+
+ if (NULL == g_service_name || NULL == g_service_object || NULL == g_service_interface) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
+ __ttsd_dbus_service_free();
+ __ttsd_dbus_connection_free();
+ return -1;
+ }
- strcpy(g_service_name, TTS_SERVER_SERVICE_NAME);
- strcpy(g_service_object, TTS_SERVER_SERVICE_OBJECT_PATH);
- strcpy(g_service_interface, TTS_SERVER_SERVICE_INTERFACE);
+ snprintf(g_service_name, strlen(TTS_SERVER_SERVICE_NAME) + 1, "%s", TTS_SERVER_SERVICE_NAME);
+ snprintf(g_service_object, strlen(TTS_SERVER_SERVICE_OBJECT_PATH) + 1, "%s", TTS_SERVER_SERVICE_OBJECT_PATH);
+ snprintf(g_service_interface, strlen(TTS_SERVER_SERVICE_INTERFACE) + 1, "%s", TTS_SERVER_SERVICE_INTERFACE);
}
/* request our name on the bus and check for errors */
- ret = dbus_bus_request_name(g_conn, g_service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
-
+ ret = dbus_bus_request_name(g_conn_listener, g_service_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
- printf("Fail to be primary owner in dbus request. \n");
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] fail to be primary owner \n");
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to be primary owner");
+ __ttsd_dbus_connection_free();
return -1;
}
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] dbus_bus_request_name() : %s \n", err.message);
- dbus_error_free(&err);
-
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to request dbus name : %s", err.message);
+ dbus_error_free(&err);
+ __ttsd_dbus_connection_free();
return -1;
}
/* add a rule for getting signal */
char rule[128];
- snprintf(rule, 128, "type='signal',interface='%s'", g_service_interface);
+ snprintf(rule, 128, "type='method_call',interface='%s'", g_service_interface);
/* add a rule for which messages we want to see */
- dbus_bus_add_match(g_conn, rule, &err); /* see signals from the given interface */
- dbus_connection_flush(g_conn);
+ dbus_bus_add_match(g_conn_listener, rule, &err);/* see signals from the given interface */
+ dbus_connection_flush(g_conn_listener);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] dbus_bus_add_match() : %s \n", err.message);
- return -1;
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
+ __ttsd_dbus_connection_free();
+ return -1;
}
int fd = 0;
- dbus_connection_get_unix_fd(g_conn, &fd);
-
- Ecore_Fd_Handler* fd_handler;
- fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ , (Ecore_Fd_Cb)listener_event_callback, g_conn, NULL, NULL);
+ dbus_connection_get_unix_fd(g_conn_listener, &fd);
- if (NULL == fd_handler) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] ecore_main_fd_handler_add() : fail to get fd handler \n");
+ g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
+ if (NULL == g_dbus_fd_handler) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get fd handler");
+ __ttsd_dbus_connection_free();
return -1;
}
- SLOG(LOG_DEBUG, get_tag(), "[Dbus SUCCESS] Open connection. ");
+ SLOG(LOG_DEBUG, tts_tag(), "@@@");
return 0;
}
int ttsd_dbus_close_connection()
{
+ SLOG(LOG_DEBUG, tts_tag(), "@@@ start dbus close connection");
DBusError err;
dbus_error_init(&err);
- dbus_bus_release_name (g_conn, g_service_name, &err);
-
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] dbus_bus_release_name() : %s\n", err.message);
- dbus_error_free(&err);
- return -1;
+ if (NULL != g_dbus_fd_handler) {
+ ecore_main_fd_handler_del(g_dbus_fd_handler);
+ g_dbus_fd_handler = NULL;
}
- if (NULL != g_service_name)
- free(g_service_name);
-
- if (NULL != g_service_object)
- free(g_service_object);
-
- if (NULL != g_service_interface)
- free(g_service_interface);
+ if (NULL != g_conn_listener) {
+ dbus_bus_release_name(g_conn_listener, g_service_name, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
+ dbus_error_free(&err);
+ }
+ }
- SLOG(LOG_DEBUG, get_tag(), "[Dbus SUCCESS] Close connection. ");
+ __ttsd_dbus_connection_free();
+ __ttsd_dbus_service_free();
- return 0;
-}
+ SLOG(LOG_DEBUG, tts_tag(), "@@@");
-int ttsd_file_msg_open_connection(int pid)
-{
- /* Make file for Inotify */
- char send_filename[64];
- memset(send_filename, 0, 64);
- snprintf(send_filename, 64, "%s_%d", MESSAGE_FILE_PATH, pid);
-
- FILE* fp;
- fp = fopen(send_filename, "a+");
- if (NULL == fp) {
- SLOG(LOG_ERROR, get_tag(), "[File message ERROR] Fail to make message file");
- return -1;
- }
- SLOG(LOG_DEBUG, get_tag(), "[File message] Make message file");
- fclose(fp);
- return 0;
-}
-
-int ttsd_file_msg_close_connection(int pid)
-{
- /* delete inotify file */
- char path[64];
- memset(path, 0, 64);
- snprintf(path, 64, "%s_%d", MESSAGE_FILE_PATH, pid);
- if (0 == access(path, R_OK)) {
- if (0 != remove(path)) {
- SLOG(LOG_WARN, get_tag(), "[File message WARN] Fail to remove message file");
- }
- }
- SLOG(LOG_DEBUG, get_tag(), "[File message] Delete message file");
return 0;
}