X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=server%2Fttsd_dbus.c;h=9e0c4f1666d8ba6647a6abace5361a99c3798b00;hb=c370c07420eccd878f9ea17b3f59e5fe952a696d;hp=e993ad55074c52402b1020d451a052be7ecb8219;hpb=c42a46210d3afb9837c9c836c867d27a4caa0530;p=platform%2Fcore%2Fuifw%2Ftts.git diff --git a/server/ttsd_dbus.c b/server/ttsd_dbus.c index e993ad5..9e0c4f1 100644 --- a/server/ttsd_dbus.c +++ b/server/ttsd_dbus.c @@ -138,10 +138,10 @@ int ttsdc_send_message(int pid, int uid, int data, const char *method) method); /* name of the signal */ if (NULL == msg) { - SLOG(LOG_ERROR, tts_tag(), "<<<< [Dbus ERROR] Fail to create message : %s", method); + 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); + 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); @@ -270,6 +270,15 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle } 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_METHOD_PLAY_PCM)) { + ttsd_dbus_server_play_pcm(g_conn_listener, 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_METHOD_ADD_PCM)) { + ttsd_dbus_server_add_pcm(g_conn_listener, msg); + } else { SLOG(LOG_DEBUG, tts_tag(), "Message is NOT valid"); /* Invalid method */ @@ -299,8 +308,21 @@ void __ttsd_dbus_service_free() } } +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); @@ -318,25 +340,25 @@ int ttsd_dbus_open_connection() return -1; } + 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); - dbus_connection_close(g_conn_sender); - dbus_connection_unref(g_conn_sender); - g_conn_sender = NULL; + __ttsd_dbus_connection_free(); return -1; } if (NULL == g_conn_listener) { SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get dbus connection"); - dbus_connection_close(g_conn_sender); - dbus_connection_unref(g_conn_sender); - g_conn_sender = NULL; + __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()) { @@ -344,6 +366,13 @@ int ttsd_dbus_open_connection() 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; + } + 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); @@ -352,53 +381,60 @@ int ttsd_dbus_open_connection() 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; + } + 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*)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; + } + 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); } - 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(); - dbus_connection_close(g_conn_listener); - dbus_connection_unref(g_conn_listener); - g_conn_listener = NULL; - dbus_connection_close(g_conn_sender); - dbus_connection_unref(g_conn_sender); - g_conn_sender = NULL; - return -1; - } - /* request our name on the bus and check for errors */ 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) { SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to be primary owner"); - dbus_connection_close(g_conn_listener); - dbus_connection_unref(g_conn_listener); - g_conn_listener = NULL; - dbus_connection_close(g_conn_sender); - dbus_connection_unref(g_conn_sender); - g_conn_sender = NULL; + __ttsd_dbus_connection_free(); return -1; } 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); - dbus_connection_close(g_conn_listener); - dbus_connection_unref(g_conn_listener); - g_conn_listener = NULL; - dbus_connection_close(g_conn_sender); - dbus_connection_unref(g_conn_sender); - g_conn_sender = NULL; + __ttsd_dbus_connection_free(); return -1; } @@ -412,12 +448,7 @@ int ttsd_dbus_open_connection() if (dbus_error_is_set(&err)) { SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] dbus_bus_add_match() : %s", err.message); - dbus_connection_close(g_conn_listener); - dbus_connection_unref(g_conn_listener); - g_conn_listener = NULL; - dbus_connection_close(g_conn_sender); - dbus_connection_unref(g_conn_sender); - g_conn_sender = NULL; + __ttsd_dbus_connection_free(); return -1; } @@ -427,20 +458,17 @@ int ttsd_dbus_open_connection() 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"); - dbus_connection_close(g_conn_listener); - dbus_connection_unref(g_conn_listener); - g_conn_listener = NULL; - dbus_connection_close(g_conn_sender); - dbus_connection_unref(g_conn_sender); - g_conn_sender = NULL; + __ttsd_dbus_connection_free(); return -1; } + 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); @@ -455,19 +483,12 @@ int ttsd_dbus_close_connection() SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] dbus_bus_release_name() : %s", err.message); dbus_error_free(&err); } - - 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; } + __ttsd_dbus_connection_free(); __ttsd_dbus_service_free(); + SLOG(LOG_DEBUG, tts_tag(), "@@@"); + return 0; }