Add logic to set default language of the engine
[platform/core/uifw/stt.git] / common / stt_config_mgr.c
old mode 100644 (file)
new mode 100755 (executable)
index d7e3105..479ac08
@@ -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)
@@ -657,23 +641,19 @@ int __stt_config_mgr_check_engine_is_valid(const char* engine_id)
 static void __get_engine_list(const char* directory)
 {
        DIR *dp = NULL;
-       int ret = -1;
-       struct dirent entry;
        struct dirent *dirp = NULL;
 
        if (NULL == directory) {
                SLOG(LOG_ERROR, stt_tag(), "[Directory ERROR] Directory is NULL");
                return;
+       } else {
+               SLOG(LOG_DEBUG, stt_tag(), "[Directory DEBUG] Directory: %s", directory);
        }
 
        dp  = opendir(directory);
        if (NULL != dp) {
                do {
-                       ret = readdir_r(dp, &entry, &dirp);
-                       if (0 != ret) {
-                               SLOG(LOG_ERROR, stt_tag(), "[File ERROR] Fail to read directory");
-                               break;
-                       }
+                       dirp = readdir(dp);
 
                        if (NULL != dirp) {
                                if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name))
@@ -683,7 +663,7 @@ static void __get_engine_list(const char* directory)
                                char* filepath = NULL;
                                int filesize;
 
-                               filesize = strlen(STT_DEFAULT_ENGINE_INFO) + strlen(dirp->d_name) + 5;
+                               filesize = strlen(directory) + strlen(dirp->d_name) + 5;
                                filepath = (char*)calloc(filesize, sizeof(char));
 
                                if (NULL != filepath) {
@@ -693,6 +673,8 @@ static void __get_engine_list(const char* directory)
                                        continue;
                                }
 
+                               SLOG(LOG_DEBUG, stt_tag(), "[File DEBUG] File path: %s", filepath);
+
                                if (0 == stt_parser_get_engine_info(filepath, &info)) {
                                        g_engine_list = g_slist_append(g_engine_list, info);
                                }
@@ -1709,7 +1691,7 @@ int stt_config_mgr_add_time_info(int index, int event, const char* text, long st
        info->start_time = start_time;
        info->end_time = end_time;
 
-       SLOG(LOG_DEBUG, stt_tag(), "[DEBUG] inside stt_config_mgr_add_time_info: index(%d), text(%s), start time(%d), end_time(%d)", info->index, (NULL == info->text) ? "NULL" : info->text, info->start_time, info->end_time);
+       SLOG(LOG_DEBUG, stt_tag(), "[DEBUG] inside stt_config_mgr_add_time_info: index(%d), text(%s), start time(%ld), end_time(%ld)", info->index, (NULL == info->text) ? "NULL" : info->text, info->start_time, info->end_time);
 
        /* Add item to global list */
        g_time_list = g_slist_append(g_time_list, info);
@@ -1731,7 +1713,7 @@ int stt_config_mgr_foreach_time_info(stt_config_result_time_cb callback, void* u
        ret = stt_parser_get_time_info(&temp_time);
        if (0 != ret) {
                SLOG(LOG_WARN, stt_tag(), "[WARNING] Fail to get time info : %d", ret);
-               return STT_CONFIG_ERROR_OPERATION_FAILED;
+               return STT_CONFIG_ERROR_NONE;
        }
 
        GSList *iter = NULL;