X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=common%2Fstt_config_mgr.c;h=d7e3105659fc174d0184205b82345d0ecc996248;hb=12b5a1c78624d158aced876d34e806fffd76d9b6;hp=6d7a95f44a0b6109b281a22d27694f136868affb;hpb=0089a515f6118b4230da30027ed7898e199188b9;p=platform%2Fcore%2Fuifw%2Fstt.git diff --git a/common/stt_config_mgr.c b/common/stt_config_mgr.c index 6d7a95f..d7e3105 100644 --- a/common/stt_config_mgr.c +++ b/common/stt_config_mgr.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "stt_config_mgr.h" #include "stt_defs.h" @@ -453,6 +454,7 @@ int __stt_config_set_auto_language() g_config_info->language = strdup(tmp_language); free(tmp_language); + tmp_language = NULL; } return 0; @@ -652,6 +654,64 @@ int __stt_config_mgr_check_engine_is_valid(const char* engine_id) return STT_CONFIG_ERROR_NONE; } +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; + } + + 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; + } + + if (NULL != dirp) { + if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name)) + continue; + + stt_engine_info_s* info; + char* filepath = NULL; + int filesize; + + filesize = strlen(STT_DEFAULT_ENGINE_INFO) + strlen(dirp->d_name) + 5; + filepath = (char*)calloc(filesize, sizeof(char)); + + if (NULL != filepath) { + snprintf(filepath, filesize, "%s/%s", directory, dirp->d_name); + } else { + SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Memory not enough!!"); + continue; + } + + if (0 == stt_parser_get_engine_info(filepath, &info)) { + g_engine_list = g_slist_append(g_engine_list, info); + } + + if (NULL != filepath) { + free(filepath); + filepath = NULL; + } + } + } while (NULL != dirp); + + closedir(dp); + } else { + SLOG(LOG_WARN, stt_tag(), "[Config WARNING] Fail to open directory"); + } + + return; +} + int stt_config_mgr_initialize(int uid) { GSList *iter = NULL; @@ -691,55 +751,57 @@ int stt_config_mgr_initialize(int uid) return STT_CONFIG_ERROR_NONE; } - /* Get file name from default engine directory */ - DIR *dp = NULL; - int ret = -1; - struct dirent entry; - struct dirent *dirp = NULL; - - g_engine_list = NULL; - - SLOG(LOG_WARN, stt_tag(), "[CONFIG] default engine info(%s)", STT_DEFAULT_ENGINE_INFO); - dp = opendir(STT_DEFAULT_ENGINE_INFO); - 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; - } + /* Make directories */ + if (0 != access(STT_CONFIG_BASE, F_OK)) { + if (0 != mkdir(STT_CONFIG_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make directory : %s", STT_CONFIG_BASE); + __stt_config_release_client(uid); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, stt_tag(), "Success to make directory : %s", STT_CONFIG_BASE); + } + } - if (NULL != dirp) { - if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name)) - continue; + if (0 != access(STT_HOME, F_OK)) { + if (0 != mkdir(STT_HOME, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make directory : %s", STT_HOME); + __stt_config_release_client(uid); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, stt_tag(), "Success to make directory : %s", STT_HOME); + } + } - stt_engine_info_s* info; - char* filepath; - int filesize; + if (0 != access(STT_DOWNLOAD_BASE, F_OK)) { + if (0 != mkdir(STT_DOWNLOAD_BASE, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make directory : %s", STT_DOWNLOAD_BASE); + __stt_config_release_client(uid); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, stt_tag(), "Success to make directory : %s", STT_DOWNLOAD_BASE); + } + } - filesize = strlen(STT_DEFAULT_ENGINE_INFO) + strlen(dirp->d_name) + 5; - filepath = (char*)calloc(filesize, sizeof(char)); + if (0 != access(STT_DOWNLOAD_ENGINE_INFO, F_OK)) { + if (0 != mkdir(STT_DOWNLOAD_ENGINE_INFO, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] Fail to make directory : %s", STT_DOWNLOAD_ENGINE_INFO); + __stt_config_release_client(uid); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, stt_tag(), "Success to make directory : %s", STT_DOWNLOAD_ENGINE_INFO); + } + } - if (NULL != filepath) { - snprintf(filepath, filesize, "%s/%s", STT_DEFAULT_ENGINE_INFO, dirp->d_name); - } else { - SLOG(LOG_ERROR, stt_tag(), "[Config ERROR] Memory not enough!!"); - continue; - } - if (0 == stt_parser_get_engine_info(filepath, &info)) { - g_engine_list = g_slist_append(g_engine_list, info); - } + /* Get file name from default engine directory */ + g_engine_list = NULL; - if (NULL != filepath) - free(filepath); - } - } while (NULL != dirp); + SLOG(LOG_WARN, stt_tag(), "[CONFIG] default engine info(%s)", STT_DEFAULT_ENGINE_INFO); - closedir(dp); - } else { - SLOG(LOG_WARN, stt_tag(), "[Config WARNING] Fail to open default directory"); - } + SLOG(LOG_DEBUG, stt_tag(), "[CONFIG] Get default engine list"); + __get_engine_list(STT_DEFAULT_ENGINE_INFO); + SLOG(LOG_DEBUG, stt_tag(), "[CONFIG] Get download engine list"); + __get_engine_list(STT_DOWNLOAD_ENGINE_INFO); __stt_config_mgr_print_engine_info(); @@ -785,8 +847,8 @@ int stt_config_mgr_initialize(int uid) } } - /* print daemon config */ - SLOG(LOG_DEBUG, stt_tag(), "== Daemon config =="); + /* print stt-service config */ + SLOG(LOG_DEBUG, stt_tag(), "== STT service config =="); SLOG(LOG_DEBUG, stt_tag(), " engine : %s", g_config_info->engine_id); SLOG(LOG_DEBUG, stt_tag(), " setting : %s", g_config_info->setting); SLOG(LOG_DEBUG, stt_tag(), " auto language : %s", g_config_info->auto_lang ? "on" : "off"); @@ -967,7 +1029,7 @@ int stt_config_mgr_get_engine_list(stt_config_supported_engine_cb callback, void return STT_CONFIG_ERROR_OPERATION_FAILED; } - if (false == callback(engine_info->uuid, engine_info->name, + if (false == callback(engine_info->uuid, engine_info->name, engine_info->setting, engine_info->support_silence_detection, user_data)) { break; } @@ -999,6 +1061,62 @@ int stt_config_mgr_get_engine(char** engine) return STT_CONFIG_ERROR_NONE; } +int __stt_config_set_buxtonkey(const char* engine) +{ + /* Set vconfkey */ + struct buxton_client * bux_cli; + struct buxton_layer * bux_layer; + struct buxton_value * bux_val; + + int ret = buxton_open(&bux_cli, NULL, NULL); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to open buxton client, ret(%d)", ret); + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + bux_layer = buxton_create_layer("system"); + if (NULL == bux_layer) { + SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL"); + buxton_close(bux_cli); + bux_cli = NULL; + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + bux_val = buxton_value_create_string(engine); + if (NULL == bux_val) { + SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL"); + buxton_free_layer(bux_layer); + buxton_close(bux_cli); + bux_layer = NULL; + bux_cli = NULL; + return STT_CONFIG_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] layer: %s", buxton_layer_get_name(bux_layer)); + } + + ret = buxton_set_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_DEFAULT, bux_val); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to set value sync, ret(%d)", ret); + buxton_value_free(bux_val); + buxton_free_layer(bux_layer); + buxton_close(bux_cli); + + bux_cli = NULL; + bux_layer = NULL; + bux_val = NULL; + return STT_CONFIG_ERROR_OPERATION_FAILED; + } + SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %s", STT_ENGINE_DB_DEFAULT); + + buxton_value_free(bux_val); + buxton_free_layer(bux_layer); + buxton_close(bux_cli); + + bux_cli = NULL; + bux_layer = NULL; + bux_val = NULL; + + return STT_CONFIG_ERROR_NONE; +} + int stt_config_mgr_set_engine(const char* engine) { if (0 >= g_slist_length(g_config_client_list)) { @@ -1021,6 +1139,12 @@ int stt_config_mgr_set_engine(const char* engine) SLOG(LOG_DEBUG, stt_tag(), "New engine id : %s", engine); + int ret = __stt_config_set_buxtonkey(engine); + if (0 != ret) { + SLOG(LOG_ERROR, stt_tag(), "[ERROR] set buxtonkey Failed!!!"); + return ret; + } + GSList *iter = NULL; stt_engine_info_s *engine_info = NULL; bool is_valid_engine = false; @@ -1043,13 +1167,16 @@ int stt_config_mgr_set_engine(const char* engine) continue; } - if (NULL != g_config_info->engine_id) + if (NULL != g_config_info->engine_id) { free(g_config_info->engine_id); + g_config_info->engine_id = NULL; + } g_config_info->engine_id = strdup(engine); if (NULL != g_config_info->setting) { free(g_config_info->setting); + g_config_info->setting = NULL; } if (NULL != engine_info->setting) { @@ -1517,7 +1644,7 @@ int __stt_config_mgr_print_engine_info() } else { SLOG(LOG_ERROR, stt_tag(), " language is NONE"); } - SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", + SLOG(LOG_DEBUG, stt_tag(), " silence support : %s", engine_info->support_silence_detection ? "true" : "false"); iter = g_slist_next(iter); i++; @@ -1582,9 +1709,13 @@ 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); + /* Add item to global list */ g_time_list = g_slist_append(g_time_list, info); + SLOG(LOG_DEBUG, stt_tag(), "[DEBUG] inside stt_config_mgr_add_time_info: g_time_list length(%d)", g_slist_length(g_time_list)); + return 0; } @@ -1611,7 +1742,7 @@ int stt_config_mgr_foreach_time_info(stt_config_result_time_cb callback, void* u while (NULL != iter) { data = iter->data; - if (false == callback(data->index, data->event, data->text, + if (false == callback(data->index, data->event, data->text, data->start_time, data->end_time, user_data)) { break; }