2 * Copyright (c) 2011-2016 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.
15 /* For multi-user support */
16 #include <tzplatform_config.h>
18 #include "tts_config_mgr.h"
19 #include "ttsd_config.h"
20 #include "ttsd_main.h"
23 static ttsd_config_changed_cb g_callback;
25 static ttsd_config_screen_reader_changed_cb g_sr_callback;
27 void __ttsd_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
29 /* Need to check engine is valid */
30 if (false == tts_config_check_default_engine_is_valid(engine_id)) {
31 SLOG(LOG_ERROR, tts_tag(), "Engine id is NOT valid : %s", engine_id);
35 if (NULL != g_callback) {
36 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Call the engine reload callback : engine id(%s)", engine_id);
37 g_callback(TTS_CONFIG_TYPE_ENGINE, engine_id, 0);
38 SECURE_SLOG(LOG_DEBUG, tts_tag(), "Call the voice changed callback : lang(%s), type(%d)", language, voice_type);
39 g_callback(TTS_CONFIG_TYPE_VOICE, language, voice_type);
41 SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
45 void __ttsd_config_voice_changed_cb(const char* before_language, int before_type, const char* language, int type, bool auto_voice, void* user_data)
47 /* Need to check voice is valid */
48 if (false == tts_config_check_default_voice_is_valid(language, type)) {
49 SLOG(LOG_ERROR, tts_tag(), "Lang(%s) type(%d) is NOT valid", language, type);
53 if (NULL != g_callback) {
54 g_callback(TTS_CONFIG_TYPE_VOICE, language, type);
56 SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
60 void __ttsd_config_speech_rate_changed_cb(int value, void* user_data)
62 if (NULL != g_callback) {
63 g_callback(TTS_CONFIG_TYPE_SPEED, NULL, value);
65 SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
69 void __ttsd_config_pitch_changed_cb(int value, void* user_data)
71 if (NULL != g_callback) {
72 g_callback(TTS_CONFIG_TYPE_PITCH, NULL, value);
74 SLOG(LOG_ERROR, tts_tag(), "Config changed callback is NULL");
78 void __ttsd_config_screen_reader_changed_cb(bool value)
80 if (NULL != g_sr_callback) {
85 int ttsd_config_initialize(ttsd_config_changed_cb config_cb)
87 if (NULL == config_cb) {
88 SLOG(LOG_ERROR, tts_tag(), "[Config] Invalid parameter");
92 g_callback = config_cb;
96 ret = tts_config_mgr_initialize(getpid());
98 SLOG(LOG_ERROR, tts_tag(), "[Config] Fail to initialize config manager");
102 ret = tts_config_mgr_set_callback(getpid(), __ttsd_config_engine_changed_cb, __ttsd_config_voice_changed_cb,
103 __ttsd_config_speech_rate_changed_cb, __ttsd_config_pitch_changed_cb, NULL);
105 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set config changed : %d", ret);
112 int ttsd_config_finalize()
114 tts_config_unset_screen_reader_callback(getpid());
116 tts_config_mgr_finalize(getpid());
121 int ttsd_config_set_screen_reader_callback(ttsd_config_screen_reader_changed_cb sr_cb)
124 SLOG(LOG_ERROR, tts_tag(), "[Config] Invalid parameter");
128 g_sr_callback = sr_cb;
130 int ret = tts_config_set_screen_reader_callback(getpid(), __ttsd_config_screen_reader_changed_cb) ;
132 SLOG(LOG_ERROR, tts_tag(), "[Config] Fail to set screen reader callback");
138 int ttsd_config_get_default_engine(char** engine_id)
140 if (NULL == engine_id)
143 if (0 != tts_config_mgr_get_engine(engine_id)) {
144 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get engine id");
145 return TTSD_ERROR_OPERATION_FAILED;
151 int ttsd_config_set_default_engine(const char* engine_id)
153 if (NULL == engine_id)
156 if (true == tts_config_check_default_engine_is_valid(engine_id)) {
157 if (0 != tts_config_mgr_set_engine(engine_id)) {
158 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to set engine id");
165 int ttsd_config_get_default_voice(char** language, int* type)
167 if (NULL == language || NULL == type)
170 if (0 != tts_config_mgr_get_voice(language, type)) {
171 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default voice");
172 return TTSD_ERROR_OPERATION_FAILED;
178 int ttsd_config_get_default_speed(int* speed)
183 if (0 != tts_config_mgr_get_speech_rate(speed)) {
184 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default speech rate");
185 return TTSD_ERROR_OPERATION_FAILED;
191 int ttsd_config_get_default_pitch(int* pitch)
196 if (0 != tts_config_mgr_get_pitch(pitch)) {
197 SLOG(LOG_ERROR, tts_tag(), "[Config ERROR] Fail to get default pitch");
198 return TTSD_ERROR_OPERATION_FAILED;
204 int ttsd_config_save_error(int uid, int uttid, const char* lang, int vctype, const char* text,
205 const char* func, int line, const char* message)
207 SLOG(LOG_DEBUG, tts_tag(), "@@@@@ TTS ERROR LOG @@@@@");
209 SLOG(LOG_DEBUG, tts_tag(), "uid(%d) uttid(%d)", uid, uttid);
212 SLOG(LOG_DEBUG, tts_tag(), "Function(%s) Line(%d)", (NULL == func) ? "NULL" : func, line);
213 SLOG(LOG_DEBUG, tts_tag(), "Message(%s)", (NULL == message) ? "NULL" : message);
214 SLOG(LOG_DEBUG, tts_tag(), "Lang(%s), type(%d)", (NULL == lang) ? "NULL" : lang, vctype);
215 SLOG(LOG_DEBUG, tts_tag(), "Text(%s)", (NULL == text) ? "NULL" : text);
217 SLOG(LOG_DEBUG, tts_tag(), "@@@@@");