From 53d1f6701452b22c2b902e7de38b4081b35a8dd3 Mon Sep 17 00:00:00 2001 From: Kim Kibum Date: Sun, 29 Apr 2012 17:02:06 +0900 Subject: [PATCH] upload tizen1.0 source --- COPYING | 10 -- LICENSE | 206 +++++++++++++++++++++++++++++ client/tts.c | 41 +++--- client/tts.h | 27 ++-- client/tts_client.c | 2 +- client/tts_client.h | 2 +- client/tts_dbus.c | 323 +++++++++++++++++++++++++++++++++++---------- client/tts_dbus.h | 5 +- client/tts_main.h | 2 +- client/tts_setting.c | 52 ++++---- client/tts_setting.h | 10 +- client/tts_setting_dbus.c | 41 +++++- client/tts_setting_dbus.h | 3 +- common/tts_defs.h | 15 ++- debian/changelog | 7 +- packaging/tts.spec | 8 +- server/ttsd_config.c | 2 +- server/ttsd_config.h | 2 +- server/ttsd_data.cpp | 2 +- server/ttsd_data.h | 2 +- server/ttsd_dbus.c | 96 ++++++++------ server/ttsd_dbus.h | 14 +- server/ttsd_dbus_server.c | 26 +++- server/ttsd_dbus_server.h | 4 +- server/ttsd_engine_agent.c | 84 ++++++++---- server/ttsd_engine_agent.h | 2 +- server/ttsd_main.c | 2 +- server/ttsd_main.h | 10 +- server/ttsd_network.c | 2 +- server/ttsd_network.h | 2 +- server/ttsd_player.cpp | 8 +- server/ttsd_player.h | 2 +- server/ttsd_server.cpp | 26 ++-- server/ttsd_server.h | 2 +- server/ttsp.h | 2 +- 35 files changed, 772 insertions(+), 272 deletions(-) delete mode 100644 COPYING create mode 100644 LICENSE diff --git a/COPYING b/COPYING deleted file mode 100644 index bf8fbd7..0000000 --- a/COPYING +++ /dev/null @@ -1,10 +0,0 @@ -Copyright (c) 2011 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 - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bbe9d02 --- /dev/null +++ b/LICENSE @@ -0,0 +1,206 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/client/tts.c b/client/tts.c index 1ff1576..9c1d5e7 100644 --- a/client/tts.c +++ b/client/tts.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -19,7 +19,7 @@ #include "tts_dbus.h" #define MAX_TEXT_COUNT 1000 -#define CONNECTION_RETRY_COUNT 3 +#define CONNECTION_RETRY_COUNT 2 /* Function definition */ int __tts_check_tts_daemon(); @@ -38,18 +38,20 @@ int tts_create(tts_h* tts) return TTS_ERROR_INVALID_PARAMETER; } - /* Check daemon is running */ - __tts_check_tts_daemon(); - if (0 == tts_client_get_size()) { if (0 != tts_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open dbus connection\n "); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open dbus connection"); SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); return TTS_ERROR_OPERATION_FAILED; } } + /* Send hello */ + if (0 != tts_dbus_request_hello()) { + __tts_check_tts_daemon(); + } + if (0 != tts_client_new(tts)) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create client!!!!!"); SLOG(LOG_DEBUG, TAG_TTSC, "====="); @@ -58,7 +60,7 @@ int tts_create(tts_h* tts) } /* do request initialize */ - int i = 0; + int i = 1; while(1) { ret = tts_dbus_request_initialize((*tts)->handle); @@ -68,11 +70,10 @@ int tts_create(tts_h* tts) SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); return ret; - } else if( ret ) { - sleep(1); + } else if (TTS_ERROR_NONE != ret) { + usleep(1); if (i == CONNECTION_RETRY_COUNT) { - tts_client_destroy(*tts); - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Connection Time out"); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to connection"); SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); return TTS_ERROR_TIMED_OUT; @@ -767,10 +768,9 @@ static bool _tts_is_alive() FILE *fp = NULL; char buff[256]; char cmd[256]; - int i=0; - memset(buff, 0, sizeof(char)); - memset(cmd, 0, sizeof(char)); + memset(buff, '\0', sizeof(char) * 256); + memset(cmd, '\0', sizeof(char) * 256); if ((fp = popen("ps -eo \"cmd\"", "r")) == NULL) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] popen error \n"); @@ -778,11 +778,6 @@ static bool _tts_is_alive() } while(fgets(buff, 255, fp)) { - if (0 == i) { - i++; - continue; - } - sscanf(buff, "%s", cmd); if (0 == strncmp(cmd, "[tts-daemon]", strlen("[tts-daemon]")) || @@ -792,11 +787,12 @@ static bool _tts_is_alive() fclose(fp); return TRUE; } - - i++; } + fclose(fp); + SLOG(LOG_DEBUG, TAG_TTSC, "THERE IS NO tts-daemon !! \n"); + return FALSE; } @@ -823,9 +819,6 @@ int __tts_check_tts_daemon() return 0; /* fork-exec tts-daemom */ - SLOG(LOG_DEBUG, TAG_TTSC, "THERE IS NO tts-daemon \n"); - SLOG(LOG_DEBUG, TAG_TTSC, "START TTS-DAEMON \n"); - int pid, i; struct sigaction act, dummy; diff --git a/client/tts.h b/client/tts.h index 6ce02b7..084f956 100644 --- a/client/tts.h +++ b/client/tts.h @@ -1,15 +1,18 @@ /* -* Copyright (c) 2011 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 -* http://www.apache.org/licenses/LICENSE-2.0 -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (c) 2011 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __TTS_H__ @@ -281,7 +284,7 @@ int tts_get_state(tts_h tts, tts_state_e* state); * @param[in] language The language selected from the foreach function * @param[in] voice_type The voice type selected from the foreach function * @param[in] speed A speaking speed -* @param[out] utt_id The utterance ID passed to the callback function. +* @param[out] utt_id The utterance ID passed to the callback function * * @return 0 on success, otherwise a negative error value * @retval #TTS_ERROR_NONE Successful diff --git a/client/tts_client.c b/client/tts_client.c index 450a30a..5b348fc 100644 --- a/client/tts_client.c +++ b/client/tts_client.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/client/tts_client.h b/client/tts_client.h index ad0a60c..494327e 100644 --- a/client/tts_client.h +++ b/client/tts_client.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/client/tts_dbus.c b/client/tts_dbus.c index 41a2cd2..d0c6538 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -17,6 +17,7 @@ #include "tts_dbus.h" #include "tts_defs.h" +#define WAITING_TIME 1000 static Ecore_Fd_Handler* g_fd_handler = NULL; @@ -50,12 +51,14 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle DBusError err; dbus_error_init(&err); + + DBusMessage *reply = NULL; char if_name[64]; snprintf(if_name, 64, "%s%d", TTS_CLIENT_SERVICE_INTERFACE, getpid()); /* check if the message is a signal from the correct interface and with the correct name */ - if (dbus_message_is_signal(msg, if_name, TTS_SIGNAL_UTTERANCE_STARTED)) { + if (dbus_message_is_method_call(msg, if_name, TTS_METHOD_UTTERANCE_STARTED)) { SLOG(LOG_DEBUG, TAG_TTSC, "===== Get utterance started"); int uid, uttid; dbus_message_get_args(msg, &err, @@ -70,11 +73,16 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance started signal : uid(%d), uttid(%d) \n", uid, uttid); __tts_cb_utt_started(uid, uttid); } + reply = dbus_message_new_method_return(msg); + dbus_connection_send(conn, reply, NULL); + dbus_connection_flush(conn); + dbus_message_unref(reply); + SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); }/* TTS_SIGNAL_UTTERANCE_STARTED */ - else if (dbus_message_is_signal(msg, if_name, TTS_SIGNAL_UTTERANCE_COMPLETED)) { + else if (dbus_message_is_method_call(msg, if_name, TTS_METHOD_UTTERANCE_COMPLETED)) { SLOG(LOG_DEBUG, TAG_TTSC, "===== Get utterance completed"); int uid, uttid; dbus_message_get_args(msg, &err, @@ -89,11 +97,17 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance completed signal : uid(%d), uttid(%d) \n", uid, uttid); __tts_cb_utt_completed(uid, uttid); } + + reply = dbus_message_new_method_return(msg); + dbus_connection_send(conn, reply, NULL); + dbus_connection_flush(conn); + dbus_message_unref(reply); + SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); }/* TTS_SIGNAL_UTTERANCE_COMPLETED */ - else if (dbus_message_is_signal(msg, if_name, TTS_SIGNAL_INTERRUPT)) { + else if (dbus_message_is_method_call(msg, if_name, TTS_METHOD_INTERRUPT)) { SLOG(LOG_DEBUG, TAG_TTSC, "===== Get interrupt callback"); int uid; int code; @@ -109,11 +123,17 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Interrupt signal : uid(%d) , interrupt code(%d)\n", uid, code); __tts_cb_interrupt(uid, (tts_interrupted_code_e)code); } + + reply = dbus_message_new_method_return(msg); + dbus_connection_send(conn, reply, NULL); + dbus_connection_flush(conn); + dbus_message_unref(reply); + SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); } /* TTS_SIGNAL_INTERRUPT */ - else if (dbus_message_is_signal(msg, if_name, TTS_SIGNAL_ERROR)) { + else if (dbus_message_is_method_call(msg, if_name, TTS_METHOD_ERROR)) { SLOG(LOG_DEBUG, TAG_TTSC, "===== Get error callback"); int uid; @@ -133,6 +153,12 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Error signal : uid(%d), error(%d), uttid(%d)\n", uid, reason, uttid); __tts_cb_error(uid, reason, uttid); } + + reply = dbus_message_new_method_return(msg); + dbus_connection_send(conn, reply, NULL); + dbus_connection_flush(conn); + dbus_message_unref(reply); + SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); }/* TTS_SIGNAL_ERROR */ @@ -170,6 +196,8 @@ int tts_dbus_open_connection() return TTS_ERROR_OPERATION_FAILED; } + dbus_connection_set_exit_on_disconnect(g_conn, false); + int pid = getpid(); char service_name[64]; @@ -206,7 +234,7 @@ int tts_dbus_open_connection() int fd = 0; dbus_connection_get_unix_fd(g_conn, &fd); - g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn, NULL, NULL); + g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ | ECORE_FD_ERROR | ECORE_FD_WRITE, (Ecore_Fd_Cb)listener_event_callback, g_conn, NULL, NULL); if (NULL == g_fd_handler) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get fd handler from ecore \n"); @@ -230,15 +258,79 @@ int tts_dbus_close_connection() dbus_bus_release_name (g_conn, service_name, &err); + dbus_connection_close(g_conn); + g_conn = NULL; return 0; } +int tts_dbus_reconnect() +{ + bool connected = dbus_connection_get_is_connected(g_conn); + SLOG(LOG_DEBUG, "[DBUS] %s\n", connected ? "Connected" : "Not connected"); + + if (false == connected) { + 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; +} + + +int tts_dbus_request_hello() +{ + DBusMessage* msg; + + msg = dbus_message_new_method_call( + TTS_SERVER_SERVICE_NAME, + TTS_SERVER_SERVICE_OBJECT_PATH, + TTS_SERVER_SERVICE_INTERFACE, + TTS_METHOD_HELLO); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts hello : Fail to make message \n"); + return TTS_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts hello"); + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg = NULL; + int result = 0; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 500, &err); + + dbus_message_unref(msg); + + if (NULL != result_msg) { + dbus_message_unref(result_msg); + + SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts hello"); + result = 0; + } else { + SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts hello : no response"); + result = TTS_ERROR_OPERATION_FAILED; + } + + return result; +} + int tts_dbus_request_initialize(int uid) { DBusMessage* msg; + DBusError err; + dbus_error_init(&err); msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, @@ -247,25 +339,31 @@ int tts_dbus_request_initialize(int uid) TTS_METHOD_INITIALIZE); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to make message \n"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + return TTS_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts initialize : uid(%d)", uid); } int pid = getpid(); - dbus_message_append_args( msg, - DBUS_TYPE_INT32, &pid, - DBUS_TYPE_INT32, &uid, - DBUS_TYPE_INVALID); + if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); - DBusError err; - dbus_error_init(&err); + return TTS_ERROR_OPERATION_FAILED; + } DBusMessage* result_msg; int result = TTS_ERROR_OPERATION_FAILED; - result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err); + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, WAITING_TIME, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -281,6 +379,9 @@ int tts_dbus_request_initialize(int uid) dbus_message_unref(result_msg); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL "); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + tts_dbus_reconnect(); } if (0 == result) { @@ -289,8 +390,6 @@ int tts_dbus_request_initialize(int uid) SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts initialize : result = %d \n", result); } - dbus_message_unref(msg); - return result; } @@ -298,6 +397,8 @@ int tts_dbus_request_initialize(int uid) int tts_dbus_request_finalize(int uid) { DBusMessage* msg; + DBusError err; + dbus_error_init(&err); msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, @@ -306,21 +407,30 @@ int tts_dbus_request_finalize(int uid) TTS_METHOD_FINALIZE); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts finalize : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts finalize : Fail to make message"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + return TTS_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts finalize : uid(%d)", uid); } - dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); + if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); - DBusError err; - dbus_error_init(&err); + return TTS_ERROR_OPERATION_FAILED; + } DBusMessage* result_msg; int result = TTS_ERROR_OPERATION_FAILED; - result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err); + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, WAITING_TIME, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID); @@ -334,6 +444,9 @@ int tts_dbus_request_finalize(int uid) dbus_message_unref(result_msg); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL "); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + tts_dbus_reconnect(); } if (0 == result) { @@ -342,14 +455,14 @@ int tts_dbus_request_finalize(int uid) SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts finalize : result = %d \n", result); } - dbus_message_unref(msg); - return result; } int tts_dbus_request_get_support_voice(int uid, tts_h tts, tts_supported_voice_cb callback, void* user_data) { DBusMessage* msg; + DBusError err; + dbus_error_init(&err); msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, @@ -358,24 +471,33 @@ int tts_dbus_request_get_support_voice(int uid, tts_h tts, tts_supported_voice_c TTS_METHOD_GET_SUPPORT_VOICES); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get supported voices : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get supported voices : Fail to make message"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + return TTS_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts get supported voices : uid(%d)", uid); } - dbus_message_append_args( msg, - DBUS_TYPE_INT32, &uid, - DBUS_TYPE_INVALID); + if (true != dbus_message_append_args( msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); - DBusError err; - dbus_error_init(&err); + return TTS_ERROR_OPERATION_FAILED; + } DBusMessage* result_msg; DBusMessageIter args; int result = TTS_ERROR_OPERATION_FAILED; - result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err ); + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, WAITING_TIME, &err ); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + printf("result message : %p\n", result_msg); + } if (NULL != result_msg) { if (dbus_message_iter_init(result_msg, &args)) { @@ -423,10 +545,11 @@ int tts_dbus_request_get_support_voice(int uid, tts_h tts, tts_supported_voice_c dbus_message_unref(result_msg); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + tts_dbus_reconnect(); } - dbus_message_unref(msg); - return result; } @@ -438,6 +561,8 @@ int tts_dbus_request_get_default_voice(int uid , char** lang, tts_voice_type_e* } DBusMessage* msg; + DBusError err; + dbus_error_init(&err); msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, @@ -446,25 +571,34 @@ int tts_dbus_request_get_default_voice(int uid , char** lang, tts_voice_type_e* TTS_METHOD_GET_CURRENT_VOICE); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get default voice : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get default voice : Fail to make message"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + return TTS_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts get default voice : uid(%d)", uid); } - dbus_message_append_args( msg, - DBUS_TYPE_INT32, &uid, - DBUS_TYPE_INVALID); + if (true != dbus_message_append_args( msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); - DBusError err; - dbus_error_init(&err); + return TTS_ERROR_OPERATION_FAILED; + } DBusMessage* result_msg; int result = TTS_ERROR_OPERATION_FAILED; char* temp_lang; int voice_type; - result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 3000, &err); + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, WAITING_TIME, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + printf("result message : %p\n", result_msg); + } if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -481,6 +615,9 @@ int tts_dbus_request_get_default_voice(int uid , char** lang, tts_voice_type_e* dbus_message_unref(result_msg); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL "); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + tts_dbus_reconnect(); } if (0 == result) { @@ -497,8 +634,6 @@ int tts_dbus_request_get_default_voice(int uid , char** lang, tts_voice_type_e* SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get default voice : result(%d) \n", result); } - dbus_message_unref(msg); - return result; } @@ -511,6 +646,8 @@ int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int v } DBusMessage* msg; + DBusError err; + dbus_error_init(&err); msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, @@ -519,29 +656,38 @@ int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int v TTS_METHOD_ADD_QUEUE); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts add text : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts add text : Fail to make message"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + return TTS_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), id(%d)", uid, text, lang, vctype, speed, uttid); } - dbus_message_append_args( msg, + if (true != dbus_message_append_args( msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_STRING, &text, DBUS_TYPE_STRING, &lang, DBUS_TYPE_INT32, &vctype, DBUS_TYPE_INT32, &speed, DBUS_TYPE_INT32, &uttid, - DBUS_TYPE_INVALID); + DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); - DBusError err; - dbus_error_init(&err); + return TTS_ERROR_OPERATION_FAILED; + } DBusMessage* result_msg; int result = TTS_ERROR_OPERATION_FAILED; result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 5000, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -556,15 +702,16 @@ int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int v dbus_message_unref(result_msg); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL "); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + tts_dbus_reconnect(); } if (0 == result) { SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts add text : result(%d) \n", result); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts add text : result(%d) \n", result); - } - - dbus_message_unref(msg); + } return result; } @@ -572,6 +719,8 @@ int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int v int tts_dbus_request_play(int uid) { DBusMessage* msg; + DBusError err; + dbus_error_init(&err); msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, @@ -580,23 +729,30 @@ int tts_dbus_request_play(int uid) TTS_METHOD_PLAY ); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts play : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts play : Fail to make message"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + return TTS_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts play : uid(%d)", uid); } - dbus_message_append_args( msg, - DBUS_TYPE_INT32, &uid, - DBUS_TYPE_INVALID); + if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); - DBusError err; - dbus_error_init(&err); + return TTS_ERROR_OPERATION_FAILED; + } DBusMessage* result_msg; int result = TTS_ERROR_OPERATION_FAILED; result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 5000, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -611,6 +767,9 @@ int tts_dbus_request_play(int uid) dbus_message_unref(result_msg); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL "); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + tts_dbus_reconnect(); } if (0 == result) { @@ -618,8 +777,6 @@ int tts_dbus_request_play(int uid) } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts play : result(%d) \n", result); } - - dbus_message_unref(msg); return result; } @@ -628,6 +785,8 @@ int tts_dbus_request_play(int uid) int tts_dbus_request_stop(int uid) { DBusMessage* msg; + DBusError err; + dbus_error_init(&err); msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, @@ -636,21 +795,30 @@ int tts_dbus_request_stop(int uid) TTS_METHOD_STOP); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts stop : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts stop : Fail to make message"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + return TTS_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts stop : uid(%d)", uid); } - DBusError err; - dbus_error_init(&err); - DBusMessage* result_msg; int result = TTS_ERROR_OPERATION_FAILED; - dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); + if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); + + return TTS_ERROR_OPERATION_FAILED; + } result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 5000, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -665,6 +833,9 @@ int tts_dbus_request_stop(int uid) dbus_message_unref(result_msg); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL "); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + tts_dbus_reconnect(); } if (0 == result) { @@ -673,14 +844,14 @@ int tts_dbus_request_stop(int uid) SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts stop : result(%d) \n", result); } - dbus_message_unref(msg); - return result; } int tts_dbus_request_pause(int uid) { DBusMessage* msg; + DBusError err; + dbus_error_init(&err); msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, @@ -689,21 +860,30 @@ int tts_dbus_request_pause(int uid) TTS_METHOD_PAUSE); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts pause : Fail to make message \n"); + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts pause : Fail to make message"); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + return TTS_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts pause : uid(%d)", uid); } - DBusError err; - dbus_error_init(&err); - DBusMessage* result_msg; int result = TTS_ERROR_OPERATION_FAILED; - dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); + if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args"); + + return TTS_ERROR_OPERATION_FAILED; + } result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 5000, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); if (NULL != result_msg) { dbus_message_get_args(result_msg, &err, @@ -718,6 +898,9 @@ int tts_dbus_request_pause(int uid) dbus_message_unref(result_msg); } else { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL "); + if (dbus_error_is_set(&err)) + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message); + tts_dbus_reconnect(); } if (0 == result) { @@ -726,7 +909,5 @@ int tts_dbus_request_pause(int uid) SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts pause : result(%d) \n", result); } - dbus_message_unref(msg); - return result; } diff --git a/client/tts_dbus.h b/client/tts_dbus.h index c252fc2..89ce20e 100644 --- a/client/tts_dbus.h +++ b/client/tts_dbus.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -25,6 +25,9 @@ int tts_dbus_open_connection(); int tts_dbus_close_connection(); + +int tts_dbus_request_hello(); + int tts_dbus_request_initialize(int uid); int tts_dbus_request_finalize(int uid); diff --git a/client/tts_main.h b/client/tts_main.h index e2cd331..9198a80 100644 --- a/client/tts_main.h +++ b/client/tts_main.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/client/tts_setting.c b/client/tts_setting.c index e8ecf9e..86a38e3 100644 --- a/client/tts_setting.c +++ b/client/tts_setting.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -18,6 +18,8 @@ #include "tts_setting.h" #include "tts_setting_dbus.h" +#define CONNECTION_RETRY_COUNT 2 + static bool g_is_setting_initialized = false; static int __check_tts_daemon(); @@ -28,14 +30,11 @@ int tts_setting_initialize() { SLOG(LOG_DEBUG, TAG_TTSC, "===== Initialize TTS Setting"); - /* Check daemon */ - __check_tts_daemon(); - if (true == g_is_setting_initialized) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS Setting has already been initialized. \n"); + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] TTS Setting has already been initialized. \n"); SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); - return TTS_SETTING_ERROR_INVALID_STATE; + return TTS_SETTING_ERROR_NONE; } if( 0 != tts_setting_dbus_open_connection() ) { @@ -45,8 +44,13 @@ int tts_setting_initialize() return TTS_SETTING_ERROR_OPERATION_FAILED; } + /* Send hello */ + if (0 != tts_setting_dbus_request_hello()) { + __check_tts_daemon(); + } + /* do request */ - int i = 0; + int i = 1; int ret = 0; while(1) { ret = tts_setting_dbus_request_initialize(); @@ -55,8 +59,8 @@ int tts_setting_initialize() SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Engine not found"); break; } else if(ret) { - sleep(1); - if (i == 10) { + usleep(1); + if (i == CONNECTION_RETRY_COUNT) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Connection Time out"); ret = TTS_SETTING_ERROR_TIMED_OUT; break; @@ -68,7 +72,7 @@ int tts_setting_initialize() } } - if (0 == ret) { + if (TTS_SETTING_ERROR_NONE == ret) { g_is_setting_initialized = true; SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Initialize"); } @@ -85,10 +89,10 @@ int tts_setting_finalize() SLOG(LOG_DEBUG, TAG_TTSC, "===== Finalize TTS Setting"); if (false == g_is_setting_initialized) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized"); + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Not initialized"); SLOG(LOG_DEBUG, TAG_TTSC, "====="); SLOG(LOG_DEBUG, TAG_TTSC, " "); - return TTS_SETTING_ERROR_INVALID_STATE; + return TTS_SETTING_ERROR_NONE; } int ret = tts_setting_dbus_request_finalilze(); @@ -207,7 +211,7 @@ int tts_setting_set_engine(const char* engine_id) return ret; } -int tts_setting_foreach_surppoted_voices(tts_setting_supported_voice_cb callback, void* user_data) +int tts_setting_foreach_surpported_voices(tts_setting_supported_voice_cb callback, void* user_data) { SLOG(LOG_DEBUG, TAG_TTSC, "===== Foreach supported voices"); @@ -447,23 +451,18 @@ static bool __tts_is_alive() FILE *fp = NULL; char buff[256]; char cmd[256]; - int i=0; - memset(buff, 0, sizeof(char)); - memset(cmd, 0, sizeof(char)); + memset(buff, '\0', sizeof(char) * 256); + memset(cmd, '\0', sizeof(char) * 256); - if ((fp = popen("ps -eo \"cmd\"", "r")) == NULL) { - SLOG(LOG_DEBUG, TAG_TTSC, "[TTS ERROR] popen error "); + fp = popen("ps", "r"); + if (NULL == fp) { + SLOG(LOG_DEBUG, TAG_TTSC, "[TTS SETTING ERROR] popen error \n"); return FALSE; } while (fgets(buff, 255, fp)) { - if (i == 0) { - i++; - continue; - } - - sscanf(buff, "%s", cmd); + strcpy(cmd, buff + 26); if( 0 == strncmp(cmd, "[tts-daemon]", strlen("[tts-daemon]")) || 0 == strncmp(cmd, "tts-daemon", strlen("tts-daemon")) || @@ -474,10 +473,11 @@ static bool __tts_is_alive() return TRUE; } - i++; } fclose(fp); + SLOG(LOG_DEBUG, TAG_TTSC, "THERE IS NO tts-daemon !! \n"); + return FALSE; } @@ -503,8 +503,6 @@ static int __check_tts_daemon() return 0; /* fork-exec tts-daemom */ - SLOG(LOG_DEBUG, TAG_TTSC, "tts-daemon is NOT alive. start tts-daemon."); - int pid, i; struct sigaction act, dummy; diff --git a/client/tts_setting.h b/client/tts_setting.h index a13f143..06e2219 100644 --- a/client/tts_setting.h +++ b/client/tts_setting.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -90,12 +90,12 @@ typedef bool(*tts_setting_supported_engine_cb)(const char* engine_id, const char * followed by ISO 639-1 for the two-letter language code. * For example, "ko_KR" for Korean, "en_US" for American English.. * @param[in] voice_type Voice type. -* @param[in] user_data User data passed from the tts_setting_foreach_surppoted_voices(). +* @param[in] user_data User data passed from the tts_setting_foreach_surpported_voices(). * * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. -* @pre tts_setting_foreach_surppoted_voices() will invoke this callback. +* @pre tts_setting_foreach_surpported_voices() will invoke this callback. * -* @see tts_setting_foreach_surppoted_voices() +* @see tts_setting_foreach_surpported_voices() */ typedef bool(*tts_setting_supported_voice_cb)(const char* engine_id, const char* language, tts_setting_voice_type_e voice_type, void* user_data); @@ -205,7 +205,7 @@ int tts_setting_set_engine(const char* engine_id); * * @see tts_setting_supported_voice_cb() */ -int tts_setting_foreach_surppoted_voices(tts_setting_supported_voice_cb callback, void* user_data); +int tts_setting_foreach_surpported_voices(tts_setting_supported_voice_cb callback, void* user_data); /** * @brief Get a default voice of current engine. diff --git a/client/tts_setting_dbus.c b/client/tts_setting_dbus.c index b56c099..c8c57a5 100644 --- a/client/tts_setting_dbus.c +++ b/client/tts_setting_dbus.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -87,6 +87,45 @@ int tts_setting_dbus_close_connection() return 0; } +int tts_setting_dbus_request_hello() +{ + DBusMessage* msg; + + msg = dbus_message_new_method_call( + TTS_SERVER_SERVICE_NAME, + TTS_SERVER_SERVICE_OBJECT_PATH, + TTS_SERVER_SERVICE_INTERFACE, + TTS_SETTING_METHOD_HELLO); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request setting hello : Fail to make message \n"); + return TTS_SETTING_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request setting hello"); + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg = NULL; + int result = 0; + + result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 500, &err); + + dbus_message_unref(msg); + + if (NULL != result_msg) { + dbus_message_unref(result_msg); + + SLOG(LOG_DEBUG, TAG_TTSC, "<<<< setting hello"); + result = 0; + } else { + SLOG(LOG_ERROR, TAG_TTSC, "<<<< setting hello : no response"); + result = -1; + } + + return result; +} int tts_setting_dbus_request_initialize() { diff --git a/client/tts_setting_dbus.h b/client/tts_setting_dbus.h index 5894afc..3f979ac 100644 --- a/client/tts_setting_dbus.h +++ b/client/tts_setting_dbus.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -26,6 +26,7 @@ int tts_setting_dbus_open_connection(); int tts_setting_dbus_close_connection(); +int tts_setting_dbus_request_hello(); int tts_setting_dbus_request_initialize(); diff --git a/common/tts_defs.h b/common/tts_defs.h index 520b6e5..eae80bb 100644 --- a/common/tts_defs.h +++ b/common/tts_defs.h @@ -40,6 +40,7 @@ extern "C" { * Message Definition for APIs *******************************************************************************************/ +#define TTS_METHOD_HELLO "tts_method_hello" #define TTS_METHOD_INITIALIZE "tts_method_initialize" #define TTS_METHOD_FINALIZE "tts_method_finalilze" #define TTS_METHOD_GET_SUPPORT_VOICES "tts_method_get_support_voices" @@ -49,16 +50,17 @@ extern "C" { #define TTS_METHOD_STOP "tts_method_stop" #define TTS_METHOD_PAUSE "tts_method_pause" -#define TTS_SIGNAL_INTERRUPT "tts_signal_interrupt" -#define TTS_SIGNAL_UTTERANCE_STARTED "tts_utterance_started" -#define TTS_SIGNAL_UTTERANCE_COMPLETED "tts_utterance_completed" -#define TTS_SIGNAL_ERROR "tts_signal_error" +#define TTS_METHOD_INTERRUPT "tts_method_interrupt" +#define TTS_METHOD_UTTERANCE_STARTED "tts_method_utterance_started" +#define TTS_METHOD_UTTERANCE_COMPLETED "tts_method_utterance_completed" +#define TTS_METHOD_ERROR "tts_method_error" /****************************************************************************************** * Message Definition for Setting *******************************************************************************************/ +#define TTS_SETTING_METHOD_HELLO "tts_setting_method_hello" #define TTS_SETTING_METHOD_INITIALIZE "tts_setting_method_initialize" #define TTS_SETTING_METHOD_FINALIZE "tts_setting_method_finalilze" #define TTS_SETTING_METHOD_GET_ENGINE_LIST "tts_setting_method_get_engine_list" @@ -76,8 +78,9 @@ extern "C" { * Message Definition for tts-daemon internal *******************************************************************************************/ -#define TTS_SIGNAL_NEXT_PLAY "tts_signal_start_play" -#define TTS_SIGNAL_NEXT_SYNTHESIS "tts_signal_start_synthesis" +#define TTS_METHOD_NEXT_PLAY "tts_method_start_play" +#define TTS_METHOD_NEXT_SYNTHESIS "tts_method_start_synthesis" + #ifdef __cplusplus } diff --git a/debian/changelog b/debian/changelog index ce8316b..5c6c90e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,8 @@ tts (0.1.1-1) unstable; urgency=low - * beta release - * Git: tizen2/pkgs/t/tts + * 1.0 release. + * Git: pkgs/t/tts * Tag: tts_0.1.1-1 - -- Dongyeol Lee Fri, 17 Feb 2012 14:48:00 +0900 + -- Dongyeol Lee Mon, 19 Mar 2012 11:37:32 +0900 + diff --git a/packaging/tts.spec b/packaging/tts.spec index af0e45f..3331343 100644 --- a/packaging/tts.spec +++ b/packaging/tts.spec @@ -1,10 +1,10 @@ Name: tts Summary: Text To Speech client library and daemon Version: 0.1.1 -Release: 2.1 +Release: 1 Group: libs -License: Apache-2.0 -Source0: tts-%{version}.tar.bz2 +License: Samsung +Source0: tts-0.1.1.tar.gz Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig BuildRequires: pkgconfig(glib-2.0) @@ -13,7 +13,7 @@ BuildRequires: pkgconfig(mm-player) BuildRequires: pkgconfig(mm-common) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(ecore-input) +BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(openssl) BuildRequires: cmake diff --git a/server/ttsd_config.c b/server/ttsd_config.c index ee2a08b..83dce1c 100644 --- a/server/ttsd_config.c +++ b/server/ttsd_config.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_config.h b/server/ttsd_config.h index fca7d60..45e9b89 100644 --- a/server/ttsd_config.h +++ b/server/ttsd_config.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_data.cpp b/server/ttsd_data.cpp index e2f7fb7..2d59d88 100644 --- a/server/ttsd_data.cpp +++ b/server/ttsd_data.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_data.h b/server/ttsd_data.h index 2fb2bbc..d115db6 100644 --- a/server/ttsd_data.h +++ b/server/ttsd_data.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_dbus.c b/server/ttsd_dbus.c index 20b5b28..a6fc673 100644 --- a/server/ttsd_dbus.c +++ b/server/ttsd_dbus.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -23,21 +23,26 @@ static DBusConnection* g_conn; -int ttsdc_send_signal(int pid, int uid, int uttid, char *signal) +int ttsdc_send_message(int pid, int uid, int uttid, char *method) { + 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; - /* create a signal & check for errors */ - msg = dbus_message_new_signal( - TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */ - target_if_name, /* interface name of the signal */ - signal); /* name of the signal */ + /* create a message & check for errors */ + msg = dbus_message_new_method_call( + service_name, + TTS_CLIENT_SERVICE_OBJECT_PATH, + target_if_name, + method); if (NULL == msg) { - SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] Fail to create signal message : type(%s), uid(%d)\n", signal, uid); + SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] Fail to create message : type(%s), uid(%d)\n", method, uid); return -1; } @@ -45,42 +50,49 @@ int ttsdc_send_signal(int pid, int uid, int uttid, char *signal) /* send the message and flush the connection */ if (!dbus_connection_send(g_conn, msg, NULL)) { - SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] <<<< send signal : Out Of Memory, type(%s), ifname(%s), uid(%d), uttid(%d) \n",signal, target_if_name, uid, uttid); + SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] <<<< send message : Out Of Memory, type(%s), ifname(%s), uid(%d), uttid(%d)", method, target_if_name, uid, uttid); } else { - SLOG(LOG_DEBUG, TAG_TTSD, "<<<< send signal : type(%s), uid(%d), uttid(%d) \n", signal, uid, uttid); + SLOG(LOG_DEBUG, TAG_TTSD, "<<<< send message : type(%s), uid(%d), uttid(%d)", method, uid, uttid); dbus_connection_flush(g_conn); } + dbus_message_unref(msg); return 0; } -int ttsdc_send_utt_start_signal(int pid, int uid, int uttid) +int ttsdc_send_utt_start_message(int pid, int uid, int uttid) { - return ttsdc_send_signal(pid, uid, uttid, TTS_SIGNAL_UTTERANCE_STARTED); + return ttsdc_send_message(pid, uid, uttid, TTS_METHOD_UTTERANCE_STARTED); } -int ttsdc_send_utt_finish_signal(int pid, int uid, int uttid) +int ttsdc_send_utt_finish_message(int pid, int uid, int uttid) { - return ttsdc_send_signal(pid, uid, uttid, TTS_SIGNAL_UTTERANCE_COMPLETED); + return ttsdc_send_message(pid, uid, uttid, TTS_METHOD_UTTERANCE_COMPLETED); } -int ttsdc_send_interrupt_signal(int pid, int uid, ttsd_interrupted_code_e code) +int ttsdc_send_interrupt_message(int pid, int uid, ttsd_interrupted_code_e code) { - return ttsdc_send_signal(pid, uid, (int)code, TTS_SIGNAL_INTERRUPT); + return ttsdc_send_message(pid, uid, (int)code, TTS_METHOD_INTERRUPT); } -int ttsdc_send_error_signal(int pid, int uid, int uttid, int reason) +int ttsdc_send_error_message(int pid, int uid, int uttid, int reason) { + 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; - msg = dbus_message_new_signal( - TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */ - target_if_name, /* interface name of the signal */ - TTS_SIGNAL_ERROR ); /* name of the signal */ + + msg = dbus_message_new_method_call( + service_name, + TTS_CLIENT_SERVICE_OBJECT_PATH, + target_if_name, + TTS_METHOD_ERROR); if (NULL == msg) { SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] Fail to create error message : uid(%d)\n", uid); @@ -94,9 +106,9 @@ int ttsdc_send_error_signal(int pid, int uid, int uttid, int reason) DBUS_TYPE_INVALID); if (!dbus_connection_send(g_conn, msg, NULL)) { - SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] <<<< Send error signal : Out Of Memory !\n"); + SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] <<<< error message : Out Of Memory !\n"); } else { - SLOG(LOG_DEBUG, TAG_TTSD, "<<<< Send error signal : reason(%d), uttid(%d)", reason, uttid); + SLOG(LOG_DEBUG, TAG_TTSD, "<<<< Send error signal : uid(%d), reason(%d), uttid(%d)", uid, reason, uttid); dbus_connection_flush(g_conn); } @@ -105,6 +117,7 @@ int ttsdc_send_error_signal(int pid, int uid, int uttid, int reason) return 0; } + static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { DBusConnection* conn = (DBusConnection*)data; @@ -122,7 +135,10 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle } /* client event */ - if( dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_METHOD_INITIALIZE) ) + if (dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_METHOD_HELLO)) + ttsd_dbus_server_hello(conn, msg); + + else if( dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_METHOD_INITIALIZE) ) ttsd_dbus_server_initialize(conn, msg); else if( dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_METHOD_FINALIZE) ) @@ -147,6 +163,9 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle ttsd_dbus_server_pause(conn, msg); /* setting event */ + else if (dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_SETTING_METHOD_HELLO)) + ttsd_dbus_server_hello(conn, msg); + else if (dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_SETTING_METHOD_INITIALIZE) ) ttsd_dbus_server_setting_initialize(conn, msg); @@ -183,12 +202,13 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_SETTING_METHOD_SET_ENGINE_SETTING) ) ttsd_dbus_server_setting_set_engine_setting(conn, msg); - /* daemon internal event*/ - else if (dbus_message_is_signal(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_SIGNAL_NEXT_PLAY)) + + else if (dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_METHOD_NEXT_PLAY)) ttsd_dbus_server_start_next_play(msg); - else if (dbus_message_is_signal(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_SIGNAL_NEXT_SYNTHESIS)) + else if (dbus_message_is_method_call(msg, TTS_SERVER_SERVICE_INTERFACE, TTS_METHOD_NEXT_SYNTHESIS)) ttsd_dbus_server_start_next_synthesis(msg); + /* free the message */ dbus_message_unref(msg); @@ -278,14 +298,15 @@ int ttsd_dbus_close_connection() return 0; } -int ttsd_send_start_next_play(int uid) +int ttsd_send_start_next_play_message(int uid) { DBusMessage* msg; - msg = dbus_message_new_signal( - TTS_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - TTS_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - TTS_SIGNAL_NEXT_PLAY ); /* name of the signal */ + msg = dbus_message_new_method_call( + TTS_SERVER_SERVICE_NAME, + TTS_SERVER_SERVICE_OBJECT_PATH, + TTS_SERVER_SERVICE_INTERFACE, + TTS_METHOD_NEXT_PLAY); if (NULL == msg) { SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] >>>> Fail to make message for 'start next play'"); @@ -305,14 +326,15 @@ int ttsd_send_start_next_play(int uid) return 0; } -int ttsd_send_start_next_synthesis(int uid) +int ttsd_send_start_next_synthesis_message(int uid) { DBusMessage* msg; - msg = dbus_message_new_signal( - TTS_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ - TTS_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ - TTS_SIGNAL_NEXT_SYNTHESIS ); /* name of the signal */ + msg = dbus_message_new_method_call( + TTS_SERVER_SERVICE_NAME, + TTS_SERVER_SERVICE_OBJECT_PATH, + TTS_SERVER_SERVICE_INTERFACE, + TTS_METHOD_NEXT_SYNTHESIS); if (NULL == msg) { SLOG(LOG_ERROR, TAG_TTSD, "[Dbus ERROR] >>>> Fail to make message for 'start next synthesis'\n"); diff --git a/server/ttsd_dbus.h b/server/ttsd_dbus.h index 18716cf..a176bcf 100644 --- a/server/ttsd_dbus.h +++ b/server/ttsd_dbus.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -24,17 +24,17 @@ int ttsd_dbus_open_connection(); int ttsd_dbus_close_connection(); -int ttsdc_send_utt_start_signal(int pid, int uid, int uttid); +int ttsdc_send_utt_start_message(int pid, int uid, int uttid); -int ttsdc_send_utt_finish_signal(int pid, int uid, int uttid); +int ttsdc_send_utt_finish_message(int pid, int uid, int uttid); -int ttsdc_send_error_signal(int pid, int uid, int uttid, int reason); +int ttsdc_send_error_message(int pid, int uid, int uttid, int reason); -int ttsdc_send_interrupt_signal(int pid, int uid, ttsd_interrupted_code_e code); +int ttsdc_send_interrupt_message(int pid, int uid, ttsd_interrupted_code_e code); -int ttsd_send_start_next_play(int uid); +int ttsd_send_start_next_play_message(int uid); -int ttsd_send_start_next_synthesis(int uid); +int ttsd_send_start_next_synthesis_message(int uid); #ifdef __cplusplus } diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index 0cc9066..4837fcc 100644 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -23,6 +23,30 @@ extern int ttsd_data_get_pid(const int uid); * Dbus Client-Daemon Server */ +int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg) +{ + SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS Hello"); + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<"); + SLOG(LOG_DEBUG, TAG_TTSD, " "); + + return 0; +} + int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg) { DBusError err; diff --git a/server/ttsd_dbus_server.h b/server/ttsd_dbus_server.h index 76a7410..f96bc4a 100644 --- a/server/ttsd_dbus_server.h +++ b/server/ttsd_dbus_server.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -21,6 +21,8 @@ extern "C" { #endif +int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg); + /* * Dbus Server functions for APIs */ diff --git a/server/ttsd_engine_agent.c b/server/ttsd_engine_agent.c index 08ac5c8..c7f9361 100644 --- a/server/ttsd_engine_agent.c +++ b/server/ttsd_engine_agent.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -406,44 +406,72 @@ int __internal_update_engine_list() /* get file name from engine directory and get engine information from each filename */ DIR *dp; struct dirent *dirp; - dp = opendir(ENGINE_DIRECTORY); + dp = opendir(ENGINE_DIRECTORY_DEFAULT); - if (dp == NULL) { - SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] __internal_update_engine_list : error opendir \n"); - return TTSD_ERROR_OPERATION_FAILED; - } + if (dp != NULL) { + while ((dirp = readdir(dp)) != NULL) { + ttsengine_info_s* info; + char* filepath = NULL; + int file_size; - SLOG(LOG_DEBUG, TAG_TTSD, "[Engine Agent] Search TTS Engines"); + file_size = strlen(ENGINE_DIRECTORY_DEFAULT) + strlen(dirp->d_name) + 5; + filepath = (char*)g_malloc0( sizeof(char) * file_size); - while ((dirp = readdir(dp)) != NULL) { - ttsengine_info_s* info; - char* filepath = NULL; - int file_size; + if (NULL != filepath) { + strncpy(filepath, ENGINE_DIRECTORY_DEFAULT, strlen(ENGINE_DIRECTORY_DEFAULT) ); + strncat(filepath, "/", strlen("/") ); + strncat(filepath, dirp->d_name, strlen(dirp->d_name) ); + } else { + SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not enough memory!! \n" ); + continue; + } - file_size = strlen(ENGINE_DIRECTORY) + strlen(dirp->d_name) + 5; - filepath = (char*)g_malloc0( sizeof(char) * file_size); + /* get its info and update engine list */ + if (0 == __internal_get_engine_info(filepath, &info)) { + /* add engine info to g_engine_list */ + g_engine_list = g_list_append(g_engine_list, info); + } - if (NULL != filepath) { - strncpy(filepath, ENGINE_DIRECTORY, strlen(ENGINE_DIRECTORY) ); - strncat(filepath, "/", strlen("/") ); - strncat(filepath, dirp->d_name, strlen(dirp->d_name) ); - } else { - SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not enough memory!! \n" ); - continue; + if (NULL != filepath) + g_free(filepath); } - /* get its info and update engine list */ - if (0 == __internal_get_engine_info(filepath, &info)) { - /* add engine info to g_engine_list */ - g_engine_list = g_list_append(g_engine_list, info); + closedir(dp); + } + + dp = opendir(ENGINE_DIRECTORY_DOWNLOAD); + + if (dp != NULL) { + while ((dirp = readdir(dp)) != NULL) { + ttsengine_info_s* info; + char* filepath = NULL; + int file_size; + + file_size = strlen(ENGINE_DIRECTORY_DOWNLOAD) + strlen(dirp->d_name) + 5; + filepath = (char*)g_malloc0( sizeof(char) * file_size); + + if (NULL != filepath) { + strncpy(filepath, ENGINE_DIRECTORY_DOWNLOAD, strlen(ENGINE_DIRECTORY_DOWNLOAD) ); + strncat(filepath, "/", strlen("/") ); + strncat(filepath, dirp->d_name, strlen(dirp->d_name) ); + } else { + SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] Not enough memory!! \n" ); + continue; + } + + /* get its info and update engine list */ + if (0 == __internal_get_engine_info(filepath, &info)) { + /* add engine info to g_engine_list */ + g_engine_list = g_list_append(g_engine_list, info); + } + + if (NULL != filepath) + g_free(filepath); } - if (NULL != filepath) - g_free(filepath); + closedir(dp); } - closedir(dp); - if (g_list_length(g_engine_list) <= 0) { SLOG(LOG_ERROR, TAG_TTSD, "[Engine Agent ERROR] No Engine\n"); return TTSD_ERROR_OPERATION_FAILED; diff --git a/server/ttsd_engine_agent.h b/server/ttsd_engine_agent.h index dfccf33..fccc8c3 100644 --- a/server/ttsd_engine_agent.h +++ b/server/ttsd_engine_agent.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_main.c b/server/ttsd_main.c index 0157760..6411921 100644 --- a/server/ttsd_main.c +++ b/server/ttsd_main.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_main.h b/server/ttsd_main.h index 1d0df35..78becd1 100644 --- a/server/ttsd_main.h +++ b/server/ttsd_main.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -33,7 +33,12 @@ extern "C" { /* TTS Daemon Define */ #define TAG_TTSD "ttsd" -#define ENGINE_DIRECTORY "/usr/lib/voice/tts/1.0/engine" + +#define ENGINE_DIRECTORY_DEFAULT "/usr/lib/voice/tts/1.0/engine" +#define ENGINE_DIRECTORY_DEFAULT_SETTING "/usr/lib/voice/tts/1.0/setting" + +#define ENGINE_DIRECTORY_DOWNLOAD "/opt/apps/voice/tts/1.0/engine" +#define ENGINE_DIRECTORY_DOWNLOAD_SETTING "/opt/apps/voice/tts/1.0/setting" /* for debug message */ #define DATA_DEBUG @@ -43,6 +48,7 @@ typedef enum { TTSD_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of Memory */ TTSD_ERROR_IO_ERROR = -EIO, /**< I/O error */ TTSD_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */ + TTSD_ERROR_OUT_OF_NETWORK = -ENETDOWN, /**< Out of network */ TTSD_ERROR_INVALID_STATE = -0x0100021, /**< Invalid state */ TTSD_ERROR_INVALID_VOICE = -0x0100022, /**< Invalid voice */ TTSD_ERROR_ENGINE_NOT_FOUND = -0x0100023, /**< No available TTS-engine */ diff --git a/server/ttsd_network.c b/server/ttsd_network.c index cc1febf..ae46d1f 100644 --- a/server/ttsd_network.c +++ b/server/ttsd_network.c @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_network.h b/server/ttsd_network.h index a1eaf92..f5db051 100644 --- a/server/ttsd_network.h +++ b/server/ttsd_network.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_player.cpp b/server/ttsd_player.cpp index 02a825c..01bafd1 100644 --- a/server/ttsd_player.cpp +++ b/server/ttsd_player.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -696,7 +696,7 @@ static int msg_callback(int message, void *data, void *user_param) pid = ttsd_data_get_pid(uid); /* send utterance start message */ - if (0 == ttsdc_send_utt_start_signal(pid, uid, utt_id)) { + if (0 == ttsdc_send_utt_start_message(pid, uid, utt_id)) { SLOG(LOG_DEBUG, TAG_TTSD, "[Send SUCCESS] Send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)", pid, uid, utt_id); } else SLOG(LOG_ERROR, TAG_TTSD, "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)", pid, uid, utt_id); @@ -763,13 +763,13 @@ static int msg_callback(int message, void *data, void *user_param) /* send utterence finish signal */ if (TTSP_RESULT_EVENT_FINISH == current->event) { - if (0 == ttsdc_send_utt_finish_signal(pid, uid, utt_id)) + if (0 == ttsdc_send_utt_finish_message(pid, uid, utt_id)) SLOG(LOG_DEBUG, TAG_TTSD, "[Send SUCCESS] Send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)", pid, uid, utt_id); else SLOG(LOG_ERROR, TAG_TTSD, "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)", pid, uid, utt_id); } - ttsd_send_start_next_play(uid); + ttsd_send_start_next_play_message(uid); SLOG(LOG_DEBUG, TAG_TTSD, "====="); SLOG(LOG_DEBUG, TAG_TTSD, " "); diff --git a/server/ttsd_player.h b/server/ttsd_player.h index 66af293..c77dca8 100644 --- a/server/ttsd_player.h +++ b/server/ttsd_player.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsd_server.cpp b/server/ttsd_server.cpp index 5de3618..60ae8ec 100644 --- a/server/ttsd_server.cpp +++ b/server/ttsd_server.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 @@ -51,7 +51,7 @@ int __server_send_error(int uid, int utt_id, int error_code) int pid = ttsd_data_get_pid(uid); /* send error */ - if ( 0 != ttsdc_send_error_signal(pid, uid, utt_id, error_code)) { + if ( 0 != ttsdc_send_error_message(pid, uid, utt_id, error_code)) { ttsd_data_delete_client(uid); } @@ -68,7 +68,7 @@ int __server_interrupt_client(int org_uid) } /* send message to client about changing state */ - ttsdc_send_interrupt_signal (pid, org_uid, TTSD_INTERRUPTED_PAUSED); + ttsdc_send_interrupt_message (pid, org_uid, TTSD_INTERRUPTED_PAUSED); /* change state */ ttsd_data_set_client_state(org_uid, APP_STATE_PAUSED); @@ -330,7 +330,7 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns if (event == TTSP_RESULT_EVENT_FINISH) { __server_set_is_synthesizing(false); - if (0 != ttsd_send_start_next_synthesis(uid)) { + if (0 != ttsd_send_start_next_synthesis_message(uid)) { /* critical error */ SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] IPC ERROR FOR NEXT SYNTHESIS \n"); } @@ -341,7 +341,7 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL"); __server_set_is_synthesizing(false); - if (0 != ttsd_send_start_next_synthesis(uid)) { + if (0 != ttsd_send_start_next_synthesis_message(uid)) { /* critical error */ SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] IPC ERROR FOR NEXT SYNTHESIS \n"); } @@ -351,7 +351,7 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns SLOG(LOG_DEBUG, TAG_TTSD, "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL"); __server_set_is_synthesizing(false); - if (0 != ttsd_send_start_next_synthesis(uid)) { + if (0 != ttsd_send_start_next_synthesis_message(uid)) { /* critical error */ SLOG(LOG_ERROR, TAG_TTSD, "[SERVER ERROR] IPC ERROR FOR NEXT SYNTHESIS \n"); } @@ -536,7 +536,7 @@ int ttsd_server_play(int uid) if (ttsd_engine_agent_need_network()) { if (false == ttsd_network_is_connected()) { SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Disconnect network. Current engine needs network service!!!.\n"); - return TTSD_ERROR_OPERATION_FAILED; + return TTSD_ERROR_OUT_OF_NETWORK; } } @@ -550,8 +550,8 @@ int ttsd_server_play(int uid) /* Change current play */ if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) { - SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Current play has already existed \n"); - return 0; + SLOG(LOG_ERROR, TAG_TTSD, "[Server ERROR] Fail to set state : uid(%d)\n", uid); + return TTSD_ERROR_OPERATION_FAILED; } if (0 != __server_play_internal(uid, state)) { @@ -571,6 +571,9 @@ int ttsd_server_stop(int uid) return TTSD_ERROR_INVALID_PARAMETER; } + /* Reset all data */ + ttsd_data_clear_data(uid); + if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) { ttsd_data_set_client_state(uid, APP_STATE_READY); @@ -587,9 +590,6 @@ int ttsd_server_stop(int uid) __server_set_is_synthesizing(false); } - - /* Reset all data */ - ttsd_data_clear_data(uid); } else { SLOG(LOG_WARN, TAG_TTSD, "[Server WARNING] Current state is 'ready' \n"); } @@ -765,7 +765,7 @@ bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data) ttsd_data_set_client_state(uid, APP_STATE_READY); /* send message */ - if ( 0 != ttsdc_send_interrupt_signal(pid, uid, TTSD_INTERRUPTED_STOPPED)) { + if ( 0 != ttsdc_send_interrupt_message(pid, uid, TTSD_INTERRUPTED_STOPPED)) { /* remove client */ ttsd_data_delete_client(uid); } diff --git a/server/ttsd_server.h b/server/ttsd_server.h index 7e1f40f..7b283ce 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 diff --git a/server/ttsp.h b/server/ttsp.h index 4a49a26..74c9875 100644 --- a/server/ttsp.h +++ b/server/ttsp.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* Copyright (c) 2011 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 -- 2.7.4