Add g_steal_pointer to avoid double-free
[platform/core/uifw/tts.git] / server / ttsd_dbus.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 #include <dbus/dbus.h>
15 #include <dirent.h>
16 #include <dlfcn.h>
17 #include <Ecore.h>
18
19 #include "ttsd_main.h"
20 #include "ttsd_dbus_server.h"
21 #include "ttsd_dbus.h"
22
23 static DBusConnection* g_conn_sender = NULL;
24 static DBusConnection* g_conn_listener = NULL;
25
26 static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
27
28 //static int g_waiting_time = 3000;
29
30 static char *g_service_name = NULL;
31 static char *g_service_object = NULL;
32 static char *g_service_interface = NULL;
33
34 const char* __ttsd_get_error_code(ttsd_error_e err)
35 {
36         switch (err) {
37         case TTSD_ERROR_NONE:                   return "TTS_ERROR_NONE";
38         case TTSD_ERROR_OUT_OF_MEMORY:          return "TTS_ERROR_OUT_OF_MEMORY";
39         case TTSD_ERROR_IO_ERROR:               return "TTS_ERROR_IO_ERROR";
40         case TTSD_ERROR_INVALID_PARAMETER:      return "TTS_ERROR_INVALID_PARAMETER";
41         case TTSD_ERROR_OUT_OF_NETWORK:         return "TTS_ERROR_OUT_OF_NETWORK";
42         case TTSD_ERROR_INVALID_STATE:          return "TTS_ERROR_INVALID_STATE";
43         case TTSD_ERROR_INVALID_VOICE:          return "TTS_ERROR_INVALID_VOICE";
44         case TTSD_ERROR_ENGINE_NOT_FOUND:       return "TTS_ERROR_ENGINE_NOT_FOUND";
45         case TTSD_ERROR_TIMED_OUT:              return "TTS_ERROR_TIMED_OUT";
46         case TTSD_ERROR_OPERATION_FAILED:       return "TTS_ERROR_OPERATION_FAILED";
47         case TTSD_ERROR_AUDIO_POLICY_BLOCKED:   return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
48         case TTSD_ERROR_NOT_SUPPORTED_FEATURE:  return "TTSD_ERROR_NOT_SUPPORTED_FEATURE";
49         case TTSD_ERROR_SERVICE_RESET:          return "TTSD_ERROR_SERVICE_RESET";
50         default:
51                 return "Invalid error code";
52         }
53
54         return NULL;
55 }
56
57 int ttsdc_dbus_send_hello(int pid, unsigned int uid, int ret, int service_state, int credential_needed)
58 {
59         if (NULL == g_conn_sender) {
60                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
61                 return -1;
62         }
63
64         DBusMessage* msg;
65         char target_if_name[64];
66         snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
67
68         /* create a message */
69         msg = dbus_message_new_signal(
70                 TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
71                 target_if_name,                         /* interface name of the signal */
72                 TTSD_METHOD_HELLO);                     /* name of the signal */
73
74         if (NULL == msg) {
75                 SLOG(LOG_ERROR, tts_tag(), "<<<< [Dbus ERROR] Fail to create hello message : uid(%u), ret(%d), credential_needed(%d)", uid, ret, credential_needed);
76                 return -1;
77         } else {
78                 SLOG(LOG_INFO, tts_tag(), "<<<< [Dbus] Send hello message : uid(%u), ret(%d), credential_needed(%d)", uid, ret, credential_needed);
79         }
80
81         dbus_message_append_args(msg,
82                         DBUS_TYPE_UINT32, &uid,
83                         DBUS_TYPE_INT32, &ret,
84                         DBUS_TYPE_INT32, &service_state,
85                         DBUS_TYPE_INT32, &credential_needed,
86                         DBUS_TYPE_INVALID);
87
88         if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
89                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to Send");
90                 return TTSD_ERROR_OPERATION_FAILED;
91         } else {
92                 SLOG(LOG_INFO, tts_tag(), "[Dbus] SUCCESS Send");
93                 dbus_connection_flush(g_conn_sender);
94         }
95
96         dbus_message_unref(msg);
97         return 0;
98 }
99
100 static int __send_message(int pid, unsigned int uid, int data, const char *method)
101 {
102         if (NULL == g_conn_sender) {
103                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
104                 return -1;
105         }
106
107         DBusMessage* msg = NULL;
108
109         char target_if_name[64];
110         snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
111
112         /* create a message */
113         msg = dbus_message_new_signal(
114                 TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
115                 target_if_name,                         /* interface name of the signal */
116                 method);                        /* name of the signal */
117
118         if (NULL == msg) {
119                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to create message : %s", method);
120                 return -1;
121         } else {
122                 SLOG(LOG_DEBUG, tts_tag(), "[Dbus] Send %s message : uid(%u) data(%d)", method, uid, data);
123         }
124
125         dbus_message_append_args(msg, DBUS_TYPE_UINT32, &uid, DBUS_TYPE_INT32, &data, DBUS_TYPE_INVALID);
126
127         if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
128                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to Send");
129                 return -1;
130         } else {
131                 SLOG(LOG_DEBUG, tts_tag(), "[Dbus] SUCCESS Send");
132                 dbus_connection_flush(g_conn_sender);
133         }
134
135         dbus_message_unref(msg);
136
137         return 0;
138 }
139
140 int ttsdc_dbus_send_utt_start_message(int pid, unsigned int uid, int uttid)
141 {
142         return __send_message(pid, uid, uttid, TTSD_METHOD_UTTERANCE_STARTED);
143 }
144
145 int ttsdc_dbus_send_utt_finish_message(int pid, unsigned int uid, int uttid)
146 {
147         return __send_message(pid, uid, uttid, TTSD_METHOD_UTTERANCE_COMPLETED);
148 }
149
150 int ttsdc_dbus_send_set_state_message(int pid, unsigned int uid, int state)
151 {
152         return __send_message(pid, uid, state, TTSD_METHOD_SET_STATE);
153 }
154
155 int ttsdc_dbus_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state)
156 {
157         if (NULL == g_conn_sender) {
158                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
159                 return TTSD_ERROR_OPERATION_FAILED;
160         }
161
162         DBusMessage* msg = NULL;
163
164         char target_if_name[64];
165         snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
166
167         /* create a message */
168         msg = dbus_message_new_signal(
169                 TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
170                 target_if_name,                         /* interface name of the signal */
171                 TTSD_METHOD_SET_SERVICE_STATE);                 /* name of the signal */
172
173         if (NULL == msg) {
174                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to create message : %s", TTSD_METHOD_SET_SERVICE_STATE);
175                 return TTSD_ERROR_OPERATION_FAILED;
176         } else {
177                 SLOG(LOG_DEBUG, tts_tag(), "[Dbus] Send set service state message : uid(%u) before_state(%d), current_state(%d)", uid, before_state, current_state);
178         }
179
180         dbus_message_append_args(msg, DBUS_TYPE_UINT32, &uid, DBUS_TYPE_INT32, &before_state, DBUS_TYPE_INT32, &current_state, DBUS_TYPE_INVALID);
181
182         if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
183                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to Send");
184                 return TTSD_ERROR_OPERATION_FAILED;
185         } else {
186                 SLOG(LOG_DEBUG, tts_tag(), "[Dbus] SUCCESS Send");
187                 dbus_connection_flush(g_conn_sender);
188         }
189
190         dbus_message_unref(msg);
191
192         return TTSD_ERROR_NONE;
193 }
194
195 int ttsdc_dbus_send_pcm(int pid, unsigned int uid, int uttid, int event, const void* pcm_data, int pcm_data_size, ttse_audio_type_e audio_type, int sample_rate)
196 {
197         if (NULL == g_conn_sender) {
198                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
199                 return -1;
200         }
201
202         DBusMessage* msg = NULL;
203
204         char target_if_name[64];
205         snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
206
207         /* create a message */
208         msg = dbus_message_new_signal(
209                 TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
210                 target_if_name,                         /* interface name of the signal */
211                 TTSD_METHOD_SEND_PCM);          /* name of the signal */
212
213         if (NULL == msg) {
214                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to create error message : uid(%u)", uid);
215                 return -1;
216         }
217
218         dbus_message_append_args(msg,
219                 DBUS_TYPE_UINT32, &uid,
220                 DBUS_TYPE_INT32, &uttid,
221                 DBUS_TYPE_INT32, &event,
222                 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &pcm_data, pcm_data_size,
223                 DBUS_TYPE_INT32, &audio_type,
224                 DBUS_TYPE_INT32, &sample_rate,
225                 DBUS_TYPE_INVALID);
226
227         if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
228                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to Send");
229                 return TTSD_ERROR_OPERATION_FAILED;
230         } else {
231                 SLOG(LOG_DEBUG, tts_tag(), "[Dbus] SUCCESS Send");
232                 dbus_connection_flush(g_conn_sender);
233         }
234
235         dbus_message_unref(msg);
236
237         return 0;
238 }
239
240 int ttsdc_dbus_send_error_message(int pid, unsigned int uid, int uttid, int reason, char* err_msg)
241 {
242         if (NULL == g_conn_sender) {
243                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
244                 return -1;
245         }
246
247         DBusMessage* msg = NULL;
248
249         char target_if_name[64];
250         snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
251
252         /* create a message */
253         msg = dbus_message_new_signal(
254                 TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
255                 target_if_name,                         /* interface name of the signal */
256                 TTSD_METHOD_ERROR);             /* name of the signal */
257
258         if (NULL == msg) {
259                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to create error message : uid(%u)", uid);
260                 return -1;
261         }
262
263         dbus_message_append_args(msg,
264                 DBUS_TYPE_UINT32, &uid,
265                 DBUS_TYPE_INT32, &uttid,
266                 DBUS_TYPE_INT32, &reason,
267                 DBUS_TYPE_STRING, &err_msg,
268                 DBUS_TYPE_INVALID);
269
270         dbus_message_set_no_reply(msg, TRUE);
271
272         if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
273                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] <<<< error message : Out Of Memory !");
274         } else {
275                 SLOG(LOG_DEBUG, tts_tag(), "<<<< Send error message : uid(%u), reason(%s), uttid(%d), err_msg(%s)",
276                          uid, __ttsd_get_error_code(reason), uttid, (NULL == err_msg) ? "NULL" : err_msg);
277                 dbus_connection_flush(g_conn_sender);
278         }
279
280         dbus_message_unref(msg);
281
282         return 0;
283 }
284
285 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
286 {
287         if (NULL == g_conn_listener)    return ECORE_CALLBACK_RENEW;
288
289         dbus_connection_read_write_dispatch(g_conn_listener, 50);
290
291         while (1) {
292                 DBusMessage* msg = NULL;
293                 msg = dbus_connection_pop_message(g_conn_listener);
294
295                 if (true != dbus_connection_get_is_connected(g_conn_listener)) {
296                         SLOG(LOG_ERROR, tts_tag(), "[ERROR] Connection is disconnected");
297                         return ECORE_CALLBACK_RENEW;
298                 }
299
300                 /* loop again if we haven't read a message */
301                 if (NULL == msg) {
302                         return ECORE_CALLBACK_RENEW;
303                 }
304
305                 /* client event */
306                 if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_HELLO)) {
307                         ttsd_dbus_server_hello(g_conn_listener, msg);
308
309                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_HELLO_SYNC)) {
310                         ttsd_dbus_server_hello_sync(g_conn_listener, msg);
311
312                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_INITIALIZE)) {
313                         ttsd_dbus_server_initialize(g_conn_listener, msg);
314
315                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_FINALIZE)) {
316                         ttsd_dbus_server_finalize(g_conn_listener, msg);
317
318                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_SUPPORT_VOICES)) {
319                         ttsd_dbus_server_get_support_voices(g_conn_listener, msg);
320
321                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_CURRENT_VOICE)) {
322                         ttsd_dbus_server_get_current_voice(g_conn_listener, msg);
323
324                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_ADD_TEXT)) {
325                         ttsd_dbus_server_add_text(g_conn_listener, msg);
326
327                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_ADD_SILENT_UTTERANCE)) {
328                         ttsd_dbus_server_add_silent_utterance(g_conn_listener, msg);
329
330                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PLAY)) {
331                         ttsd_dbus_server_play(g_conn_listener, msg);
332
333                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_STOP)) {
334                         ttsd_dbus_server_stop(g_conn_listener, msg);
335
336                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PAUSE)) {
337                         ttsd_dbus_server_pause(g_conn_listener, msg);
338
339                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_SET_PRIVATE_DATA)) {
340                         ttsd_dbus_server_set_private_data(g_conn_listener, msg);
341
342                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_PRIVATE_DATA)) {
343                         ttsd_dbus_server_get_private_data(g_conn_listener, msg);
344
345                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_PLAY_PCM)) {
346                         ttsd_dbus_server_play_pcm(g_conn_listener, msg);
347
348                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_STOP_PCM)) {
349                         ttsd_dbus_server_stop_pcm(g_conn_listener, msg);
350
351                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_ADD_PCM)) {
352                         ttsd_dbus_server_add_pcm(g_conn_listener, msg);
353
354                 } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_SERVICE_STATE)) {
355                         ttsd_dbus_server_get_service_state(g_conn_listener, msg);
356
357                 } else {
358                         SLOG(LOG_DEBUG, tts_tag(), "Message is NOT valid");
359                         /* Invalid method */
360                 }
361                 /* free the message */
362                 dbus_message_unref(msg);
363         }
364
365         return ECORE_CALLBACK_RENEW;
366 }
367
368 void __ttsd_dbus_service_free()
369 {
370         if (NULL != g_service_name) {
371                 free(g_service_name);
372                 g_service_name = NULL;
373         }
374
375         if (NULL != g_service_object) {
376                 free(g_service_object);
377                 g_service_object = NULL;
378         }
379
380         if (NULL != g_service_interface) {
381                 free(g_service_interface);
382                 g_service_interface = NULL;
383         }
384 }
385
386 void __ttsd_dbus_connection_free()
387 {
388         if (NULL != g_conn_listener) {
389                 dbus_connection_close(g_conn_listener);
390                 dbus_connection_unref(g_conn_listener);
391                 g_conn_listener = NULL;
392         }
393         if (NULL != g_conn_sender) {
394                 dbus_connection_close(g_conn_sender);
395                 dbus_connection_unref(g_conn_sender);
396                 g_conn_sender = NULL;
397         }
398 }
399
400 int ttsd_dbus_open_connection()
401 {
402         SLOG(LOG_DEBUG, tts_tag(), "@@@ start dbus open connection");
403         DBusError err;
404         dbus_error_init(&err);
405
406         int ret;
407
408         /* Create connection for sender */
409         g_conn_sender = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
410         if (dbus_error_is_set(&err)) {
411                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
412                 dbus_error_free(&err);
413         }
414
415         if (NULL == g_conn_sender) {
416                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get dbus connection sender");
417                 return -1;
418         }
419
420         dbus_connection_set_exit_on_disconnect(g_conn_sender, false);
421
422         /* connect to the bus and check for errors */
423         g_conn_listener = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
424         if (dbus_error_is_set(&err)) {
425                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
426                 dbus_error_free(&err);
427                 __ttsd_dbus_connection_free();
428                 return -1;
429         }
430
431         if (NULL == g_conn_listener) {
432                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get dbus connection");
433                 __ttsd_dbus_connection_free();
434                 return -1;
435         }
436
437         dbus_connection_set_exit_on_disconnect(g_conn_listener, false);
438
439         __ttsd_dbus_service_free();
440
441         g_service_name = (char*)calloc(strlen(TTS_SERVER_SERVICE_NAME) + 1, sizeof(char));
442         g_service_object = (char*)calloc(strlen(TTS_SERVER_SERVICE_OBJECT_PATH) + 1, sizeof(char));
443         g_service_interface = (char*)calloc(strlen(TTS_SERVER_SERVICE_INTERFACE) + 1, sizeof(char));
444
445         if (NULL == g_service_name || NULL == g_service_object || NULL == g_service_interface) {
446                 SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to allocate memory");
447                 __ttsd_dbus_service_free();
448                 __ttsd_dbus_connection_free();
449                 return -1;
450         }
451
452         snprintf(g_service_name, strlen(TTS_SERVER_SERVICE_NAME) + 1, "%s", TTS_SERVER_SERVICE_NAME);
453         snprintf(g_service_object, strlen(TTS_SERVER_SERVICE_OBJECT_PATH) + 1, "%s", TTS_SERVER_SERVICE_OBJECT_PATH);
454         snprintf(g_service_interface, strlen(TTS_SERVER_SERVICE_INTERFACE) + 1, "%s", TTS_SERVER_SERVICE_INTERFACE);
455
456         /* request our name on the bus and check for errors */
457         ret = dbus_bus_request_name(g_conn_listener, g_service_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
458         if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
459                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to be primary owner");
460                 __ttsd_dbus_connection_free();
461                 return -1;
462         }
463
464         if (dbus_error_is_set(&err)) {
465                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to request dbus name : %s", err.message);
466                 dbus_error_free(&err);
467                 __ttsd_dbus_connection_free();
468                 return -1;
469         }
470
471         /* Flush messages which are received before fd event handler registration */
472         while (DBUS_DISPATCH_DATA_REMAINS == dbus_connection_get_dispatch_status(g_conn_listener)) {
473                 listener_event_callback(NULL, NULL);
474         }
475
476         /* add a rule for getting signal */
477         char rule[128];
478         snprintf(rule, 128, "type='method_call',interface='%s'", g_service_interface);
479
480         /* add a rule for which messages we want to see */
481         dbus_bus_add_match(g_conn_listener, rule, &err);/* see signals from the given interface */
482         dbus_connection_flush(g_conn_listener);
483
484         if (dbus_error_is_set(&err)) {
485                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
486                 __ttsd_dbus_connection_free();
487                 return -1;
488         }
489
490         int fd = 0;
491         dbus_connection_get_unix_fd(g_conn_listener, &fd);
492
493         g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
494         if (NULL == g_dbus_fd_handler) {
495                 SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to get fd handler");
496                 __ttsd_dbus_connection_free();
497                 return -1;
498         }
499
500         SLOG(LOG_DEBUG, tts_tag(), "@@@");
501         return 0;
502 }
503
504 int ttsd_dbus_close_connection()
505 {
506         SLOG(LOG_DEBUG, tts_tag(), "@@@ start dbus close connection");
507         DBusError err;
508         dbus_error_init(&err);
509
510         if (NULL != g_dbus_fd_handler) {
511                 ecore_main_fd_handler_del(g_dbus_fd_handler);
512                 g_dbus_fd_handler = NULL;
513         }
514
515         if (NULL != g_conn_listener) {
516                 dbus_bus_release_name(g_conn_listener, g_service_name, &err);
517                 if (dbus_error_is_set(&err)) {
518                         SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
519                         dbus_error_free(&err);
520                 }
521         }
522
523         __ttsd_dbus_connection_free();
524         __ttsd_dbus_service_free();
525
526         SLOG(LOG_DEBUG, tts_tag(), "@@@");
527
528         return 0;
529 }