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