Call ttse_terminate() when TTS engine is changed 89/261989/3
authorsooyeon <sooyeon.kim@samsung.com>
Fri, 30 Jul 2021 15:37:04 +0000 (00:37 +0900)
committersooyeon <sooyeon.kim@samsung.com>
Fri, 30 Jul 2021 16:37:31 +0000 (01:37 +0900)
- Previously, when TTS engine is changed, TTS clients call unprepare() and prepare() in order to connect to a new TTS engine.
In this case, dbus primary owner issue is occurred, because some clients request prepare() before the old TTS engine is terminated.(timing issue)
To solve this issue, we make TTS engine terminated by itself with calling ttse_terminate().
When TTS engine is terminated, all TTS clients can receive SERVICE_RESET and try to reprepare for the new TTS engine.
This can solve the dbus primary owner issue.

Change-Id: I431677f58f76322b6751cfbbf24009073fd35fc6
Signed-off-by: sooyeon <sooyeon.kim@samsung.com>
client/tts.c
client/tts_core.c
client/tts_tidl.c
server/ttse.c

index 065f973..32ce983 100644 (file)
@@ -114,7 +114,7 @@ static void __tts_config_voice_changed_cb(const char* before_lang, int before_vo
 
        return;
 }
-
+/*
 static Eina_Bool __reconnect_by_engine_changed(void* data)
 {
        tts_h tts = (tts_h)data;
@@ -143,7 +143,7 @@ static Eina_Bool __reconnect_by_engine_changed(void* data)
 
        return EINA_FALSE;
 }
-
+*/
 static void __tts_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
 {
        tts_h tts = (tts_h)user_data;
@@ -160,7 +160,7 @@ static void __tts_config_engine_changed_cb(const char* engine_id, const char* se
        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;
+/*     int ret = -1;
 
        tts_state_e current_state = tts_client_get_current_state(client);
        if (TTS_STATE_PLAYING == current_state || TTS_STATE_PAUSED == current_state) {
@@ -181,7 +181,7 @@ static void __tts_config_engine_changed_cb(const char* engine_id, const char* se
                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
                }
        }
-
+*/
        /* call callback function */
        tts_core_notify_engine_changed(client, engine_id, language, voice_type, need_credential);
        return;
index 7a4df9a..798cf68 100644 (file)
@@ -1127,7 +1127,7 @@ int tts_core_reprepare()
 
                while (NULL != iter) {
                        tts_client_s* client = iter->data;
-                       if (false == tts_client_is_valid_client(client)) {
+                       if (true == tts_client_is_valid_client(client)) {
                                tts_client_set_current_state(client, TTS_STATE_CREATED);
                                client->reason = TTS_ERROR_NONE;
                        }
index 8e3653f..122f2f2 100644 (file)
@@ -271,7 +271,7 @@ int tts_tidl_open_connection(int uid)
        info->uid = uid;
        g_tidl_infos = g_list_append(g_tidl_infos, info);
 
-       SLOG(LOG_ERROR, TAG_TTSC, "[TIDL] uid(%d) rpc_h(%p)", uid, info->rpc_h);
+       SLOG(LOG_ERROR, TAG_TTSC, "[TIDL] uid(%d) rpc_h(%p), engine_app_id(%s)", uid, info->rpc_h, info->engine_app_id);
        return TTS_ERROR_NONE;
 }
 
@@ -340,8 +340,8 @@ int tts_tidl_request_hello(int uid)
        char engine_app_id[256] = {0, };
        __get_engine_app_id(mode, 256, engine_app_id);
 
-       if (NULL == info->engine_app_id || 0 != strncmp(info->engine_app_id, engine_app_id, strlen(info->engine_app_id))) {
-               SLOG(LOG_INFO, TAG_TTSC, "[TIDL] tts engine is changed from (%s) to (%s)", info->engine_app_id, engine_app_id);
+       if (NULL == info->engine_app_id || 0 != strncmp(info->engine_app_id, engine_app_id, 256)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[TIDL] tts engine is changed from (%s) to (%s)", info->engine_app_id, engine_app_id);
                if (0 != rpc_port_proxy_tts_destroy(info->rpc_h)) {
                        SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to destroy old rpc_port");
                        return TTS_ERROR_OPERATION_FAILED;
index 30f5297..2d514bf 100755 (executable)
@@ -114,6 +114,21 @@ static ttsd_mode_e __get_mode_from_appid()
        return mode;
 }
 
+static void __engine_changed_cb(keynode_t* key, void* data)
+{
+       SLOG(LOG_INFO, tts_tag(), "[INFO] TTS engine vconfkey is changed");
+
+       /* If a new TTS engine is different from the current engine, call ttse_terminate() */
+       if (FALSE == __is_default_engine()) {
+               SLOG(LOG_WARN, tts_tag(), "[WARNING] TTS engine is changed. Please call ttse_terminate()");
+               ttse_terminate();
+       } else {
+               SLOG(LOG_INFO, tts_tag(), "[INFO] A new TTS engine is same as the current engine.");
+       }
+
+       return;
+}
+
 int ttse_main(int argc, char** argv, ttse_request_callback_s *callback)
 {
        bundle *b = NULL;
@@ -177,6 +192,9 @@ int ttse_main(int argc, char** argv, ttse_request_callback_s *callback)
                SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to initialize network");
        }
 
+       /* Register vconfkey callback to detect engine change */
+       vconf_notify_key_changed(TTS_ENGINE_DB_DEFAULT, __engine_changed_cb, NULL);
+
        SLOG(LOG_DEBUG, tts_tag(), "@@@");
 
        return TTSE_ERROR_NONE;
@@ -186,6 +204,9 @@ int ttse_terminate()
 {
        ttsd_terminate();
 
+       /* Unregister vconfkey callback */
+       vconf_ignore_key_changed(TTS_ENGINE_DB_DEFAULT, __engine_changed_cb);
+
        return TTSE_ERROR_NONE;
 }