upload tizen1.0 source
[platform/core/uifw/tts.git] / server / ttsd_dbus_server.c
1 /*
2 *  Copyright (c) 2011 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
26 int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg)
27 {
28         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS Hello");
29
30         DBusMessage* reply;
31         reply = dbus_message_new_method_return(msg);
32
33         if (NULL != reply) {
34                 if (!dbus_connection_send(conn, reply, NULL)) {
35                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] Out Of Memory!");
36                 }
37
38                 dbus_connection_flush(conn);
39                 dbus_message_unref(reply);
40         } else {
41                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] Fail to create reply message!!"); 
42         }
43
44         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
45         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
46
47         return 0;
48 }
49
50 int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg)
51 {
52         DBusError err;
53         dbus_error_init(&err);
54
55         int pid, uid;
56         int ret = 0; 
57
58         dbus_message_get_args(msg, &err,
59                 DBUS_TYPE_INT32, &pid,
60                 DBUS_TYPE_INT32, &uid,
61                 DBUS_TYPE_INVALID);
62
63         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS INITIALIZE");
64
65         if (dbus_error_is_set(&err)) { 
66                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] tts initialize : get arguments error (%s)\n", err.message);
67                 dbus_error_free(&err); 
68                 ret = TTSD_ERROR_OPERATION_FAILED;
69         } else {
70
71                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] tts initialize : pid(%d), uid(%d) \n", pid , uid); 
72                 ret =  ttsd_server_initialize(pid, uid);
73         }
74
75         DBusMessage* reply;
76         reply = dbus_message_new_method_return(msg);
77
78         if (NULL != reply) {
79                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
80
81                 if (0 == ret) {
82                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] tts initialize : result(%d) \n", ret); 
83                 } else {
84                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts initialize : result(%d) \n", ret); 
85                 }
86
87                 if (!dbus_connection_send(conn, reply, NULL)) {
88                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts initialize : Out Of Memory!\n");
89                 }
90
91                 dbus_connection_flush(conn);
92                 dbus_message_unref(reply);
93         } else {
94                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts initialize : fail to create reply message!!"); 
95         }
96
97         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
98         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
99
100         return 0;
101 }
102
103 int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg)
104 {
105         DBusError err;
106         dbus_error_init(&err);
107
108         int uid;
109         int ret = 0; 
110
111         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
112
113         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS FINALIZE");
114
115         if (dbus_error_is_set(&err)) { 
116                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] tts finalize : get arguments error (%s)\n", err.message);
117                 dbus_error_free(&err); 
118                 ret = TTSD_ERROR_OPERATION_FAILED;
119         } else {
120                 
121                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] tts finalize : uid(%d) \n", uid); 
122                 ret =  ttsd_server_finalize(uid);
123         }
124
125         DBusMessage* reply;
126         reply = dbus_message_new_method_return(msg);
127
128         if (NULL != reply) {
129                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
130
131                 if (0 == ret) {
132                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] tts finalize : result(%d) \n", ret); 
133                 } else {
134                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts finalize : result(%d) \n", ret); 
135                 }
136
137                 if (!dbus_connection_send(conn, reply, NULL)) {
138                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts finalize : Out Of Memory!\n");
139                 }
140
141                 dbus_connection_flush(conn);
142                 dbus_message_unref(reply);
143         } else {
144                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts finalize : fail to create reply message!!"); 
145         }
146
147         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
148         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
149
150         return 0;
151 }
152
153 int ttsd_dbus_server_get_support_voices(DBusConnection* conn, DBusMessage* msg)
154 {
155         DBusError err;
156         dbus_error_init(&err);
157
158         int uid;
159         int ret = 0;
160         GList* voice_list = NULL;
161
162         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
163
164         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS GET VOICES");
165
166         if (dbus_error_is_set(&err)) { 
167                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] tts get supported voices : get arguments error (%s)\n", err.message);
168                 dbus_error_free(&err); 
169                 ret = TTSD_ERROR_OPERATION_FAILED;
170         } else {
171                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] get supported voices : uid(%d) \n", uid ); 
172                 ret = ttsd_server_get_support_voices(uid, &voice_list);
173         }
174
175         DBusMessage* reply;
176         reply = dbus_message_new_method_return(msg);
177
178         if (NULL != reply) {
179                 DBusMessageIter args;
180                 dbus_message_iter_init_append(reply, &args);
181
182                 /* Append result*/
183                 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret));
184
185                 if (0 == ret) {
186                         /* Append voice size */
187                         int size = g_list_length(voice_list);
188                         
189                         if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
190                                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts supported voices : Fail to append type \n"); 
191                                 ret = TTSD_ERROR_OPERATION_FAILED;
192                         } else {
193
194                                 GList *iter = NULL;
195                                 voice_s* voice;
196
197                                 iter = g_list_first(voice_list);
198
199                                 while (NULL != iter) {
200                                         voice = iter->data;
201
202                                         dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(voice->language) );
203                                         dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(voice->type) );
204
205                                         if (NULL != voice->language)
206                                                 g_free(voice->language);
207                                         if (NULL != voice);
208                                                 g_free(voice);
209
210                                         voice_list = g_list_remove_link(voice_list, iter);
211
212                                         iter = g_list_first(voice_list);
213                                 } 
214                         }
215                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] tts supported voices : result(%d) \n", ret); 
216                 } else {
217                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts supported voices : result(%d) \n", ret); 
218                 }
219
220                 if (!dbus_connection_send(conn, reply, NULL)) {
221                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] error : Out Of Memory!\n");
222                 }
223
224                 dbus_connection_flush(conn);
225                 dbus_message_unref(reply);
226         } else {
227                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts supported voices : fail to create reply message!!");                 
228         }
229
230         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
231         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
232
233         return 0;
234 }
235
236 int ttsd_dbus_server_get_current_voice(DBusConnection* conn, DBusMessage* msg)
237 {
238         DBusError err;
239         dbus_error_init(&err);
240
241         int uid;
242         char* lang;
243         int voice_type;
244         int ret;
245
246         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
247
248         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS GET DEFAULT VOICE");
249
250         if (dbus_error_is_set(&err)) { 
251                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] tts get default voice : Get arguments error (%s)\n", err.message);
252                 dbus_error_free(&err);
253                 ret = TTSD_ERROR_OPERATION_FAILED;
254         } else {
255                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] tts get default voice : uid(%d) \n", uid); 
256                 ret = ttsd_server_get_current_voice(uid, &lang, &voice_type);
257         }
258
259         DBusMessage* reply;
260         reply = dbus_message_new_method_return(msg);
261
262         if (NULL != reply) {
263                 if (0 == ret) { 
264                         /* Append result and voice */
265                         dbus_message_append_args( reply, 
266                                 DBUS_TYPE_INT32, &ret,
267                                 DBUS_TYPE_STRING, &lang,
268                                 DBUS_TYPE_INT32, &voice_type,
269                                 DBUS_TYPE_INVALID);
270                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] tts default voice : lang(%s), vctype(%d)\n", lang, voice_type );
271                 } else {
272                         dbus_message_append_args( reply, 
273                                 DBUS_TYPE_INT32, &ret,
274                                 DBUS_TYPE_INVALID);
275                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts default voice : result(%d) \n", ret); 
276                 }
277
278                 if (!dbus_connection_send(conn, reply, NULL)) {
279                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts default voice : Out Of Memory!\n");
280                 }
281
282                 dbus_connection_flush(conn);
283                 dbus_message_unref(reply);
284         } else {
285                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts default voice : fail to create reply message!!"); 
286         }
287
288         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
289         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
290
291         return 0;
292 }
293
294 int ttsd_dbus_server_add_text(DBusConnection* conn, DBusMessage* msg)
295 {
296         DBusError err;
297         dbus_error_init(&err);
298
299         int uid, voicetype, speed, uttid;
300         char *text, *lang;
301         int ret = 0;
302
303         dbus_message_get_args(msg, &err,
304                 DBUS_TYPE_INT32, &uid,
305                 DBUS_TYPE_STRING, &text,
306                 DBUS_TYPE_STRING, &lang,
307                 DBUS_TYPE_INT32, &voicetype,
308                 DBUS_TYPE_INT32, &speed,
309                 DBUS_TYPE_INT32, &uttid,
310                 DBUS_TYPE_INVALID);
311
312         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS ADD TEXT");
313
314         if (dbus_error_is_set(&err)) { 
315                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] tts add text : Get arguments error (%s)\n", err.message);
316                 dbus_error_free(&err); 
317                 ret = TTSD_ERROR_OPERATION_FAILED;
318         } else {
319                 
320                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), uttid(%d) \n", 
321                         uid, text, lang, voicetype, speed, uttid); 
322                 ret =  ttsd_server_add_queue(uid, text, lang, voicetype, speed, uttid);
323         }
324
325         DBusMessage* reply;
326         reply = dbus_message_new_method_return(msg);
327
328         if (NULL != reply) {
329                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
330
331                 if (0 == ret) {
332                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] tts add text : result(%d) \n", ret); 
333                 } else {
334                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts add text : result(%d) \n", ret); 
335                 }
336
337                 if (!dbus_connection_send(conn, reply, NULL)) {
338                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts add text : Out Of Memory!\n");
339                 }
340
341                 dbus_connection_flush(conn);
342                 dbus_message_unref(reply);
343         } else {
344                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts add text : fail to create reply message!!"); 
345         }
346
347         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
348         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
349
350         return 0;
351 }
352
353 int ttsd_dbus_server_play(DBusConnection* conn, DBusMessage* msg)
354 {
355         DBusError err;
356         dbus_error_init(&err);
357
358         int uid;
359         int ret = 0;
360
361         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
362
363         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS PLAY");
364
365         if (dbus_error_is_set(&err)) { 
366                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] tts play : Get arguments error (%s)\n", err.message);
367                 dbus_error_free(&err); 
368                 ret = TTSD_ERROR_OPERATION_FAILED;
369         } else {
370                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] tts play : uid(%d) \n", uid ); 
371                 ret =  ttsd_server_play(uid);
372         }
373
374         DBusMessage* reply;
375         reply = dbus_message_new_method_return(msg);
376
377         if (NULL != reply) {
378                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
379
380                 if (0 == ret) {
381                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] tts play : result(%d) \n", ret); 
382                 } else {
383                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts play : result(%d) \n", ret); 
384                 }
385         
386                 if (!dbus_connection_send(conn, reply, NULL)) {
387                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts play : Out Of Memory!\n");
388                 }
389
390                 dbus_connection_flush(conn);
391                 dbus_message_unref(reply);
392         } else {
393                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts play : fail to create reply message!!"); 
394         }
395
396         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
397         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
398
399         return 0;
400 }
401
402 int ttsd_dbus_server_stop(DBusConnection* conn, DBusMessage* msg)
403 {
404         DBusError err;
405         dbus_error_init(&err);
406
407         int uid;
408         int ret = 0;
409         dbus_message_get_args(msg, &err, 
410                 DBUS_TYPE_INT32, &uid, 
411                 DBUS_TYPE_INVALID);
412
413         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS STOP");
414
415         if (dbus_error_is_set(&err)) { 
416                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] tts stop : Get arguments error (%s)\n", err.message);
417                 dbus_error_free(&err); 
418                 ret = TTSD_ERROR_OPERATION_FAILED;
419         } else {
420                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] tts stop : uid(%d)\n", uid);
421                 ret = ttsd_server_stop(uid);
422         }
423
424         DBusMessage* reply;
425         reply = dbus_message_new_method_return(msg);
426
427         if (NULL != reply) {
428                 dbus_message_append_args(reply, 
429                         DBUS_TYPE_INT32, &ret, 
430                         DBUS_TYPE_INVALID);
431
432                 if (0 == ret) {
433                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] tts stop : result(%d) \n", ret); 
434                 } else {
435                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts stop : result(%d) \n", ret); 
436                 }
437
438                 if (!dbus_connection_send(conn, reply, NULL)) {
439                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts stop : Out Of Memory!\n");
440                 }
441
442                 dbus_connection_flush(conn);
443                 dbus_message_unref(reply);
444         } else {
445                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts stop : fail to create reply message!!"); 
446         }
447
448         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
449         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
450
451         return 0;
452 }
453
454 int ttsd_dbus_server_pause(DBusConnection* conn, DBusMessage* msg)
455 {
456         DBusError err;
457         dbus_error_init(&err);
458
459         int uid;
460         int uttid;
461         int ret = 0;
462         dbus_message_get_args(msg, &err, 
463                 DBUS_TYPE_INT32, &uid, 
464                 DBUS_TYPE_INVALID);
465
466         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTS PAUSE");
467
468         if (dbus_error_is_set(&err)) { 
469                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] tts pause : Get arguments error (%s)\n", err.message);
470                 dbus_error_free(&err); 
471                 ret = TTSD_ERROR_OPERATION_FAILED;
472         } else {
473                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] tts pause : uid(%d)\n", uid);
474                 ret = ttsd_server_pause(uid, &uttid);
475         }
476
477         DBusMessage* reply;
478         reply = dbus_message_new_method_return(msg);
479
480         if (NULL != reply) {
481                 dbus_message_append_args(reply, 
482                         DBUS_TYPE_INT32, &ret, 
483                         DBUS_TYPE_INVALID);
484
485                 if (0 == ret) {
486                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] tts pause : result(%d) \n", ret); 
487                 } else {
488                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts pause : result(%d) \n", ret); 
489                 }
490
491                 if (!dbus_connection_send(conn, reply, NULL)) {
492                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts pause : Out Of Memory!\n");
493                 }
494
495                 dbus_connection_flush(conn);
496                 dbus_message_unref(reply);
497         } else {
498                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] tts pause : fail to create reply message!!"); 
499         }
500
501         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
502         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
503
504         return 0;
505 }
506
507
508 /*
509 * Dbus Setting-Daemon Server
510 */ 
511
512 int ttsd_dbus_server_setting_initialize(DBusConnection* conn, DBusMessage* msg)
513 {
514         DBusError err;
515         dbus_error_init(&err);
516
517         int pid;
518         int ret = 0;
519
520         dbus_message_get_args(msg, &err,
521                 DBUS_TYPE_INT32, &pid,
522                 DBUS_TYPE_INVALID);
523
524         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING INITIALIZE");
525
526         if (dbus_error_is_set(&err)) { 
527                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] Receivce setting initialize : Get arguments error (%s)\n", err.message);
528                 dbus_error_free(&err);
529                 ret = TTSD_ERROR_OPERATION_FAILED;
530         } else {
531                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] Receivce setting initialize : pid(%d) \n", pid); 
532                 ret =  ttsd_server_setting_initialize(pid);
533         }
534         
535         DBusMessage* reply;
536         reply = dbus_message_new_method_return(msg);
537
538         if (NULL != reply) {
539                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
540
541                 if (0 == ret) {
542                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting initialize : result(%d) \n", ret);
543                 } else {
544                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting initialize : result(%d) \n", ret);
545                 }
546
547                 if (!dbus_connection_send(conn, reply, NULL)) {
548                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting initialize : Out Of Memory!\n");
549                 }
550
551                 dbus_connection_flush(conn);
552                 dbus_message_unref(reply);
553         } else {
554                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting initialize : fail to create reply message!!"); 
555         }
556
557         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
558         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
559
560         return 0;
561 }
562
563 int ttsd_dbus_server_setting_finalize(DBusConnection* conn, DBusMessage* msg)
564 {
565         DBusError err;
566         dbus_error_init(&err);
567
568         int pid;
569         int ret = 0;
570
571         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
572
573         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING FINALIZE");
574
575         if (dbus_error_is_set(&err)) { 
576                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting finalize : Get arguments error (%s)\n", err.message);
577                 dbus_error_free(&err); 
578                 ret = TTSD_ERROR_OPERATION_FAILED;
579         } else {
580                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting finalize : pid(%d)\n", pid); 
581                 ret =  ttsd_server_setting_finalize(pid);       
582         }
583
584         DBusMessage* reply;
585         reply = dbus_message_new_method_return(msg);
586
587         if (NULL != reply) {
588                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
589
590                 if (0 == ret) {
591                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting finalize : result(%d) \n", ret);
592                 } else {
593                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting finalize : result(%d) \n", ret);
594                 }
595                 
596                 if (!dbus_connection_send(conn, reply, NULL)) {
597                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting finalize : Out Of Memory!\n");
598                 }
599
600                 dbus_connection_flush(conn);
601                 dbus_message_unref(reply);
602         } else {
603                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting finalize : fail to create reply message!!"); 
604         }
605
606         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
607         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
608
609         return 0;
610 }
611
612 int ttsd_dbus_server_setting_get_engine_list(DBusConnection* conn, DBusMessage* msg)
613 {
614         DBusError err;
615         dbus_error_init(&err);
616
617         int pid;
618         int ret = 0;
619         GList* engine_list = NULL;
620         
621         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
622
623         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING GET ENGINE LIST");
624
625         if (dbus_error_is_set(&err)) { 
626                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting engine list : Get arguments error (%s)\n", err.message);
627                 dbus_error_free(&err); 
628                 ret = TTSD_ERROR_OPERATION_FAILED;
629         } else {
630                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting engine list : pid(%d) \n", pid); 
631                 ret = ttsd_server_setting_get_engine_list(pid, &engine_list);   
632         }
633         
634         DBusMessage* reply;
635         reply = dbus_message_new_method_return(msg);
636
637         if (NULL != reply) {
638                 DBusMessageIter args;
639                 dbus_message_iter_init_append(reply, &args);
640
641                 /* Append result*/
642                 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret) );
643
644                 if (0 == ret) {
645                         /* Append size */
646                         int size = g_list_length(engine_list);
647                         if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
648                                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting engine list : fail to append engine size \n");
649                         } else {
650
651                                 GList *iter = NULL;
652                                 engine_s* engine;
653
654                                 iter = g_list_first(engine_list);
655
656                                 while (NULL != iter) {
657                                         engine = iter->data;
658                                         SLOG(LOG_DEBUG, TAG_TTSD, "engine id : %s, engine name : %s, ug_name, : %s", 
659                                                 engine->engine_id, engine->engine_name, engine->ug_name);
660
661                                         dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine->engine_id) );
662                                         dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine->engine_name) );
663                                         dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine->ug_name) );
664
665                                         if (NULL != engine->engine_id)
666                                                 g_free(engine->engine_id);
667                                         if (NULL != engine->engine_name);
668                                                 g_free(engine->engine_name);
669                                         if (NULL != engine->ug_name);
670                                                 g_free(engine->ug_name);
671                                         if (NULL != engine);
672                                                 g_free(engine);
673
674                                         engine_list = g_list_remove_link(engine_list, iter);
675
676                                         iter = g_list_first(engine_list);
677                                 } 
678                                 SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting engine list : result(%d) \n", ret);
679                         }
680                 } else {
681                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting engine list : result(%d) \n", ret);
682                 }
683
684                 if (!dbus_connection_send(conn, reply, NULL)) {
685                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting engine list : Out Of Memory!\n");
686                 }
687
688                 dbus_connection_flush(conn);
689                 dbus_message_unref(reply);
690         } else {
691                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting engine list : fail to create reply message!!"); 
692         }
693
694         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
695         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
696
697         return 0;
698 }
699
700 int ttsd_dbus_server_setting_get_engine(DBusConnection* conn, DBusMessage* msg)
701 {
702         DBusError err;
703         dbus_error_init(&err);
704
705         int pid;
706         int ret = 0;
707         char* engine_id = NULL;
708
709         dbus_message_get_args(msg, &err,
710                 DBUS_TYPE_INT32, &pid,
711                 DBUS_TYPE_INVALID);
712
713         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING GET ENGINE");
714
715         if (dbus_error_is_set(&err)) { 
716                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting get engine : Get arguments error (%s)\n", err.message);
717                 dbus_error_free(&err); 
718                 ret = TTSD_ERROR_OPERATION_FAILED;
719         } else {
720                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting get engine : pid(%d)\n", pid); 
721                 ret = ttsd_server_setting_get_current_engine(pid, &engine_id);
722         }
723
724         DBusMessage* reply;
725         reply = dbus_message_new_method_return(msg);
726
727         if (NULL != reply) {
728                 if (0 == ret) {
729                         dbus_message_append_args( reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_STRING, &engine_id, DBUS_TYPE_INVALID);
730                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting get engine : result(%d), engine id(%s)\n", ret, engine_id);
731                 } else {
732                         dbus_message_append_args( reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
733                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get engine : result(%d)", ret);
734                 }
735
736                 if (!dbus_connection_send(conn, reply, NULL)) {
737                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get engine : Out Of Memory!\n");
738                 }
739
740                 dbus_connection_flush(conn);
741                 dbus_message_unref(reply);
742         } else {
743                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get engine : fail to create reply message!!"); 
744         }
745
746         if (NULL != engine_id)
747                 free(engine_id);
748
749         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
750         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
751
752         return 0;
753 }
754
755 int ttsd_dbus_server_setting_set_engine(DBusConnection* conn, DBusMessage* msg)
756 {
757         DBusError err;
758         dbus_error_init(&err);
759
760         int pid;
761         char* engine_id;
762         int ret = 0;
763
764         dbus_message_get_args(msg, &err,
765                 DBUS_TYPE_INT32, &pid,
766                 DBUS_TYPE_STRING, &engine_id,
767                 DBUS_TYPE_INVALID);
768
769         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING SET ENGINE");
770
771         if (dbus_error_is_set(&err)) { 
772                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting set engine : Get arguments error (%s)\n", err.message);
773                 dbus_error_free(&err); 
774                 ret = TTSD_ERROR_OPERATION_FAILED;
775         } else {
776                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting set engine : pid(%d), engine id(%s)\n", pid,  engine_id); 
777                 ret = ttsd_server_setting_set_current_engine(pid, engine_id);
778         }
779         
780         DBusMessage* reply;
781         reply = dbus_message_new_method_return(msg);
782
783         if (NULL != reply) {
784                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
785
786                 if (0 == ret) {
787                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting set engine : result(%d) \n", ret);
788                 } else {
789                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set engine : result(%d) \n", ret);
790                 }
791
792                 if (!dbus_connection_send(conn, reply, NULL)) {
793                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set engine : Out Of Memory!\n");
794                 }
795
796                 dbus_connection_flush(conn);
797                 dbus_message_unref(reply);
798         } else {
799                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set engine : fail to create reply message!!"); 
800         }
801
802         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
803         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
804
805         return 0;
806 }
807
808 int ttsd_dbus_server_setting_get_voice_list(DBusConnection* conn, DBusMessage* msg)
809 {
810         DBusError err;
811         dbus_error_init(&err);
812
813         int pid;
814         char* engine_id = NULL;
815         int ret = 0;
816         GList* voice_list = NULL;
817
818         dbus_message_get_args(msg, &err,
819                 DBUS_TYPE_INT32, &pid,
820                 DBUS_TYPE_INVALID);
821
822         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING GET VOICE LIST");
823
824         if (dbus_error_is_set(&err)) { 
825                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting voice list : Get arguments error (%s)\n", err.message);
826                 dbus_error_free(&err); 
827                 ret = TTSD_ERROR_OPERATION_FAILED;
828         } else {
829                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting voice list : pid(%d)\n", pid); 
830                 ret = ttsd_server_setting_get_voice_list(pid, &engine_id, &voice_list);
831         }
832         
833         DBusMessage* reply;
834         reply = dbus_message_new_method_return(msg);
835
836         if (NULL != reply) {
837                 DBusMessageIter args;
838
839                 dbus_message_iter_init_append(reply, &args);
840
841                 /* Append result*/
842                 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret) );
843
844                 if (0 == ret) {
845                         if (dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine_id))) {
846                                 /* Append voice size */
847                                 int size = g_list_length(voice_list);
848                                 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
849                                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting voice list : Fail to append type \n"); 
850                                         ret = TTSD_ERROR_OPERATION_FAILED;
851                                 } else {
852
853                                         GList *iter = NULL;
854                                         voice_s* voice;
855
856                                         iter = g_list_first(voice_list);
857
858                                         while (NULL != iter) {
859                                                 voice = iter->data;
860
861                                                 dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(voice->language) );
862                                                 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(voice->type) );
863
864                                                 if (NULL != voice->language)
865                                                         g_free(voice->language);
866                                                 if (NULL != voice);
867                                                         g_free(voice);
868
869                                                 voice_list = g_list_remove_link(voice_list, iter);
870
871                                                 iter = g_list_first(voice_list);
872                                         } 
873                                 }
874                                 SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting voice list : result(%d) \n", ret); 
875                         } else {
876                                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting voice list : Fail to append engine_id \n"); 
877                         }
878
879                         if (NULL != engine_id)
880                                 free(engine_id);
881                 } else {
882                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting voice list : result(%d) \n", ret);
883                 }
884
885                 if (!dbus_connection_send(conn, reply, NULL)) {
886                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting voice list : Out Of Memory!\n");
887                 }
888
889                 dbus_connection_flush(conn);
890                 dbus_message_unref(reply);
891         } else {
892                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting voice list : fail to create reply message!!"); 
893         }
894
895         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
896         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
897
898         return 0;
899 }
900
901 int ttsd_dbus_server_setting_get_default_voice(DBusConnection* conn, DBusMessage* msg)
902 {
903         DBusError err;
904         dbus_error_init(&err);
905
906         int pid;
907         int ret = 0;
908         char* lang;
909         ttsp_voice_type_e type;
910
911         dbus_message_get_args(msg, &err,
912                 DBUS_TYPE_INT32, &pid,
913                 DBUS_TYPE_INVALID);
914
915         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING GET DEFAULT VOICE");
916
917         if (dbus_error_is_set(&err)) { 
918                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting get default voice : Get arguments error (%s)\n", err.message);
919                 dbus_error_free(&err); 
920                 ret = TTSD_ERROR_OPERATION_FAILED;
921         } else {        
922                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting get default voice : pid(%d)\n", pid); 
923                 ret = ttsd_server_setting_get_default_voice(pid, &lang, &type);
924         }
925         
926         DBusMessage* reply;
927         reply = dbus_message_new_method_return(msg);
928
929         if (NULL != reply) {
930                 if (0 == ret) {
931                         dbus_message_append_args(reply, 
932                                 DBUS_TYPE_INT32, &ret, 
933                                 DBUS_TYPE_STRING, &lang, 
934                                 DBUS_TYPE_INT32, &type, 
935                                 DBUS_TYPE_INVALID);
936                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting get default voice : result(%d), language(%s), type(%d) \n", ret, lang, type);
937                 } else {
938                         dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
939                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get default voice : result(%d) \n", ret);
940                 }
941
942                 if (!dbus_connection_send(conn, reply, NULL)) {
943                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get default voice : Out Of Memory!\n");
944                 }
945
946                 dbus_connection_flush(conn);
947                 dbus_message_unref(reply);
948         } else {
949                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get default voice : fail to create reply message!!"); 
950         }
951
952         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
953         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
954
955         return 0;
956 }
957
958 int ttsd_dbus_server_setting_set_default_voice(DBusConnection* conn, DBusMessage* msg)
959 {
960         DBusError err;
961         dbus_error_init(&err);
962
963         int pid;
964         char* language;
965         int voicetype;
966         int ret = 0;
967
968         dbus_message_get_args(msg, &err,
969                 DBUS_TYPE_INT32, &pid,
970                 DBUS_TYPE_STRING, &language,
971                 DBUS_TYPE_INT32, &voicetype,
972                 DBUS_TYPE_INVALID);
973
974         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SET DEFAULT VOICE");
975
976         if (dbus_error_is_set(&err)) { 
977                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting set default voice : Get arguments error (%s)\n", err.message);
978                 dbus_error_free(&err); 
979                 ret = TTSD_ERROR_OPERATION_FAILED;
980         } else {
981                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting set default voice : pid(%d), lang(%s), type(%d)\n"
982                         , pid, language, voicetype); 
983                 ret =  ttsd_server_setting_set_default_voice(pid, language, voicetype);
984         }
985         
986         DBusMessage* reply;
987         reply = dbus_message_new_method_return(msg);
988
989         if (NULL != reply) {
990                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
991
992                 if (0 == ret) {
993                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting set default voice : result(%d) \n", ret);
994                 } else {
995                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set default voice : result(%d) \n", ret);
996                 }
997
998                 if (!dbus_connection_send(conn, reply, NULL)) {
999                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set default voice : Out Of Memory!\n");
1000                 }
1001
1002                 dbus_connection_flush(conn);
1003                 dbus_message_unref(reply);
1004         } else {
1005                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set default voice : fail to create reply message!!"); 
1006         }
1007
1008         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
1009         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
1010
1011         return 0;
1012 }
1013
1014 int ttsd_dbus_server_setting_get_speed(DBusConnection* conn, DBusMessage* msg)
1015 {
1016         DBusError err;
1017         dbus_error_init(&err);
1018
1019         int pid;
1020         int ret = 0;
1021         int speed;
1022
1023         dbus_message_get_args(msg, &err,
1024                 DBUS_TYPE_INT32, &pid,
1025                 DBUS_TYPE_INVALID);
1026
1027         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING GET SPEED");
1028
1029         if (dbus_error_is_set(&err)) { 
1030                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting get speed : Get arguments error (%s)\n", err.message);
1031                 dbus_error_free(&err); 
1032                 ret = TTSD_ERROR_OPERATION_FAILED;
1033         } else {
1034                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting get default speed : pid(%d)\n", pid); 
1035                 ret =  ttsd_server_setting_get_default_speed(pid, &speed);
1036         }
1037         
1038         DBusMessage* reply;
1039         reply = dbus_message_new_method_return(msg);
1040
1041         if (NULL != reply) {
1042                 if (0 == ret) {
1043                         dbus_message_append_args( reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &speed, DBUS_TYPE_INVALID);
1044                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting get default speed : result(%d), speed(%d) \n", ret, speed);
1045                 } else {
1046                         dbus_message_append_args( reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
1047                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get default speed : result(%d) \n", ret);
1048                 }
1049
1050                 if (!dbus_connection_send(conn, reply, NULL)) {
1051                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get default speed : Out Of Memory!\n");
1052                 }
1053
1054                 dbus_connection_flush(conn);
1055                 dbus_message_unref(reply);
1056         } else {
1057                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get default speed : fail to create reply message!!"); 
1058         }
1059
1060         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
1061         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
1062
1063         return 0;
1064 }
1065
1066 int ttsd_dbus_server_setting_set_speed(DBusConnection* conn, DBusMessage* msg)
1067 {
1068         DBusError err;
1069         dbus_error_init(&err);
1070
1071         int pid;
1072         int speed;
1073         int ret = 0;
1074
1075         dbus_message_get_args(msg, &err,
1076                 DBUS_TYPE_INT32, &pid,
1077                 DBUS_TYPE_INT32, &speed,
1078                 DBUS_TYPE_INVALID);
1079
1080         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING GET SPEED");
1081
1082         if (dbus_error_is_set(&err)) { 
1083                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting set default speed : Get arguments error (%s)\n", err.message);
1084                 dbus_error_free(&err); 
1085                 ret = TTSD_ERROR_OPERATION_FAILED;
1086         } else {
1087                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting set default speed : pid(%d), speed(%d)\n", pid, speed); 
1088                 ret = ttsd_server_setting_set_default_speed(pid, speed);
1089         }
1090
1091         DBusMessage* reply;
1092         reply = dbus_message_new_method_return(msg);
1093
1094         if (NULL != reply) {
1095                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
1096
1097                 if (0 == ret) {
1098                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting set default speed : result(%d)", ret);
1099                 } else {
1100                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set default speed : result(%d)", ret);
1101                 }
1102
1103                 if (!dbus_connection_send(conn, reply, NULL)) {
1104                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set default speed : Out Of Memory!\n");
1105                 }
1106
1107                 dbus_connection_flush(conn);
1108                 dbus_message_unref(reply);
1109         } else {
1110                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set default speed : fail to create reply message!!"); 
1111         }
1112
1113         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
1114         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
1115
1116         return 0;
1117 }
1118
1119 int ttsd_dbus_server_setting_get_engine_setting(DBusConnection* conn, DBusMessage* msg)
1120 {
1121         DBusError err;
1122         dbus_error_init(&err);
1123
1124         int pid;
1125         int ret = 0;
1126         char* engine_id;
1127         GList* engine_setting_list = NULL;
1128
1129         dbus_message_get_args(msg, &err,
1130                 DBUS_TYPE_INT32, &pid,
1131                 DBUS_TYPE_INVALID);
1132
1133         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING GET ENGINE SETTING");
1134
1135         if (dbus_error_is_set(&err)) { 
1136                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting get engine option : Get arguments error (%s)\n", err.message);
1137                 dbus_error_free(&err); 
1138                 ret = TTSD_ERROR_OPERATION_FAILED;
1139         } else {
1140                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting get engine option : pid(%d)", pid); 
1141                 ret = ttsd_server_setting_get_engine_setting(pid, &engine_id, &engine_setting_list);
1142         }
1143
1144         DBusMessage* reply;
1145         reply = dbus_message_new_method_return(msg);
1146
1147         if (NULL != reply) {
1148                 DBusMessageIter args;
1149                 dbus_message_iter_init_append(reply, &args);
1150
1151                 /* Append result*/
1152                 dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(ret) );
1153
1154                 if (0 == ret) {
1155                         if (dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(engine_id))) {
1156                                 /* Append voice size */
1157                                 int size = g_list_length(engine_setting_list);
1158                                 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(size))) {
1159                                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting voice list : Fail to append type \n"); 
1160                                         ret = TTSD_ERROR_OPERATION_FAILED;
1161                                 } else {
1162
1163                                         GList *iter = NULL;
1164                                         engine_setting_s* setting;
1165
1166                                         iter = g_list_first(engine_setting_list);
1167
1168                                         while (NULL != iter) {
1169                                                 setting = iter->data;
1170
1171                                                 dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(setting->key) );
1172                                                 dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(setting->value) );
1173
1174                                                 if (NULL != setting->key)
1175                                                         g_free(setting->key);
1176                                                 if (NULL != setting->value)
1177                                                         g_free(setting->value);
1178                                                 if (NULL != setting);
1179                                                         g_free(setting);
1180
1181                                                 engine_setting_list = g_list_remove_link(engine_setting_list, iter);
1182
1183                                                 iter = g_list_first(engine_setting_list);
1184                                         } 
1185                                 }
1186                                 SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting engine setting list : result(%d) \n", ret); 
1187                         } else {
1188                                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting voice list : Fail to append engine_id \n"); 
1189                         }
1190
1191                         if (NULL != engine_id)
1192                                 free(engine_id);
1193                 } else {
1194                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get engine option : result(%d) \n", ret);
1195                 }
1196
1197                 if (!dbus_connection_send(conn, reply, NULL)) {
1198                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get engine option : Out Of Memory!\n");
1199                 }
1200
1201                 dbus_connection_flush(conn);
1202                 dbus_message_unref(reply);
1203         } else {
1204                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting get engine option : fail to create reply message!!"); 
1205         }
1206
1207         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
1208         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
1209
1210         return 0;
1211 }
1212
1213 int ttsd_dbus_server_setting_set_engine_setting(DBusConnection* conn, DBusMessage* msg)
1214 {
1215         DBusError err;
1216         dbus_error_init(&err);
1217
1218         int pid;
1219         char* key;
1220         char* value;
1221         int ret = 0;
1222
1223         dbus_message_get_args(msg, &err,
1224                 DBUS_TYPE_INT32, &pid,
1225                 DBUS_TYPE_STRING, &key,
1226                 DBUS_TYPE_STRING, &value,
1227                 DBUS_TYPE_INVALID);
1228
1229         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> SETTING SET ENGINE SETTING");
1230
1231         if (dbus_error_is_set(&err)) { 
1232                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] setting set engine option : Get arguments error (%s)\n", err.message);
1233                 dbus_error_free(&err); 
1234                 ret = TTSD_ERROR_OPERATION_FAILED;
1235         } else {
1236                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] setting set engine option : pid(%d), key(%s), value(%s)\n", pid, key, value); 
1237                 ret = ttsd_server_setting_set_engine_setting(pid, key, value);
1238         }
1239         
1240         DBusMessage* reply;
1241         reply = dbus_message_new_method_return(msg);
1242
1243         if (NULL != reply) {
1244                 dbus_message_append_args( reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
1245
1246                 if (0 == ret) {
1247                         SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] setting set engine option : result(%d)", ret);
1248                 } else {
1249                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set engine option : result(%d)", ret);
1250                 }
1251
1252                 if (!dbus_connection_send(conn, reply, NULL)) {
1253                         SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set engine option : Out Of Memory!\n");
1254                 }
1255                 dbus_connection_flush(conn);
1256                 dbus_message_unref(reply);
1257         } else {
1258                 SLOG(LOG_ERROR, TAG_TTSD, "[OUT ERROR] setting set engine option : fail to create reply message!!"); 
1259         }
1260
1261         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
1262         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
1263
1264         return 0;
1265 }
1266
1267
1268 /*
1269 * Dbus Server functions for tts daemon intenal
1270 */ 
1271
1272 int ttsd_dbus_server_start_next_play(DBusMessage* msg)
1273 {
1274         DBusError err;
1275         dbus_error_init(&err);
1276
1277         int uid;
1278
1279         dbus_message_get_args(msg, &err,
1280                 DBUS_TYPE_INT32, &uid,
1281                 DBUS_TYPE_INVALID);
1282
1283         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTSD NEXT PLAY");
1284
1285         if (dbus_error_is_set(&err)) { 
1286                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] ttsd 'start next play' : Get arguments error (%s)\n", err.message);
1287                 dbus_error_free(&err); 
1288         } else {
1289                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] ttsd 'start next play' : uid(%d) \n", uid);
1290                 int ret = ttsd_server_start_next_play(uid);
1291                 SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] ttsd 'start next play' : result(%d) \n", ret);
1292         }
1293
1294         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
1295         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
1296
1297         return 0;
1298 }
1299
1300 int ttsd_dbus_server_start_next_synthesis(DBusMessage* msg)
1301 {
1302         DBusError err;
1303         dbus_error_init(&err);
1304
1305         int uid;
1306
1307         dbus_message_get_args(msg, &err,
1308                 DBUS_TYPE_INT32, &uid,
1309                 DBUS_TYPE_INVALID);
1310         
1311         SLOG(LOG_DEBUG, TAG_TTSD, ">>>>> TTSD NEXT SYNTHESIS");
1312
1313         if (dbus_error_is_set(&err)) { 
1314                 SLOG(LOG_ERROR, TAG_TTSD, "[IN ERROR] ttsd 'start next synthesis' : Get arguments error (%s)\n", err.message);
1315                 dbus_error_free(&err); 
1316         } else {
1317                 SLOG(LOG_DEBUG, TAG_TTSD, "[IN] ttsd 'start next synthesis' : uid(%d) \n", uid);
1318                 int ret = ttsd_server_start_next_synthesis(uid);
1319                 SLOG(LOG_DEBUG, TAG_TTSD, "[OUT] ttsd 'start next synthesis' : result(%d) \n", ret);
1320         }
1321
1322         SLOG(LOG_DEBUG, TAG_TTSD, "<<<<<");
1323         SLOG(LOG_DEBUG, TAG_TTSD, "  ");
1324
1325         return 0;
1326 }