[ACR-1216][tts][Add tts_repeat()]
[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                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), uttid(%d), credential(%s)", 
313                         uid, (NULL == text) ? "NULL" : text, (NULL == lang) ? "NULL" : lang, voicetype, speed, uttid, (NULL == credential) ? "NULL" : credential);
314                 ret =  ttsd_server_add_queue(uid, text, lang, voicetype, speed, uttid, credential);
315         }
316
317         DBusMessage* reply;
318         reply = dbus_message_new_method_return(msg);
319
320         if (NULL != reply) {
321                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
322
323                 if (0 == ret) {
324                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts add text : result(%d)", ret);
325                 } else {
326                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add text : result(%d)", ret);
327                 }
328
329                 if (!dbus_connection_send(conn, reply, NULL)) {
330                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add text : Out Of Memory!");
331                 }
332
333                 dbus_connection_flush(conn);
334                 dbus_message_unref(reply);
335         } else {
336                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add text : Fail to create reply message!!");
337         }
338
339         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
340         SLOG(LOG_DEBUG, tts_tag(), "  ");
341
342         return 0;
343 }
344
345 int ttsd_dbus_server_play(DBusConnection* conn, DBusMessage* msg)
346 {
347         DBusError err;
348         dbus_error_init(&err);
349
350         int uid;
351         char* credential;
352         int ret = 0;
353
354         dbus_message_get_args(msg, &err,
355                 DBUS_TYPE_INT32, &uid,
356                 DBUS_TYPE_STRING, &credential,
357                 DBUS_TYPE_INVALID);
358
359         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS PLAY");
360
361         if (dbus_error_is_set(&err)) {
362                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts play : Get arguments error (%s)", err.message);
363                 dbus_error_free(&err);
364                 ret = TTSD_ERROR_OPERATION_FAILED;
365         } else {
366                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts play : uid(%d), credential(%s)", uid, (NULL == credential) ? "NULL" : credential);
367                 ret =  ttsd_server_play(uid, credential);
368         }
369
370         DBusMessage* reply;
371         reply = dbus_message_new_method_return(msg);
372
373         if (NULL != reply) {
374                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
375
376                 if (0 == ret) {
377                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts play : result(%d)", ret);
378                 } else {
379                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play : result(%d)", ret);
380                 }
381
382                 if (!dbus_connection_send(conn, reply, NULL)) {
383                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play : Out Of Memory!");
384                 }
385
386                 dbus_connection_flush(conn);
387                 dbus_message_unref(reply);
388         } else {
389                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play : Fail to create reply message!!");
390         }
391
392         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
393         SLOG(LOG_DEBUG, tts_tag(), "  ");
394
395         return 0;
396 }
397
398 int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg)
399 {
400         DBusError err;
401         dbus_error_init(&err);
402
403         int uid;
404         int ret = 0;
405         dbus_message_get_args(msg, &err, 
406                 DBUS_TYPE_INT32, &uid, 
407                 DBUS_TYPE_INVALID);
408
409         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS STOP");
410
411         if (dbus_error_is_set(&err)) {
412                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts stop : Get arguments error (%s)", err.message);
413                 dbus_error_free(&err);
414                 ret = TTSD_ERROR_OPERATION_FAILED;
415         } else {
416                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts stop : uid(%d)", uid);
417                 ret = ttsd_server_stop(uid);
418         }
419
420         DBusMessage* reply;
421         reply = dbus_message_new_method_return(msg);
422
423         if (NULL != reply) {
424                 dbus_message_append_args(reply, 
425                         DBUS_TYPE_INT32, &ret, 
426                         DBUS_TYPE_INVALID);
427
428                 if (0 == ret) {
429                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts stop : result(%d)", ret);
430                 } else {
431                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop : result(%d)", ret);
432                 }
433
434                 if (!dbus_connection_send(conn, reply, NULL)) {
435                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop : Out Of Memory!");
436                 }
437
438                 dbus_connection_flush(conn);
439                 dbus_message_unref(reply);
440         } else {
441                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop : Fail to create reply message!!");
442         }
443
444         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
445         SLOG(LOG_DEBUG, tts_tag(), "  ");
446
447         return 0;
448 }
449
450 int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg)
451 {
452         DBusError err;
453         dbus_error_init(&err);
454
455         int uid;
456         int uttid;
457         int ret = 0;
458         dbus_message_get_args(msg, &err, 
459                 DBUS_TYPE_INT32, &uid, 
460                 DBUS_TYPE_INVALID);
461
462         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS PAUSE");
463
464         if (dbus_error_is_set(&err)) {
465                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts pause : Get arguments error (%s)", err.message);
466                 dbus_error_free(&err);
467                 ret = TTSD_ERROR_OPERATION_FAILED;
468         } else {
469                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts pause : uid(%d)", uid);
470                 ret = ttsd_server_pause(uid, &uttid);
471         }
472
473         DBusMessage* reply;
474         reply = dbus_message_new_method_return(msg);
475
476         if (NULL != reply) {
477                 dbus_message_append_args(reply, 
478                         DBUS_TYPE_INT32, &ret, 
479                         DBUS_TYPE_INVALID);
480
481                 if (0 == ret) {
482                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts pause : result(%d)", ret);
483                 } else {
484                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts pause : result(%d)", ret);
485                 }
486
487                 if (!dbus_connection_send(conn, reply, NULL)) {
488                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts pause : Out Of Memory!");
489                 }
490
491                 dbus_connection_flush(conn);
492                 dbus_message_unref(reply);
493         } else {
494                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts pause : Fail to create reply message!!");
495         }
496
497         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
498         SLOG(LOG_DEBUG, tts_tag(), "  ");
499
500         return 0;
501 }
502
503 int ttsd_dbus_server_set_private_data(DBusConnection* conn, DBusMessage* msg)
504 {
505         DBusError err;
506         dbus_error_init(&err);
507
508         int uid;
509         char* key;
510         char* data;
511         int ret = 0;
512         dbus_message_get_args(msg, &err,
513                 DBUS_TYPE_INT32, &uid,
514                 DBUS_TYPE_STRING, &key,
515                 DBUS_TYPE_STRING, &data,
516                 DBUS_TYPE_INVALID);
517
518         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS set private data");
519
520         if (dbus_error_is_set(&err)) {
521                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] Fail to get arguments (%s)", err.message);
522                 dbus_error_free(&err);
523                 ret = TTSD_ERROR_OPERATION_FAILED;
524         } else {
525                 SLOG(LOG_DEBUG, tts_tag(), "[IN] tts set private data(%d)", uid);
526                 ret = ttsd_server_set_private_data(uid, key, data);
527         }
528
529         DBusMessage* reply;
530         reply = dbus_message_new_method_return(msg);
531
532         if (NULL != reply) {
533                 dbus_message_append_args(reply,
534                         DBUS_TYPE_INT32, &ret,
535                         DBUS_TYPE_INVALID);
536
537                 if (0 == ret) {
538                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts set private data : (%d)", ret);
539                 } else {
540                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts set private data : (%d)", ret);
541                 }
542
543                 if (!dbus_connection_send(conn, reply, NULL)) {
544                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to send reply");
545                 }
546
547                 dbus_connection_flush(conn);
548                 dbus_message_unref(reply);
549         } else {
550                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to create reply message");
551         }
552
553         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
554         SLOG(LOG_DEBUG, tts_tag(), "");
555
556         return 0;
557 }
558
559 int ttsd_dbus_server_get_private_data(DBusConnection* conn, DBusMessage* msg)
560 {
561         DBusError err;
562         dbus_error_init(&err);
563
564         int uid;
565         char* key = NULL;
566         char* data = NULL;
567         int ret = 0;
568         dbus_message_get_args(msg, &err,
569                 DBUS_TYPE_INT32, &uid,
570                 DBUS_TYPE_STRING, &key,
571                 DBUS_TYPE_INVALID);
572
573         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS get private data");
574
575         if (dbus_error_is_set(&err)) {
576                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] Fail to get arguments (%s)", err.message);
577                 dbus_error_free(&err);
578                 ret = TTSD_ERROR_OPERATION_FAILED;
579         } else {
580                 SLOG(LOG_DEBUG, tts_tag(), "[IN] tts get private data(%d)", uid);
581                 ret = ttsd_server_get_private_data(uid, key, &data);
582         }
583
584         DBusMessage* reply;
585         reply = dbus_message_new_method_return(msg);
586
587         if (NULL != reply) {
588                 dbus_message_append_args(reply,
589                         DBUS_TYPE_INT32, &ret,
590                         DBUS_TYPE_STRING, &data,
591                         DBUS_TYPE_INVALID);
592
593                 if (0 == ret) {
594                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts get private data : Result(%d), data(%s)", ret, (NULL == data) ? "NULL" : data);
595                 } else {
596                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts get private data : (%d)", ret);
597                 }
598
599                 if (!dbus_connection_send(conn, reply, NULL)) {
600                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to send reply");
601                 }
602
603                 dbus_connection_flush(conn);
604                 dbus_message_unref(reply);
605         } else {
606                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to create reply message");
607         }
608
609         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
610         SLOG(LOG_DEBUG, tts_tag(), "");
611
612         if (NULL != data) {
613                 free(data);
614                 data = NULL;
615         }
616
617         return 0;
618 }
619
620 int ttsd_dbus_server_play_pcm(DBusConnection* conn, DBusMessage* msg)
621 {
622         DBusError err;
623         dbus_error_init(&err);
624
625         int uid;
626         int ret = 0;
627
628         dbus_message_get_args(msg, &err,
629                 DBUS_TYPE_INT32, &uid,
630                 DBUS_TYPE_INVALID);
631
632         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS PLAY PCM");
633
634         if (dbus_error_is_set(&err)) {
635                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts play pcm : Get arguments error (%s)", err.message);
636                 dbus_error_free(&err);
637                 ret = TTSD_ERROR_OPERATION_FAILED;
638         } else {
639                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts play pcm : uid(%d)", uid);
640                 ret =  ttsd_server_play_pcm(uid);
641         }
642
643         DBusMessage* reply;
644         reply = dbus_message_new_method_return(msg);
645
646         if (NULL != reply) {
647                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
648
649                 if (0 == ret) {
650                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts play pcm : result(%d)", ret);
651                 } else {
652                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play pcm : result(%d)", ret);
653                 }
654
655                 if (!dbus_connection_send(conn, reply, NULL)) {
656                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play pcm : Out Of Memory!");
657                 }
658
659                 dbus_connection_flush(conn);
660                 dbus_message_unref(reply);
661         } else {
662                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts play pcm : Fail to create reply message!!");
663         }
664
665         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
666         SLOG(LOG_DEBUG, tts_tag(), "  ");
667
668         return 0;
669 }
670
671 int ttsd_dbus_server_stop_pcm(DBusConnection* conn, DBusMessage* msg)
672 {
673         DBusError err;
674         dbus_error_init(&err);
675
676         int uid;
677         int ret = 0;
678
679         dbus_message_get_args(msg, &err,
680                 DBUS_TYPE_INT32, &uid,
681                 DBUS_TYPE_INVALID);
682
683         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS STOP PCM");
684
685         if (dbus_error_is_set(&err)) {
686                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts stop pcm : Get arguments error (%s)", err.message);
687                 dbus_error_free(&err);
688                 ret = TTSD_ERROR_OPERATION_FAILED;
689         } else {
690                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts stop pcm : uid(%d)", uid);
691                 ret =  ttsd_server_stop_pcm(uid);
692         }
693
694         DBusMessage* reply;
695         reply = dbus_message_new_method_return(msg);
696
697         if (NULL != reply) {
698                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
699
700                 if (0 == ret) {
701                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts stop pcm : result(%d)", ret);
702                 } else {
703                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop pcm : result(%d)", ret);
704                 }
705
706                 if (!dbus_connection_send(conn, reply, NULL)) {
707                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop pcm : Out Of Memory!");
708                 }
709
710                 dbus_connection_flush(conn);
711                 dbus_message_unref(reply);
712         } else {
713                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts stop pcm : Fail to create reply message!!");
714         }
715
716         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
717         SLOG(LOG_DEBUG, tts_tag(), "  ");
718
719         return 0;
720 }
721
722 int ttsd_dbus_server_add_pcm(DBusConnection* conn, DBusMessage* msg)
723 {
724         DBusError err;
725         dbus_error_init(&err);
726
727         int uid;
728         int event;
729         int audio_type;
730         int rate;
731         char* data = NULL;
732         int data_size;
733         int ret = 0;
734
735         dbus_message_get_args(msg, &err,
736                 DBUS_TYPE_INT32, &uid,
737                 DBUS_TYPE_INT32, &event,
738                 DBUS_TYPE_INT32, &audio_type,
739                 DBUS_TYPE_INT32, &rate,
740                 //DBUS_TYPE_STRING, &data,
741                 //DBUS_TYPE_INT32, &data_size,
742                 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
743                 &data, &data_size,
744                 DBUS_TYPE_INVALID);
745
746         SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS ADD PCM");
747
748         if (dbus_error_is_set(&err)) {
749                 SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts add pcm : Get arguments error (%s)", err.message);
750                 dbus_error_free(&err);
751                 ret = TTSD_ERROR_OPERATION_FAILED;
752         } else {
753                 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts add pcm : uid(%d)", uid);
754                 ret =  ttsd_server_add_pcm(uid, event, (void*)data, data_size, audio_type, rate);
755         }
756
757         DBusMessage* reply;
758         reply = dbus_message_new_method_return(msg);
759
760         if (NULL != reply) {
761                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
762
763                 if (0 == ret) {
764                         SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts add pcm : result(%d)", ret);
765                 } else {
766                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add pcm : result(%d)", ret);
767                 }
768
769                 if (!dbus_connection_send(conn, reply, NULL)) {
770                         SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add pcm : Out Of Memory!");
771                 }
772
773                 dbus_connection_flush(conn);
774                 dbus_message_unref(reply);
775         } else {
776                 SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts add pcm : Fail to create reply message!!");
777         }
778
779         SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
780         SLOG(LOG_DEBUG, tts_tag(), "  ");
781
782         return 0;
783 }