g_config_info->language = strdup(tmp_language);
free(tmp_language);
+ tmp_language = NULL;
}
return 0;
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;
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();
}
}
- /* 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");
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;
}
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) {
} 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++;
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;
}
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;
}