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