Add to set playing mode to decide where the synthesized pcm data will be played
[platform/core/uifw/tts.git] / server / ttsd_dbus_server.c
1 /*
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.
12 */
13
14
15 #include "ttsd_main.h"
16 #include "ttsd_dbus.h"
17 #include "ttsd_dbus_server.h"
18 #include "ttsd_server.h"
19
20 extern int ttsd_data_get_pid(const unsigned int uid);
21
22 /*
23 * Dbus Client-Daemon Server
24 */
25 int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg)
26 {
27         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS Hello");
28
29         DBusError err;
30         dbus_error_init(&err);
31
32         int pid;
33         unsigned int uid;
34         int mode = 0;
35         int playing_mode = 0;
36         int registered_event_mask = 0;
37         dbus_message_get_args(msg, &err,
38                 DBUS_TYPE_INT32, &pid,
39                 DBUS_TYPE_UINT32, &uid,
40                 DBUS_TYPE_INT32, &mode,
41                 DBUS_TYPE_INT32, &playing_mode,
42                 DBUS_TYPE_INT32, &registered_event_mask,
43                 DBUS_TYPE_INVALID);
44
45         if (dbus_error_is_set(&err)) {
46                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : get arguments error (%s)", err.message);
47                 dbus_error_free(&err);
48         } else {
49                 SLOG(LOG_INFO, tts_tag(), "[IN] ttsd hello : pid(%d), uid(%u), mode(%d), playing_mode(%d)", pid, uid, mode, playing_mode);
50                 bool is_initialized = false;
51                 bool is_credential_needed = false;
52                 ttsd_state_e service_state = TTSD_STATE_INVALID;
53                 int credential_needed = 0;
54                 int ret = -1;
55
56                 ttsd_server_is_already_initialized(pid, uid, &is_initialized);
57                 if (false == is_initialized) {
58                         ret = ttsd_server_initialize(pid, uid, (ttsd_mode_e)mode, (ttsd_playing_mode_e)playing_mode, registered_event_mask, TTS_IPC_METHOD_DBUS, &service_state, &is_credential_needed);
59                         if (0 != ret) {
60                                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize, ret(%d)", ret);
61                         }
62                         ttsd_server_update_instant_reprepare_client();
63
64                         credential_needed = is_credential_needed ? 1 : 0;
65                 } else {
66                         SLOG(LOG_INFO, tts_tag(), "[IN] ttsd hello : already initialized. pid(%d), uid(%u)", pid, uid);
67                         ret = TTS_ERROR_ALREADY_INITIALIZED;
68                         credential_needed = TTS_CREDENTIAL_NEEDED_ALREADY_INITIALIZED;
69                 }
70
71                 SLOG(LOG_INFO, tts_tag(), "[INFO] send_hello. pid(%d), uid(%u), ret(%d), service_state(%d), credential_needed(%d)",
72                                 pid, uid, ret, (int)service_state, credential_needed);
73
74                 ttsdc_dbus_send_hello(pid, uid, ret, (int)service_state, credential_needed);
75         }
76
77         return 0;
78 }
79
80 int ttsd_dbus_server_hello_sync(DBusConnection* conn, DBusMessage* msg)
81 {
82         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS Hello");
83
84         DBusMessage* reply;
85         reply = dbus_message_new_method_return(msg);
86
87         if (NULL != reply) {
88                 if (!dbus_connection_send(conn, reply, NULL)) {
89                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Out Of Memory!");
90                 }
91
92                 dbus_connection_flush(conn);
93                 dbus_message_unref(reply);
94         } else {
95                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to create reply message!!");
96         }
97
98         return 0;
99 }
100
101 int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg)
102 {
103         DBusError err;
104         dbus_error_init(&err);
105
106         int pid;
107         unsigned int uid;
108         bool credential_needed = 0;
109         ttsd_state_e service_state = TTSD_STATE_INVALID;
110         int mode = 0;
111         int playing_mode = 0;
112         int registered_event_mask = 0;
113         int ret = 0;
114
115         dbus_message_get_args(msg, &err,
116                 DBUS_TYPE_INT32, &pid,
117                 DBUS_TYPE_UINT32, &uid,
118                 DBUS_TYPE_INT32, &mode,
119                 DBUS_TYPE_INT32, &playing_mode,
120                 DBUS_TYPE_INT32, &registered_event_mask,
121                 DBUS_TYPE_INVALID);
122
123         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS INITIALIZE");
124
125         if (dbus_error_is_set(&err)) {
126                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts initialize : get arguments error (%s)", err.message);
127                 dbus_error_free(&err);
128                 ret = TTSD_ERROR_OPERATION_FAILED;
129         } else {
130                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts initialize : pid(%d), uid(%u), mode(%d), playing_mode(%d)", pid, uid, mode, playing_mode);
131                 ret = ttsd_server_initialize(pid, uid, (ttsd_mode_e)mode, (ttsd_playing_mode_e)playing_mode, registered_event_mask, TTS_IPC_METHOD_DBUS, &service_state, &credential_needed);
132                 ttsd_server_update_instant_reprepare_client();
133         }
134
135         DBusMessage* reply;
136         reply = dbus_message_new_method_return(msg);
137
138         int tmp_credential_needed = (int)credential_needed;
139         int tmp_service_state = (int)service_state;
140         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts initialize : result(%d), service_state(%d), credential_needed(%d)", ret, tmp_service_state, tmp_credential_needed);
141         if (NULL != reply) {
142                 dbus_message_append_args(reply,
143                         DBUS_TYPE_INT32, &ret,
144                         DBUS_TYPE_INT32, &tmp_service_state,
145                         DBUS_TYPE_INT32, &tmp_credential_needed,
146                         DBUS_TYPE_INVALID);
147
148                 if (0 == ret) {
149                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts initialize : result(%d), service_state(%d), credential_needed(%d)", ret, tmp_service_state, tmp_credential_needed);
150                 } else {
151                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts initialize : result(%d)", ret);
152                 }
153
154                 if (!dbus_connection_send(conn, reply, NULL)) {
155                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts initialize : Out Of Memory!");
156                 }
157
158                 dbus_connection_flush(conn);
159                 dbus_message_unref(reply);
160         } else {
161                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts initialize : Fail to create reply message!!");
162         }
163
164         return 0;
165 }
166
167 int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg)
168 {
169         DBusError err;
170         dbus_error_init(&err);
171
172         unsigned int uid;
173         int ret = 0;
174
175         dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &uid, DBUS_TYPE_INVALID);
176
177         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS FINALIZE");
178
179         if (dbus_error_is_set(&err)) {
180                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts finalize : get arguments error (%s)", err.message);
181                 dbus_error_free(&err);
182                 ret = TTSD_ERROR_OPERATION_FAILED;
183         } else {
184                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts finalize : uid(%u)", uid);
185                 ret = ttsd_server_finalize(uid);
186                 ttsd_server_update_instant_reprepare_client();
187         }
188
189         DBusMessage* reply;
190         reply = dbus_message_new_method_return(msg);
191
192         if (NULL != reply) {
193                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
194
195                 if (0 == ret) {
196                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts finalize : result(%d)", ret);
197                 } else {
198                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts finalize : result(%d)", ret);
199                 }
200
201                 if (!dbus_connection_send(conn, reply, NULL)) {
202                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts finalize : Out Of Memory!");
203                 }
204
205                 dbus_connection_flush(conn);
206                 dbus_message_unref(reply);
207         } else {
208                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts finalize : Fail to create reply message!!");
209         }
210
211         return 0;
212 }
213
214 int ttsd_dbus_server_get_support_voices(DBusConnection* conn, DBusMessage* msg)
215 {
216         DBusError err;
217         dbus_error_init(&err);
218
219         unsigned int uid;
220         int ret = 0;
221         GList* voice_list = NULL;
222
223         dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &uid, DBUS_TYPE_INVALID);
224
225         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS GET VOICES");
226
227         if (dbus_error_is_set(&err)) {
228                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts get supported voices : get arguments error (%s)", err.message);
229                 dbus_error_free(&err);
230                 ret = TTSD_ERROR_OPERATION_FAILED;
231         } else {
232                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] get supported voices : uid(%u)", uid);
233                 ret = ttsd_server_get_support_voices(uid, &voice_list);
234         }
235
236         DBusMessage* reply;
237         reply = dbus_message_new_method_return(msg);
238
239         if (NULL != reply) {
240                 DBusMessageIter args;
241                 dbus_message_iter_init_append(reply, &args);
242
243                 /* Append result*/
244                 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret));
245
246                 if (0 == ret) {
247                         /* Append voice size */
248                         unsigned int size = g_list_length(voice_list);
249
250                         if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
251                                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts supported voices : Fail to append type");
252                                 ret = TTSD_ERROR_OPERATION_FAILED;
253                         } else {
254
255                                 GList *iter = NULL;
256                                 voice_s* voice;
257
258                                 iter = g_list_first(voice_list);
259
260                                 while (NULL != iter) {
261                                         voice = iter->data;
262
263                                         if (NULL != voice) {
264                                                 dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(voice->language));
265                                                 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(voice->type));
266
267                                                 if (NULL != voice->language)
268                                                         g_free(voice->language);
269
270                                                 g_free(voice);
271                                         }
272
273                                         voice_list = g_list_remove_link(voice_list, iter);
274                                         g_list_free(iter);
275                                         iter = g_list_first(voice_list);
276                                 }
277                         }
278                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts supported voices : result(%d)", ret);
279                 } else {
280                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts supported voices : result(%d)", ret);
281                 }
282
283                 if (!dbus_connection_send(conn, reply, NULL)) {
284                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] error : Out Of Memory!");
285                 }
286
287                 dbus_connection_flush(conn);
288                 dbus_message_unref(reply);
289         } else {
290                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts supported voices : Fail to create reply message!!");
291         }
292
293         return 0;
294 }
295
296 int ttsd_dbus_server_get_current_voice(DBusConnection* conn, DBusMessage* msg)
297 {
298         DBusError err;
299         dbus_error_init(&err);
300
301         unsigned int uid;
302         char* lang = NULL;
303         int voice_type;
304         int ret;
305
306         dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &uid, DBUS_TYPE_INVALID);
307
308         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS GET DEFAULT VOICE");
309
310         if (dbus_error_is_set(&err)) {
311                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts get default voice : Get arguments error (%s)", err.message);
312                 dbus_error_free(&err);
313                 ret = TTSD_ERROR_OPERATION_FAILED;
314         } else {
315                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts get default voice : uid(%u)", uid);
316                 ret = ttsd_server_get_current_voice(uid, &lang, &voice_type);
317         }
318
319         DBusMessage* reply;
320         reply = dbus_message_new_method_return(msg);
321
322         if (NULL != reply) {
323                 if (0 == ret) {
324                         /* Append result and voice */
325                         dbus_message_append_args(reply,
326                                 DBUS_TYPE_INT32, &ret,
327                                 DBUS_TYPE_STRING, &lang,
328                                 DBUS_TYPE_INT32, &voice_type,
329                                 DBUS_TYPE_INVALID);
330                         SECURE_SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts default voice : lang(%s), vctype(%d)", lang, voice_type);
331                 } else {
332                         dbus_message_append_args(reply,
333                                 DBUS_TYPE_INT32, &ret,
334                                 DBUS_TYPE_INVALID);
335                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts default voice : result(%d)", ret);
336                 }
337
338                 if (!dbus_connection_send(conn, reply, NULL)) {
339                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts default voice : Out Of Memory!");
340                 }
341
342                 dbus_connection_flush(conn);
343                 dbus_message_unref(reply);
344         } else {
345                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts default voice : Fail to create reply message!!");
346         }
347
348         if (NULL != lang)       free(lang);
349         return 0;
350 }
351
352 int ttsd_dbus_server_add_text(DBusConnection* conn, DBusMessage* msg)
353 {
354         DBusError err;
355         dbus_error_init(&err);
356
357         unsigned int uid, voicetype, speed, uttid;
358         char *text, *lang, *credential;
359         int ret = 0;
360
361         dbus_message_get_args(msg, &err,
362                 DBUS_TYPE_UINT32, &uid,
363                 DBUS_TYPE_STRING, &text,
364                 DBUS_TYPE_STRING, &lang,
365                 DBUS_TYPE_INT32, &voicetype,
366                 DBUS_TYPE_INT32, &speed,
367                 DBUS_TYPE_INT32, &uttid,
368                 DBUS_TYPE_STRING, &credential,
369                 DBUS_TYPE_INVALID);
370
371         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS ADD TEXT");
372
373         if (dbus_error_is_set(&err)) {
374                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts add text : Get arguments error (%s)", err.message);
375                 dbus_error_free(&err);
376                 ret = TTSD_ERROR_OPERATION_FAILED;
377         } else {
378                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts add text : uid(%u), text(%s), lang(%s), type(%d), speed(%d), uttid(%d), credential(%s)",
379                         uid, (NULL == text) ? "NULL" : text, (NULL == lang) ? "NULL" : lang, voicetype, speed, uttid, (NULL == credential) ? "NULL" : credential);
380                 ret = ttsd_server_add_text(uid, text, lang, voicetype, speed, uttid, credential);
381         }
382
383         DBusMessage* reply;
384         reply = dbus_message_new_method_return(msg);
385
386         if (NULL != reply) {
387                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
388
389                 if (0 == ret) {
390                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts add text : result(%d)", ret);
391                 } else {
392                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add text : result(%d)", ret);
393                 }
394
395                 if (!dbus_connection_send(conn, reply, NULL)) {
396                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add text : Out Of Memory!");
397                 }
398
399                 dbus_connection_flush(conn);
400                 dbus_message_unref(reply);
401         } else {
402                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add text : Fail to create reply message!!");
403         }
404
405         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
406         SLOG(LOG_DEBUG, tts_tag(), "  ");
407
408         return 0;
409 }
410
411 int ttsd_dbus_server_play(DBusConnection* conn, DBusMessage* msg)
412 {
413         DBusError err;
414         dbus_error_init(&err);
415
416         unsigned int uid;
417         char* credential;
418         int ret = 0;
419
420         dbus_message_get_args(msg, &err,
421                 DBUS_TYPE_UINT32, &uid,
422                 DBUS_TYPE_STRING, &credential,
423                 DBUS_TYPE_INVALID);
424
425         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS PLAY");
426
427         if (dbus_error_is_set(&err)) {
428                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts play : Get arguments error (%s)", err.message);
429                 dbus_error_free(&err);
430                 ret = TTSD_ERROR_OPERATION_FAILED;
431         } else {
432                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts play : uid(%u), credential(%s)", uid, (NULL == credential) ? "NULL" : credential);
433                 ret =  ttsd_server_play(uid, credential);
434         }
435
436         DBusMessage* reply;
437         reply = dbus_message_new_method_return(msg);
438
439         if (NULL != reply) {
440                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
441
442                 if (0 == ret) {
443                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts play : result(%d)", ret);
444                 } else {
445                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play : result(%d)", ret);
446                 }
447
448                 if (!dbus_connection_send(conn, reply, NULL)) {
449                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play : Out Of Memory!");
450                 }
451
452                 dbus_connection_flush(conn);
453                 dbus_message_unref(reply);
454         } else {
455                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play : Fail to create reply message!!");
456         }
457
458         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
459         SLOG(LOG_DEBUG, tts_tag(), "  ");
460
461         return 0;
462 }
463
464 int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg)
465 {
466         DBusError err;
467         dbus_error_init(&err);
468
469         unsigned int uid;
470         int ret = 0;
471         dbus_message_get_args(msg, &err,
472                 DBUS_TYPE_UINT32, &uid,
473                 DBUS_TYPE_INVALID);
474
475         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS STOP");
476
477         if (dbus_error_is_set(&err)) {
478                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts stop : Get arguments error (%s)", err.message);
479                 dbus_error_free(&err);
480                 ret = TTSD_ERROR_OPERATION_FAILED;
481         } else {
482                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts stop : uid(%u)", uid);
483                 ret = ttsd_server_stop(uid);
484         }
485
486         DBusMessage* reply;
487         reply = dbus_message_new_method_return(msg);
488
489         if (NULL != reply) {
490                 dbus_message_append_args(reply,
491                         DBUS_TYPE_INT32, &ret,
492                         DBUS_TYPE_INVALID);
493
494                 if (0 == ret) {
495                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts stop : result(%d)", ret);
496                 } else {
497                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop : result(%d)", ret);
498                 }
499
500                 if (!dbus_connection_send(conn, reply, NULL)) {
501                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop : Out Of Memory!");
502                 }
503
504                 dbus_connection_flush(conn);
505                 dbus_message_unref(reply);
506         } else {
507                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop : Fail to create reply message!!");
508         }
509
510         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
511         SLOG(LOG_DEBUG, tts_tag(), "  ");
512
513         return 0;
514 }
515
516 int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg)
517 {
518         DBusError err;
519         dbus_error_init(&err);
520
521         unsigned int uid;
522         int ret = 0;
523         dbus_message_get_args(msg, &err,
524                 DBUS_TYPE_UINT32, &uid,
525                 DBUS_TYPE_INVALID);
526
527         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS PAUSE");
528
529         if (dbus_error_is_set(&err)) {
530                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts pause : Get arguments error (%s)", err.message);
531                 dbus_error_free(&err);
532                 ret = TTSD_ERROR_OPERATION_FAILED;
533         } else {
534                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts pause : uid(%u)", uid);
535                 ret = ttsd_server_pause(uid);
536         }
537
538         DBusMessage* reply;
539         reply = dbus_message_new_method_return(msg);
540
541         if (NULL != reply) {
542                 dbus_message_append_args(reply,
543                         DBUS_TYPE_INT32, &ret,
544                         DBUS_TYPE_INVALID);
545
546                 if (0 == ret) {
547                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts pause : result(%d)", ret);
548                 } else {
549                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts pause : result(%d)", ret);
550                 }
551
552                 if (!dbus_connection_send(conn, reply, NULL)) {
553                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts pause : Out Of Memory!");
554                 }
555
556                 dbus_connection_flush(conn);
557                 dbus_message_unref(reply);
558         } else {
559                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts pause : Fail to create reply message!!");
560         }
561
562         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
563         SLOG(LOG_DEBUG, tts_tag(), "  ");
564
565         return 0;
566 }
567
568 int ttsd_dbus_server_set_private_data(DBusConnection* conn, DBusMessage* msg)
569 {
570         DBusError err;
571         dbus_error_init(&err);
572
573         unsigned int uid;
574         char* key;
575         char* data;
576         int ret = 0;
577         dbus_message_get_args(msg, &err,
578                 DBUS_TYPE_UINT32, &uid,
579                 DBUS_TYPE_STRING, &key,
580                 DBUS_TYPE_STRING, &data,
581                 DBUS_TYPE_INVALID);
582
583         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS set private data");
584
585         if (dbus_error_is_set(&err)) {
586                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] Fail to get arguments (%s)", err.message);
587                 dbus_error_free(&err);
588                 ret = TTSD_ERROR_OPERATION_FAILED;
589         } else {
590                 SLOG(LOG_DEBUG, tts_tag(), "[IN] tts set private data(%d)", uid);
591                 ret = ttsd_server_set_private_data(uid, key, data);
592         }
593
594         DBusMessage* reply;
595         reply = dbus_message_new_method_return(msg);
596
597         if (NULL != reply) {
598                 dbus_message_append_args(reply,
599                         DBUS_TYPE_INT32, &ret,
600                         DBUS_TYPE_INVALID);
601
602                 if (0 == ret) {
603                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts set private data : (%d)", ret);
604                 } else {
605                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts set private data : (%d)", ret);
606                 }
607
608                 if (!dbus_connection_send(conn, reply, NULL)) {
609                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to send reply");
610                 }
611
612                 dbus_connection_flush(conn);
613                 dbus_message_unref(reply);
614         } else {
615                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to create reply message");
616         }
617
618         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
619         SLOG(LOG_DEBUG, tts_tag(), "");
620
621         return 0;
622 }
623
624 int ttsd_dbus_server_get_private_data(DBusConnection* conn, DBusMessage* msg)
625 {
626         DBusError err;
627         dbus_error_init(&err);
628
629         unsigned int uid;
630         char* key = NULL;
631         char* data = NULL;
632         int ret = 0;
633         dbus_message_get_args(msg, &err,
634                 DBUS_TYPE_UINT32, &uid,
635                 DBUS_TYPE_STRING, &key,
636                 DBUS_TYPE_INVALID);
637
638         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS get private data");
639
640         if (dbus_error_is_set(&err)) {
641                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] Fail to get arguments (%s)", err.message);
642                 dbus_error_free(&err);
643                 ret = TTSD_ERROR_OPERATION_FAILED;
644         } else {
645                 SLOG(LOG_DEBUG, tts_tag(), "[IN] tts get private data : uid(%u)", uid);
646                 ret = ttsd_server_get_private_data(uid, key, &data);
647         }
648
649         DBusMessage* reply;
650         reply = dbus_message_new_method_return(msg);
651
652         if (NULL != reply) {
653                 dbus_message_append_args(reply,
654                         DBUS_TYPE_INT32, &ret,
655                         DBUS_TYPE_STRING, &data,
656                         DBUS_TYPE_INVALID);
657
658                 if (0 == ret) {
659                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts get private data : Result(%d), data(%s)", ret, (NULL == data) ? "NULL" : data);
660                 } else {
661                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts get private data : (%d)", ret);
662                 }
663
664                 if (!dbus_connection_send(conn, reply, NULL)) {
665                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to send reply");
666                 }
667
668                 dbus_connection_flush(conn);
669                 dbus_message_unref(reply);
670         } else {
671                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to create reply message");
672         }
673
674         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
675         SLOG(LOG_DEBUG, tts_tag(), "");
676
677         if (NULL != data) {
678                 free(data);
679                 data = NULL;
680         }
681
682         return 0;
683 }
684
685 int ttsd_dbus_server_play_pcm(DBusConnection* conn, DBusMessage* msg)
686 {
687         DBusError err;
688         dbus_error_init(&err);
689
690         unsigned int uid;
691         int ret = 0;
692
693         dbus_message_get_args(msg, &err,
694                 DBUS_TYPE_UINT32, &uid,
695                 DBUS_TYPE_INVALID);
696
697         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS PLAY PCM");
698
699         if (dbus_error_is_set(&err)) {
700                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts play pcm : Get arguments error (%s)", err.message);
701                 dbus_error_free(&err);
702                 ret = TTSD_ERROR_OPERATION_FAILED;
703         } else {
704                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts play pcm : uid(%u)", uid);
705                 ret =  ttsd_server_play_pcm(uid);
706         }
707
708         DBusMessage* reply;
709         reply = dbus_message_new_method_return(msg);
710
711         if (NULL != reply) {
712                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
713
714                 if (0 == ret) {
715                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts play pcm : result(%d)", ret);
716                 } else {
717                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play pcm : result(%d)", ret);
718                 }
719
720                 if (!dbus_connection_send(conn, reply, NULL)) {
721                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play pcm : Out Of Memory!");
722                 }
723
724                 dbus_connection_flush(conn);
725                 dbus_message_unref(reply);
726         } else {
727                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play pcm : Fail to create reply message!!");
728         }
729
730         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
731         SLOG(LOG_DEBUG, tts_tag(), "  ");
732
733         return 0;
734 }
735
736 int ttsd_dbus_server_stop_pcm(DBusConnection* conn, DBusMessage* msg)
737 {
738         DBusError err;
739         dbus_error_init(&err);
740
741         unsigned int uid;
742         int ret = 0;
743
744         dbus_message_get_args(msg, &err,
745                 DBUS_TYPE_UINT32, &uid,
746                 DBUS_TYPE_INVALID);
747
748         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS STOP PCM");
749
750         if (dbus_error_is_set(&err)) {
751                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts stop pcm : Get arguments error (%s)", err.message);
752                 dbus_error_free(&err);
753                 ret = TTSD_ERROR_OPERATION_FAILED;
754         } else {
755                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts stop pcm : uid(%u)", uid);
756                 ret = ttsd_server_stop(uid);
757         }
758
759         DBusMessage* reply;
760         reply = dbus_message_new_method_return(msg);
761
762         if (NULL != reply) {
763                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
764
765                 if (0 == ret) {
766                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts stop pcm : result(%d)", ret);
767                 } else {
768                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop pcm : result(%d)", ret);
769                 }
770
771                 if (!dbus_connection_send(conn, reply, NULL)) {
772                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop pcm : Out Of Memory!");
773                 }
774
775                 dbus_connection_flush(conn);
776                 dbus_message_unref(reply);
777         } else {
778                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop pcm : Fail to create reply message!!");
779         }
780
781         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
782         SLOG(LOG_DEBUG, tts_tag(), "  ");
783
784         return 0;
785 }
786
787 int ttsd_dbus_server_add_pcm(DBusConnection* conn, DBusMessage* msg)
788 {
789         DBusError err;
790         dbus_error_init(&err);
791
792         unsigned int uid;
793         int event;
794         int audio_type;
795         int rate;
796         char* data = NULL;
797         int data_size;
798         int ret = 0;
799
800         dbus_message_get_args(msg, &err,
801                 DBUS_TYPE_UINT32, &uid,
802                 DBUS_TYPE_INT32, &event,
803                 DBUS_TYPE_INT32, &audio_type,
804                 DBUS_TYPE_INT32, &rate,
805                 //DBUS_TYPE_STRING, &data,
806                 //DBUS_TYPE_INT32, &data_size,
807                 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
808                 &data, &data_size,
809                 DBUS_TYPE_INVALID);
810
811         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS ADD PCM");
812
813         if (dbus_error_is_set(&err)) {
814                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts add pcm : Get arguments error (%s)", err.message);
815                 dbus_error_free(&err);
816                 ret = TTSD_ERROR_OPERATION_FAILED;
817         } else {
818                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts add pcm : uid(%u)", uid);
819                 ret =  ttsd_server_add_pcm(uid, event, (void*)data, data_size, audio_type, rate);
820         }
821
822         DBusMessage* reply;
823         reply = dbus_message_new_method_return(msg);
824
825         if (NULL != reply) {
826                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
827
828                 if (0 == ret) {
829                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts add pcm : result(%d)", ret);
830                 } else {
831                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add pcm : result(%d)", ret);
832                 }
833
834                 if (!dbus_connection_send(conn, reply, NULL)) {
835                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add pcm : Out Of Memory!");
836                 }
837
838                 dbus_connection_flush(conn);
839                 dbus_message_unref(reply);
840         } else {
841                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add pcm : Fail to create reply message!!");
842         }
843
844         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
845         SLOG(LOG_DEBUG, tts_tag(), "  ");
846
847         return 0;
848 }
849
850 int ttsd_dbus_server_get_service_state(DBusConnection* conn, DBusMessage* msg)
851 {
852         DBusError err;
853         dbus_error_init(&err);
854
855         unsigned int uid;
856         int state = (int)TTSD_STATE_READY;
857         int ret = 0;
858
859         dbus_message_get_args(msg, &err,
860                 DBUS_TYPE_UINT32, &uid,
861                 DBUS_TYPE_INVALID);
862
863         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS GET SERVICE STATE");
864
865         if (dbus_error_is_set(&err)) {
866                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts get service state : Get arguments error (%s)", err.message);
867                 dbus_error_free(&err);
868                 ret = TTSD_ERROR_OPERATION_FAILED;
869         } else {
870                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts get service state : uid(%u)", uid);
871                 ret = ttsd_server_get_service_state(uid, &state);
872         }
873
874         DBusMessage* reply;
875         reply = dbus_message_new_method_return(msg);
876
877         if (NULL != reply) {
878                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID);
879
880                 if (0 == ret) {
881                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts get service state : result(%d)", ret);
882                 } else {
883                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts get service state : result(%d)", ret);
884                 }
885
886                 if (!dbus_connection_send(conn, reply, NULL)) {
887                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts get service state : Out Of Memory!");
888                 }
889
890                 dbus_connection_flush(conn);
891                 dbus_message_unref(reply);
892         } else {
893                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts get service state : Fail to create reply message!!");
894         }
895
896         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
897         SLOG(LOG_DEBUG, tts_tag(), "  ");
898
899         return 0;
900 }