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