2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
14 #include <Ecore_File.h>
15 #include "ttsd_main.h"
16 #include "ttsd_config.h"
18 #define CONFIG_FILE_PATH BASE_DIRECTORY_DOWNLOAD"/ttsd.conf"
19 #define CONFIG_DEFAULT BASE_DIRECTORY_DEFAULT"/ttsd.conf"
21 #define ENGINE_ID "ENGINE_ID"
26 static char* g_engine_id;
27 static char* g_language;
31 int __ttsd_config_save()
33 if (0 != access(CONFIG_FILE_PATH, R_OK|W_OK)) {
34 if (0 == ecore_file_mkpath(BASE_DIRECTORY_DOWNLOAD)) {
35 SLOG(LOG_ERROR, TAG_TTSD, "[Config ERROR ] Fail to create directory (%s)", BASE_DIRECTORY_DOWNLOAD);
39 SLOG(LOG_WARN, TAG_TTSD, "[Config] Create directory (%s)", BASE_DIRECTORY_DOWNLOAD);
43 config_fp = fopen(CONFIG_FILE_PATH, "w+");
45 if (NULL == config_fp) {
46 /* make file and file default */
47 SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to open config (%s)", CONFIG_FILE_PATH);
51 SLOG(LOG_DEBUG, TAG_TTSD, "[Config] Rewrite config file");
54 fprintf(config_fp, "%s %s\n", ENGINE_ID, g_engine_id);
57 fprintf(config_fp, "%s %s %d\n", VOICE, g_language, g_vc_type);
60 fprintf(config_fp, "%s %d\n", SPEED, g_speed);
68 int __ttsd_config_load()
71 char buf_id[256] = {0};
72 char buf_param[256] = {0};
74 bool is_default_open = false;
76 config_fp = fopen(CONFIG_FILE_PATH, "r");
78 if (NULL == config_fp) {
79 SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Not open file(%s)", CONFIG_FILE_PATH);
81 config_fp = fopen(CONFIG_DEFAULT, "r");
82 if (NULL == config_fp) {
83 SLOG(LOG_ERROR, TAG_TTSD, "[Config WARNING] Not open original config file(%s)", CONFIG_FILE_PATH);
86 is_default_open = true;
90 fscanf(config_fp, "%s %s", buf_id, buf_param);
91 if (0 == strncmp(ENGINE_ID, buf_id, strlen(ENGINE_ID))) {
92 g_engine_id = strdup(buf_param);
95 SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to load config (engine id)");
101 fscanf(config_fp, "%s %s %d", buf_id, buf_param, &int_param);
102 if (0 == strncmp(VOICE, buf_id, strlen(VOICE))) {
103 g_language = strdup(buf_param);
104 g_vc_type = int_param;
107 SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to load config (voice)");
108 __ttsd_config_save();
113 fscanf(config_fp, "%s %d", buf_id, &int_param);
114 if (0 == strncmp(SPEED, buf_id, strlen(SPEED))) {
118 SLOG(LOG_WARN, TAG_TTSD, "[Config WARNING] Fail to load config (speed)");
119 __ttsd_config_save();
125 SLOG(LOG_DEBUG, TAG_TTSD, "[Config] Load config : engine(%s), voice(%s,%d), speed(%d)",
126 g_engine_id, g_language, g_vc_type, g_speed);
128 if (true == is_default_open) {
129 if(0 == __ttsd_config_save()) {
130 SLOG(LOG_DEBUG, TAG_TTSD, "[Config] Create config(%s)", CONFIG_FILE_PATH);
137 int ttsd_config_initialize()
144 __ttsd_config_load();
149 int ttsd_config_finalize()
151 __ttsd_config_save();
155 int ttsd_config_get_default_engine(char** engine_id)
157 if (NULL == engine_id)
160 *engine_id = strdup(g_engine_id);
164 int ttsd_config_set_default_engine(const char* engine_id)
166 if (NULL == engine_id)
169 if (NULL != g_engine_id)
172 g_engine_id = strdup(engine_id);
173 __ttsd_config_save();
177 int ttsd_config_get_default_voice(char** language, int* type)
179 if (NULL == language || NULL == type)
182 *language = strdup(g_language);
188 int ttsd_config_set_default_voice(const char* language, int type)
190 if (NULL == language)
193 if (NULL != g_language)
196 g_language = strdup(language);
199 __ttsd_config_save();
204 int ttsd_config_get_default_speed(int* speed)
214 int ttsd_config_set_default_speed(int speed)
217 __ttsd_config_save();