2 * Copyright (c) 2011-2014 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_dbus.h"
17 #include "ttsd_dbus_server.h"
18 #include "ttsd_server.h"
20 extern int ttsd_data_get_pid(const int uid);
23 * Dbus Client-Daemon Server
25 int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg)
27 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS Hello");
30 reply = dbus_message_new_method_return(msg);
33 if (!dbus_connection_send(conn, reply, NULL)) {
34 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] Out Of Memory!");
37 dbus_connection_flush(conn);
38 dbus_message_unref(reply);
40 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] Fail to create reply message!!");
46 int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg)
49 dbus_error_init(&err);
54 dbus_message_get_args(msg, &err,
55 DBUS_TYPE_INT32, &pid,
56 DBUS_TYPE_INT32, &uid,
59 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS INITIALIZE");
61 if (dbus_error_is_set(&err)) {
62 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] tts initialize : get arguments error (%s)", err.message);
63 dbus_error_free(&err);
64 ret = TTSD_ERROR_OPERATION_FAILED;
67 SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts initialize : pid(%d), uid(%d)", pid , uid);
68 ret = ttsd_server_initialize(pid, uid);
72 reply = dbus_message_new_method_return(msg);
75 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
78 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts initialize : result(%d)", ret);
80 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts initialize : result(%d)", ret);
83 if (!dbus_connection_send(conn, reply, NULL)) {
84 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts initialize : Out Of Memory!");
87 dbus_connection_flush(conn);
88 dbus_message_unref(reply);
90 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts initialize : Fail to create reply message!!");
96 int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg)
99 dbus_error_init(&err);
104 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
106 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS FINALIZE");
108 if (dbus_error_is_set(&err)) {
109 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] tts finalize : get arguments error (%s)", err.message);
110 dbus_error_free(&err);
111 ret = TTSD_ERROR_OPERATION_FAILED;
113 SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts finalize : uid(%d)", uid);
114 ret = ttsd_server_finalize(uid);
118 reply = dbus_message_new_method_return(msg);
121 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
124 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts finalize : result(%d)", ret);
126 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts finalize : result(%d)", ret);
129 if (!dbus_connection_send(conn, reply, NULL)) {
130 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts finalize : Out Of Memory!");
133 dbus_connection_flush(conn);
134 dbus_message_unref(reply);
136 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts finalize : Fail to create reply message!!");
142 int ttsd_dbus_server_get_support_voices(DBusConnection* conn, DBusMessage* msg)
145 dbus_error_init(&err);
149 GList* voice_list = NULL;
151 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
153 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS GET VOICES");
155 if (dbus_error_is_set(&err)) {
156 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] tts get supported voices : get arguments error (%s)", err.message);
157 dbus_error_free(&err);
158 ret = TTSD_ERROR_OPERATION_FAILED;
160 SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] get supported voices : uid(%d)", uid);
161 ret = ttsd_server_get_support_voices(uid, &voice_list);
165 reply = dbus_message_new_method_return(msg);
168 DBusMessageIter args;
169 dbus_message_iter_init_append(reply, &args);
172 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret));
175 /* Append voice size */
176 int size = g_list_length(voice_list);
178 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
179 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts supported voices : Fail to append type");
180 ret = TTSD_ERROR_OPERATION_FAILED;
186 iter = g_list_first(voice_list);
188 while (NULL != iter) {
192 dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(voice->language));
193 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(voice->type));
195 if (NULL != voice->language)
196 g_free(voice->language);
201 voice_list = g_list_remove_link(voice_list, iter);
203 iter = g_list_first(voice_list);
206 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts supported voices : result(%d)", ret);
208 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts supported voices : result(%d)", ret);
211 if (!dbus_connection_send(conn, reply, NULL)) {
212 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] error : Out Of Memory!");
215 dbus_connection_flush(conn);
216 dbus_message_unref(reply);
218 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts supported voices : Fail to create reply message!!");
224 int ttsd_dbus_server_get_current_voice(DBusConnection* conn, DBusMessage* msg)
227 dbus_error_init(&err);
234 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
236 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS GET DEFAULT VOICE");
238 if (dbus_error_is_set(&err)) {
239 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] tts get default voice : Get arguments error (%s)", err.message);
240 dbus_error_free(&err);
241 ret = TTSD_ERROR_OPERATION_FAILED;
243 SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts get default voice : uid(%d)", uid);
244 ret = ttsd_server_get_current_voice(uid, &lang, &voice_type);
248 reply = dbus_message_new_method_return(msg);
252 /* Append result and voice */
253 dbus_message_append_args(reply,
254 DBUS_TYPE_INT32, &ret,
255 DBUS_TYPE_STRING, &lang,
256 DBUS_TYPE_INT32, &voice_type,
258 SECURE_SLOG(LOG_DEBUG, get_tag(), "[OUT] tts default voice : lang(%s), vctype(%d)", lang, voice_type);
260 dbus_message_append_args(reply,
261 DBUS_TYPE_INT32, &ret,
263 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts default voice : result(%d)", ret);
266 if (!dbus_connection_send(conn, reply, NULL)) {
267 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts default voice : Out Of Memory!");
270 dbus_connection_flush(conn);
271 dbus_message_unref(reply);
273 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts default voice : Fail to create reply message!!");
276 if (NULL != lang) free(lang);
280 int ttsd_dbus_server_add_text(DBusConnection* conn, DBusMessage* msg)
283 dbus_error_init(&err);
285 int uid, voicetype, speed, uttid;
289 dbus_message_get_args(msg, &err,
290 DBUS_TYPE_INT32, &uid,
291 DBUS_TYPE_STRING, &text,
292 DBUS_TYPE_STRING, &lang,
293 DBUS_TYPE_INT32, &voicetype,
294 DBUS_TYPE_INT32, &speed,
295 DBUS_TYPE_INT32, &uttid,
298 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS ADD TEXT");
300 if (dbus_error_is_set(&err)) {
301 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] tts add text : Get arguments error (%s)", err.message);
302 dbus_error_free(&err);
303 ret = TTSD_ERROR_OPERATION_FAILED;
306 SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), uttid(%d)",
307 uid, text, lang, voicetype, speed, uttid);
308 ret = ttsd_server_add_queue(uid, text, lang, voicetype, speed, uttid);
312 reply = dbus_message_new_method_return(msg);
315 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
318 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts add text : result(%d)", ret);
320 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts add text : result(%d)", ret);
323 if (!dbus_connection_send(conn, reply, NULL)) {
324 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts add text : Out Of Memory!");
327 dbus_connection_flush(conn);
328 dbus_message_unref(reply);
330 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts add text : Fail to create reply message!!");
333 SLOG(LOG_DEBUG, get_tag(), "<<<<<");
334 SLOG(LOG_DEBUG, get_tag(), " ");
339 int ttsd_dbus_server_play(DBusConnection* conn, DBusMessage* msg)
342 dbus_error_init(&err);
347 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
349 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS PLAY");
351 if (dbus_error_is_set(&err)) {
352 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] tts play : Get arguments error (%s)", err.message);
353 dbus_error_free(&err);
354 ret = TTSD_ERROR_OPERATION_FAILED;
356 SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts play : uid(%d)", uid);
357 ret = ttsd_server_play(uid);
361 reply = dbus_message_new_method_return(msg);
364 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
367 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts play : result(%d)", ret);
369 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts play : result(%d)", ret);
372 if (!dbus_connection_send(conn, reply, NULL)) {
373 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts play : Out Of Memory!");
376 dbus_connection_flush(conn);
377 dbus_message_unref(reply);
379 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts play : Fail to create reply message!!");
382 SLOG(LOG_DEBUG, get_tag(), "<<<<<");
383 SLOG(LOG_DEBUG, get_tag(), " ");
388 int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg)
391 dbus_error_init(&err);
395 dbus_message_get_args(msg, &err,
396 DBUS_TYPE_INT32, &uid,
399 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS STOP");
401 if (dbus_error_is_set(&err)) {
402 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] tts stop : Get arguments error (%s)", err.message);
403 dbus_error_free(&err);
404 ret = TTSD_ERROR_OPERATION_FAILED;
406 SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts stop : uid(%d)", uid);
407 ret = ttsd_server_stop(uid);
411 reply = dbus_message_new_method_return(msg);
414 dbus_message_append_args(reply,
415 DBUS_TYPE_INT32, &ret,
419 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts stop : result(%d)", ret);
421 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts stop : result(%d)", ret);
424 if (!dbus_connection_send(conn, reply, NULL)) {
425 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts stop : Out Of Memory!");
428 dbus_connection_flush(conn);
429 dbus_message_unref(reply);
431 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts stop : Fail to create reply message!!");
434 SLOG(LOG_DEBUG, get_tag(), "<<<<<");
435 SLOG(LOG_DEBUG, get_tag(), " ");
440 int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg)
443 dbus_error_init(&err);
448 dbus_message_get_args(msg, &err,
449 DBUS_TYPE_INT32, &uid,
452 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS PAUSE");
454 if (dbus_error_is_set(&err)) {
455 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] tts pause : Get arguments error (%s)", err.message);
456 dbus_error_free(&err);
457 ret = TTSD_ERROR_OPERATION_FAILED;
459 SECURE_SLOG(LOG_DEBUG, get_tag(), "[IN] tts pause : uid(%d)", uid);
460 ret = ttsd_server_pause(uid, &uttid);
464 reply = dbus_message_new_method_return(msg);
467 dbus_message_append_args(reply,
468 DBUS_TYPE_INT32, &ret,
472 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts pause : result(%d)", ret);
474 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts pause : result(%d)", ret);
477 if (!dbus_connection_send(conn, reply, NULL)) {
478 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts pause : Out Of Memory!");
481 dbus_connection_flush(conn);
482 dbus_message_unref(reply);
484 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts pause : Fail to create reply message!!");
487 SLOG(LOG_DEBUG, get_tag(), "<<<<<");
488 SLOG(LOG_DEBUG, get_tag(), " ");
493 int ttsd_dbus_server_set_private_data(DBusConnection* conn, DBusMessage* msg)
496 dbus_error_init(&err);
502 dbus_message_get_args(msg, &err,
503 DBUS_TYPE_INT32, &uid,
504 DBUS_TYPE_STRING, &key,
505 DBUS_TYPE_STRING, &data,
508 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS set private data");
510 if (dbus_error_is_set(&err)) {
511 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] Fail to get arguments (%s)", err.message);
512 dbus_error_free(&err);
513 ret = TTSD_ERROR_OPERATION_FAILED;
515 SLOG(LOG_DEBUG, get_tag(), "[IN] tts set private data(%d)", uid);
516 ret = ttsd_server_set_private_data(uid, key, data);
520 reply = dbus_message_new_method_return(msg);
523 dbus_message_append_args(reply,
524 DBUS_TYPE_INT32, &ret,
528 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts set private data : (%d)", ret);
530 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts set private data : (%d)", ret);
533 if (!dbus_connection_send(conn, reply, NULL)) {
534 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] Fail to send reply");
537 dbus_connection_flush(conn);
538 dbus_message_unref(reply);
540 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] Fail to create reply message");
543 SLOG(LOG_DEBUG, get_tag(), "<<<<<");
544 SLOG(LOG_DEBUG, get_tag(), "");
549 int ttsd_dbus_server_get_private_data(DBusConnection* conn, DBusMessage* msg)
552 dbus_error_init(&err);
558 dbus_message_get_args(msg, &err,
559 DBUS_TYPE_INT32, &uid,
560 DBUS_TYPE_STRING, &key,
563 SLOG(LOG_DEBUG, get_tag(), ">>>>> TTS get private data");
565 if (dbus_error_is_set(&err)) {
566 SLOG(LOG_ERROR, get_tag(), "[IN ERROR] Fail to get arguments (%s)", err.message);
567 dbus_error_free(&err);
568 ret = TTSD_ERROR_OPERATION_FAILED;
570 SLOG(LOG_DEBUG, get_tag(), "[IN] tts get private data(%d)", uid);
571 ret = ttsd_server_get_private_data(uid, key, &data);
575 reply = dbus_message_new_method_return(msg);
578 dbus_message_append_args(reply,
579 DBUS_TYPE_INT32, &ret,
583 SLOG(LOG_DEBUG, get_tag(), "[OUT] tts get private data : (%d)", ret);
585 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] tts get private data : (%d)", ret);
588 if (!dbus_connection_send(conn, reply, NULL)) {
589 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] Fail to send reply");
592 dbus_connection_flush(conn);
593 dbus_message_unref(reply);
595 SLOG(LOG_ERROR, get_tag(), "[OUT ERROR] Fail to create reply message");
598 SLOG(LOG_DEBUG, get_tag(), "<<<<<");
599 SLOG(LOG_DEBUG, get_tag(), "");