2 * Copyright (c) 2012, 2013 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 <vconf-internal-keys.h>
17 #include <runtime_info.h>
18 #include "ttsd_main.h"
19 #include "ttsd_config.h"
20 #include "ttsd_engine_agent.h"
21 #include "ttsd_data.h"
23 #define CONFIG_DEFAULT BASE_DIRECTORY_DEFAULT"/ttsd.conf"
24 #define SR_ERROR_FILE_NAME CONFIG_DIRECTORY"/ttsd_sr.err"
26 #define ENGINE_ID "ENGINE_ID"
28 static char* g_engine_id;
29 static char* g_language;
33 static ttsd_config_lang_changed_cb g_lang_cb;
34 static ttsd_config_speed_changed_cb g_speed_cb;
36 void __sr_system_language_changed_cb(runtime_info_key_e key, void *user_data)
38 if (RUNTIME_INFO_KEY_LANGUAGE == key) {
39 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
43 ret = runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &value);
45 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to get system language : %d", ret);
48 SLOG(LOG_DEBUG, get_tag(), "[Config] System language changed : %s", value);
49 if (NULL != g_lang_cb)
50 g_lang_cb(value, g_vc_type);
61 void __sr_speech_rate_changed_cb(keynode_t *key, void *data)
64 sprintf(buf, "%s", vconf_keynode_get_name(key));
66 if (!strcmp(buf, VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE)) {
67 int temp_speech_rate = vconf_keynode_get_int(key);
70 if (g_speed != temp_speech_rate) {
71 SLOG(LOG_DEBUG, get_tag(), "[Config] Speech rate changed : current(%d), previous(%d)",
72 temp_speech_rate, g_speed);
73 g_speed = temp_speech_rate;
75 if (NULL != g_speed_cb)
81 int ttsd_config_initialize(ttsd_config_lang_changed_cb lang_cb, ttsd_config_speed_changed_cb speed_cb)
86 char buf_id[256] = {0};
87 char buf_param[256] = {0};
95 g_speed_cb = speed_cb;
97 ecore_file_mkpath(CONFIG_DIRECTORY);
99 /* Get default engine id */
100 config_fp = fopen(CONFIG_DEFAULT, "r");
101 if (NULL == config_fp) {
102 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Not open original config file(%s)", CONFIG_DEFAULT);
107 if (EOF == fscanf(config_fp, "%s %s", buf_id, buf_param)) {
109 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to read config (engine id)");
115 /* Get display language */
116 ret = runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &value);
117 if (0 != ret || NULL == value) {
118 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to get system language : %d", ret);
121 SLOG(LOG_DEBUG, get_tag(), "[Config] System language changed : %s", value);
123 g_language = strdup(value);
129 /* Register system language changed callback */
130 ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, __sr_system_language_changed_cb, NULL);
132 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to register callback : %d", ret);
133 return TTSD_ERROR_OPERATION_FAILED;
136 /* Get speech rate */
137 ret = vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, &g_speed);
140 * vconf key value scope
147 /* vconf key value is between 0 ~ 4 but tts speech rate value is between 1 ~ 5 */
149 SLOG(LOG_DEBUG, get_tag(), "[Config] Current speech rate : %d", g_speed);
151 /* register callback function */
152 vconf_notify_key_changed (VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, __sr_speech_rate_changed_cb, NULL);
157 int ttsd_config_finalize()
159 vconf_ignore_key_changed (VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, __sr_speech_rate_changed_cb);
161 if (NULL != g_language) {
165 if (NULL != g_engine_id) {
172 int ttsd_config_update_language()
174 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
178 ret = runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &value);
180 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to get system language : %d", ret);
184 SLOG(LOG_ERROR, get_tag(), "[Config] Fail to get system language");
187 SLOG(LOG_DEBUG, get_tag(), "[Config] System language : %s", value);
189 if (0 != strcmp(value, g_language)) {
190 if (NULL != g_lang_cb)
191 g_lang_cb(value, g_vc_type);
202 int ttsd_config_get_default_engine(char** engine_id)
204 if (NULL == engine_id)
207 if (NULL != g_engine_id) {
208 *engine_id = strdup(g_engine_id);
210 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Current engine id is NULL");
216 int ttsd_config_set_default_engine(const char* engine_id)
218 /* Not available in screen mode */
222 int ttsd_config_get_default_voice(char** language, int* type)
224 if (NULL == language || NULL == type)
227 if (NULL != g_language) {
228 *language = strdup(g_language);
231 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Current language is NULL");
237 int ttsd_config_set_default_voice(const char* language, int type)
239 /* Not available in screen mode */
243 int ttsd_config_get_default_speed(int* speed)
253 int ttsd_config_set_default_speed(int speed)
255 /* Not available in screen mode */
259 int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text,
260 const char* func, int line, const char* message)
263 err_fp = fopen(SR_ERROR_FILE_NAME, "a");
264 if (NULL == err_fp) {
265 SLOG(LOG_WARN, get_tag(), "[WARNING] Fail to open error file (%s)", SR_ERROR_FILE_NAME);
268 SLOG(LOG_DEBUG, get_tag(), "Save Error File (%s)", SR_ERROR_FILE_NAME);
272 fprintf(err_fp, "function - %s\n", func);
276 fprintf(err_fp, "line - %d\n", line);
279 if (NULL != message) {
280 fprintf(err_fp, "message - %s\n", message);
285 fprintf(err_fp, "uid - %d\n", uid);
288 fprintf(err_fp, "uttid - %d\n", uttid);
292 fprintf(err_fp, "language - %s\n", lang);
296 fprintf(err_fp, "vctype - %d\n", vctype);
300 fprintf(err_fp, "text - %s\n", text);
303 /* get current engine */
304 char *engine_id = NULL;
306 ret = ttsd_engine_setting_get_engine(&engine_id);
308 SLOG(LOG_ERROR, get_tag(), "[ERROR] Fail to get current engine");
310 fprintf(err_fp, "current engine - %s", engine_id);
314 ttsd_data_save_error_log(uid, err_fp);