Add null checker when memory is released
[platform/core/uifw/tts.git] / client / tts.c
index 7e327cb..3ea3717 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
@@ -11,6 +11,7 @@
 *  limitations under the License.
 */
 
+#include <app_manager.h>
 #include <dirent.h>
 #include <Ecore.h>
 #include <iconv.h>
 #include "tts_main.h"
 
 
-static Ecore_Timer* g_connect_timer = NULL;
-
 static bool g_screen_reader;
 
+static int g_feature_enabled = -1;
+
+static bool g_err_callback_status = false;
+
 /* Function definition */
 static Eina_Bool __tts_notify_state_changed(void *data);
 static Eina_Bool __tts_notify_error(void *data);
@@ -40,6 +43,30 @@ const char* tts_tag()
        return "ttsc";
 }
 
+static int __tts_get_feature_enabled()
+{
+       if (0 == g_feature_enabled) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
+               return TTS_ERROR_NOT_SUPPORTED;
+       } else if (-1 == g_feature_enabled) {
+               bool tts_supported = false;
+               if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
+                       if (false == tts_supported) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS feature NOT supported");
+                               g_feature_enabled = 0;
+                               return TTS_ERROR_NOT_SUPPORTED;
+                       }
+
+                       g_feature_enabled = 1;
+               } else {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get feature value");
+                       return TTS_ERROR_NOT_SUPPORTED;
+               }
+       }
+
+       return 0;
+}
+
 static const char* __tts_get_error_code(tts_error_e err)
 {
        switch (err) {
@@ -56,6 +83,8 @@ static const char* __tts_get_error_code(tts_error_e err)
        case TTS_ERROR_ENGINE_NOT_FOUND:        return "TTS_ERROR_ENGINE_NOT_FOUND";
        case TTS_ERROR_OPERATION_FAILED:        return "TTS_ERROR_OPERATION_FAILED";
        case TTS_ERROR_AUDIO_POLICY_BLOCKED:    return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
+       case TTS_ERROR_NOT_SUPPORTED_FEATURE:   return "TTS_ERROR_NOT_SUPPORTED_FEATURE";
+       case TTS_ERROR_SERVICE_RESET:           return "TTS_ERROR_SERVICE_RESET";
        default:
                return "Invalid error code";
        }
@@ -72,7 +101,7 @@ static int __tts_convert_config_error_code(tts_config_error_e code)
        if (code == TTS_CONFIG_ERROR_INVALID_VOICE)             return TTS_ERROR_INVALID_VOICE;
        if (code == TTS_CONFIG_ERROR_ENGINE_NOT_FOUND)          return TTS_ERROR_ENGINE_NOT_FOUND;
        if (code == TTS_CONFIG_ERROR_OPERATION_FAILED)          return TTS_ERROR_OPERATION_FAILED;
-       if (code == TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE)     return TTS_ERROR_OPERATION_FAILED;
+       if (code == TTS_CONFIG_ERROR_NOT_SUPPORTED_FEATURE)     return TTS_ERROR_NOT_SUPPORTED_FEATURE;
 
        return code;
 }
@@ -80,7 +109,7 @@ static int __tts_convert_config_error_code(tts_config_error_e code)
 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)",
-                before_lang, before_voice_type, language, voice_type);
+               before_lang, before_voice_type, language, voice_type);
 
        GList* client_list = NULL;
        client_list = tts_client_get_client_list();
@@ -108,17 +137,64 @@ void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_typ
        return;
 }
 
-int tts_create(tts_h* tts)
+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)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
+       tts_h tts = (tts_h)user_data;
+
+       tts_client_s* client = tts_client_get(tts);
+       if (NULL == client) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[WARNING] A handle is not valid");
+               return;
+       }
+
+       if (NULL != engine_id)  SLOG(LOG_DEBUG, TAG_TTSC, "Engine id(%s)", engine_id);
+       if (NULL != setting)    SLOG(LOG_DEBUG, TAG_TTSC, "Engine setting(%s)", setting);
+       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...");
+               }
+               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);
+               }
+       } 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);
                }
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Create TTS");
+       /* 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);
+       } else {
+               SLOG(LOG_WARN, TAG_TTSC, "No registered callback function for changed engine");
+       }
+       return;
+}
+
+int tts_create(tts_h* tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "===== Create TTS");
 
        /* check param */
        if (NULL == tts) {
@@ -153,7 +229,7 @@ int tts_create(tts_h* tts)
                return __tts_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(client->uid, NULL, __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);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                tts_client_destroy(*tts);
@@ -168,15 +244,11 @@ int tts_create(tts_h* tts)
 
 int tts_destroy(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               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");
@@ -233,9 +305,10 @@ int tts_destroy(tts_h tts)
                client->current_state = TTS_STATE_CREATED;
 
        case TTS_STATE_CREATED:
-               if (NULL != g_connect_timer) {
+               if (NULL != client->conn_timer) {
                        SLOG(LOG_DEBUG, TAG_TTSC, "Connect Timer is deleted");
-                       ecore_timer_del(g_connect_timer);
+                       ecore_timer_del(client->conn_timer);
+                       client->conn_timer = NULL;
                }
                /* Free resources */
                tts_client_destroy(tts);
@@ -266,15 +339,11 @@ void __tts_screen_reader_changed_cb(bool value)
 
 int tts_set_mode(tts_h tts, tts_mode_e mode)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               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);
 
@@ -325,12 +394,8 @@ int tts_set_mode(tts_h tts, tts_mode_e mode)
 
 int tts_get_mode(tts_h tts, tts_mode_e* mode)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "===== Get TTS mode");
@@ -366,6 +431,117 @@ int tts_get_mode(tts_h tts, tts_mode_e* mode)
        return TTS_ERROR_NONE;
 }
 
+int tts_set_credential(tts_h tts, const char* credential)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       if (NULL == tts || NULL == credential) {
+               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->credential = strdup(credential);
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return TTS_ERROR_NONE;
+}
+
+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");
+                       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) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get appid, ret(%d), pid(%d), appid(%s)", ret, pid, appid);
+               free(key);
+               key = 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;
+               return ret;
+       }
+
+       free(appid);
+       appid = NULL;
+       free(key);
+       key = NULL;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return TTS_ERROR_NONE;
+}
+
 static Eina_Bool __tts_connect_daemon(void *data)
 {
        tts_h tts = (tts_h)data;
@@ -374,7 +550,6 @@ static Eina_Bool __tts_connect_daemon(void *data)
        /* check handle */
        if (NULL == client) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
-               g_connect_timer = NULL;
                return EINA_FALSE;
        }
 
@@ -383,11 +558,13 @@ static Eina_Bool __tts_connect_daemon(void *data)
                return EINA_TRUE;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Connect daemon");
+       SLOG(LOG_INFO, TAG_TTSC, "===== Connect daemon");
 
        /* do request initialize */
        int ret = -1;
-       ret = tts_dbus_request_initialize(client->uid);
+       bool credential_needed = false;
+
+       ret = tts_dbus_request_initialize(client->uid, &credential_needed);
 
        if (TTS_ERROR_ENGINE_NOT_FOUND == ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
@@ -396,7 +573,7 @@ static Eina_Bool __tts_connect_daemon(void *data)
                client->utt_id = -1;
 
                ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
-               g_connect_timer = NULL;
+               client->conn_timer = NULL;
                return EINA_FALSE;
 
        } else if (TTS_ERROR_NONE != ret) {
@@ -405,9 +582,11 @@ static Eina_Bool __tts_connect_daemon(void *data)
 
        } 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");
        }
 
-       g_connect_timer = NULL;
+       client->conn_timer = NULL;
 
        client = tts_client_get(tts);
        /* check handle */
@@ -435,15 +614,11 @@ static Eina_Bool __tts_connect_daemon(void *data)
 
 int tts_prepare(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       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);
 
@@ -463,7 +638,7 @@ int tts_prepare(tts_h tts)
                return TTS_ERROR_INVALID_STATE;
        }
 
-       g_connect_timer = ecore_timer_add(0, __tts_connect_daemon, (void*)tts);
+       client->conn_timer = ecore_timer_add(0, __tts_connect_daemon, (void*)tts);
 
        SLOG(LOG_DEBUG, TAG_TTSC, "=====");
        SLOG(LOG_DEBUG, TAG_TTSC, " ");
@@ -473,15 +648,11 @@ int tts_prepare(tts_h tts)
 
 int tts_unprepare(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               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);
 
@@ -559,12 +730,8 @@ bool __tts_supported_voice_cb(const char* engine_id, const char* language, int t
 
 int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "===== Foreach supported voices");
@@ -599,8 +766,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;
@@ -618,12 +787,8 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi
 
 int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "===== Get default voice");
@@ -662,12 +827,8 @@ int tts_get_default_voice(tts_h tts, char** lang, int* vctype)
 
 int tts_get_max_text_size(tts_h tts, unsigned int* size)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts || NULL == size) {
@@ -695,12 +856,8 @@ int tts_get_max_text_size(tts_h tts, unsigned int* size)
 
 int tts_get_state(tts_h tts, tts_state_e* state)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts || NULL == state) {
@@ -718,11 +875,11 @@ int tts_get_state(tts_h tts, tts_state_e* state)
        *state = client->current_state;
 
        switch (*state) {
-               case TTS_STATE_CREATED: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Created'");        break;
-               case TTS_STATE_READY:   SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Ready'");          break;
-               case TTS_STATE_PLAYING: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Playing'");        break;
-               case TTS_STATE_PAUSED:  SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Paused'");         break;
-               default:                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid value");             break;
+       case TTS_STATE_CREATED: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Created'");        break;
+       case TTS_STATE_READY:   SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Ready'");          break;
+       case TTS_STATE_PLAYING: SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Playing'");        break;
+       case TTS_STATE_PAUSED:  SLOG(LOG_DEBUG, TAG_TTSC, "Current state is 'Paused'");         break;
+       default:                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid value");             break;
        }
 
        return TTS_ERROR_NONE;
@@ -730,12 +887,8 @@ int tts_get_state(tts_h tts, tts_state_e* state)
 
 int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts || NULL == min || NULL == normal || NULL == max) {
@@ -757,14 +910,54 @@ int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max)
        return TTS_ERROR_NONE;
 }
 
+int tts_get_error_message(tts_h tts, char** err_msg)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       if (NULL == tts || NULL == err_msg) {
+               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 (NULL != client->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, " ");
+
+       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)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       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;
+       }
+
+       if (speed < 0) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Speed should not be negative(%d)", speed);
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (voice_type < 0) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Voice type should not be negative(%d)", voice_type);
+               return TTS_ERROR_INVALID_PARAMETER;
        }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "===== Add text");
@@ -809,6 +1002,11 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
                return TTS_ERROR_INVALID_STATE;
        }
 
+       if (true == client->credential_needed && NULL == client->credential) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
+               return TTS_ERROR_PERMISSION_DENIED;
+       }
+
        /* check valid utf8 */
        iconv_t *ict;
        ict = iconv_open("utf-8", "");
@@ -858,7 +1056,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        int ret = -1;
        int count = 0;
        while (0 != ret) {
-               ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id);
+               ret = tts_dbus_request_add_text(client->uid, out_buf, temp, voice_type, speed, client->current_utt_id, client->credential);
                if (0 != ret) {
                        if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
@@ -867,7 +1065,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
                                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;
                                }
@@ -877,7 +1075,10 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
                }
        }
 
-       if (NULL != temp)       free(temp);
+       if (NULL != temp) {
+               free(temp);
+               temp = NULL;
+       }
 
        SLOG(LOG_DEBUG, TAG_TTSC, "=====");
        SLOG(LOG_DEBUG, TAG_TTSC, " ");
@@ -885,64 +1086,47 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        return ret;
 }
 
-int tts_play(tts_h tts)
+static void __tts_play_async(void *data)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
-       }
-
-       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, " ");
-               return TTS_ERROR_INVALID_PARAMETER;
-       }
-
+       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.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               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;
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
+               return;
        }
 
        int ret = -1;
        int count = 0;
        while (0 != ret) {
-               ret = tts_dbus_request_play(client->uid);
+               ret = tts_dbus_request_play(client->uid, client->credential);
                if (0 != ret) {
                        if (TTS_ERROR_TIMED_OUT != ret) {
                                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
-                               return ret;
+                               break;
                        } else {
                                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play : %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;
+                                       break;
                                }
                        }
                }
        }
 
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play tts : %s", __tts_get_error_code(ret));
+
+               client->reason = ret;
+               client->utt_id = -1;
+
+               ecore_timer_add(0, __tts_notify_error, client->tts);
+               return;
+       }
+
        client->before_state = client->current_state;
        client->current_state = TTS_STATE_PLAYING;
 
@@ -956,24 +1140,19 @@ int tts_play(tts_h tts)
        SLOG(LOG_DEBUG, TAG_TTSC, "=====");
        SLOG(LOG_DEBUG, TAG_TTSC, " ");
 
-       return TTS_ERROR_NONE;
+       return;
 }
 
-
-int tts_stop(tts_h tts)
+int tts_play_async(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Stop tts");
+       SLOG(LOG_DEBUG, TAG_TTSC, "===== Play tts");
 
        if (NULL == tts) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null.");
                SLOG(LOG_DEBUG, TAG_TTSC, "=====");
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
                return TTS_ERROR_INVALID_PARAMETER;
@@ -982,14 +1161,14 @@ int tts_stop(tts_h tts)
        tts_client_s* client = tts_client_get(tts);
 
        if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid");
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid.");
                SLOG(LOG_DEBUG, TAG_TTSC, "=====");
                SLOG(LOG_DEBUG, TAG_TTSC, " ");
                return TTS_ERROR_INVALID_PARAMETER;
        }
 
-       if (TTS_STATE_CREATED == client->current_state) {
-               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
+       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;
        }
 
@@ -998,35 +1177,357 @@ int tts_stop(tts_h tts)
                return TTS_ERROR_INVALID_STATE;
        }
 
-       int ret = -1;
-       int count = 0;
-       while (0 != ret) {
-               ret = tts_dbus_request_stop(client->uid);
-               if (0 != ret) {
-                       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 : %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;
-                               }
-                       }
-               }
+       if (true == client->credential_needed && NULL == client->credential) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
+               return TTS_ERROR_PERMISSION_DENIED;
        }
 
-       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");
-       }
+       ecore_main_loop_thread_safe_call_async(__tts_play_async, (void*)tts);
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return TTS_ERROR_NONE;
+}
+
+int tts_play(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       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, " ");
+               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, "=====");
+               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;
+       }
+
+       if (true == client->credential_needed && NULL == client->credential) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine");
+               return TTS_ERROR_PERMISSION_DENIED;
+       }
+
+       int ret = -1;
+       int count = 0;
+       while (0 != ret) {
+               ret = tts_dbus_request_play(client->uid, client->credential);
+               if (0 != ret) {
+                       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 : %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, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return TTS_ERROR_NONE;
+}
+
+static void __tts_stop_async(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");
+               return;
+       }
+
+       int ret = -1;
+       int count = 0;
+       while (0 != ret) {
+               ret = tts_dbus_request_stop(client->uid);
+               if (0 != ret) {
+                       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 stop : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to stop tts : %s", __tts_get_error_code(ret));
+
+               client->reason = ret;
+               client->utt_id = -1;
+
+               ecore_timer_add(0, __tts_notify_error, client->tts);
+               return;
+       }
+
+       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, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return;
+}
+
+int tts_stop_aync(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       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, " ");
+               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, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_CREATED == client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
+               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;
+       }
+
+       ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return TTS_ERROR_NONE;
+}
+
+int tts_stop(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       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, " ");
+               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, "=====");
+               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_CREATED == client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'.");
+               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;
+       while (0 != ret) {
+               ret = tts_dbus_request_stop(client->uid);
+               if (0 != ret) {
+                       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 : %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, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return TTS_ERROR_NONE;
+}
+
+static void __tts_pause_async(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");
+               return;
+       }
+
+       int ret = -1;
+       int count = 0;
+       while (0 != ret) {
+               ret = tts_dbus_request_pause(client->uid);
+               if (0 != ret) {
+                       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 pause : %s", __tts_get_error_code(ret));
+                               usleep(10000);
+                               count++;
+                               if (TTS_RETRY_COUNT == count) {
+                                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to pause tts : %s", __tts_get_error_code(ret));
+
+               client->reason = ret;
+               client->utt_id = -1;
+
+               ecore_timer_add(0, __tts_notify_error, client->tts);
+               return;
+       }
+
+       client->before_state = client->current_state;
+       client->current_state = TTS_STATE_PAUSED;
+
+       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, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       return;
+}
+
+int tts_pause_async(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       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, " ");
+               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, "=====");
+               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, " ");
+               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;
+       }
+
+       ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
 
        SLOG(LOG_DEBUG, TAG_TTSC, "=====");
        SLOG(LOG_DEBUG, TAG_TTSC, " ");
@@ -1034,18 +1535,13 @@ int tts_stop(tts_h tts)
        return TTS_ERROR_NONE;
 }
 
-
 int tts_pause(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       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");
@@ -1111,6 +1607,128 @@ int tts_pause(tts_h tts)
        return TTS_ERROR_NONE;
 }
 
+int tts_set_private_data(tts_h tts, const char* key, const char* data)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       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 isnull");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == key || NULL == data) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter");
+               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");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'");
+               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;
+       while (0 != ret) {
+               ret = tts_dbus_request_set_private_data(client->uid, key, data);
+               if (0 != ret) {
+                       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 : %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, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, "");
+
+       return 0;
+}
+
+int tts_get_private_data(tts_h tts, const char* key, char** data)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "===== Get private data, key(%s)", key);
+
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input handle is null");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == key || NULL == data) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid parameter");
+               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");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_READY != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       int ret = -1;
+       int count = 0;
+       while (0 != ret) {
+               ret = tts_dbus_request_get_private_data(client->uid, key, data);
+               if (0 != ret) {
+                       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 : %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;
+                               }
+                       }
+               }
+       }
+
+       if (0 == strncmp(*data, "NULL", strlen(*data))) {
+               free(*data);
+               *data = NULL;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
+       SLOG(LOG_DEBUG, TAG_TTSC, "");
+
+       return 0;
+}
+
 static Eina_Bool __tts_notify_error(void *data)
 {
        tts_h tts = (tts_h)data;
@@ -1128,7 +1746,9 @@ static Eina_Bool __tts_notify_error(void *data)
        if (NULL != client->error_cb) {
                SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of error");
                tts_client_use_callback(client);
+               g_err_callback_status = true;
                client->error_cb(client->tts, client->utt_id, client->reason, client->error_user_data);
+               g_err_callback_status = false;
                tts_client_not_use_callback(client);
        } else {
                SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
@@ -1137,23 +1757,83 @@ static Eina_Bool __tts_notify_error(void *data)
        return EINA_FALSE;
 }
 
-int __tts_cb_error(int uid, tts_error_e reason, int utt_id)
+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 (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;
+                                       if (0 != tts_prepare(data->tts)) {
+                                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+                                       }
+                               }
+
+                               /* 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;
+               }
+
+               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);
+
+               /* 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;
+                       if (0 != tts_prepare(client->tts)) {
+                               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+                       }
+               }
        }
 
        return 0;
@@ -1210,30 +1890,6 @@ int __tts_cb_set_state(int uid, int state)
        return 0;
 }
 
-static Eina_Bool __tts_notify_utt_started(void *data)
-{
-       tts_h tts = (tts_h)data;
-
-       tts_client_s* client = tts_client_get(tts);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to notify utt started : A handle is not valid");
-               return EINA_FALSE;
-       }
-
-       if (NULL != client->utt_started_cb) {
-               SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance started ");
-               tts_client_use_callback(client);
-               client->utt_started_cb(client->tts, client->utt_id, client->utt_started_user_data);
-               tts_client_not_use_callback(client);
-       } else {
-               SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance started ");
-       }
-
-       return EINA_FALSE;
-}
-
 int __tts_cb_utt_started(int uid, int utt_id)
 {
        tts_client_s* client = tts_client_get_by_uid(uid);
@@ -1243,42 +1899,21 @@ 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;
 
        /* call callback function */
        if (NULL != client->utt_started_cb) {
-               ecore_timer_add(0, __tts_notify_utt_started, client->tts);
-       } else {
-               SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance started ");
-       }
-
-       return 0;
-}
-
-static Eina_Bool __tts_notify_utt_completed(void *data)
-{
-       tts_h tts = (tts_h)data;
-
-       tts_client_s* client = tts_client_get(tts);
-
-       /* check handle */
-       if (NULL == client) {
-               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to notify utt completed : A handle is not valid");
-               return EINA_FALSE;
-       }
-
-       if (NULL != client->utt_completeted_cb) {
-               SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance completed ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance started ");
                tts_client_use_callback(client);
-               client->utt_completeted_cb(client->tts, client->utt_id, client->utt_completed_user_data);
+               client->utt_started_cb(client->tts, client->utt_id, client->utt_started_user_data);
                tts_client_not_use_callback(client);
        } else {
-               SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance completed ");
+               SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance started ");
        }
 
-       return EINA_FALSE;
+       return 0;
 }
 
 int __tts_cb_utt_completed(int uid, int utt_id)
@@ -1290,13 +1925,16 @@ 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;
 
        /* call callback function */
        if (NULL != client->utt_completeted_cb) {
-               ecore_timer_add(0, __tts_notify_utt_completed, client->tts);
+               SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of utterance completed ");
+               tts_client_use_callback(client);
+               client->utt_completeted_cb(client->tts, client->utt_id, client->utt_completed_user_data);
+               tts_client_not_use_callback(client);
        } else {
                SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of utterance completed ");
        }
@@ -1306,12 +1944,8 @@ int __tts_cb_utt_completed(int uid, int utt_id)
 
 int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts || NULL == callback) {
@@ -1334,19 +1968,15 @@ 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;
 }
 
 int tts_unset_state_changed_cb(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts) {
@@ -1376,12 +2006,8 @@ int tts_unset_state_changed_cb(tts_h tts)
 
 int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts || NULL == callback) {
@@ -1411,12 +2037,8 @@ int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, v
 
 int tts_unset_utterance_started_cb(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts) {
@@ -1446,12 +2068,8 @@ int tts_unset_utterance_started_cb(tts_h tts)
 
 int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts || NULL == callback) {
@@ -1481,12 +2099,8 @@ int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callbac
 
 int tts_unset_utterance_completed_cb(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts) {
@@ -1515,12 +2129,8 @@ int tts_unset_utterance_completed_cb(tts_h tts)
 
 int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts || NULL == callback) {
@@ -1550,12 +2160,8 @@ int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data)
 
 int tts_unset_error_cb(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts) {
@@ -1585,12 +2191,8 @@ int tts_unset_error_cb(tts_h tts)
 
 int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts || NULL == callback) {
@@ -1620,12 +2222,8 @@ int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb cal
 
 int tts_unset_default_voice_changed_cb(tts_h tts)
 {
-       bool tts_supported = false;
-       if (0 == system_info_get_platform_bool(TTS_FEATURE_PATH, &tts_supported)) {
-               if (false == tts_supported) {
-                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] TTS NOT supported");
-                       return TTS_ERROR_NOT_SUPPORTED;
-               }
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
        }
 
        if (NULL == tts) {
@@ -1652,3 +2250,66 @@ int tts_unset_default_voice_changed_cb(tts_h tts)
 
        return 0;
 }
+
+int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       if (NULL == tts || NULL == callback) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : 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] Set engine changed cb : A handle is not valid");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_CREATED != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : Current state is not 'Created'.");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       client->engine_changed_cb = callback;
+       client->engine_changed_user_data = user_data;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set engine changed cb");
+
+       return 0;
+}
+
+int tts_unset_engine_changed_cb(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               return TTS_ERROR_NOT_SUPPORTED;
+       }
+
+       if (NULL == tts) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : 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] Unset engine changed cb : A handle is not valid");
+               return TTS_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TTS_STATE_CREATED != client->current_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : Current state is not 'Created'.");
+               return TTS_ERROR_INVALID_STATE;
+       }
+
+       client->engine_changed_cb = NULL;
+       client->engine_changed_user_data = NULL;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset engine changed cb");
+
+       return 0;
+}
+