Add logic to set default language of the engine 64/158164/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 30 Oct 2017 07:16:11 +0000 (16:16 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 30 Oct 2017 07:16:11 +0000 (16:16 +0900)
Change-Id: I88c1e2670513b12ddb63163e58fdbe9c6c675d73
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/stt_config_mgr.c
common/stt_config_parser.c
common/stt_config_parser.h
common/stt_defs.h

index 12fe905..479ac08 100755 (executable)
@@ -112,7 +112,7 @@ int __stt_config_mgr_select_lang(const char* engine_id, char** language)
 {
        if (NULL == engine_id || NULL == language) {
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] Input parameter is NULL");
-               return false;
+               return STT_CONFIG_ERROR_INVALID_PARAMETER;
        }
 
        GSList *iter = NULL;
@@ -120,7 +120,7 @@ int __stt_config_mgr_select_lang(const char* engine_id, char** language)
 
        if (0 >= g_slist_length(g_engine_list)) {
                SLOG(LOG_ERROR, stt_tag(), "[ERROR] There is no engine!!");
-               return false;
+               return STT_CONFIG_ERROR_OPERATION_FAILED;
        }
 
        /* Get a first item */
@@ -131,7 +131,8 @@ int __stt_config_mgr_select_lang(const char* engine_id, char** language)
 
                if (NULL == engine_info) {
                        SLOG(LOG_ERROR, stt_tag(), "engine info is NULL");
-                       return false;
+                       iter = g_slist_next(iter);
+                       continue;
                }
 
                if (0 != strcmp(engine_id, engine_info->uuid)) {
@@ -139,37 +140,20 @@ int __stt_config_mgr_select_lang(const char* engine_id, char** language)
                        continue;
                }
 
-               GSList *iter_lang = NULL;
-               char* engine_lang = NULL;
-               if (g_slist_length(engine_info->languages) > 0) {
-                       /* Get a first item */
-                       iter_lang = g_slist_nth(engine_info->languages, 0);
-
-                       while (NULL != iter_lang) {
-                               engine_lang = iter_lang->data;
-                               if (NULL != engine_lang) {
-                                       /* Default language is STT_BASE_LANGUAGE */
-                                       if (0 == strcmp(STT_BASE_LANGUAGE, engine_lang)) {
-                                               *language = strdup(engine_lang);
-                                               SLOG(LOG_DEBUG, stt_tag(), "Selected language : %s", (NULL == *language) ? "NULL" : *language);
-                                               return 0;
-                                       }
-                               }
+               if (NULL == engine_info->default_lang) {
+                       SLOG(LOG_ERROR, stt_tag(), "[ERROR] Default language of the engine info is NULL");
+                       return STT_CONFIG_ERROR_INVALID_LANGUAGE;
+               }
 
-                               iter_lang = g_slist_next(iter_lang);
-                       }
+               *language = strdup(engine_info->default_lang);
 
-                       /* Not support STT_BASE_LANGUAGE */
-                       if (NULL != engine_lang) {
-                               *language = strdup(engine_lang);
-                               SLOG(LOG_DEBUG, stt_tag(), "Selected language : %s", (NULL == *language) ? "NULL" : *language);
-                               return 0;
-                       }
+               if (NULL != *language) {
+                       SLOG(LOG_DEBUG, stt_tag(), "Selected language : %s", *language);
+                       return STT_CONFIG_ERROR_NONE;
                }
-               break;
        }
 
-       return -1;
+       return STT_CONFIG_ERROR_OPERATION_FAILED;
 }
 
 Eina_Bool stt_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handler)
index 3f192e5..6a7925d 100644 (file)
@@ -23,6 +23,7 @@
 #define STT_TAG_ENGINE_ID              "id"
 #define STT_TAG_ENGINE_SETTING         "setting"
 #define STT_TAG_ENGINE_AGREEMENT       "agreement"
+#define STT_TAG_ENGINE_DEFAULT         "default"
 #define STT_TAG_ENGINE_LANGUAGE_SET    "languages"
 #define STT_TAG_ENGINE_LANGUAGE                "lang"
 #define STT_TAG_ENGINE_SILENCE_SUPPORT "silence-detection-support"
@@ -98,10 +99,13 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
        temp->uuid = NULL;
        temp->setting = NULL;
        temp->agreement = NULL;
+       temp->default_lang = NULL;
        temp->languages = NULL;
        temp->support_silence_detection = false;
        temp->need_credential = false;
 
+       bool is_default_lang_set = false;
+
        while (cur != NULL) {
                if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_NAME)) {
                        key = xmlNodeGetContent(cur);
@@ -143,6 +147,18 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
                        } else {
                                SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_AGREEMENT);
                        }
+               } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_DEFAULT)) {
+                       key = xmlNodeGetContent(cur);
+                       if (NULL != key) {
+                               SLOG(LOG_DEBUG, stt_tag(), "Engine agreement : %s", (char *)key);
+                               if (NULL != temp->default_lang) free(temp->default_lang);
+                               temp->default_lang = strdup((char*)key);
+
+                               is_default_lang_set = true;
+                               xmlFree(key);
+                       } else {
+                               SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_DEFAULT);
+                       }
                } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)STT_TAG_ENGINE_LANGUAGE_SET)) {
                        xmlNodePtr lang_node = NULL;
                        char* temp_lang = NULL;
@@ -156,6 +172,13 @@ int stt_parser_get_engine_info(const char* path, stt_engine_info_s** engine_info
                                                /* SLOG(LOG_DEBUG, stt_tag(), "language : %s", (char *)key); */
                                                temp_lang = strdup((char*)key);
                                                temp->languages = g_slist_append(temp->languages, temp_lang);
+
+                                               if (false == is_default_lang_set) {
+                                                       if (NULL != temp->default_lang) free(temp->default_lang);
+                                                       temp->default_lang = strdup((char*)key);
+
+                                                       is_default_lang_set = true;
+                                               }
                                                xmlFree(key);
                                        } else {
                                                SLOG(LOG_ERROR, stt_tag(), "[ERROR] <%s> has no content", STT_TAG_ENGINE_LANGUAGE);
index 2987661..71716d0 100644 (file)
@@ -28,6 +28,7 @@ typedef struct {
        char*   uuid;
        char*   setting;
        char*   agreement;
+       char*   default_lang;
        GSList* languages;
        bool    support_silence_detection;
        bool    need_credential;
index 2fd8fd6..abcabe4 100644 (file)
@@ -98,8 +98,6 @@ extern "C" {
 #define STT_DOWNLOAD_BASE              tzplatform_mkpath(TZ_USER_HOME, "share/.voice/stt/1.0")
 #define STT_DOWNLOAD_ENGINE_INFO       tzplatform_mkpath(TZ_USER_HOME, "share/.voice/stt/1.0/engine-info")
 
-#define STT_BASE_LANGUAGE              "en_US"
-
 #define STT_RETRY_COUNT                        5
 
 #define STT_FEATURE_PATH               "tizen.org/feature/speech.recognition"