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"
18 #include "ttsd_network.h"
21 #include <bundle_internal.h>
27 #define CLIENT_CLEAN_UP_TIME 500
29 static Ecore_Timer* g_check_client_timer = NULL;
31 static ttsd_mode_e g_tts_mode = TTSD_MODE_DEFAULT;
35 if (TTSD_MODE_NOTIFICATION == g_tts_mode) {
37 } else if (TTSD_MODE_SCREEN_READER == g_tts_mode) {
44 ttsd_mode_e ttsd_get_mode()
49 void ttsd_set_mode(ttsd_mode_e mode)
55 int ttse_main(int argc, char** argv, ttse_request_callback_s *callback)
58 ttsd_mode_e mode = TTSD_MODE_DEFAULT;
59 int ret = TTSE_ERROR_NONE;
61 b = bundle_import_from_argv(argc, argv);
64 if (0 == bundle_get_str(b, "mode", &val)) {
66 if (!strcmp("noti", val)) {
67 mode = TTSD_MODE_NOTIFICATION;
68 } else if (!strcmp("sr", val)) {
69 mode = TTSD_MODE_SCREEN_READER;
71 SLOG(LOG_WARN, tts_tag(), "[WARNING] mode (%s)", val);
74 SLOG(LOG_ERROR, tts_tag(), "[ERROR] NULL data");
77 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get data from bundle");
82 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get bundle");
87 SLOG(LOG_DEBUG, tts_tag(), "Start engine as [%d] mode", mode);
90 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to initialize Ecore");
91 return TTSE_ERROR_OPERATION_FAILED;
94 if (0 != ttsd_dbus_open_connection()) {
95 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open dbus connection");
97 return TTSE_ERROR_OPERATION_FAILED;
100 ret = ttsd_initialize(callback);
102 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to initialize");
103 ttsd_dbus_close_connection();
108 if (0 != ttsd_network_initialize()) {
109 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to initialize network");
112 g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
113 if (NULL == g_check_client_timer) {
114 SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
117 SLOG(LOG_DEBUG, tts_tag(), "====");
118 SLOG(LOG_DEBUG, tts_tag(), "");
120 return TTSE_ERROR_NONE;
123 int ttse_get_speed_range(int* min, int* normal, int* max)
125 if (NULL == min || NULL == normal || NULL == max) {
126 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
127 return TTSE_ERROR_INVALID_PARAMETER;
130 *min = TTS_SPEED_MIN;
131 *normal = TTS_SPEED_NORMAL;
132 *max = TTS_SPEED_MAX;
137 int ttse_get_pitch_range(int* min, int* normal, int* max)
139 if (NULL == min || NULL == normal || NULL == max) {
140 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
141 return TTSE_ERROR_INVALID_PARAMETER;
144 *min = TTS_PITCH_MIN;
145 *normal = TTS_PITCH_NORMAL;
146 *max = TTS_PITCH_MAX;
151 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)
156 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
159 ret = ttsd_send_result(event, data, data_size, audio_type, rate, user_data);
162 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to send result");
168 int ttse_send_error(ttse_error_e error, const char* msg)
173 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Input parameter is null");
174 return TTSE_ERROR_INVALID_PARAMETER;
177 ret = ttsd_send_error(error, msg);
180 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to send error");
186 int ttse_set_private_data_set_cb(ttse_private_data_set_cb callback_func)
188 if (NULL == callback_func) {
189 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter");
190 return TTSE_ERROR_INVALID_PARAMETER;
193 int ret = ttsd_set_private_data_set_cb(callback_func);
196 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set private data set cb");
202 int ttse_set_private_data_requested_cb(ttse_private_data_requested_cb callback_func)
204 if (NULL == callback_func) {
205 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid parameter");
206 return TTSE_ERROR_INVALID_PARAMETER;
209 int ret = ttsd_set_private_data_requested_cb(callback_func);
212 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set private data requested cb");