Add a new TTS Interrupt mode
[platform/core/uifw/tts.git] / server / ttsd_server.c
old mode 100755 (executable)
new mode 100644 (file)
index d2dd19c..24365e5
@@ -11,6 +11,7 @@
 *  limitations under the License.
 */
 
+#include <app_manager.h>
 #include <aul.h>
 #include <Ecore.h>
 
@@ -25,6 +26,9 @@
 #include "ttsd_server.h"
 
 
+#define CLIENT_CLEAN_UP_TIME 500
+
+
 typedef enum {
        TTSD_SYNTHESIS_CONTROL_DOING    = 0,
        TTSD_SYNTHESIS_CONTROL_DONE     = 1,
@@ -42,6 +46,7 @@ typedef struct {
 /* If engine is running */
 static ttsd_synthesis_control_e        g_synth_control;
 
+static Ecore_Timer* g_check_client_timer = NULL;
 static Ecore_Timer* g_wait_timer = NULL;
 
 static utterance_t g_utt;
@@ -70,7 +75,6 @@ static Eina_Bool __wait_synthesis(void *data)
 
        if (uid > 0) {
                if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
-                       usleep(100000);
                        return EINA_TRUE;
                } else {
                        g_wait_timer = NULL;
@@ -88,11 +92,12 @@ static Eina_Bool __wait_synthesis(void *data)
 
 static int __synthesis(int uid, const char* credential)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== SYNTHESIS  START");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS  START");
 
        speak_data_s* speak_data = NULL;
        if (0 == ttsd_data_get_speak_data(uid, &speak_data)) {
                if (NULL == speak_data) {
+                       SLOG(LOG_WARN, tts_tag(), "[Server] speak data is null");
                        return 0;
                }
 
@@ -125,12 +130,12 @@ static int __synthesis(int uid, const char* credential)
                g_utt.uid = uid;
                g_utt.uttid = speak_data->utt_id;
 
-               SLOG(LOG_DEBUG, tts_tag(), "-----------------------------------------------------------");
-               SECURE_SLOG(LOG_DEBUG, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
-               SECURE_SLOG(LOG_DEBUG, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
-               SECURE_SLOG(LOG_DEBUG, tts_tag(), "Text : %s", speak_data->text);
-               SECURE_SLOG(LOG_DEBUG, tts_tag(), "Credential : %s", credential);
-               SLOG(LOG_DEBUG, tts_tag(), "-----------------------------------------------------------");
+               SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
+               SLOG(LOG_INFO, tts_tag(), "ID : uid (%d), uttid(%d) ", g_utt.uid, g_utt.uttid);
+               SLOG(LOG_INFO, tts_tag(), "Voice : langauge(%s), type(%d), speed(%d)", speak_data->lang, speak_data->vctype, speak_data->speed);
+               SLOG(LOG_INFO, tts_tag(), "Text : %s", speak_data->text);
+               SLOG(LOG_INFO, tts_tag(), "Credential : %s", credential);
+               SLOG(LOG_INFO, tts_tag(), "-----------------------------------------------------------");
 
                int ret = 0;
                __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DOING);
@@ -145,7 +150,7 @@ static int __synthesis(int uid, const char* credential)
                        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, (void*)credential);
+                       g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
                }
 
                if (NULL != speak_data) {
@@ -160,8 +165,7 @@ static int __synthesis(int uid, const char* credential)
                }
        }
 
-       SLOG(LOG_DEBUG, tts_tag(), "===== SYNTHESIS  END");
-       SLOG(LOG_DEBUG, tts_tag(), "  ");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS  END");
 
        return 0;
 }
@@ -175,7 +179,7 @@ int ttsd_send_error(ttse_error_e error, const char* msg)
        int uttid = g_utt.uttid;
        int tmp_pid = ttsd_data_get_pid(uid);
 
-       SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%d), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, msg);
+       SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Error msg from engine, pid(%d), uid(%d), uttid(%d), error(%d), msg(%s)", tmp_pid, uid, uttid, error, (NULL == msg ? "NULL" : msg));
 
        __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
 
@@ -198,9 +202,8 @@ int ttsd_send_error(ttse_error_e error, const char* msg)
 }
 
 int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void* user_data)
-
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== SEND SYNTHESIS RESULT START");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ SEND SYNTHESIS RESULT START");
 
        int uid = g_utt.uid;
        int uttid = g_utt.uttid;
@@ -208,11 +211,11 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
        /* Synthesis is success */
        if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
                if (TTSE_RESULT_EVENT_START == event) {
-                       SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
+                       SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
                        SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", 
                                uid, uttid, data, data_size, audio_type, rate);
                } else if (TTSE_RESULT_EVENT_FINISH == event) {
-                       SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
+                       SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
                        SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", 
                                uid, uttid, data, data_size, audio_type, rate);
                } else {
@@ -223,16 +226,14 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
                if (false == ttsd_data_is_uttid_valid(uid, uttid)) {
                        __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                        SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] uttid is NOT valid !!!! - uid(%d), uttid(%d)", uid, uttid);
-                       SLOG(LOG_DEBUG, tts_tag(), "=====");
-                       SLOG(LOG_DEBUG, tts_tag(), "  ");
+                       SLOG(LOG_DEBUG, tts_tag(), "@@@");
                        return TTSD_ERROR_OPERATION_FAILED;
                }
 
                if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
                        __server_set_synth_control(TTSD_SYNTHESIS_CONTROL_DONE);
                        SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
-                       SLOG(LOG_DEBUG, tts_tag(), "=====");
-                       SLOG(LOG_DEBUG, tts_tag(), "  ");
+                       SLOG(LOG_DEBUG, tts_tag(), "@@@");
                        return TTSD_ERROR_INVALID_PARAMETER;
                }
 
@@ -253,7 +254,7 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
                        if (NULL != temp_sound_data->data) {
                                memcpy(temp_sound_data->data, data, data_size);
                                temp_sound_data->data_size = data_size;
-                               SLOG(LOG_ERROR, tts_tag(), "[DEBUG][free] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)", 
+                               SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)", 
                                        uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
                        } else {
                                SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
@@ -291,13 +292,13 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
        }
 
 
-       /*SLOG(LOG_DEBUG, tts_tag(), "===== SYNTHESIS RESULT CALLBACK END");
+       /*SLOG(LOG_DEBUG, tts_tag(), "@@@ SYNTHESIS RESULT CALLBACK END");
        SLOG(LOG_DEBUG, tts_tag(), "  ");*/
 
        return TTSD_ERROR_NONE;
 }
 
-bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
+bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        /* clear client data */
        ttsd_data_clear_data(uid);
@@ -369,7 +370,10 @@ void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_
                        /* Current language is not available */
                        SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set voice : lang(%s), type(%d)", str_param, int_param);
                }
-               if (NULL != out_lang)   free(out_lang);
+               if (NULL != out_lang) {
+                       free(out_lang);
+                       out_lang = NULL;
+               }
                break;
        }
 
@@ -403,9 +407,9 @@ void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_
        return;
 }
 
-bool __terminate_client(int pid, int uid, app_state_e state, void* user_data)
+bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "=== Start to terminate client [%d] ===", uid);
+       SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
        ttsd_server_finalize(uid);
        return true;
 }
@@ -419,7 +423,7 @@ Eina_Bool ttsd_terminate_daemon(void *data)
 void __screen_reader_changed_cb(bool value)
 {
        if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
-               SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
+               SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
                ecore_timer_add(1, ttsd_terminate_daemon, NULL);
        } else {
                SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
@@ -430,37 +434,9 @@ void __screen_reader_changed_cb(bool value)
 /*
 * Server APIs
 */
-static bool __send_reset_signal(int pid, int uid, app_state_e state, void* user_data)
-{
-       ttsdc_send_error_message(pid, uid, -1, TTSD_ERROR_SERVICE_RESET, "TTS service reset");
-       return true;
-}
-
-static void __sig_handler(int signo)
-{
-       /* restore signal handler */
-       signal(signo, SIG_DFL);
-
-       /* Send error signal via foreach clients */
-       ttsd_data_foreach_clients(__send_reset_signal, NULL);
-
-       /* invoke signal again */
-       raise(signo);
-}
-
-static void __register_sig_handler()
-{
-       signal(SIGSEGV, __sig_handler);
-       signal(SIGABRT, __sig_handler);
-       signal(SIGTERM, __sig_handler);
-       signal(SIGINT, __sig_handler);
-       signal(SIGQUIT, __sig_handler);
-}
-
 int ttsd_initialize(ttse_request_callback_s *callback)
 {
-       /* Register signal handler */
-       __register_sig_handler();
+       SLOG(LOG_INFO, tts_tag(), "[Server] Initialize");
 
        if (ttsd_config_initialize(__config_changed_cb)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
@@ -496,11 +472,18 @@ int ttsd_initialize(ttse_request_callback_s *callback)
                ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
        }
 
+       g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
+       if (NULL == g_check_client_timer) {
+               SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
+       }
+
        return TTSD_ERROR_NONE;
 }
 
 int ttsd_finalize()
 {
+       SLOG(LOG_INFO, tts_tag(), "[Server] Finalize");
+
        GList *iter = NULL;
        if (0 < g_list_length(g_proc_list)) {
                iter = g_list_first(g_proc_list);
@@ -517,6 +500,13 @@ int ttsd_finalize()
 
        ttsd_engine_agent_release();
 
+       if (NULL != g_check_client_timer) {
+               ecore_timer_del(g_check_client_timer);
+               g_check_client_timer = NULL;
+
+               SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore timer handle");
+       }
+
        return TTSD_ERROR_NONE;
 }
 
@@ -526,15 +516,39 @@ int ttsd_finalize()
 
 int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
 {
+       SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
+
        if (-1 != ttsd_data_is_client(uid)) {
                SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Uid has already been registered");
                return TTSD_ERROR_NONE;
        }
 
        if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
-               SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to get credential necessity");
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
                return TTSD_ERROR_OPERATION_FAILED;
        }
+
+       if (true == *credential_needed) {
+               char* appid = NULL;
+               if (0 != app_manager_get_app_id(pid, &appid)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
+               }
+               bool is_agreed = false;
+               if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
+                       SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
+                       if (!appid)
+                               free(appid);
+                       return TTSD_ERROR_OPERATION_FAILED;
+               }
+               if (!appid)
+                       free(appid);
+
+               if (false == is_agreed) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+                       return TTSD_ERROR_PERMISSION_DENIED;
+               }
+       }
+
        if (0 != ttsd_data_new_client(pid, uid)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
                return TTSD_ERROR_OPERATION_FAILED;
@@ -551,12 +565,10 @@ int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
 static Eina_Bool __quit_ecore_loop(void *data)
 {
        ttsd_dbus_close_connection();
-
        ttsd_network_finalize();
-
        ttsd_finalize();
-
        ecore_main_loop_quit();
+
        return EINA_FALSE;
 }
 
@@ -595,7 +607,7 @@ static void __read_proc()
        return;
 }
 
-bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
+bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        bool exist = false;
        int i = 0;
@@ -646,17 +658,16 @@ bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_d
 
 Eina_Bool ttsd_cleanup_client(void *data)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== CLEAN UP CLIENT START");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ CLEAN UP CLIENT START");
        __read_proc();
 
        if (0 < ttsd_data_get_client_count()) {
-       ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
-               } else {
+               ttsd_data_foreach_clients(__get_client_for_clean_up, NULL);
+       } else {
                ecore_timer_add(0, __quit_ecore_loop, NULL);
        }
 
-       SLOG(LOG_DEBUG, tts_tag(), "=====");
-       SLOG(LOG_DEBUG, tts_tag(), "  ");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@");
 
        return EINA_TRUE;
 }
@@ -671,7 +682,9 @@ void __used_voice_cb(const char* lang, int type)
 
 int ttsd_server_finalize(int uid)
 {
-       app_state_e state;
+       SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
+
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
        }
@@ -700,7 +713,7 @@ int ttsd_server_finalize(int uid)
 
 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -711,7 +724,10 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice
        int temp_type;
        if (true != ttsd_engine_select_valid_voice((const char*)lang, voice_type, &temp_lang, &temp_type)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to select valid voice");
-               if (NULL != temp_lang)  free(temp_lang);
+               if (NULL != temp_lang) {
+                       free(temp_lang);
+                       temp_lang = NULL;
+               }
                return TTSD_ERROR_INVALID_VOICE;
        }
 
@@ -724,7 +740,10 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice
        speak_data = (speak_data_s*)calloc(1, sizeof(speak_data_s));
        if (NULL == speak_data) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to allocate memory");
-               if (NULL != temp_lang)  free(temp_lang);
+               if (NULL != temp_lang) {
+                       free(temp_lang);
+                       temp_lang = NULL;
+               }
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
@@ -736,10 +755,17 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice
 
        speak_data->text = strdup(text);
 
+       SLOG(LOG_INFO, tts_tag(), "[Server] Add queue, lang(%s), vctype(%d), speed(%d), uttid(%d), credential(%s)", lang, voice_type, speed, utt_id, credential);
+
        /* if state is APP_STATE_READY , APP_STATE_PAUSED , only need to add speak data to queue*/
-       if (0 != ttsd_data_add_speak_data(uid, speak_data)) {
+       int ret = -1;
+       ret = ttsd_data_add_speak_data(uid, speak_data);
+       if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add speak data");
-               if (NULL != temp_lang)  free(temp_lang);
+               if (NULL != temp_lang) {
+                       free(temp_lang);
+                       temp_lang = NULL;
+               }
                if (NULL != speak_data) {
                        if (NULL != speak_data->lang)   free(speak_data->lang);
                        if (NULL != speak_data->text)   free(speak_data->text);
@@ -751,7 +777,7 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice
                        speak_data = NULL;
                }
 
-               return TTSD_ERROR_OPERATION_FAILED;
+               return ret;
        }
 
        if (0 != ttsd_data_set_used_voice(uid, temp_lang, temp_type)) {
@@ -762,7 +788,10 @@ int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice
                }
        }
 
-       if (NULL != temp_lang)  free(temp_lang);
+       if (NULL != temp_lang) {
+               free(temp_lang);
+               temp_lang = NULL;
+       }
 
        if (APP_STATE_PLAYING == state) {
                /* check if engine use network */
@@ -803,7 +832,7 @@ Eina_Bool __send_interrupt_client(void *data)
 
 int ttsd_server_play(int uid, const char* credential)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid  ", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -822,8 +851,21 @@ int ttsd_server_play(int uid, const char* credential)
                }
        }
 
+       /* check the current playback focus */
+       if (TTSD_MODE_INTERRUPT != ttsd_get_mode()) {
+               bool is_current_interrupt = false;
+               if (0 != ttsd_player_check_current_playback_focus(&is_current_interrupt)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to check the current playback focus");
+               } else {
+                       if (true == is_current_interrupt) {
+                               SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
+                               return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
+                       }
+               }
+       }
+
        int current_uid = ttsd_data_get_current_playing();
-       SLOG(LOG_ERROR, tts_tag(), "[Server] playing uid (%d)", current_uid);
+       SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
 
        if (uid != current_uid && -1 != current_uid) {
                if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
@@ -884,17 +926,18 @@ int ttsd_server_play(int uid, const char* credential)
        return TTSD_ERROR_NONE;
 }
 
-
 int ttsd_server_stop(int uid)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
        }
 
+       SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
+
        if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
-               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control()) {
+               if (TTSD_SYNTHESIS_CONTROL_DOING == __server_get_synth_control() && uid == ttsd_data_get_current_playing()) {
                        SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS-engine is running");
 
                        int ret = 0;
@@ -919,7 +962,7 @@ int ttsd_server_stop(int uid)
 
 int ttsd_server_pause(int uid, int* utt_id)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -930,6 +973,9 @@ int ttsd_server_pause(int uid, int* utt_id)
                return TTSD_ERROR_INVALID_STATE;
        }
 
+       *utt_id = g_utt.uttid;
+       SLOG(LOG_INFO, tts_tag(), "[Server] server pause, uid(%d), g_uid(%d), utt_id(%d)", uid, g_utt.uid, *utt_id);
+
        int ret = 0;
        ret = ttsd_player_pause(uid);
        if (0 != ret) {
@@ -944,7 +990,7 @@ int ttsd_server_pause(int uid, int* utt_id)
 
 int ttsd_server_get_support_voices(int uid, GList** voice_list)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -964,7 +1010,7 @@ int ttsd_server_get_support_voices(int uid, GList** voice_list)
 
 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -984,7 +1030,7 @@ int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
 
 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -999,7 +1045,7 @@ int ttsd_server_set_private_data(int uid, const char* key, const char* data)
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data : ret(%d)", ret);
        } else {
-               SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data");
+               SLOG(LOG_DEBUG, tts_tag(), "[Server] Set private data, key(%s), data(%s)", key, data);
        }
 
        return ret;
@@ -1007,7 +1053,7 @@ int ttsd_server_set_private_data(int uid, const char* key, const char* data)
 
 int ttsd_server_get_private_data(int uid, const char* key, char** data)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -1022,7 +1068,7 @@ int ttsd_server_get_private_data(int uid, const char* key, char** data)
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get private data : ret(%d)", ret);
        } else {
-               SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data");
+               SLOG(LOG_DEBUG, tts_tag(), "[Server] Get private data, key(%s), data(%s)", key, *data);
        }
 
        return ret;
@@ -1054,4 +1100,193 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
        return ret;
 }
 
+int ttsd_server_play_pcm(int uid)
+{
+       app_tts_state_e state;
+       if (0 > ttsd_data_get_client_state(uid, &state)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid  ", uid);
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (APP_STATE_PLAYING == state) {
+               SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current state(%d) is 'play' ", uid);
+               return TTSD_ERROR_NONE;
+       }
+
+       int current_uid = ttsd_data_get_current_playing();
+       SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
+
+       if (uid != current_uid && -1 != current_uid) {
+               if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
+                       /* Send interrupt message */
+                       SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
+
+                       /* pause player */
+                       if (0 != ttsd_server_stop(current_uid)) {
+                               SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to stop : uid (%d)", current_uid);
+                       }
+                       if (0 != ttsd_player_stop(current_uid)) {
+                               SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to player stop : uid (%d)", current_uid);
+                       }
+
+                       intptr_t pcurrent_uid = (intptr_t)current_uid;
+                       ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
+               } else {
+                       /* Default mode policy of interrupt is "Pause" */
+
+                       /* Send interrupt message */
+                       SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Pause' state ", current_uid);
+
+                       /* pause player */
+                       if (0 != ttsd_player_pause(current_uid)) {
+                               SLOG(LOG_WARN, tts_tag(), "[Server ERROR] Fail to ttsd_player_pause() : uid (%d)", current_uid);
+                       }
+
+                       /* change state */
+                       ttsd_data_set_client_state(current_uid, APP_STATE_PAUSED);
 
+                       intptr_t pcurrent_uid = (intptr_t)current_uid;
+                       ecore_timer_add(0, __send_interrupt_client, (void*)pcurrent_uid);
+               }
+       }
+
+       /* Change current play */
+       if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       if (APP_STATE_PAUSED == state) {
+               SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
+
+               /* Resume player */
+               if (0 != ttsd_player_resume(uid)) {
+                       SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
+               }
+       } else {
+               if (0 != ttsd_player_play_pcm(uid)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
+
+                       // Change ready state
+                       ttsd_server_stop_pcm(uid);
+
+                       int tmp_pid;
+                       tmp_pid = ttsd_data_get_pid(uid);
+                       ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+               }
+       }
+
+       return TTSD_ERROR_NONE;
+}
+
+int ttsd_server_stop_pcm(int uid)
+{
+       app_tts_state_e state;
+       if (0 > ttsd_data_get_client_state(uid, &state)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+
+       SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
+
+       if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
+               ttsd_data_set_client_state(uid, APP_STATE_READY);
+       }
+
+       /* Reset all data */
+       ttsd_data_clear_data(uid);
+
+       ttsd_player_stop(uid);
+
+
+       return TTSD_ERROR_NONE;
+}
+
+int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio_type, int rate)
+{
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ ADD PCM");
+
+       int uttid = -1;
+
+       /* Synthesis is success */
+       if (TTSE_RESULT_EVENT_START == event || TTSE_RESULT_EVENT_CONTINUE == event || TTSE_RESULT_EVENT_FINISH == event) {
+               if (TTSE_RESULT_EVENT_START == event) {
+                       SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START");
+                       SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", 
+                               uid, uttid, data, data_size, audio_type, rate);
+               } else if (TTSE_RESULT_EVENT_FINISH == event) {
+                       SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH");
+                       SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] PCM Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", 
+                               uid, uttid, data, data_size, audio_type, rate);
+               } else {
+                       /*if (TTSE_RESULT_EVENT_CONTINUE == event)  SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_CONTINUE");*/
+               }
+
+               if (rate <= 0 || audio_type < 0 || audio_type > TTSE_AUDIO_TYPE_MAX) {
+                       SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] audio data is invalid");
+                       SLOG(LOG_DEBUG, tts_tag(), "@@@");
+                       return TTSD_ERROR_INVALID_PARAMETER;
+               }
+
+               /* add wav data */
+               sound_data_s* temp_sound_data = NULL;
+               temp_sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
+               if (NULL == temp_sound_data) {
+                       SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Out of memory");
+                       return TTSD_ERROR_OUT_OF_MEMORY;
+               }
+
+               temp_sound_data->data = NULL;
+               temp_sound_data->rate = 0;
+               temp_sound_data->data_size = 0;
+
+               if (0 < data_size) {
+                       temp_sound_data->data = (char*)calloc(data_size + 5, sizeof(char));
+                       if (NULL != temp_sound_data->data) {
+                               memcpy(temp_sound_data->data, data, data_size);
+                               temp_sound_data->data_size = data_size;
+                               SLOG(LOG_INFO, tts_tag(), "[DEBUG][memcpy] uid(%d), event(%d) sound_data(%p) data(%p) size(%d)", 
+                                       uid, event, temp_sound_data, temp_sound_data->data, temp_sound_data->data_size);
+                       } else {
+                               SLOG(LOG_ERROR, tts_tag(), "Fail to allocate memory");
+                       }
+               } else {
+                       SLOG(LOG_ERROR, tts_tag(), "Sound data is NULL");
+               }
+
+               temp_sound_data->utt_id = uttid;
+               temp_sound_data->event = event;
+               temp_sound_data->audio_type = audio_type;
+               temp_sound_data->rate = rate;
+
+               if (0 != ttsd_data_add_sound_data(uid, temp_sound_data)) {
+                       SECURE_SLOG(LOG_ERROR, tts_tag(), "[SERVER ERROR] Fail to add sound data : uid(%d)", uid);
+
+                       if (NULL != temp_sound_data->data) {
+                               free(temp_sound_data->data);
+                               temp_sound_data->data = NULL;
+                       }
+
+                       free(temp_sound_data);
+                       temp_sound_data = NULL;
+               }
+
+/*             if (0 != ttsd_player_play(uid)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
+
+                       // Change ready state
+                       ttsd_server_stop(uid);
+
+                       int tmp_pid;
+                       tmp_pid = ttsd_data_get_pid(uid);
+                       ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+               }
+*/
+       } else {
+               SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
+       }
+
+       SLOG(LOG_DEBUG, tts_tag(), "@@@");
+
+       return TTSD_ERROR_NONE;
+}