Fix bug on resume tts and add code for file message(IPC)
authorKwangyoun Kim <ky85.kim@samsung.com>
Wed, 20 Mar 2013 09:08:40 +0000 (18:08 +0900)
committerKwangyoun Kim <ky85.kim@samsung.com>
Wed, 20 Mar 2013 09:08:40 +0000 (18:08 +0900)
Change-Id: I7e4e3d6c0c33f74dece0c26b58b2be5ccdfa1e3f

23 files changed:
changelog [changed mode: 0755->0644]
client/tts.c
client/tts_client.c
client/tts_client.h
client/tts_dbus.c
client/tts_dbus.h
common/tts_defs.h
packaging/tts.spec
server/ttsd_config.c
server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_dbus.c
server/ttsd_dbus.h
server/ttsd_dbus_server.c
server/ttsd_dbus_server.h
server/ttsd_engine_agent.c
server/ttsd_main_noti.c
server/ttsd_main_sr.c
server/ttsd_player.c [changed mode: 0755->0644]
server/ttsd_player.h [changed mode: 0755->0644]
server/ttsd_server.c [changed mode: 0755->0644]
server/ttsd_server.h
tts-server.rule

old mode 100755 (executable)
new mode 100644 (file)
index dfbfb49..0cbfdc1
--- a/changelog
+++ b/changelog
@@ -1,3 +1,32 @@
+tts (0.1.56) -- Wed, 20 Mar 2013
+
+  * Release version (Dongyeol Lee <dy3.lee@samsung.com>)
+
+tts (0.1.55-2) -- Wed, 20 Mar 2013
+
+  * Fix bug not to resume tts in 'pause' state (Dongyeol Lee <dy3.lee@samsung.com>)
+
+tts (0.1.55-1) -- Wed, 20 Mar 2013
+
+  * File message(IPC) is applied (Kwangyoun Kim <ky85.kim@samsung.com)
+
+tts (0.1.55) -- Mon, 04 Mar 2013
+
+  * Clean up code (Dongyeol Lee <dy3.lee@samsung.com>)
+  * Fix prevent issue (Kwangyoun Kim <ky85.kim@samsung.com>)
+
+tts (0.1.1-54)
+
+  * Fix code for synthesis by dbus
+
+ -- Kwangyoun Kim <ky85.kim@samsung.com>  Mon, 4 Mar 2013
+tts (0.1.1-53)
+
+  * Update smack rule
+
+ -- Kwangyoun Kim <ky85.kim@samsung.com>  Wed, 27 Feb 2013
+
 tts (0.1.1-52)
 
   * Improve high CPU share
index 6d1bbddb87959bd803027241096cf78d1fd3b38d..0a0f5e97e5b454f5bc34409da647c8889919ed7f 100755 (executable)
@@ -22,7 +22,7 @@
 #include "tts_client.h"
 #include "tts_dbus.h"
 
-#define MAX_TEXT_COUNT 1000
+#define MAX_TEXT_COUNT 2000
 
 static bool g_is_daemon_started = false;
 
@@ -111,8 +111,9 @@ int tts_destroy(tts_h tts)
        case TTS_STATE_READY:
                /* Request Finalize */
                ret = tts_dbus_request_finalize(client->uid);
-               if (0 != ret) 
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request finalize");
+               if (0 != ret) {
+                       SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to request finalize");
+               }
 
                if (TTS_MODE_SCREEN_READER == client->mode) 
                        g_is_sr_daemon_started = false;
@@ -121,6 +122,19 @@ int tts_destroy(tts_h tts)
                else 
                        g_is_daemon_started = false;
 
+               client->before_state = client->current_state;
+               client->current_state = TTS_STATE_CREATED;
+
+               ecore_timer_add(0, __tts_notify_state_changed, (void*)tts);
+
+               /* Close file message connection */
+               if (0 == tts_client_get_connected_client_count()) {
+                       SLOG(LOG_DEBUG, TAG_TTSC, "Close file msg connection");
+                       ret = tts_file_msg_close_connection();
+                       if (0 != ret)
+                               SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to close file message connection");
+               }
+
        case TTS_STATE_CREATED:
                if (NULL != g_connect_timer) {
                        SLOG(LOG_DEBUG, TAG_TTSC, "Connect Timer is deleted");
@@ -279,6 +293,16 @@ static Eina_Bool __tts_connect_daemon(void *data)
                /* success to connect tts-daemon */
        }
 
+       if (0 == tts_client_get_connected_client_count()) {
+               SLOG(LOG_DEBUG, TAG_TTSC, "Open file msg connection");
+               ret = tts_file_msg_open_connection();
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open file message connection");
+                       ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+                       return EINA_FALSE;
+               }
+       }
+
        client->before_state = client->current_state;
        client->current_state = TTS_STATE_READY;
 
@@ -343,8 +367,10 @@ int tts_unprepare(tts_h tts)
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
                return TTS_ERROR_INVALID_STATE;
        }
+       
+       int ret;
 
-       int ret = tts_dbus_request_finalize(client->uid);
+       ret = tts_dbus_request_finalize(client->uid);
        if (0 != ret) {
                SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to request finalize");
        }
@@ -356,12 +382,19 @@ int tts_unprepare(tts_h tts)
        else 
                g_is_daemon_started = false;
 
-
        client->before_state = client->current_state;
        client->current_state = TTS_STATE_CREATED;
 
        ecore_timer_add(0, __tts_notify_state_changed, (void*)tts);
 
+       /* Close file message connection */
+       if (0 == tts_client_get_connected_client_count()) {
+               SLOG(LOG_DEBUG, TAG_TTSC, "Close file msg connection");
+               ret = tts_file_msg_close_connection();
+               if (0 != ret)
+                       SLOG(LOG_WARN, TAG_TTSC, "[ERROR] Fail to close file message connection");
+       }
+
        SLOG(LOG_DEBUG, TAG_TTSC, "=====");
        SLOG(LOG_DEBUG, TAG_TTSC, " ");
 
index 501bfbff464c014f0cc5d8b4768e951fb0721a0b..574e095507432ec0429ec44ce6f3070e29514cc3 100755 (executable)
@@ -193,4 +193,27 @@ int tts_client_not_use_callback(tts_client_s* client)
 int tts_client_get_use_callback(tts_client_s* client)
 {
        return client->cb_ref_count;
+}
+
+int tts_client_get_connected_client_count()
+{
+       GList *iter = NULL;
+       tts_client_s *data = NULL;
+       int number = 0;
+
+       if (g_list_length(g_client_list) > 0) {
+               /* Get a first item */
+               iter = g_list_first(g_client_list);
+
+               while (NULL != iter) {
+                       data = iter->data;
+                       if (0 < data->current_state) {
+                               number++;
+                       }
+
+                       /* Next item */
+                       iter = g_list_next(iter);
+               }
+       }
+       return number;
 }
\ No newline at end of file
index e8eb89a3a16594a8de6718efd13674325136f285..17909774475c2678ce63b990de506a2b24acd469 100755 (executable)
@@ -69,6 +69,8 @@ int tts_client_not_use_callback(tts_client_s* client);
 
 int tts_client_get_use_callback(tts_client_s* client);
 
+int tts_client_get_connected_client_count();
+
 #ifdef __cplusplus
 }
 #endif
index 7f5eca1de096fe92fe6a7ff59bb6f46e39d3f476..eb5690ef37d8468ae9e43acb3a2fb6e6c0a72916 100755 (executable)
@@ -13,6 +13,8 @@
 
 
 #include <Ecore.h>
+#include <sys/inotify.h>
+
 #include "tts_main.h"
 #include "tts_dbus.h"
 #include "tts_defs.h"
 #define INIT_WAITING_TIME 5000
 #define WAITING_TIME 1000
 
+#define BUFFER_SIZE 20
+
 static Ecore_Fd_Handler* g_fd_handler = NULL;
 
 static DBusConnection* g_conn = NULL;
 
+static Ecore_Fd_Handler* g_fd_handler_noti = NULL;
+static int g_fd_noti;
+static int g_wd_noti;
 
 extern int __tts_cb_error(int uid, tts_error_e reason, int utt_id);
 
@@ -100,6 +107,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
        } /* TTSD_METHOD_HELLO */
 
+#if 0
        else if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_UTTERANCE_STARTED)) {
                SLOG(LOG_DEBUG, TAG_TTSC, "===== Get utterance started");
                int uid, uttid;
@@ -160,6 +168,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                SLOG(LOG_DEBUG, TAG_TTSC, "=====");
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
        } /* TTSD_METHOD_SET_STATE */
+#endif
 
        else if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_ERROR)) {
                SLOG(LOG_DEBUG, TAG_TTSC, "===== Get error callback");
@@ -192,7 +201,6 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
        return ECORE_CALLBACK_PASS_ON;
 }
 
-
 int tts_dbus_open_connection()
 {
        if (NULL != g_conn) {
@@ -295,7 +303,7 @@ int tts_dbus_close_connection()
 int tts_dbus_reconnect()
 {
        bool connected = dbus_connection_get_is_connected(g_conn);
-       SLOG(LOG_DEBUG, "[DBUS] %s\n", connected ? "Connected" : "Not connected");
+       SLOG(LOG_DEBUG, TAG_TTSC, "[DBUS] %s\n", connected ? "Connected" : "Not connected");
 
        if (false == connected) {
                tts_dbus_close_connection();
@@ -682,7 +690,6 @@ int tts_dbus_request_get_default_voice(int uid , char** lang, tts_voice_type_e*
        return result;
 }
 
-
 int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid)
 {
        if (NULL == text || NULL == lang) {
@@ -940,3 +947,130 @@ int tts_dbus_request_pause(int uid)
 
        return result;
 }
+
+
+static Eina_Bool inotify_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
+{
+       SLOG(LOG_DEBUG, TAG_TTSC, "===== [File message] Inotify event call");
+
+       int length;
+
+       char buffer[sizeof(struct inotify_event) * BUFFER_SIZE];
+
+       length = read(g_fd_noti, buffer, (sizeof(struct inotify_event) * BUFFER_SIZE));
+       if (0 > length) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[File message] Empty Inotify event");
+               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return ECORE_CALLBACK_RENEW; 
+       }
+
+       bool is_empty_file = true;
+
+       char filename[64];
+       memset(filename, 0, 64);
+       snprintf(filename, 64, "%s_%d", MESSAGE_FILE_PATH, getpid());
+       FILE *fp;
+
+       int i = 0;
+       while (i < length) {
+               char text[256];
+               char msg[256];
+               int uid, send_data;
+
+               struct inotify_event *event = (struct inotify_event *)&buffer[i];
+               i = i + sizeof(struct inotify_event) + event->len;
+
+               if (IN_CLOSE_WRITE == event->mask) {
+
+                       fp = fopen(filename, "r");
+                       if (NULL == fp) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] open file failed");
+                               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+                               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+                               return ECORE_CALLBACK_RENEW;
+                       }
+
+                       while (NULL != fgets(text, 256, fp)) {
+                               if (0 > sscanf(text, "%s %d %d", msg, &uid, &send_data)) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[File message] sscanf failed");
+                                       continue;
+                               }
+                               SLOG(LOG_DEBUG, TAG_TTSC, "[File message] message - %s, uid - %d, send_data - %d", msg, uid, send_data);
+                               is_empty_file = false;
+
+                               int uttid;
+                               if (!strcmp(TTSD_METHOD_UTTERANCE_STARTED, msg)) {
+                                       uttid = send_data;
+                                       SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance started message : uid(%d), uttid(%d) \n", uid, uttid);
+                                       __tts_cb_utt_started(uid, uttid);
+                               } else if (!strcmp(TTSD_METHOD_UTTERANCE_COMPLETED, msg)) {
+                                       uttid = send_data;
+                                       SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance completed message : uid(%d), uttid(%d) \n", uid, uttid);
+                                       __tts_cb_utt_completed(uid, uttid);
+
+                               } else if (!strcmp(TTSD_METHOD_SET_STATE, msg)) {
+                                       int state = send_data;
+                                       SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get state change : uid(%d) , state(%d)", uid, state);
+                                       __tts_cb_set_state(uid, state);
+                               }
+                       }
+                       fclose(fp);
+               } else {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[File message] Undefined event");
+               }
+       }
+
+       if (true == is_empty_file)
+               return ECORE_CALLBACK_PASS_ON;
+
+       fp = fopen(filename, "w+");
+       if (NULL == fp) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] open file failed");
+       } else {
+               fclose(fp);
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return ECORE_CALLBACK_PASS_ON;
+}
+
+int tts_file_msg_open_connection()
+{
+       /* get file notification handler */
+       int fd;
+       int wd;
+
+       fd = inotify_init();
+       if (fd < 0) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] Fail get inotify_fd");
+               return -1;
+       }
+       g_fd_noti = fd;
+
+       int pid = getpid();
+       char path[64];
+       memset(path, 0, 64);
+       snprintf(path, 64, "%s_%d", MESSAGE_FILE_PATH, pid);
+
+       wd = inotify_add_watch(fd, path, IN_CLOSE_WRITE);
+       g_wd_noti = wd;
+       g_fd_handler_noti = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)inotify_event_callback, NULL, NULL, NULL);                
+       if (NULL == g_fd_handler_noti) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] Fail to get handler_noti");
+               return -1;
+       }
+       return 0;
+}
+
+int tts_file_msg_close_connection()
+{
+       /* del inotify variable */
+       ecore_main_fd_handler_del(g_fd_handler_noti);
+       inotify_rm_watch(g_fd_noti, g_wd_noti);
+       close(g_fd_noti);
+
+       return 0;
+}
\ No newline at end of file
index 9993bc2b2021781c113c72972104726151a9b32b..3636e8f3f3d49c41f2f98c375ecad26ed82300c0 100755 (executable)
@@ -46,6 +46,11 @@ int tts_dbus_request_stop(int uid);
 
 int tts_dbus_request_pause(int uid);
 
+
+int tts_file_msg_open_connection();
+
+int tts_file_msg_close_connection();
+
 #ifdef __cplusplus
 }
 #endif
index 2396dc1d278b825b08c5580d590dfc120dab8e42..6f65a1c58d2518891b79d88ba535cced82f737f5 100755 (executable)
@@ -63,6 +63,8 @@ extern "C" {
 #define TTSD_METHOD_ERROR              "ttsd_method_error"
 #define TTSD_METHOD_SET_STATE          "ttsd_method_set_state"
 #define TTSD_METHOD_GET_STATE          "ttsd_method_get_state"
+       
+#define MESSAGE_FILE_PATH              "/opt/home/app/.voice/tts"
 
 /******************************************************************************************
 * Message Definition for Setting
@@ -82,11 +84,13 @@ extern "C" {
 #define TTS_SETTING_METHOD_GET_ENGINE_SETTING  "tts_setting_method_get_engine_setting"
 #define TTS_SETTING_METHOD_SET_ENGINE_SETTING  "tts_setting_method_set_engine_setting"
 
+#if 0
 /******************************************************************************************
 * Message Definition for tts-daemon internal
 *******************************************************************************************/
 
 #define TTSD_SIGNAL_NEXT_SYNTHESIS     "ttsd_signal_start_synthesis"
+#endif
 
 #ifdef __cplusplus
 }
index e917be937dd232b218ccd55ef47e3d418e5def0b..e642a8d004e8b719b5afca3a21f34c544e1d56ae 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       tts
 Summary:    Text To Speech client library and daemon
-Version:    0.1.1
+Version:    0.1.56
 Release:    1
 Group:      libs
 License:    Samsung
index c51f4d998aa4db6ef772b04df66a616e4be9e000..dcda3176b77a78310c74f5e7d43f07488be4f0fc 100755 (executable)
@@ -215,7 +215,7 @@ int ttsd_config_initialize(ttsd_config_lang_changed_cb callback)
        __ttsd_config_load();
 
        /* Register system language changed callback */
-       int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, __system_language_changed_cb, NULL);\r
+       int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, __system_language_changed_cb, NULL);
        if (0 != ret) {
                SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to register callback : %d", ret);
                return TTSD_ERROR_OPERATION_FAILED;
@@ -246,15 +246,19 @@ int ttsd_config_update_language()
                        SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to get system language : %d", ret);
                        return -1;
                } else {
-                       SLOG(LOG_DEBUG, get_tag(), "[Config] System language : %s", value);
+                       if (NULL == value) {
+                               SLOG(LOG_ERROR, get_tag(), "[Config] Fail to get system language");
+                               return -1;
+                       } else {
+                               SLOG(LOG_DEBUG, get_tag(), "[Config] System language : %s", value);
+
+                               if (0 != strcmp(value, g_language)) {
+                                       if (NULL != g_callback)
+                                               g_callback(value, g_vc_type);
+                               }
 
-                       if (0 != strcmp(value, g_language)) {
-                               if (NULL != g_callback)
-                                       g_callback(value, g_vc_type);
-                       }
-                       
-                       if (NULL != value)
                                free(value);
+                       }
                }
        }
 
@@ -334,14 +338,26 @@ int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, con
 
        if (TTSD_MODE_NOTIFICATION == ttsd_get_mode()) {
                err_file = (char*)malloc(strlen(CONFIG_DIRECTORY) + strlen(NOTI_ERROR_FILE_NAME) + 1);
+               if (NULL == err_file) {
+                       SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to get error file name");
+                       return -1;
+               }
                strcpy(err_file, CONFIG_DIRECTORY);
                strcat(err_file, NOTI_ERROR_FILE_NAME);
        } else if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
                err_file = (char*)malloc(strlen(CONFIG_DIRECTORY) + strlen(SR_ERROR_FILE_NAME) + 1);
+               if (NULL == err_file) {
+                       SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to get error file name");
+                       return -1;
+               }
                strcpy(err_file, CONFIG_DIRECTORY);
                strcat(err_file, SR_ERROR_FILE_NAME);
        } else {
                err_file = (char*)malloc(strlen(CONFIG_DIRECTORY) + strlen(DEFAULT_ERROR_FILE_NAME) + 1);
+               if (NULL == err_file) {
+                       SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to get error file name");
+                       return -1;
+               }
                strcpy(err_file, CONFIG_DIRECTORY);
                strcat(err_file, DEFAULT_ERROR_FILE_NAME);
        }
@@ -350,6 +366,7 @@ int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, con
        err_fp = fopen(err_file, "w+");
        if (NULL == err_fp) {
                SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to open error file (%s)", err_file);
+               free(err_file);
                return -1;
        }
        SLOG(LOG_DEBUG, get_tag(), "Save Error File (%s)", err_file);
@@ -400,6 +417,8 @@ int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, con
        /* get data */
        ttsd_data_save_error_log(uid, err_fp);
 
+       free(err_file);
+
        fclose(err_fp);
 
        return 0;
index 88191ddf49b499246160c0644eba71e468901ead..7979d982099b949f3355c037871cceb894f68348 100755 (executable)
@@ -576,4 +576,18 @@ int ttsd_data_save_error_log(int uid, FILE* fp)
        fprintf(fp, "---------------------");
        
        return 0;
+}
+
+int ttsd_data_get_same_pid_client_count(int pid)
+{
+       int vsize = g_app_list.size();
+       int number = 0;
+
+       for (int i=0; i<vsize; i++) {
+               if(g_app_list[i].pid == pid) {
+                       number++;               
+               }
+       }
+
+       return number;
 }
\ No newline at end of file
index 7cb4be9a45b2c50ca23ce74686c583335aa0bbd8..a73bc0e761032a624a659f70c214d5b3d8c21d39 100755 (executable)
@@ -87,6 +87,8 @@ bool ttsd_data_is_uttid_valid(int uid, int uttid);
 
 int ttsd_data_is_current_playing();
 
+int ttsd_data_get_same_pid_client_count(int pid);
+
 
 int ttsd_setting_data_add(int pid);
 
@@ -94,9 +96,11 @@ int ttsd_setting_data_delete(int pid);
 
 int ttsd_setting_data_is_setting(int pid);
 
+
 /* for error log */
 int ttsd_data_save_error_log(int uid, FILE* fp);
 
+
 #ifdef __cplusplus
 }
 #endif
index 62bbb955b5f8cced70459d40f7534c8d0126f9af..8bcd52cf1fec635cefa67c3077df120ac3b0283d 100755 (executable)
@@ -31,6 +31,11 @@ static char *g_service_interface;
 
 int ttsdc_send_hello(int pid, int uid)
 {
+       if (NULL == g_conn) { 
+               SLOG(LOG_ERROR, get_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);
@@ -84,7 +89,13 @@ int ttsdc_send_hello(int pid, int uid)
 }
 
 int ttsdc_send_message(int pid, int uid, int data, char *method)
-{   
+{
+#if 0
+       if (NULL == g_conn) { 
+               SLOG(LOG_ERROR, get_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);
@@ -118,6 +129,23 @@ int ttsdc_send_message(int pid, int uid, int data, char *method)
        }
 
        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;
 }
@@ -139,6 +167,11 @@ int ttsdc_send_set_state_message(int pid, int uid, int state)
 
 int ttsdc_send_error_message(int pid, int uid, int uttid, int reason)
 {
+       if (NULL == g_conn) { 
+               SLOG(LOG_ERROR, get_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);
@@ -177,6 +210,39 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason)
        return 0;
 }
 
+#if 0
+int ttsd_send_start_next_synthesis()
+{
+       if (NULL == g_conn) { 
+               SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] Dbus connection is not available" );
+               return -1;
+       }
+
+       DBusMessage* msg;
+
+       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 */
+
+       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
 
 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
 {
@@ -221,10 +287,11 @@ 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_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
 
        /* setting event */
        else if (dbus_message_is_method_call(msg, g_service_interface, TTS_SETTING_METHOD_HELLO))
@@ -390,27 +457,35 @@ int ttsd_dbus_close_connection()
        return 0;
 }
 
-int ttsd_send_start_next_synthesis()
+int ttsd_file_msg_open_connection(int pid)
 {
-       DBusMessage* msg;
-
-       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 */
-
-       if (NULL == msg) { 
-               SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] >>>> Fail to make message for 'start next synthesis'"); 
+       /* 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;
+}
 
-       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;
+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");
+               }
        }
-
-       dbus_connection_flush(g_conn);
-       dbus_message_unref(msg);
-
+       SLOG(LOG_DEBUG, get_tag(), "[File message] Delete message file");
        return 0;
 }
index 30b4ab2fbf97172e762de48f2358a26da612b35c..2862afd657e420b5584d0032351b697c6d6ad4b7 100755 (executable)
@@ -23,6 +23,9 @@ int ttsd_dbus_open_connection();
 
 int ttsd_dbus_close_connection();
 
+int ttsd_file_msg_open_connection(int pid);
+
+int ttsd_file_msg_close_connection(int pid);
 
 int ttsdc_send_hello(int pid, int uid);
 
@@ -34,7 +37,9 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason);
 
 int ttsdc_send_set_state_message(int pid, int uid, int state);
 
+#if 0
 int ttsd_send_start_next_synthesis();
+#endif
 
 #ifdef __cplusplus
 }
index 2681f275e22d64394dfcd4bf78b0923865494a03..1662200d5760c09dd2acd8e7df5bde82b9c75cfb 100755 (executable)
@@ -119,6 +119,7 @@ int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg)
        } else {
                
                SLOG(LOG_DEBUG, get_tag(), "[IN] tts finalize : uid(%d) \n", uid); 
+
                ret =  ttsd_server_finalize(uid);
        }
 
@@ -506,6 +507,7 @@ int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg)
        return 0;
 }
 
+#if 0
 /*
 * Dbus Server functions for tts daemon internal
 */ 
@@ -513,6 +515,7 @@ int ttsd_dbus_server_start_next_synthesis()
 {
        return ttsd_server_start_next_synthesis();
 }
+#endif
 
 /*
 * Dbus Setting-Daemon Server
index aa627cf532618e6d510a7fe06e4fee3d8dd2ec6c..d1e2affb35ceba0db5d6db57f3d9135b5daf7775 100755 (executable)
@@ -43,10 +43,12 @@ int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg);
 
 int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg);
 
+#if 0
 /*
 * Dbus Server functions for tts daemon internal
 */ 
 int ttsd_dbus_server_start_next_synthesis();
+#endif
 
 /*
 * Dbus Server functions for Setting
index e873ba1164eb1c79590d8dbef632cd30975f6ba3..2afe31b75a46d7a02dfb98bb612a23b8656ff47c 100755 (executable)
@@ -933,7 +933,10 @@ int ttsd_engine_agent_set_default_voice(const char* language, ttsp_voice_type_e
                        g_cur_engine.default_lang, g_cur_engine.default_vctype); 
        } else {
                SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] fail to write default voice to config (%d)", ret); 
+               return TTSD_ERROR_OPERATION_FAILED;
        }
+
+       return 0;
 }
 
 /******************************************************************************************
index 523ec2ea046ba6dff2955da959c50317975909be..9186ee0643831a1a1feb28542c8276ac741ae406 100755 (executable)
@@ -47,7 +47,7 @@ int main()
                SLOG(LOG_ERROR, get_tag(), "[Main ERROR] fail to initialize tts-daemon-noti"); 
                return EXIT_FAILURE;
        }
-       
+
        if (0 != ttsd_dbus_open_connection()) {
                printf("Fail to initialize IPC connection \n");
                SLOG(LOG_ERROR, get_tag(), "[Main ERROR] fail to open dbus connection");
index 0add23dd0dc2bb7ddecc17ab95969f26b4e37aa5..3442e60628ee75686c37f1523b87aac2ae767c30 100755 (executable)
@@ -46,7 +46,7 @@ int main()
                SLOG(LOG_ERROR, get_tag(), "[Main ERROR] fail to initialize tts-daemon-sr"); 
                return EXIT_FAILURE;
        }
-       
+
        if (0 != ttsd_dbus_open_connection()) {
                printf("Fail to initialize IPC connection \n");
                SLOG(LOG_ERROR, get_tag(), "[Main ERROR] fail to open dbus connection");
old mode 100755 (executable)
new mode 100644 (file)
index 6caaa42..dcd3cbb
@@ -95,7 +95,7 @@ static int g_paused_uid;
 
 player_s* __player_get_item(int uid);
 
-int __save_file(const int uid, const int index, const sound_data_s data, char** filename);
+int __save_file(int uid, int index, sound_data_s data, char** filename);
 
 int __set_and_start(player_s* player);
 
@@ -147,7 +147,7 @@ int ttsd_player_release(void)
        return 0;
 }
 
-int ttsd_player_create_instance(const int uid)
+int ttsd_player_create_instance(int uid)
 {
        if (false == g_player_init) {
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" );
@@ -183,7 +183,6 @@ int ttsd_player_create_instance(const int uid)
        return 0;
 }
 
-
 int ttsd_player_destroy_instance(int uid)
 {
        if (false == g_player_init) {
@@ -262,7 +261,7 @@ int ttsd_player_destroy_instance(int uid)
        return 0;
 }
 
-int ttsd_player_play(const int uid)
+int ttsd_player_play(int uid)
 {
        SLOG(LOG_DEBUG, get_tag(), "[Player] start play : uid(%d)", uid );
 
@@ -401,7 +400,7 @@ int ttsd_player_next_play(int uid)
 }
 
 
-int ttsd_player_stop(const int uid)
+int ttsd_player_stop(int uid)
 {
        SLOG(LOG_DEBUG, get_tag(), "[Player] stop player : uid(%d)", uid );
 
@@ -459,7 +458,7 @@ int ttsd_player_stop(const int uid)
        return 0;
 }
 
-int ttsd_player_pause(const int uid)
+int ttsd_player_pause(int uid)
 {
        SLOG(LOG_DEBUG, get_tag(), "[Player] pause player : uid(%d)", uid );
 
@@ -505,7 +504,7 @@ int ttsd_player_pause(const int uid)
        return 0;
 }
 
-int ttsd_player_resume(const int uid)
+int ttsd_player_resume(int uid)
 {
        SLOG(LOG_DEBUG, get_tag(), "[Player] Resume player : uid(%d)", uid );
 
@@ -564,6 +563,49 @@ int ttsd_player_resume(const int uid)
        return 0;
 }
 
+int ttsd_player_get_state(int uid, ttsd_player_state_e* state)
+{
+       if (false == g_player_init) {
+               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" );
+               return -1;
+       }
+
+       player_s* current;
+       current = __player_get_item(uid);
+       if (NULL == current) {
+               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
+               return -1;
+       }
+
+       MMPlayerStateType player_state;
+       mm_player_get_state(current->player_handle, &player_state);
+
+       SLOG(LOG_DEBUG, get_tag(), "[PLAYER] State changed : state(%d)", player_state);
+
+       int ret = -1;
+       /* destroy player */
+       switch (player_state) {
+               case MM_PLAYER_STATE_PLAYING:
+                       *state = TTSD_PLAYER_STATE_PLAYING;
+                       break;
+               case MM_PLAYER_STATE_PAUSED:
+                       *state = TTSD_PLAYER_STATE_PAUSED;
+                       break;
+               
+               case MM_PLAYER_STATE_NULL:
+                       *state = TTSD_PLAYER_STATE_NULL;
+                       break;
+
+               case MM_PLAYER_STATE_READY:
+               default:
+                       SLOG(LOG_ERROR, get_tag(), "[Player ERROR] player state of uid(%d) is not valid", uid); 
+                       return -1;
+                       break;
+       }
+
+       return 0;
+}
+
 int ttsd_player_get_current_client()
 {
        if (false == g_player_init) {
@@ -579,7 +621,7 @@ int ttsd_player_get_current_client()
        return 0;
 }
 
-int ttsd_player_get_current_utterance_id(const int uid)
+int ttsd_player_get_current_utterance_id(int uid)
 {
        SLOG(LOG_DEBUG, get_tag(), "[Player] get current utt id : uid(%d)", uid );
 
@@ -838,7 +880,7 @@ player_s* __player_get_item(int uid)
        return NULL;
 }
 
-int __save_file(const int uid, const int index, const sound_data_s data, char** filename)
+int __save_file(int uid, int index, sound_data_s data, char** filename)
 {
        char postfix[5];
        memset(postfix, '\0', 5);
@@ -1024,12 +1066,12 @@ int __set_and_start(player_s* player)
                return -1;
        }
 
-       //if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
-       //      ret = mm_player_ignore_session(player->player_handle);
-       //      if (MM_ERROR_NONE != ret) {
-       //              SLOG(LOG_WARN, get_tag(), "[Player WARNING] fail mm_player_ignore_session() : %x", ret);
-       //      }
-       //}
+       if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
+               ret = mm_player_ignore_session(player->player_handle);
+               if (MM_ERROR_NONE != ret) {
+                       SLOG(LOG_WARN, get_tag(), "[Player WARNING] fail mm_player_ignore_session() : %x", ret);
+               }
+       }
        
        /* realize and start mm player */ 
        ret = mm_player_realize(player->player_handle);
old mode 100755 (executable)
new mode 100644 (file)
index 9a37340..cc8d2f1
@@ -25,6 +25,12 @@ typedef enum {
        PLAYER_ERROR
 }player_event_e;
 
+typedef enum {
+       TTSD_PLAYER_STATE_NULL,
+       TTSD_PLAYER_STATE_PAUSED,
+       TTSD_PLAYER_STATE_PLAYING
+}ttsd_player_state_e;
+
 typedef int (*player_result_callback_func)(player_event_e event, int uid, int utt_id);
 
 /*
@@ -35,23 +41,25 @@ int ttsd_player_init(player_result_callback_func result_cb);
 
 int ttsd_player_release(void);
 
-int ttsd_player_create_instance(const int uid);
+int ttsd_player_create_instance(int uid);
 
-int ttsd_player_destroy_instance(const int uid);
+int ttsd_player_destroy_instance(int uid);
 
-int ttsd_player_play(const int uid);
+int ttsd_player_play(int uid);
 
 int ttsd_player_next_play(int uid);
 
-int ttsd_player_stop(const int uid);
+int ttsd_player_stop(int uid);
+
+int ttsd_player_pause(int uid);
 
-int ttsd_player_pause(const int uid);
+int ttsd_player_resume(int uid);
 
-int ttsd_player_resume(const int uid);
+int ttsd_player_get_state(int uid, ttsd_player_state_e* state);
 
 int ttsd_player_get_current_client();
 
-int ttsd_player_get_current_utterance_id(const int uid);
+int ttsd_player_get_current_utterance_id(int uid);
 
 int ttsd_player_all_stop();
 
old mode 100755 (executable)
new mode 100644 (file)
index 4575d12..10dc01e
 #include "ttsd_config.h"
 #include "ttsd_network.h"
 
+typedef enum {
+       TTSD_SYNTHESIS_CONTROL_DOING    = 0,
+       TTSD_SYNTHESIS_CONTROL_DONE     = 1,
+       TTSD_SYNTHESIS_CONTROL_EXPIRED  = 2
+}ttsd_synthesis_control_e;
 
 typedef struct {
        int uid;
        int uttid;
-} utterance_t;
+}utterance_t;
 
 /* If current engine exist */
 static bool    g_is_engine;
 
 /* If engine is running */
-static bool    g_is_synthesizing;
+static ttsd_synthesis_control_e        g_synth_control;
 
-/* If the daemon get the result */
-static bool    g_is_next_synthesis = false;
+static Ecore_Timer* g_wait_timer = NULL;
 
 /* Function definitions */
 int __server_next_synthesis(int uid);
 
 
-int __server_set_is_synthesizing(bool flag)
+int __server_set_synth_control(ttsd_synthesis_control_e control)
 {
-       g_is_synthesizing = flag;
+       g_synth_control = control;
        return 0;
 }
 
-bool __server_get_is_synthesizing()
+ttsd_synthesis_control_e __server_get_synth_control()
 {
-       return g_is_synthesizing;
-}
-
-int __server_set_is_next_synthesis(bool flag)
-{
-       g_is_next_synthesis = flag;
-       return 0;
-}
-
-bool __server_get_is_next_synthesis()
-{
-       return g_is_next_synthesis;
+       return g_synth_control;
 }
 
 int __server_send_error(int uid, int utt_id, int error_code)
@@ -76,124 +69,32 @@ int __server_send_error(int uid, int utt_id, int error_code)
        return 0;
 }
 
-int __server_start_synthesis(int uid, int mode)
+Eina_Bool __wait_synthesis(void *data)
 {
-       int result = 0;
-
-       /* check if tts-engine is running */
-       if (true == __server_get_is_synthesizing()) {
-               SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running ");
-       } else {
-               speak_data_s sdata;
-               if (0 == ttsd_data_get_speak_data(uid, &sdata)) {
-                       utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
-
-                       if (NULL == utt) {
-                               SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Out of memory : utterance ");
-                               return TTSD_ERROR_OUT_OF_MEMORY;
-                       }
-
-                       utt->uid = uid;
-                       utt->uttid = sdata.utt_id;
-                       
-                       SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
-                       SLOG(LOG_DEBUG, get_tag(), "ID : uid (%d), uttid(%d) ", utt->uid, utt->uttid );
-                       SLOG(LOG_DEBUG, get_tag(), "Voice : langauge(%s), type(%d), speed(%d)", sdata.lang, sdata.vctype, sdata.speed);
-                       SLOG(LOG_DEBUG, get_tag(), "Text : %s", sdata.text);
-                       SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
-
-                       __server_set_is_synthesizing(true);
-                       int ret = 0;
-                       ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
-                       if (0 != ret) {
-                               SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] * FAIL to start SYNTHESIS !!!! * ", __FUNCTION__);
-
-                               __server_set_is_synthesizing(false);
-
-                               result = TTSD_ERROR_OPERATION_FAILED;
-
-                               g_free(utt);
-
-                               /* mode 2 : Add text in playing state */
-                               if (2 == mode) {
-                                       __server_send_error(uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED);
-                                       ttsd_config_save_error(utt->uid, utt->uttid, sdata.lang, sdata.vctype, sdata.text, __FUNCTION__, __LINE__, "fail to start synthesis (mode=2)");
-
-                                       ttsd_server_stop(uid);
-
-                                       int pid = ttsd_data_get_pid(uid);
-                                       ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
-                               }
-                       } else {
-                               SLOG(LOG_DEBUG, get_tag(), "[Server] SUCCESS to start synthesis");
-                       }
-
-                       if(sdata.text != NULL)  
-                               g_free(sdata.text);
+       /* get current play */
+       int uid = ttsd_data_is_current_playing();
 
+       if (uid > 0) {
+               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+                       return EINA_TRUE;
                } else {
-                       SLOG(LOG_DEBUG, get_tag(), "[Server] Text List is EMPTY!! ");
-               }
-       }
-
-       return result;
-}
-
-int __server_play_internal(int uid, app_state_e state)
-{
-       /* precondition                 */
-       /* - uid is valid               */
-       /* - input uid is current play  */
-
-       int ret = 0;
-
-       if (APP_STATE_PAUSED == state) {
-               SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Pause' state : Next step is resume player and start synthesis ", uid);
-
-               /* resume player and start speech synthesis */
-               if (0 != ttsd_player_resume(uid)) {
-                       SLOG(LOG_WARN, get_tag(), "[Server WARNING] fail to ttsd_player_resume()");
-               } 
-               
-               /* mode 1 for play */
-               ret = __server_start_synthesis(uid, 1);
-
-       } else if(APP_STATE_READY == state) {
-               SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Ready' state : Next step is start synthesis ", uid);
-               
-               /* mode 1 for play */
-               ret = __server_start_synthesis(uid, 1);
+                       g_wait_timer = NULL;
+                       if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) {
+                               /* Start next synthesis */
+                               __server_next_synthesis(uid);
+                       }
+               }       
        } else {
-               /* NO this case */
+               g_wait_timer = NULL;
        }
 
-       return ret;
+       return EINA_FALSE;
 }
 
-int __server_next_synthesis(int uid)
+int __synthesis(int uid)
 {
-       SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY START");
-
-       /* get current playing client */
-       int current_uid = ttsd_data_get_current_playing();
-
-       if (0 > current_uid) {
-               SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current uid is not valid");
-               SLOG(LOG_DEBUG, get_tag(), "=====");
-               SLOG(LOG_DEBUG, get_tag(), "  ");
-               return 0;
-       }
-
-       if (true == __server_get_is_synthesizing()) {
-               SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running. ");
-               SLOG(LOG_DEBUG, get_tag(), "=====");
-               SLOG(LOG_DEBUG, get_tag(), "  ");
-               return 0;
-       }
-
-       /* synthesize next text */
        speak_data_s sdata;
-       if (0 == ttsd_data_get_speak_data(current_uid, &sdata)) {
+       if (0 == ttsd_data_get_speak_data(uid, &sdata)) {
 
                utterance_t* utt = (utterance_t*)g_malloc0(sizeof(utterance_t));
 
@@ -202,7 +103,7 @@ int __server_next_synthesis(int uid)
                        return TTSD_ERROR_OUT_OF_MEMORY;
                }
 
-               utt->uid = current_uid;
+               utt->uid = uid;
                utt->uttid = sdata.utt_id;
 
                SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
@@ -211,24 +112,24 @@ int __server_next_synthesis(int uid)
                SLOG(LOG_DEBUG, get_tag(), "Text : %s", sdata.text);
                SLOG(LOG_DEBUG, get_tag(), "-----------------------------------------------------------");
 
-               __server_set_is_synthesizing(true);
-
                int ret = 0;
+               __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
                ret = ttsd_engine_start_synthesis(sdata.lang, sdata.vctype, sdata.text, sdata.speed, (void*)utt);
                if (0 != ret) {
                        SLOG(LOG_ERROR, get_tag(), "[Server ERROR][%s] * FAIL to start SYNTHESIS !!!! * ", __FUNCTION__);
 
-                       __server_set_is_synthesizing(false);
+                       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
 
-                       __server_send_error(current_uid, sdata.utt_id, TTSD_ERROR_OPERATION_FAILED);
                        ttsd_config_save_error(utt->uid, utt->uttid, sdata.lang, sdata.vctype, sdata.text, __FUNCTION__, __LINE__, "fail to start synthesis");
 
                        g_free(utt);
 
-                       ttsd_server_stop(current_uid);
+                       ttsd_server_stop(uid);
 
-                       int pid = ttsd_data_get_pid(current_uid);
-                       ttsdc_send_set_state_message(pid, current_uid, APP_STATE_READY);
+                       int pid = ttsd_data_get_pid(uid);
+                       ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
+               } else {
+                       g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL);
                }
 
                if(sdata.text != NULL)  
@@ -239,8 +140,34 @@ int __server_next_synthesis(int uid)
                SLOG(LOG_DEBUG, get_tag(), "[Server] --------------------");
        }
 
+       return 0;
+}
+
+int __server_next_synthesis(int uid)
+{
+       SLOG(LOG_DEBUG, get_tag(), "===== NEXT SYNTHESIS & PLAY START");
+
+       /* get current playing client */
+       int current_uid = ttsd_data_get_current_playing();
+
+       if (0 > current_uid) {
+               SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current uid is not valid");
+               SLOG(LOG_DEBUG, get_tag(), "=====");
+               SLOG(LOG_DEBUG, get_tag(), "  ");
+               return 0;
+       }
+
+       if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+               SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running. ");
+               SLOG(LOG_DEBUG, get_tag(), "=====");
+               SLOG(LOG_DEBUG, get_tag(), "  ");
+               return 0;
+       }
+
+       __synthesis(current_uid);
+
        if (0 != ttsd_player_play(current_uid)) {
-               SLOG(LOG_WARN, get_tag(), "[Server WARNING] __server_next_synthesis : fail ttsd_player_play() ");
+               SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail ttsd_player_play() ");
        } else {
                /* success playing */
                SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player");
@@ -263,11 +190,10 @@ int __player_result_callback(player_event_e event, int uid, int utt_id)
                SLOG(LOG_ERROR, get_tag(), "[SERVER ERROR][%s] player result error", __FUNCTION__);
                __server_send_error(uid, utt_id, TTSD_ERROR_OPERATION_FAILED);
                ttsd_config_save_error(uid, utt_id, NULL, -1, NULL, __FUNCTION__, __LINE__, "PLAYER_ERROR");
-               // break;
 
        case PLAYER_EMPTY_SOUND_QUEUE:
                /* check whether synthesis is running */
-               if (false == __server_get_is_synthesizing()) {
+               if (TTSD_SYNTHESIS_CONTROL_DONE == __server_get_synth_control()) {
                        /* check text queue is empty */
                        if (0 == ttsd_data_get_speak_data_size(uid) && 0 == ttsd_data_get_sound_data_size(uid)) {
                                SLOG(LOG_DEBUG, get_tag(), "[SERVER Callback] all play completed ");
@@ -346,17 +272,14 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns
                }
 
                if (event == TTSP_RESULT_EVENT_FINISH) {
-                       __server_set_is_synthesizing(false);
-                       __server_set_is_next_synthesis(true);
+                       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                }
        } else if (event == TTSP_RESULT_EVENT_CANCEL) {
                SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_CANCEL");
-               __server_set_is_synthesizing(false);
-               __server_set_is_next_synthesis(true);
+               __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
        } else {
-               SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event ERROR");
-               __server_set_is_synthesizing(false);
-               __server_set_is_next_synthesis(true);
+               SLOG(LOG_DEBUG, get_tag(), "[SERVER] Event : TTSP_RESULT_EVENT_ERROR");
+               __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
        } 
 
        if (TTSP_RESULT_EVENT_FINISH == event || TTSP_RESULT_EVENT_CANCEL == event || TTSP_RESULT_EVENT_FAIL == event) {
@@ -367,6 +290,7 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns
        SLOG(LOG_DEBUG, get_tag(), "===== SYNTHESIS RESULT CALLBACK END");
        SLOG(LOG_DEBUG, get_tag(), "  ");
 
+#if 0
        if (true == __server_get_is_next_synthesis()) {
                __server_set_is_next_synthesis(false);
 
@@ -374,6 +298,7 @@ int __synthesis_result_callback(ttsp_result_event_e event, const void* data, uns
                /* need to send dbus message event */
                ttsd_send_start_next_synthesis();
        }
+#endif
 
        return 0;
 }
@@ -400,7 +325,7 @@ void __config_lang_changed_cb(const char* language, int type)
        int ret = -1;
 
        if (true == ttsd_engine_select_valid_voice(language, type, &out_lang, &out_type)) {
-               SLOG(LOG_ERROR, get_tag(), "[Server] vaild language : lang(%s), type(%d)", out_lang, out_type);
+               SLOG(LOG_ERROR, get_tag(), "[Server] valid language : lang(%s), type(%d)", out_lang, out_type);
                ret = ttsd_engine_setting_set_default_voice(out_lang, out_type);
                if (0 != ret)
                        SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set vaild language : lang(%s), type(%d)", out_lang, out_type);
@@ -412,7 +337,7 @@ void __config_lang_changed_cb(const char* language, int type)
                if (true == ttsd_engine_select_valid_voice("en_US", type, &out_lang, &out_type)) {
                        ret = ttsd_engine_setting_set_default_voice(out_lang, out_type);
                        if (0 != ret) 
-                               SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set vaild language : lang(%s), type(%d)", out_lang, out_type);
+                               SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to set valid language : lang(%s), type(%d)", out_lang, out_type);
                        
                        if (NULL == out_lang)
                                free(out_lang);
@@ -424,7 +349,7 @@ void __config_lang_changed_cb(const char* language, int type)
 
 
 /*
-* Daemon init
+* Server APIs
 */
 
 int ttsd_initialize()
@@ -452,6 +377,8 @@ int ttsd_initialize()
        } else 
                g_is_engine = true;
        
+       __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
+
        return TTSD_ERROR_NONE;
 }
 
@@ -520,11 +447,18 @@ int ttsd_server_initialize(int pid, int uid)
                        SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to load current engine ");
                        return TTSD_ERROR_OPERATION_FAILED;
                }
-
                /* Check system language */
                ttsd_config_update_language();
        }
 
+       if (0 == ttsd_data_get_same_pid_client_count(pid)) {
+               SLOG(LOG_DEBUG, get_tag(), "[Server] open file msg connection");
+               if (0 != ttsd_file_msg_open_connection(pid)) {
+                       SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail to open file message connection");
+                       return TTSD_ERROR_OPERATION_FAILED;
+               }
+       }
+
        if (0 != ttsd_data_new_client(pid, uid)) {
                SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to add client info ");
                return TTSD_ERROR_OPERATION_FAILED;
@@ -557,8 +491,15 @@ int ttsd_server_finalize(int uid)
        
        ttsd_player_destroy_instance(uid);
 
+       int pid = ttsd_data_get_pid(uid);
+
        ttsd_data_delete_client(uid);
 
+       if (0 == ttsd_data_get_same_pid_client_count(pid)) {
+               SLOG(LOG_DEBUG, get_tag(), "[Sever] File msg close connection");
+               ttsd_file_msg_close_connection(pid);
+       }
+
        /* unload engine, if ref count of client is 0 */
        if (0 == ttsd_data_get_client_count()) {
                ecore_timer_add(0, __quit_ecore_loop, NULL);
@@ -611,10 +552,11 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice
                        }
                }
 
-               /* mode 2 for add text */
-               if (0 != __server_start_synthesis(uid, 2)) {
-                       SLOG(LOG_ERROR, get_tag(), "[Server ERROR] fail to schedule synthesis : uid(%d)", uid);
-                       return TTSD_ERROR_OPERATION_FAILED;
+               /* Check whether tts-engine is running or not */
+               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+                       SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running.");
+               } else {
+                       __synthesis(uid);
                }
        }
 
@@ -680,9 +622,41 @@ int ttsd_server_play(int uid)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       if (0 != __server_play_internal(uid, state)) {
-               SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to start synthesis : uid(%d)", uid);
-               return TTSD_ERROR_OPERATION_FAILED;
+       if (APP_STATE_PAUSED == state) {
+               SLOG(LOG_DEBUG, get_tag(), "[Server] uid(%d) is 'Pause' state : Next step is resume player and start synthesis ", uid);
+
+               ttsd_player_state_e state;
+               if (0 != ttsd_player_get_state(uid, &state)) {
+                       SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to get player state : uid(%d)", uid);
+                       return TTSD_ERROR_OPERATION_FAILED;
+               }
+
+               if (TTSD_PLAYER_STATE_PAUSED == state) {
+                       /* Resume player */
+                       if (0 != ttsd_player_resume(uid)) {
+                               SLOG(LOG_WARN, get_tag(), "[Server WARNING] fail to ttsd_player_resume()");
+                       }
+               } else if (TTSD_PLAYER_STATE_NULL == state) {
+                       if (0 != ttsd_player_play(uid)) {
+                               SLOG(LOG_WARN, get_tag(), "[Server WARNING] Fail ttsd_player_play() ");
+                               
+                               /* Need to wait synthesis */
+                               if (NULL == g_wait_timer)
+                                       g_wait_timer = ecore_timer_add(0, __wait_synthesis, NULL);
+                       } else {
+                               /* success playing */
+                               SLOG(LOG_DEBUG, get_tag(), "[Server] Success to start player");
+                       }       
+               } else {
+                       /* error */
+               }
+       }
+
+       /* Check whether tts-engine is running or not */
+       if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+               SLOG(LOG_WARN, get_tag(), "[Server WARNING] Engine has already been running.");
+       } else {
+               __synthesis(uid);
        }
 
        return TTSD_ERROR_NONE;
@@ -706,16 +680,21 @@ int ttsd_server_stop(int uid)
                if (0 != ttsd_player_stop(uid)) 
                        SLOG(LOG_WARN, get_tag(), "[Server] Fail to ttsd_player_stop()");
 
-               if (true == __server_get_is_synthesizing()) {
+               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
                        SLOG(LOG_DEBUG, get_tag(), "[Server] TTS-engine is running ");
 
                        int ret = 0;
                        ret = ttsd_engine_cancel_synthesis();
                        if (0 != ret)
                                SLOG(LOG_ERROR, get_tag(), "[Server ERROR] Fail to cancel synthesis : ret(%d)", ret);
+               }
 
-                       __server_set_is_synthesizing(false);
-               } 
+               if (NULL != g_wait_timer) {
+                       SLOG(LOG_DEBUG, get_tag(), "Wait timer is deleted");
+                       ecore_timer_del(g_wait_timer);
+               }
+
+               __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
        } else {
                SLOG(LOG_WARN, get_tag(), "[Server WARNING] Current state is 'ready' ");
        }
@@ -787,10 +766,10 @@ int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
        return TTSD_ERROR_NONE;
 }
 
+#if 0
 /*
 * Server API for Internal event
 */
-
 int ttsd_server_start_next_synthesis()
 {
        /* get current play */
@@ -802,6 +781,7 @@ int ttsd_server_start_next_synthesis()
 
        return __server_next_synthesis(uid);
 }
+#endif
 
 /*
 * TTS Server Functions for Setting                                                                                                               *
index 8eac9b9478212ae320be8f9334c2f0c01f8f5eb7..5221668721471c3e89d6deb61ee2a1a596338f51 100755 (executable)
@@ -23,10 +23,8 @@ extern "C" {
 #endif
 
 /**
-* Daemon init
+* Server APIs
 */
-
-/** Daemon initialize */
 int ttsd_initialize();
 
 int ttsd_finalize();
@@ -53,10 +51,12 @@ int ttsd_server_stop(int uid);
 
 int ttsd_server_pause(int uid, int* utt_id);
 
+#if 0
 /*
 * Server API for internal event
 */
 int ttsd_server_start_next_synthesis();
+#endif
 
 /*
 * Server API for setting
index a61eddb94f7723f58308321ce249c0e04ba46531..b72dfbfd8d6783b2b6db28930aacbea25dc66bdf 100755 (executable)
@@ -1,4 +1,4 @@
-tts-server system::app_logging wx
+tts-server device::app_logging wx
 tts-server tts-engine-samsung::vdata rx
 tts-server system::vconf rwxat
 tts-server sound_server rw