Implement set_engine for setting TTS default engine 87/107187/3
authorsooyeon.kim <sooyeon.kim@samsung.com>
Tue, 27 Dec 2016 06:02:39 +0000 (15:02 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Tue, 27 Dec 2016 07:54:06 +0000 (16:54 +0900)
Change-Id: I1bb94d89742ca548630b4b8742d104bc4fbd7553
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/tts.c
engine-parser/src/tts-engine-parser.c

index 05daf46..75498b3 100644 (file)
@@ -152,6 +152,33 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c
        if (NULL != language)   SLOG(LOG_DEBUG, TAG_TTSC, "Language(%s)", language);
        SLOG(LOG_DEBUG, TAG_TTSC, "Voice type(%d), Auto voice(%s), Credential(%s)", voice_type, auto_voice ? "on" : "off", need_credential ? "need" : "no need");
 
+       /* When the default engine is changed, please unload the old engine and load the new one. */
+       int ret = -1;
+
+       if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_PAUSED == client->current_state) {
+               ret = tts_stop(tts);
+               if (0 != ret) {
+                       SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping...");
+               }
+               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);
+               }
+       }
+
        /* 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);
index 1a3e8dc..2016f5e 100644 (file)
@@ -443,6 +443,42 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        return -1;
                }
 
+               /* Save in /etc/skel/share/ */
+               g_dir_config_base = strdup(TTS_GLOBAL_CONFIG_BASE);
+               g_dir_home = strdup(TTS_GLOBAL_HOME);
+               g_dir_engine_base = strdup(TTS_GLOBAL_ENGINE_BASE);
+               g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
+
+               if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
+                       LOGE("[ERROR] Fail to allocate memory");
+                       if (NULL != g_dir_config_base) {
+                               free(g_dir_config_base);
+                               g_dir_config_base = NULL;
+                       }
+                       if (NULL != g_dir_home) {
+                               free(g_dir_home);
+                               g_dir_home = NULL;
+                       }
+                       if (NULL != g_dir_engine_base) {
+                               free(g_dir_engine_base);
+                               g_dir_engine_base = NULL;
+                       }
+                       if (NULL != g_dir_engine_info) {
+                               free(g_dir_engine_info);
+                               g_dir_engine_info = NULL;
+                       }
+                       xmlFreeDoc(g_doc);
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid)) {
+                       LOGE("[ERROR] Fail to make engine info file");
+                       xmlFreeDoc(g_doc);
+                       g_free(g_user_type);
+                       return -1;
+               }
+
                /* Get user data by using libgum */
 
                GumUserService *gus = NULL;
@@ -721,6 +757,18 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                /* global directory */
                LOGD("[DEBUG] usertype: %s", g_user_type);
 
+               /* Remove files in /etc/skel/share/ */
+               g_dir_engine_info = strdup(TTS_GLOBAL_ENGINE_INFO);
+               if (NULL == g_dir_engine_info) {
+                       LOGE("[ERROR] Fail to allocate memory");
+                       g_free(g_user_type);
+                       return -1;
+               }
+
+               if (0 != __remove_engine_info_xml(pkgid, g_user_type, g_uid)) {
+                       LOGE("[ERROR] Fail to remove engine info file");
+               }
+
                /* Get user data by using libgum */
 
                GumUserService *gus = NULL;