Merge "Support download engine language" into tizen
[platform/core/uifw/tts.git] / client / tts.c
index 59ae6b2..19684fc 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
 #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);
@@ -82,6 +82,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";
        }
@@ -98,7 +100,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;
 }
@@ -251,9 +253,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);
@@ -376,6 +379,37 @@ 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;
+       }
+
+       client->credential = strdup(credential);
+
+       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;
@@ -384,7 +418,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;
        }
 
@@ -397,7 +430,9 @@ static Eina_Bool __tts_connect_daemon(void *data)
 
        /* 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));
@@ -406,7 +441,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) {
@@ -415,9 +450,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 */
@@ -469,7 +506,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, " ");
@@ -704,11 +741,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;
@@ -739,18 +776,49 @@ 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 {
+               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)
 {
        if (0 != __tts_get_feature_enabled()) {
                return TTS_ERROR_NOT_SUPPORTED;
        }
 
-       if( speed < 0 ) {
+       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 ) {
+       if (voice_type < 0) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Voice type should not be negative(%d)", voice_type);
                return TTS_ERROR_INVALID_PARAMETER;
        }
@@ -797,6 +865,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", "");
@@ -846,7 +919,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));
@@ -873,6 +946,110 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty
        return ret;
 }
 
+static void __tts_play_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_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));
+                               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");
+                                       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;
+
+       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_play_async(tts_h tts)
+{
+       if (0 != __tts_get_feature_enabled()) {
+               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_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;
+       }
+
+       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()) {
@@ -907,10 +1084,15 @@ int tts_play(tts_h tts)
                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);
+               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));
@@ -943,6 +1125,104 @@ int tts_play(tts_h tts)
        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)
 {
@@ -1014,6 +1294,106 @@ int tts_stop(tts_h tts)
        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, " ");
+
+       return TTS_ERROR_NONE;
+}
 
 int tts_pause(tts_h tts)
 {
@@ -1087,6 +1467,118 @@ 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_DEBUG, TAG_TTSC, "===== Set private data");
+
+       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_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_DEBUG, TAG_TTSC, "===== Get private data");
+
+       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;
+                               }
+                       }
+               }
+       }
+
+       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;
@@ -1104,7 +1596,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 ");
@@ -1113,7 +1607,7 @@ 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);
 
@@ -1124,6 +1618,11 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id)
 
        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);
 
        /* call callback function */
        if (NULL != client->error_cb) {
@@ -1132,6 +1631,15 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id)
                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;
 }