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 SR_ERROR_FILE_NAME CONFIG_DIRECTORY"/ttsd_sr.err"
25 #define ENGINE_ID "ENGINE_ID"
27 static char* g_engine_id;
28 static char* g_language;
32 static ttsd_config_changed_cb g_callback;
34 void __sr_system_language_changed_cb(runtime_info_key_e key, void *user_data)
36 if (RUNTIME_INFO_KEY_LANGUAGE == key) {
37 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
41 ret = runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &value);
43 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to get system language : %d", ret);
46 SLOG(LOG_DEBUG, get_tag(), "[Config] System language changed : %s", value);
47 if (NULL != g_callback)
48 g_callback(TTS_CONFIG_TYPE_VOICE, value, g_vc_type);
59 void __sr_speech_rate_changed_cb(keynode_t *key, void *data)
62 sprintf(buf, "%s", vconf_keynode_get_name(key));
64 if (!strcmp(buf, VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE)) {
65 int temp_speech_rate = vconf_keynode_get_int(key);
68 if (g_speed != temp_speech_rate) {
69 SLOG(LOG_DEBUG, get_tag(), "[Config] Speech rate changed : current(%d), previous(%d)",
70 temp_speech_rate, g_speed);
71 g_speed = temp_speech_rate;
73 if (NULL != g_callback)
74 g_callback(TTS_CONFIG_TYPE_SPEED, NULL, g_speed);
79 int ttsd_config_initialize(ttsd_config_changed_cb callback)
84 char buf_id[256] = {0};
85 char buf_param[256] = {0};
92 g_callback = callback;
94 ecore_file_mkpath(CONFIG_DIRECTORY);
96 /* Get default engine id */
97 config_fp = fopen(CONFIG_DEFAULT, "r");
98 if (NULL == config_fp) {
99 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Not open original config file(%s)", CONFIG_DEFAULT);
104 if (EOF == fscanf(config_fp, "%s %s", buf_id, buf_param)) {
106 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to read config (engine id)");
110 if (0 == strncmp(ENGINE_ID, buf_id, strlen(ENGINE_ID))) {
111 g_engine_id = strdup(buf_param);
112 SLOG(LOG_DEBUG, get_tag(), "[Config] Current engine id : %s", g_engine_id);
117 SLOG(LOG_WARN, get_tag(), "[Config WARNING] Fail to load config (engine id)");
121 /* Get display language */
122 ret = runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &value);
123 if (0 != ret || NULL == value) {
124 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to get system language : %d", ret);
127 SLOG(LOG_DEBUG, get_tag(), "[Config] Current system language : %s", value);
129 g_language = strdup(value);
135 /* Register system language changed callback */
136 ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, __sr_system_language_changed_cb, NULL);
138 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to register callback : %d", ret);
139 return TTSD_ERROR_OPERATION_FAILED;
142 /* Get speech rate */
143 ret = vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, &g_speed);
146 * vconf key value scope
153 /* vconf key value is between 0 ~ 4 but tts speech rate value is between 1 ~ 5 */
155 SLOG(LOG_DEBUG, get_tag(), "[Config] Current speech rate : %d", g_speed);
157 /* register callback function */
158 vconf_notify_key_changed (VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, __sr_speech_rate_changed_cb, NULL);
163 int ttsd_config_finalize()
165 vconf_ignore_key_changed (VCONFKEY_SETAPPL_ACCESSIBILITY_SPEECH_RATE, __sr_speech_rate_changed_cb);
167 if (NULL != g_language) {
171 if (NULL != g_engine_id) {
178 int ttsd_config_update_language()
180 if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
184 ret = runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &value);
186 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Fail to get system language : %d", ret);
190 SLOG(LOG_ERROR, get_tag(), "[Config] Fail to get system language");
193 SLOG(LOG_DEBUG, get_tag(), "[Config] System language : %s", value);
195 if (0 != strcmp(value, g_language)) {
196 if (NULL != g_callback)
197 g_callback(TTS_CONFIG_TYPE_VOICE, value, g_vc_type);
208 int ttsd_config_get_default_engine(char** engine_id)
210 if (NULL == engine_id)
213 if (NULL != g_engine_id) {
214 *engine_id = strdup(g_engine_id);
216 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Current engine id is NULL");
222 int ttsd_config_set_default_engine(const char* engine_id)
224 /* Not available in screen mode */
228 int ttsd_config_get_default_voice(char** language, int* type)
230 if (NULL == language || NULL == type)
233 if (NULL != g_language) {
234 *language = strdup(g_language);
237 SLOG(LOG_ERROR, get_tag(), "[Config ERROR] Current language is NULL");
243 int ttsd_config_set_default_voice(const char* language, int type)
245 /* Not available in screen mode */
249 int ttsd_config_get_default_speed(int* speed)
259 int ttsd_config_set_default_speed(int speed)
261 /* Not available in screen mode */
265 int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text,
266 const char* func, int line, const char* message)
268 SLOG(LOG_ERROR, get_tag(), "=============== TTS ERROR LOG ====================");
270 SLOG(LOG_ERROR, get_tag(), "uid(%d) uttid(%d)", uid, uttid);
272 if (NULL != func) SLOG(LOG_ERROR, get_tag(), "Function(%s) Line(%d)", func, line);
273 if (NULL != message) SLOG(LOG_ERROR, get_tag(), "Message(%s)", message);
274 if (NULL != lang) SLOG(LOG_ERROR, get_tag(), "Lang(%s), type(%d)", lang, vctype);
275 if (NULL != text) SLOG(LOG_ERROR, get_tag(), "Text(%s)", text);
277 SLOG(LOG_ERROR, get_tag(), "==================================================");