Update hello protocol
[platform/core/uifw/tts.git] / client / tts.c
index 3917840..b7176fc 100644 (file)
@@ -11,6 +11,7 @@
 *  limitations under the License.
 */
 
+#include <app_manager.h>
 #include <dirent.h>
 #include <Ecore.h>
 #include <iconv.h>
@@ -19,6 +20,8 @@
 #include <sys/wait.h>
 #include <system_info.h>
 #include <vconf.h>
+#include <package-manager.h>
+#include <pthread.h>
 
 #include "tts.h"
 #include "tts_client.h"
@@ -26,6 +29,7 @@
 #include "tts_dbus.h"
 #include "tts_main.h"
 
+#include "tts_internal.h"
 
 static bool g_screen_reader;
 
@@ -33,9 +37,31 @@ static int g_feature_enabled = -1;
 
 static bool g_err_callback_status = false;
 
+static int g_max_text_size = -1;
+
+static Ecore_Timer* g_check_state_timer = NULL;
+
+static Ecore_Timer* g_hello_timer;
+
+/* for repetition */
+static char* g_language = NULL;
+
+static int g_voice_type = -1;
+
+static int g_speed = -1;
+
+/* for checking engine update */
+static pkgmgr_client* g_pkgmgr = NULL;
+static char* g_engine_name = NULL;
+static int g_engine_update_status = 0;
+static pthread_mutex_t g_pkgmgr_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+
 /* Function definition */
 static Eina_Bool __tts_notify_state_changed(void *data);
 static Eina_Bool __tts_notify_error(void *data);
+int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg);
+
 
 const char* tts_tag()
 {
@@ -105,6 +131,7 @@ static int __tts_convert_config_error_code(tts_config_error_e code)
        return code;
 }
 
+//LCOV_EXCL_START
 void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_type, const char* language, int voice_type, bool auto_voice, void* user_data)
 {
        SLOG(LOG_DEBUG, TAG_TTSC, "Voice changed : Before lang(%s) type(%d) , Current lang(%s), type(%d)",
@@ -128,6 +155,14 @@ void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_typ
                                        language, voice_type, data->default_voice_changed_user_data);
                        }
 
+                       /* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
+                       if (0 != strncmp(before_lang, language, strlen(before_lang))) {
+                               if (NULL != data->text_repeat) {
+                                       free(data->text_repeat);
+                                       data->text_repeat = NULL;
+                               }
+                       }
+
                        /* Next item */
                        iter = g_list_next(iter);
                }
@@ -136,6 +171,33 @@ void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_typ
        return;
 }
 
+static Eina_Bool __reconnect_by_engine_changed(void* data)
+{
+       tts_h tts = (tts_h)data;
+
+       tts_client_s* client = tts_client_get(tts);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
+               return EINA_FALSE;
+       }
+
+       if (TTS_STATE_READY != client->current_state) {
+               usleep(10000);
+               return EINA_TRUE;
+       }
+
+       int ret = tts_unprepare(tts);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+       }
+       ret = tts_prepare(tts);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+       }
+
+       return EINA_FALSE;
+}
+
 void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
 {
        tts_h tts = (tts_h)user_data;
@@ -151,6 +213,27 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c
        if (NULL != language)   SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
        SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
 
+       /* When the default engine is changed, please unload the old engine and load the new one. */
+       int ret = -1;
+
+       if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_PAUSED == client->current_state) {
+               ret = tts_stop(tts);
+               if (0 != ret) {
+                       SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
+               }
+
+               ecore_idler_add(__reconnect_by_engine_changed, (void*)tts);
+       } else if (TTS_STATE_READY == client->current_state) {
+               ret = tts_unprepare(tts);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret);
+               }
+               ret = tts_prepare(tts);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
+               }
+       }
+
        /* call callback function */
        if (NULL != client->engine_changed_cb) {
                client->engine_changed_cb(tts, engine_id, language, voice_type, need_credential, client->engine_changed_user_data);
@@ -159,6 +242,85 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c
        }
        return;
 }
+//LCOV_EXCL_STOP
+
+void __tts_unset_all_callbacks(tts_h tts)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ unset all callbacks");
+
+       tts_unset_state_changed_cb(tts);
+       tts_unset_utterance_started_cb(tts);
+       tts_unset_utterance_completed_cb(tts);
+       tts_unset_error_cb(tts);
+       tts_unset_default_voice_changed_cb(tts);
+       tts_unset_engine_changed_cb(tts);
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+}
+
+static int __pkgmgr_status_cb(uid_t target_uid, int req_id, const char *type, const char *pkgname, const char *key, const char *val, const void *pmsg, void *data)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] pkgmgr status cb is invoked. pkgname(%s), type(%s), key(%s), val(%s)", pkgname, type, key, val);
+
+       if (0 != strncmp(g_engine_name, pkgname, strlen(g_engine_name))) {
+               SLOG(LOG_DEBUG, TAG_TTSC, "[WARN] this is not tts engine");
+               return 0;
+       } else {
+               if (key && 0 == strncmp(key, "start", strlen(key))) {
+                       if (val && (0 == strncmp(val, "update", strlen(val) || 0 == strncmp(val, "uninstall", strlen(val))))) {
+                               SLOG(LOG_INFO, TAG_TTSC, "[INFO] start to install.");
+                               g_engine_update_status = 1;
+                       }
+               } else if (key && 0 == strncmp(key, "end", strlen(key))) {
+                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] finish to install");
+                       g_engine_update_status = 0;
+               }
+       }
+
+       return 0;
+}
+
+static void __create_pkgmgr_thread(void* data, Ecore_Thread* thread)
+{
+       SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] create pkgmgr thread");
+
+       pthread_mutex_lock(&g_pkgmgr_mutex);
+
+       while (!g_pkgmgr) {
+               g_pkgmgr = pkgmgr_client_new(PC_LISTENING);
+               if (NULL == g_pkgmgr) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to create pkgmgr handle");
+               } else {
+                       if (pkgmgr_client_listen_status(g_pkgmgr, __pkgmgr_status_cb, NULL) < 0) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to listen pkgmgr status. remove and recreate client");
+                               pkgmgr_client_free(g_pkgmgr);
+                               g_pkgmgr = NULL;
+                               continue;
+                       } else {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] Succeed to register pkgmgr cb");
+                       }
+               }
+               usleep(10000);
+       }
+
+       pthread_mutex_unlock(&g_pkgmgr_mutex);
+
+       return ;
+}
+
+static void __finish_pkgmgr_thread(void* data, Ecore_Thread* thread)
+{
+       SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] Finish pkgmgr thread");
+}
+
+static void __pkgmgr_thread(void* data)
+{
+       SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] call pkgmgr_thread");
+
+       ecore_thread_run(__create_pkgmgr_thread, __finish_pkgmgr_thread, NULL, NULL);
+
+       return ;
+}
 
 int tts_create(tts_h* tts)
 {
@@ -166,13 +328,12 @@ int tts_create(tts_h* tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Create TTS");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS");
 
        /* check param */
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -201,14 +362,25 @@ int tts_create(tts_h* tts)
                return __tts_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL);
+       ret = tts_config_mgr_set_callback(client->uid, _tts_config_engine_changed_cb, __tts_config_voice_changed_cb, NULL, NULL, NULL, client->tts);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                tts_client_destroy(*tts);
                return __tts_convert_config_error_code(ret);
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       ecore_main_loop_thread_safe_call_async(__pkgmgr_thread, NULL);
+
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] call ecore thread for creating pkgmgr thread");
+
+       g_engine_name = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
+       if (NULL == g_engine_name) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get engine name");
+       } else {
+               SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Engine name(%s)", g_engine_name);
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
        SLOG(LOG_DEBUG, TAG_TTSC, " ");
 
        return TTS_ERROR_NONE;
@@ -220,7 +392,7 @@ int tts_destroy(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Destroy TTS");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
@@ -241,20 +413,37 @@ int tts_destroy(tts_h tts)
                return TTS_ERROR_OPERATION_FAILED;
        }
 
+       pthread_mutex_lock(&g_pkgmgr_mutex);
+       if (g_pkgmgr) {
+               pkgmgr_client_remove_listen_status(g_pkgmgr);
+               pkgmgr_client_free(g_pkgmgr);
+               g_pkgmgr = NULL;
+       }
+       pthread_mutex_unlock(&g_pkgmgr_mutex);
+
        tts_config_mgr_finalize(client->uid);
 
        int ret = -1;
        int count = 0;
+       int screen_reader = -1;
 
        /* check state */
        switch (client->current_state) {
        case TTS_STATE_PAUSED:
        case TTS_STATE_PLAYING:
        case TTS_STATE_READY:
+               ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader");
+               } else {
+                       SLOG(LOG_INFO, tts_tag(), "[INFO] Success to get screen reader(%d), g_screen_reader(%s), client->mode(%d)", screen_reader, (true == g_screen_reader) ? "True" : "False", client->mode);
+                       g_screen_reader = (bool)screen_reader;
+               }
                if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
-                       while (0 != ret) {
+                       do {
                                ret = tts_dbus_request_finalize(client->uid);
                                if (0 != ret) {
+                                       //LCOV_EXCL_START
                                        if (TTS_ERROR_TIMED_OUT != ret) {
                                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                                break;
@@ -267,8 +456,9 @@ int tts_destroy(tts_h tts)
                                                        break;
                                                }
                                        }
+                                       //LCOV_EXCL_STOP
                                }
-                       }
+                       } while (0 != ret);
                } else {
                        SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
                }
@@ -282,6 +472,9 @@ int tts_destroy(tts_h tts)
                        ecore_timer_del(client->conn_timer);
                        client->conn_timer = NULL;
                }
+               /* Unset registered callbacks */
+               __tts_unset_all_callbacks(tts);
+
                /* Free resources */
                tts_client_destroy(tts);
                break;
@@ -296,18 +489,30 @@ int tts_destroy(tts_h tts)
                }
        }
 
+       if (NULL != g_language) {
+               free(g_language);
+               g_language = NULL;
+       }
+
+       /* Delete state timer before destroying handle */
+       if (NULL != g_check_state_timer) {
+               ecore_timer_del(g_check_state_timer);
+               g_check_state_timer = NULL;
+       }
+
        tts = NULL;
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
 
+//LCOV_EXCL_START
 void __tts_screen_reader_changed_cb(bool value)
 {
        g_screen_reader = value;
 }
+//LCOV_EXCL_STOP
 
 int tts_set_mode(tts_h tts, tts_mode_e mode)
 {
@@ -315,31 +520,30 @@ int tts_set_mode(tts_h tts, tts_mode_e mode)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set TTS mode");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode);
 
        tts_client_s* client = tts_client_get(tts);
 
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
        /* check state */
        if (client->current_state != TTS_STATE_CREATED) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
                return TTS_ERROR_INVALID_STATE;
        }
 
-       if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_SCREEN_READER) {
+       if (TTS_MODE_DEFAULT <= mode && mode <= TTS_MODE_INTERRUPT) {
                client->mode = mode;
        } else {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid : %d", mode);
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
                return TTS_ERROR_INVALID_PARAMETER;
        }
@@ -358,8 +562,7 @@ int tts_set_mode(tts_h tts, tts_mode_e mode)
                tts_config_unset_screen_reader_callback(client->uid);
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
@@ -370,14 +573,14 @@ int tts_get_mode(tts_h tts, tts_mode_e* mode)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get TTS mode");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode");
 
        tts_client_s* client = tts_client_get(tts);
 
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
                return TTS_ERROR_INVALID_PARAMETER;
        }
@@ -385,7 +588,7 @@ int tts_get_mode(tts_h tts, tts_mode_e* mode)
        /* check state */
        if (client->current_state != TTS_STATE_CREATED) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
                return TTS_ERROR_INVALID_STATE;
        }
@@ -397,7 +600,7 @@ int tts_get_mode(tts_h tts, tts_mode_e* mode)
 
        *mode = client->mode;
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
        SLOG(LOG_DEBUG, TAG_TTSC, " ");
 
        return TTS_ERROR_NONE;
@@ -426,13 +629,103 @@ int tts_set_credential(tts_h tts, const char* credential)
                return TTS_ERROR_INVALID_STATE;
        }
 
+       if (NULL != client->credential) {
+               free(client->credential);
+               client->credential = NULL;
+       }
        client->credential = strdup(credential);
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return TTS_ERROR_NONE;
+}
+
+//LCOV_EXCL_START
+int tts_set_server_tts(tts_h tts, const char* credential)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       tts_client_s* client = tts_client_get(tts);
+
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state);
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       if (NULL != client->credential) {
+               free(client->credential);
+               client->credential = NULL;
+       }
+
+       client->internal = true;
+
+       char* key = NULL;
+       if (NULL != credential) {
+               key = strdup("EnableServerTTS");
+               client->credential = strdup(credential);
+               if (NULL == client->credential) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+                       if (NULL != key) {
+                               free(key);
+                               key = NULL;
+                       }
+                       return TTS_ERROR_OUT_OF_MEMORY;
+               }
+       } else {
+               key = strdup("DisableServerTTS");
+       }
+
+       if (NULL == key) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to allocate memory");
+               return TTS_ERROR_OUT_OF_MEMORY;
+       }
+
+       int pid = getpid();
+       char* appid = NULL;
+       int ret = app_manager_get_app_id(pid, &appid);
+       if (0 != ret || NULL == appid) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
+               free(key);
+               key = NULL;
+               if (NULL != appid) {
+                       free(appid);
+                       appid = NULL;
+               }
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       ret = tts_set_private_data(tts, key, appid);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set private data, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
+               free(key);
+               key = NULL;
+               free(appid);
+               appid = NULL;
+               return ret;
+       }
+
+       free(appid);
+       appid = NULL;
+       free(key);
+       key = NULL;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
+// LCOV_EXCL_STOP
 
 static Eina_Bool __tts_connect_daemon(void *data)
 {
@@ -445,12 +738,20 @@ static Eina_Bool __tts_connect_daemon(void *data)
                return EINA_FALSE;
        }
 
+       /* check whether engine is updating or not */
+       if (g_engine_update_status) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] cannot prepare due to engine update");
+               __tts_cb_error(-1, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
+
+               return EINA_FALSE;
+       }
+
        /* Send hello */
-       if (0 != tts_dbus_request_hello(client->uid)) {
+       if (0 != tts_dbus_request_hello_sync(client->uid)) {
                return EINA_TRUE;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Connect daemon");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Connect daemon");
 
        /* do request initialize */
        int ret = -1;
@@ -465,7 +766,23 @@ static Eina_Bool __tts_connect_daemon(void *data)
                client->utt_id = -1;
 
                ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
-               client->conn_timer = NULL;
+               if (client->conn_timer) {
+                       ecore_timer_del(client->conn_timer);
+                       client->conn_timer = NULL;
+               }
+               return EINA_FALSE;
+
+       } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
+
+               client->reason = TTS_ERROR_PERMISSION_DENIED;
+               client->utt_id = -1;
+
+               ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+               if (client->conn_timer) {
+                       ecore_timer_del(client->conn_timer);
+                       client->conn_timer = NULL;
+               }
                return EINA_FALSE;
 
        } else if (TTS_ERROR_NONE != ret) {
@@ -478,7 +795,10 @@ static Eina_Bool __tts_connect_daemon(void *data)
                SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need");
        }
 
-       client->conn_timer = NULL;
+       if (client->conn_timer) {
+               ecore_timer_del(client->conn_timer);
+               client->conn_timer = NULL;
+       }
 
        client = tts_client_get(tts);
        /* check handle */
@@ -498,45 +818,178 @@ static Eina_Bool __tts_connect_daemon(void *data)
                SLOG(LOG_WARN, TAG_TTSC, "State changed callback is NULL");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return EINA_FALSE;
 }
 
+int __tts_cb_hello(int uid, int ret, int credential_needed)
+{
+       tts_client_s* client = tts_client_get_by_uid(uid);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "Fail to get TTS client or ignore this uid(%d)", uid);
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       if (g_hello_timer) {
+               ecore_timer_del(g_hello_timer);
+               g_hello_timer = NULL;
+       }
+
+       if (TTS_STATE_READY == client->current_state) {
+               SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts client is already READY");
+               return TTS_ERROR_NONE;
+       }
+
+       if (TTS_ERROR_ENGINE_NOT_FOUND == ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
+
+               client->reason = TTS_ERROR_ENGINE_NOT_FOUND;
+               client->utt_id = -1;
+
+               ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+               return TTS_ERROR_OPERATION_FAILED;
+
+       } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
+
+               client->reason = TTS_ERROR_PERMISSION_DENIED;
+               client->utt_id = -1;
+
+               ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+               return TTS_ERROR_PERMISSION_DENIED;
+
+       } else if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", __tts_get_error_code(ret));
+               return TTS_ERROR_OPERATION_FAILED;
+
+       } else {
+               /* success to connect tts-daemon */
+               client->credential_needed = credential_needed;
+               SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need");
+       }
+
+       client->before_state = client->current_state;
+       client->current_state = TTS_STATE_READY;
+
+       ecore_timer_add(0.0, __tts_notify_state_changed, client->tts);
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+       return TTS_ERROR_NONE;
+}
+
+static Eina_Bool __send_hello(void *data)
+{
+       tts_h tts = (tts_h)data;
+       tts_client_s* client = tts_client_get(tts);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
+               g_hello_timer = NULL;
+               return EINA_FALSE;
+       }
+
+       /* check state */
+       if (client->current_state == TTS_STATE_READY) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[INFO] TTS client has been already connected to tts service"); //LCOV_EXCL_LINE
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               g_hello_timer = NULL;
+               return EINA_FALSE;
+       }
+
+       /* Send hello */
+       int ret = tts_dbus_request_hello(client->uid);
+       if (0 != ret)  {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request hello !!"); //LCOV_EXCL_LINE
+       } else {
+               SLOG(LOG_ERROR, TAG_TTSC, "@@@ Send Hello");
+       }
+
+       if (!g_hello_timer) {
+               SLOG(LOG_ERROR, TAG_TTSC, "@@@ Call checking Hello timer callback");
+               g_hello_timer = ecore_timer_add(0.5, __send_hello, tts);
+               return EINA_FALSE;
+       }
+       return EINA_TRUE;
+}
+
 int tts_prepare(tts_h tts)
 {
        if (0 != __tts_get_feature_enabled()) {
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Prepare TTS");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
 
        tts_client_s* client = tts_client_get(tts);
 
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
        /* check state */
        if (client->current_state != TTS_STATE_CREATED) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_STATE;
        }
 
-       client->conn_timer = ecore_timer_add(0, __tts_connect_daemon, (void*)tts);
+       if (NULL == g_hello_timer) {
+               SLOG(LOG_ERROR, TAG_TTSC, "@@@ Call checking Hello timer callback");
+               ecore_thread_main_loop_begin();
+               ecore_timer_add(0.0, __send_hello, (void*)tts);
+               ecore_thread_main_loop_end();
+       }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return TTS_ERROR_NONE;
+}
+
+//LCOV_EXCL_START
+int tts_prepare_sync(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Prepare TTS");
+
+       tts_client_s* client = tts_client_get(tts);
+
+       /* check handle */
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       /* check state */
+       if (client->current_state != TTS_STATE_CREATED) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       int cnt = 0;
+       while (EINA_TRUE == __tts_connect_daemon((void*)tts) && TTS_CONNECTION_RETRY_COUNT > cnt) {
+               cnt++;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       if (TTS_CONNECTION_RETRY_COUNT == cnt) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to connect daemon");
+               return TTS_ERROR_OPERATION_FAILED;
+       }
 
        return TTS_ERROR_NONE;
 }
+//LCOV_EXCL_STOP
 
 int tts_unprepare(tts_h tts)
 {
@@ -544,7 +997,7 @@ int tts_unprepare(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Unprepare TTS");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Unprepare TTS");
 
        tts_client_s* client = tts_client_get(tts);
 
@@ -562,11 +1015,29 @@ int tts_unprepare(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       int screen_reader = -1;
+
+       ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get screen reader");
+       } else {
+               SLOG(LOG_INFO, tts_tag(), "[INFO] Success to get screen reader(%d), g_screen_reader(%s), client->mode(%d)", screen_reader, (true == g_screen_reader) ? "True" : "False", client->mode);
+               g_screen_reader = (bool)screen_reader;
+       }
+
+       bool is_prepared = false;
        if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) {
-               while (0 != ret) {
+               do {
                        ret = tts_dbus_request_finalize(client->uid);
                        if (0 != ret) {
-                               if (TTS_ERROR_TIMED_OUT != ret) {
+                               //LCOV_EXCL_START
+                               if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                                       client->current_state = TTS_STATE_CREATED;
+                                       if (0 == tts_prepare_sync(tts)) {
+                                               is_prepared = true;
+                                               SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                                       }
+                               } else if (TTS_ERROR_TIMED_OUT != ret) {
                                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                        break;
                                } else {
@@ -578,8 +1049,9 @@ int tts_unprepare(tts_h tts)
                                                break;
                                        }
                                }
+                               //LCOV_EXCL_STOP
                        }
-               }
+               } while (0 != ret);
        } else {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode);
        }
@@ -594,8 +1066,7 @@ int tts_unprepare(tts_h tts)
                SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
@@ -626,12 +1097,11 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Foreach supported voices");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Foreach supported voices");
 
        if (NULL == tts || NULL == callback) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -640,8 +1110,7 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -658,8 +1127,10 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi
 
        ret = tts_config_mgr_get_voice_list(current_engine, __tts_supported_voice_cb, client->tts);
 
-       if (NULL != current_engine)
+       if (NULL != current_engine) {
                free(current_engine);
+               current_engine = NULL;
+       }
 
        client->supported_voice_cb = NULL;
        client->supported_voice_user_data = NULL;
@@ -669,8 +1140,7 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi
                ret = TTS_ERROR_OPERATION_FAILED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return ret;
 }
@@ -681,12 +1151,11 @@ int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get default voice");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
 
        }
@@ -694,8 +1163,7 @@ int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -709,8 +1177,7 @@ int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
                SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Default language(%s), type(%d)", *lang, *vctype);
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return ret;
 }
@@ -738,7 +1205,12 @@ int tts_get_max_text_size(tts_h tts, unsigned int* size)
                return TTS_ERROR_INVALID_STATE;
        }
 
-       *size = TTS_MAX_TEXT_SIZE;
+       if (0 != tts_config_mgr_get_max_text_size(size)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       g_max_text_size = (int)*size;
 
        SLOG(LOG_DEBUG, TAG_TTSC, "Get max text count : %d", *size);
        return TTS_ERROR_NONE;
@@ -822,17 +1294,19 @@ int tts_get_error_message(tts_h tts, char** err_msg)
                *err_msg = strdup(client->err_msg);
                SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (%s)", *err_msg);
        } else {
+               *err_msg = NULL;
                SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (NULL)");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
 
 int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id)
 {
+       SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type);
+
        if (0 != __tts_get_feature_enabled()) {
                return TTS_ERROR_NOT_SUPPORTED;
        }
@@ -847,12 +1321,11 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Add text");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Add text");
 
        if (NULL == tts || NULL == utt_id) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -860,8 +1333,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -870,17 +1342,33 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
                return TTS_ERROR_INVALID_STATE;
        }
 
-       if (TTS_MAX_TEXT_SIZE < strlen(text) || strlen(text) <= 0) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
-               return TTS_ERROR_INVALID_PARAMETER;
+       if (-1 == g_max_text_size) {
+               SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
+               if (0 != tts_config_mgr_get_max_text_size((unsigned int*)&g_max_text_size)) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get max text size");
+                       return TTS_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       if (0 == g_max_text_size) {
+               if (strlen(text) <= 0) {
+                       SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Max Text Size is %d", g_max_text_size);
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid. (max text size is unlimited.)");
+                       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+                       return TTS_ERROR_INVALID_PARAMETER;
+               }
+       } else {
+               SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] g_max_text_size is %d", g_max_text_size);
+               if (g_max_text_size < strlen(text) || strlen(text) <= 0) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input text size is invalid.");
+                       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+                       return TTS_ERROR_INVALID_PARAMETER;
+               }
        }
 
        if (TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] speed value(%d) is invalid.", speed);
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -895,36 +1383,45 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        }
 
        /* check valid utf8 */
-       iconv_t *ict;
-       ict = iconv_open("utf-8", "");
-       if ((iconv_t)-1 == ict) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to init for text check");
-               return TTS_ERROR_OPERATION_FAILED;
+       bool valid = false;
+
+       DBusError err;
+       dbus_error_init(&err);
+
+       valid = dbus_validate_utf8(text, &err);
+       if (dbus_error_is_set(&err)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Error(%s), text(%s)", err.message, text);
+               dbus_error_free(&err);
+               return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       size_t len = strlen(text);
-       char *in_tmp = NULL;
-       char in_buf[TTS_MAX_TEXT_SIZE];
-       char *out_tmp = NULL;
-       char out_buf[TTS_MAX_TEXT_SIZE];
-       size_t len_tmp = sizeof(out_buf);
+       if (valid != true) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", text);
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+       SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - text is '%s'", text);
 
-       memset(in_buf, 0, TTS_MAX_TEXT_SIZE);
-       snprintf(in_buf, TTS_MAX_TEXT_SIZE, "%s", text);
-       in_tmp = in_buf;
+       /* save texts for repetition */
+       if (NULL != client->text_repeat) {
+               free(client->text_repeat);
+               client->text_repeat = NULL;
+       }
 
-       memset(out_buf, 0, TTS_MAX_TEXT_SIZE);
-       out_tmp = out_buf;
+       client->text_repeat = strdup(text);
 
-       size_t st;
-       st = iconv(ict, &in_tmp, &len, &out_tmp, &len_tmp);
-       if ((size_t)-1 == st) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Text is invalid - '%s'", in_buf);
-               iconv_close(ict);
-               return TTS_ERROR_INVALID_PARAMETER;
+       if (NULL != g_language) {
+               free(g_language);
+               g_language = NULL;
        }
-       iconv_close(ict);
-       SLOG(LOG_DEBUG, TAG_TTSC, "Text is valid - Converted text is '%s'", out_buf);
+       if (NULL == language)
+               g_language = NULL;
+       else
+               g_language = strdup(language);
+
+       g_voice_type = voice_type;
+       g_speed = speed;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] repeat: text(%s), language(%s), voice type(%d), speed(%d)", client->text_repeat, (g_language) ? g_language : "NULL", g_voice_type, g_speed);
 
        /* change default language value */
        char* temp = NULL;
@@ -942,34 +1439,46 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        /* do request */
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
-               ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id, client->credential);
+               ret = tts_dbus_request_add_text(client->uid, text, temp, voice_type, speed, client->current_utt_id, client->credential);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       //LCOV_EXCL_START
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                break;
                        } else {
                                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add text : %s", __tts_get_error_code(ret));
                                usleep(10000);
                                count++;
-                               if (TTS_RETRY_COUNT == count) {
+                               if (TTS_RETRY_MIN_COUNT == count) {
                                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
                                        break;
                                }
                        }
+                       //LCOV_EXCL_STOP
                } else {
                        *utt_id = client->current_utt_id;
                }
        }
 
-       if (NULL != temp)       free(temp);
+       if (NULL != temp) {
+               free(temp);
+               temp = NULL;
+       }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return ret;
 }
 
+//LCOV_EXCL_START
 static void __tts_play_async(void *data)
 {
        tts_h tts = (tts_h)data;
@@ -983,10 +1492,17 @@ static void __tts_play_async(void *data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_play(client->uid, client->credential);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                break;
                        } else {
@@ -1021,8 +1537,7 @@ static void __tts_play_async(void *data)
                SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return;
 }
@@ -1033,12 +1548,11 @@ int tts_play_async(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Play tts");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Play tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1046,8 +1560,7 @@ int tts_play_async(tts_h tts)
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1068,24 +1581,22 @@ int tts_play_async(tts_h tts)
 
        ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
-
+//LCOV_EXCL_STOP
 int tts_play(tts_h tts)
 {
        if (0 != __tts_get_feature_enabled()) {
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Play tts");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1093,7 +1604,7 @@ int tts_play(tts_h tts)
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
                return TTS_ERROR_INVALID_PARAMETER;
        }
@@ -1115,10 +1626,18 @@ int tts_play(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_play(client->uid, client->credential);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       //LCOV_EXCL_START
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1130,6 +1649,7 @@ int tts_play(tts_h tts)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
@@ -1143,12 +1663,11 @@ int tts_play(tts_h tts)
                SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
-
+//LCOV_EXCL_START
 static void __tts_stop_async(void *data)
 {
        tts_h tts = (tts_h)data;
@@ -1162,10 +1681,17 @@ static void __tts_stop_async(void *data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_stop(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                break;
                        } else {
@@ -1200,8 +1726,7 @@ static void __tts_stop_async(void *data)
                SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return;
 }
@@ -1212,12 +1737,11 @@ int tts_stop_aync(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Stop tts");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Stop tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1225,8 +1749,7 @@ int tts_stop_aync(tts_h tts)
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1242,24 +1765,22 @@ int tts_stop_aync(tts_h tts)
 
        ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
-
+//LCOV_EXCL_STOP
 int tts_stop(tts_h tts)
 {
        if (0 != __tts_get_feature_enabled()) {
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Stop tts");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1267,8 +1788,7 @@ int tts_stop(tts_h tts)
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1284,10 +1804,18 @@ int tts_stop(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_stop(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       //LCOV_EXCL_START
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1299,6 +1827,7 @@ int tts_stop(tts_h tts)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
@@ -1312,12 +1841,11 @@ int tts_stop(tts_h tts)
                SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
-
+//LCOV_EXCL_START
 static void __tts_pause_async(void *data)
 {
        tts_h tts = (tts_h)data;
@@ -1331,10 +1859,17 @@ static void __tts_pause_async(void *data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_pause(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                break;
                        } else {
@@ -1369,8 +1904,7 @@ static void __tts_pause_async(void *data)
                SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return;
 }
@@ -1381,12 +1915,11 @@ int tts_pause_async(tts_h tts)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Pause tts");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Pause tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1394,15 +1927,13 @@ int tts_pause_async(tts_h tts)
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
        if (TTS_STATE_PLAYING != client->current_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_STATE;
        }
 
@@ -1413,24 +1944,22 @@ int tts_pause_async(tts_h tts)
 
        ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
-
+//LCOV_EXCL_STOP
 int tts_pause(tts_h tts)
 {
        if (0 != __tts_get_feature_enabled()) {
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Pause tts");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts");
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
@@ -1438,15 +1967,13 @@ int tts_pause(tts_h tts)
 
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
        if (TTS_STATE_PLAYING != client->current_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_ERROR_INVALID_STATE;
        }
 
@@ -1457,10 +1984,18 @@ int tts_pause(tts_h tts)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_pause(client->uid);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       //LCOV_EXCL_START
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1472,6 +2007,7 @@ int tts_pause(tts_h tts)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
@@ -1485,8 +2021,7 @@ int tts_pause(tts_h tts)
                SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_ERROR_NONE;
 }
@@ -1497,7 +2032,7 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set private data");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data);
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
@@ -1521,12 +2056,25 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
                return TTS_ERROR_INVALID_STATE;
        }
 
+       if (true != client->internal && (0 == strcmp(key, "EnableServerTTS") || 0 == strcmp(key, "DisableServerTTS"))) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] This is not an internal app");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_set_private_data(client->uid, key, data);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       //LCOV_EXCL_START
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1538,11 +2086,11 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, "");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return 0;
 }
@@ -1553,7 +2101,7 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get private data");
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Get private data, key(%s)", key);
 
        if (NULL == tts) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
@@ -1579,10 +2127,18 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
 
        int ret = -1;
        int count = 0;
+       bool is_prepared = false;
        while (0 != ret) {
                ret = tts_dbus_request_get_private_data(client->uid, key, data);
                if (0 != ret) {
-                       if (TTS_ERROR_TIMED_OUT != ret) {
+                       //LCOV_EXCL_START
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
                                return ret;
                        } else {
@@ -1594,15 +2150,21 @@ int tts_get_private_data(tts_h tts, const char* key, char** data)
                                        return ret;
                                }
                        }
+                       //LCOV_EXCL_STOP
                }
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, "");
+       if (0 == strncmp(*data, "NULL", strlen(*data))) {
+               free(*data);
+               *data = NULL;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return 0;
 }
 
+//LCOV_EXCL_START
 static Eina_Bool __tts_notify_error(void *data)
 {
        tts_h tts = (tts_h)data;
@@ -1628,39 +2190,121 @@ static Eina_Bool __tts_notify_error(void *data)
                SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
        }
 
-       return EINA_FALSE;
+       return EINA_FALSE;
+}
+
+static void __start_reprepare_thread(void* data, Ecore_Thread* thread)
+{
+       SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] start reprepare thread. engine update status(%d)", g_engine_update_status);
+
+       tts_client_s* temp = (tts_client_s*)data;
+       if (NULL == temp) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] data is null");
+               return ;
+       }
+
+       int cnt = 0;
+       while (!g_engine_update_status && (cnt < 10)) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] wait for starting update");
+               usleep(50000);
+               cnt++;
+       }
+
+       SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] update status(%d)", g_engine_update_status);
+
+       while (g_engine_update_status && (NULL != g_pkgmgr)) {
+//             SLOG(LOG_WARN, TAG_TTSC, "[WARNING] wait for finishing update");
+               usleep(200000);
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] finish updating. request to prepare");
+
+       if (0 != tts_prepare(temp->tts)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+       }
+
+       return ;
+}
+
+static void __end_reprepare_thread(void* data, Ecore_Thread* thread)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] end reprepare thread");
 }
 
 int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
 {
-       tts_client_s* client = tts_client_get_by_uid(uid);
+       if (-1 == uid) {
+               GList* client_list = NULL;
+               client_list = tts_client_get_client_list();
 
-       if (NULL == client) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
+               GList *iter = NULL;
+               tts_client_s *data = NULL;
 
-       client->utt_id = utt_id;
-       client->reason = reason;
-       if (NULL != client->err_msg) {
-               free(client->err_msg);
-               client->err_msg = NULL;
-       }
-       client->err_msg = strdup(err_msg);
+               if (g_list_length(client_list) > 0) {
+                       /* Get a first item */
+                       iter = g_list_first(client_list);
 
-       /* call callback function */
-       if (NULL != client->error_cb) {
-               ecore_timer_add(0, __tts_notify_error, client->tts);
+                       while (NULL != iter) {
+                               data = iter->data;
+
+                               data->utt_id = utt_id;
+                               data->reason = reason;
+                               if (NULL != data->err_msg) {
+                                       free(data->err_msg);
+                                       data->err_msg = NULL;
+                               }
+                               if (NULL != err_msg)
+                                       data->err_msg = strdup(err_msg);
+
+                               /* call callback function */
+                               if (NULL != data->error_cb) {
+                                       ecore_timer_add(0, __tts_notify_error, data->tts);
+                               } else {
+                                       SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
+                               }
+
+                               if (TTS_ERROR_SERVICE_RESET == reason) {
+                                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+
+                                       data->current_state = TTS_STATE_CREATED;
+                                       data->reason = 0;
+                                       ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, data);
+                               }
+
+                               /* Next item */
+                               iter = g_list_next(iter);
+                       }
+               }
        } else {
-               SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
-       }
+               tts_client_s* client = tts_client_get_by_uid(uid);
+
+               if (NULL == client) {
+                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] A handle is not valid");
+                       return TTS_ERROR_INVALID_PARAMETER;
+               }
 
-       if (TTS_ERROR_SERVICE_RESET == reason) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+               client->utt_id = utt_id;
+               client->reason = reason;
+               if (NULL != client->err_msg) {
+                       free(client->err_msg);
+                       client->err_msg = NULL;
+               }
+               if (NULL != err_msg)
+                       client->err_msg = strdup(err_msg);
 
-               client->current_state = TTS_STATE_CREATED;
-               if (0 != tts_prepare(client->tts)) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+               /* call callback function */
+               if (NULL != client->error_cb) {
+                       ecore_timer_add(0, __tts_notify_error, client->tts);
+               } else {
+                       SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
+               }
+
+               if (TTS_ERROR_SERVICE_RESET == reason) {
+                       SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+
+                       client->current_state = TTS_STATE_CREATED;
+                       client->reason = 0;
+                       ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, client);
                }
        }
 
@@ -1707,7 +2351,11 @@ int __tts_cb_set_state(int uid, int state)
        }
 
        if (NULL != client->state_changed_cb) {
-               ecore_timer_add(0, __tts_notify_state_changed, client->tts);
+               if (NULL != g_check_state_timer) {
+                       ecore_timer_del(g_check_state_timer);
+                       g_check_state_timer = NULL;
+               }
+               g_check_state_timer = ecore_timer_add(0, __tts_notify_state_changed, client->tts);
        } else {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] State changed callback is null");
        }
@@ -1717,6 +2365,7 @@ int __tts_cb_set_state(int uid, int state)
 
        return 0;
 }
+//LCOV_EXCL_STOP
 
 int __tts_cb_utt_started(int uid, int utt_id)
 {
@@ -1727,7 +2376,7 @@ int __tts_cb_utt_started(int uid, int utt_id)
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
+       SLOG(LOG_INFO, TAG_TTSC, "utterance started : utt id(%d) ", utt_id);
 
        client->utt_id = utt_id;
 
@@ -1753,7 +2402,7 @@ int __tts_cb_utt_completed(int uid, int utt_id)
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
+       SLOG(LOG_INFO, TAG_TTSC, "utterance completed : uttid(%d) ", utt_id);
 
        client->utt_id = utt_id;
 
@@ -1796,7 +2445,7 @@ int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* use
        client->state_changed_cb = callback;
        client->state_changed_user_data = user_data;
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set state changed cb");
+       SLOG(LOG_INFO, TAG_TTSC, "[SUCCESS] Set state changed cb");
 
        return 0;
 }
@@ -1827,6 +2476,11 @@ int tts_unset_state_changed_cb(tts_h tts)
        client->state_changed_cb = NULL;
        client->state_changed_user_data = NULL;
 
+       if (NULL != g_check_state_timer) {
+               ecore_timer_del(g_check_state_timer);
+               g_check_state_timer = NULL;
+       }
+
        SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset state changed cb");
 
        return 0;
@@ -2141,3 +2795,309 @@ int tts_unset_engine_changed_cb(tts_h tts)
        return 0;
 }
 
+//LCOV_EXCL_START
+int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts");
+
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       tts_client_s* client = tts_client_get(tts);
+
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_CREATED == client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       int ret = -1;
+       int count = 0;
+       bool is_prepared = false;
+       while (0 != ret) {
+               ret = tts_dbus_request_add_pcm(client->uid, event, data, data_size, audio_type, rate);
+               if (0 != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+                               return ret;
+                       } else {
+                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry add pcm : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       return ret;
+                               }
+                       }
+               }
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return TTS_ERROR_NONE;
+}
+
+int tts_play_pcm(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts");
+
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       tts_client_s* client = tts_client_get(tts);
+
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       int ret = -1;
+       int count = 0;
+       bool is_prepared = false;
+       while (0 != ret) {
+               ret = tts_dbus_request_play_pcm(client->uid);
+               if (0 != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+                               return ret;
+                       } else {
+                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play pcm : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       return ret;
+                               }
+                       }
+               }
+       }
+
+       client->before_state = client->current_state;
+       client->current_state = TTS_STATE_PLAYING;
+
+       if (NULL != client->state_changed_cb) {
+               tts_client_use_callback(client);
+               client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
+               tts_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return TTS_ERROR_NONE;
+}
+
+int tts_stop_pcm(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts");
+
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       tts_client_s* client = tts_client_get(tts);
+
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_CREATED == client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid.");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Screen reader option is NOT available. Ignore this request");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       int ret = -1;
+       int count = 0;
+       bool is_prepared = false;
+       while (0 != ret) {
+               ret = tts_dbus_request_stop_pcm(client->uid);
+               if (0 != ret) {
+                       if (TTS_ERROR_INVALID_PARAMETER == ret && false == is_prepared) {
+                               client->current_state = TTS_STATE_CREATED;
+                               if (0 == tts_prepare_sync(tts)) {
+                                       is_prepared = true;
+                                       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
+                               }
+                       } else if (TTS_ERROR_TIMED_OUT != ret) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
+                               return ret;
+                       } else {
+                               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry stop pcm : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       return ret;
+                               }
+                       }
+               }
+       }
+
+       client->before_state = client->current_state;
+       client->current_state = TTS_STATE_READY;
+
+       if (NULL != client->state_changed_cb) {
+               tts_client_use_callback(client);
+               client->state_changed_cb(client->tts, client->before_state, client->current_state, client->state_changed_user_data);
+               tts_client_not_use_callback(client);
+               SLOG(LOG_DEBUG, TAG_TTSC, "State changed callback is called");
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return TTS_ERROR_NONE;
+}
+//LCOV_EXCL_STOP
+
+int tts_repeat(tts_h tts, char** text_repeat, int* utt_id)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Repeat TTS");
+
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == text_repeat || NULL == utt_id) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       *text_repeat = NULL;
+       *utt_id = -1;
+
+       tts_client_s* client = tts_client_get(tts);
+
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid. (%d)", client->current_state);
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       /* Clear the legacy and Add texts to be played repeatedly */
+       int ret = -1;
+       ret = tts_stop(tts);
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to clear the legacy");
+               return ret;
+       }
+
+       if (NULL != client->text_repeat) {
+               char* tmp_text = strdup(client->text_repeat);
+               char* tmp_lang = NULL;
+               if (NULL != g_language) {
+                       tmp_lang = strdup(g_language);
+               }
+               ret = tts_add_text(tts, tmp_text, tmp_lang, g_voice_type, g_speed, utt_id);
+               if (TTS_ERROR_NONE != ret) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to add texts for repetition.");
+                       if (NULL != tmp_text) {
+                               free(tmp_text);
+                               tmp_text = NULL;
+                       }
+                       if (NULL != tmp_lang) {
+                               free(tmp_lang);
+                               tmp_lang = NULL;
+                       }
+                       return ret;
+               }
+               *text_repeat = strdup(client->text_repeat);
+               SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] text to repeat(%s), utt_id(%d)", (*text_repeat) ? *text_repeat : "NULL", *utt_id);
+               if (NULL != tmp_text) {
+                       free(tmp_text);
+                       tmp_text = NULL;
+               }
+               if (NULL != tmp_lang) {
+                       free(tmp_lang);
+                       tmp_lang = NULL;
+               }
+       } else {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] There is no previous added texts. Please add texts");
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       /* Play added texts */
+       ret = tts_play(tts);
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play texts for repetition.");
+               if (NULL != *text_repeat) {
+                       free(*text_repeat);
+                       *text_repeat = NULL;
+               }
+               *utt_id = -1;
+               return ret;
+       }
+
+       return TTS_ERROR_NONE;
+}