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 #include "ttsd_main.h"
16 #include "ttsd_server.h"
17 #include "ttsd_dbus.h"
22 #include <bundle_internal.h>
26 #include <app_manager.h>
30 static bool g_is_terminated = false;
37 static bool __is_default_engine()
40 engine = vconf_get_str(VCONFKEY_TTS_ENGINE_DEFAULT);
42 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get sting for vc engine");
46 char appid[1024] = {'\0', };
47 if (0 != aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1)) {
48 SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get callee appid by pid");
51 SLOG(LOG_DEBUG, tts_tag(), "[Server] TTS Default Engine(%s), appId(%s)", engine, appid);
52 if (0 == strncmp(engine, appid, strlen(engine))) {
60 static void __engine_changed_cb(keynode_t* key, void* data)
62 SLOG(LOG_INFO, tts_tag(), "[INFO] TTS engine vconfkey is changed");
64 /* If a new TTS engine is different from the current engine, call ttse_terminate() */
65 if (FALSE == __is_default_engine()) {
66 SLOG(LOG_WARN, tts_tag(), "[WARNING] TTS engine is changed. Please call ttse_terminate()");
68 ecore_main_loop_quit();
70 SLOG(LOG_INFO, tts_tag(), "[INFO] A new TTS engine is same as the current engine.");
76 static bool __is_test_app()
79 int ret = app_manager_get_app_id(getpid(), &appid);
80 if (APP_MANAGER_ERROR_NONE != ret || NULL == appid) {
83 SLOG(LOG_INFO, tts_tag(), "[INFO] app id (%s)", appid);
85 bool is_test_app = false;
86 if (0 == strncmp(appid, "org.tizen.tts-native-itc", 32) || 0 == strncmp(appid, "org.tizen.tts-native-utc", 32)) {
87 SLOG(LOG_INFO, tts_tag(), "[INFO] Test mode is on");
95 int ttse_main(int argc, char** argv, ttse_request_callback_s *callback)
97 g_is_terminated = false;
100 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to initialize Ecore");
101 return TTSE_ERROR_OPERATION_FAILED;
104 int ret = ttsd_initialize(callback);
106 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to initialize");
111 if (TRUE == __is_default_engine()) {
112 if (0 != ttsd_ipc_open_connection()) {
113 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open ipc connection");
115 return TTSE_ERROR_OPERATION_FAILED;
119 /* If a new TTS engine is different from the current engine, call ttse_terminate() */
120 if (FALSE == __is_default_engine() && !__is_test_app()) {
121 SLOG(LOG_WARN, tts_tag(), "[WARNING] Before beginning main loop of TTS engine, default TTS engine is changed. Please call ttse_terminate()");
123 return TTSE_ERROR_OPERATION_FAILED;
126 /* Register vconfkey callback to detect engine change */
127 vconf_notify_key_changed(TTS_ENGINE_DB_DEFAULT, __engine_changed_cb, NULL);
129 SLOG(LOG_DEBUG, tts_tag(), "@@@");
131 return TTSE_ERROR_NONE;
134 int ttse_terminate(void)
136 if (true == g_is_terminated) {
137 SLOG(LOG_INFO, tts_tag(), "[INFO] ttse_terminate() is already invoked.");
138 return TTSE_ERROR_NONE;
141 int ret = ttsd_terminate();
142 if (TTSD_ERROR_NONE != ret) {
143 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to ttsd_terminate(). ret(%d)", ret);
144 return TTSE_ERROR_OPERATION_FAILED;
147 /* Unregister vconfkey callback */
148 vconf_ignore_key_changed(TTS_ENGINE_DB_DEFAULT, __engine_changed_cb);
150 g_is_terminated = true;
151 return TTSE_ERROR_NONE;
154 int ttse_get_speed_range(int* min, int* normal, int* max)
156 if (NULL == min || NULL == normal || NULL == max) {
157 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
158 return TTSE_ERROR_INVALID_PARAMETER;
161 *min = TTS_SPEED_MIN;
162 *normal = TTS_SPEED_NORMAL;
163 *max = TTS_SPEED_MAX;
168 int ttse_get_pitch_range(int* min, int* normal, int* max)
170 if (NULL == min || NULL == normal || NULL == max) {
171 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
172 return TTSE_ERROR_INVALID_PARAMETER;
175 *min = TTS_PITCH_MIN;
176 *normal = TTS_PITCH_NORMAL;
177 *max = TTS_PITCH_MAX;
182 int ttse_send_result(ttse_result_event_e event, const void* data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void* user_data)
187 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
190 ret = ttsd_send_result(event, data, data_size, audio_type, rate, user_data);
193 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to send result");
199 int ttse_send_error(ttse_error_e error, const char* msg)
203 ret = ttsd_send_error(error, msg);
206 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to send error");
212 int ttse_set_private_data_set_cb(ttse_private_data_set_cb callback_func)
214 if (NULL == callback_func) {
215 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter");
216 return TTSE_ERROR_INVALID_PARAMETER;
219 int ret = ttsd_set_private_data_set_cb(callback_func);
222 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set private data set cb");
228 int ttse_set_private_data_requested_cb(ttse_private_data_requested_cb callback_func)
230 if (NULL == callback_func) {
231 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter");
232 return TTSE_ERROR_INVALID_PARAMETER;
235 int ret = ttsd_set_private_data_requested_cb(callback_func);
238 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set private data requested cb");
244 int ttse_get_activated_mode(int* activated_mode)
246 if (NULL == activated_mode) {
247 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter");
248 return TTSE_ERROR_INVALID_PARAMETER;
251 if (g_is_terminated) {
252 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Service engine is terminated.");
253 return TTSE_ERROR_INVALID_STATE;
256 int ret = ttsd_get_activated_mode(activated_mode);
257 if (TTSD_ERROR_NONE != ret) {
258 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get activated mode. ret(%d/%s)", ret, get_error_message(ret));
264 int ttse_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback)
266 if (NULL == callback) {
267 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter");
268 return TTSE_ERROR_INVALID_PARAMETER;
271 if (g_is_terminated) {
272 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Service engine is terminated.");
273 return TTSE_ERROR_INVALID_STATE;
276 int ret = ttsd_set_activated_mode_changed_cb(callback);
277 if (TTSD_ERROR_NONE != ret) {
278 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set activated mode changed cb. ret(%d/%s)", ret, get_error_message(ret));