Fix dbus connection free
[platform/core/uifw/voice-control.git] / client / vc_dbus.c
1 /*
2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #include "vc_client.h"
19 #include "vc_dbus.h"
20 #include "vc_main.h"
21
22
23 static int g_waiting_time = 3000;
24
25 static Ecore_Fd_Handler* g_fd_handler = NULL;
26
27 static DBusConnection* g_conn_sender = NULL;
28 static DBusConnection* g_conn_listener = NULL;
29
30 extern int __vc_cb_error(int reason, int daemon_pid, char* msg);
31
32 extern void __vc_cb_result();
33
34 extern int __vc_cb_service_state(int state);
35
36 extern int __vc_cb_manager_pid(int manager_pid);
37
38
39 static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
40 {
41         if (NULL == g_conn_listener)    return ECORE_CALLBACK_RENEW;
42
43         dbus_connection_read_write_dispatch(g_conn_listener, 50);
44
45         while (1) {
46                 DBusMessage* msg = NULL;
47                 msg = dbus_connection_pop_message(g_conn_listener);
48
49                 /* loop again if we haven't read a message */
50                 if (NULL == msg) {
51                         break;
52                 }
53
54                 DBusError err;
55                 dbus_error_init(&err);
56
57                 char if_name[64] = {0, };
58                 snprintf(if_name, 64, "%s", VC_CLIENT_SERVICE_INTERFACE);
59
60                 if (dbus_message_is_method_call(msg, if_name, VCD_METHOD_HELLO)) {
61                         SLOG(LOG_DEBUG, TAG_VCC, "===== Get Hello");
62                         int pid = 0;
63                         int response = -1;
64
65                         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
66
67                         if (dbus_error_is_set(&err)) {
68                                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
69                                 dbus_error_free(&err);
70                         }
71
72                         if (pid > 0) {
73                                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc get hello : pid(%d) ", pid);
74                                 response = 1;
75                         } else {
76                                 SLOG(LOG_ERROR, TAG_VCC, "<<<< vc get hello : invalid pid ");
77                         }
78
79                         DBusMessage* reply = NULL;
80                         reply = dbus_message_new_method_return(msg);
81
82                         if (NULL != reply) {
83                                 dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
84
85                                 if (!dbus_connection_send(g_conn_listener, reply, NULL))
86                                         SLOG(LOG_ERROR, TAG_VCC, ">>>> vc get hello : fail to send reply");
87                                 else
88                                         SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc get hello : result(%d)", response);
89
90                                 dbus_connection_flush(g_conn_listener);
91                                 dbus_message_unref(reply);
92                         } else {
93                                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc get hello : fail to create reply message");
94                         }
95
96                         SLOG(LOG_DEBUG, TAG_VCC, "=====");
97                         SLOG(LOG_DEBUG, TAG_VCC, " ");
98                 } /* VCD_METHOD_HELLO */
99
100                 else if (dbus_message_is_signal(msg, if_name, VCD_METHOD_SET_SERVICE_STATE)) {
101                         int state = 0;
102
103                         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID);
104                         if (dbus_error_is_set(&err)) {
105                                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Get arguments error (%s)", err.message);
106                                 dbus_error_free(&err);
107                         }
108
109                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< state changed : %d", state);
110
111                         __vc_cb_service_state(state);
112
113                 } /* VCD_METHOD_SET_SERVICE_STATE */
114
115                 else if (dbus_message_is_method_call(msg, if_name, VCD_METHOD_RESULT)) {
116                         SLOG(LOG_DEBUG, TAG_VCC, "===== Get Client Result");
117
118                         __vc_cb_result();
119
120                         SLOG(LOG_DEBUG, TAG_VCC, "=====");
121                         SLOG(LOG_DEBUG, TAG_VCC, " ");
122
123                 } /* VCD_METHOD_RESULT */
124                 else if (dbus_message_is_signal(msg, if_name, VCD_METHOD_SEND_MANAGER_PID)) {
125                         int manager_pid = 0;
126
127                         dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &manager_pid, DBUS_TYPE_INVALID);
128                         if (dbus_error_is_set(&err)) {
129                                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Get arguments error (%s)", err.message);
130                                 dbus_error_free(&err);
131                         }
132
133                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< manager pid is changed : %d", manager_pid);
134
135                         __vc_cb_manager_pid(manager_pid);
136
137                 } /* VCD_METHOD_SEND_MANAGER_PID */
138
139                 else if (dbus_message_is_signal(msg, if_name, VCD_METHOD_ERROR)) {
140                         SLOG(LOG_DEBUG, TAG_VCC, "===== Get Error");
141                         int reason;
142                         int daemon_pid;
143                         char* err_msg;
144
145                         dbus_message_get_args(msg, &err,
146                                 DBUS_TYPE_INT32, &reason,
147                                 DBUS_TYPE_INT32, &daemon_pid,
148                                 DBUS_TYPE_STRING, &err_msg,
149                                 DBUS_TYPE_INVALID);
150
151                         if (dbus_error_is_set(&err)) {
152                                 SLOG(LOG_ERROR, TAG_VCC, "<<<< vc Get Error message : Get arguments error (%s)", err.message);
153                                 dbus_error_free(&err);
154                         } else {
155                                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc Get Error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, err_msg);
156                                 __vc_cb_error(reason, daemon_pid, err_msg);
157                         }
158
159                         SLOG(LOG_DEBUG, TAG_VCC, "=====");
160                         SLOG(LOG_DEBUG, TAG_VCC, " ");
161                 } /* VCD_METHOD_ERROR */
162
163                 else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) {
164                         SLOG(LOG_DEBUG, TAG_VCC, "===== Owner Changed");
165                         DBusError err;
166                         dbus_error_init(&err);
167                         /* remove a rule for daemon error */
168                         char rule_err[256] = {0, };
169                         snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE);
170                         dbus_bus_remove_match(g_conn_listener, rule_err, &err);
171                         dbus_connection_flush(g_conn_listener);
172
173                         if (dbus_error_is_set(&err)) {
174                                 SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message);
175                                 dbus_error_free(&err);
176                         }
177                         __vc_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset");
178                         SLOG(LOG_DEBUG, TAG_VCC, "=====");
179                         SLOG(LOG_DEBUG, TAG_VCC, " ");
180                 } /* NameOwnerChanged */
181
182                 else {
183                         SLOG(LOG_DEBUG, TAG_VCC, "Message is NOT valid");
184                         dbus_message_unref(msg);
185                         break;
186                 }
187
188                 /* free the message */
189                 dbus_message_unref(msg);
190         } /* while(1) */
191
192         return ECORE_CALLBACK_PASS_ON;
193 }
194
195 static void __vc_dbus_connection_free()
196 {
197         if (NULL != g_conn_listener) {
198                 dbus_connection_close(g_conn_listener);
199                 dbus_connection_unref(g_conn_listener);
200                 g_conn_listener = NULL;
201         }
202         if (NULL != g_conn_sender) {
203                 dbus_connection_close(g_conn_sender);
204                 dbus_connection_unref(g_conn_sender);
205                 g_conn_sender = NULL;
206         }
207 }
208
209 int vc_dbus_open_connection()
210 {
211         if (NULL != g_conn_sender && NULL != g_conn_listener) {
212                 SLOG(LOG_WARN, TAG_VCC, "already existed connection ");
213                 return 0;
214         }
215
216         DBusError err;
217         int ret;
218
219         /* initialise the error value */
220         dbus_error_init(&err);
221
222         /* connect to the DBUS system bus, and check for errors */
223         g_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
224
225         if (dbus_error_is_set(&err)) {
226                 SLOG(LOG_ERROR, TAG_VCC, "Dbus Connection Error (%s)", err.message);
227                 dbus_error_free(&err);
228         }
229
230         if (NULL == g_conn_sender) {
231                 SLOG(LOG_ERROR, TAG_VCC, "Fail to get dbus connection ");
232                 return VC_ERROR_OPERATION_FAILED;
233         }
234
235         g_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
236
237         if (dbus_error_is_set(&err)) {
238                 SLOG(LOG_ERROR, TAG_VCC, "Dbus Connection Error (%s)", err.message);
239                 dbus_error_free(&err);
240         }
241
242         if (NULL == g_conn_listener) {
243                 SLOG(LOG_ERROR, TAG_VCC, "Fail to get dbus connection ");
244                 __vc_dbus_connection_free();
245                 return VC_ERROR_OPERATION_FAILED;
246         }
247
248         int pid = getpid();
249
250         char service_name[64];
251         memset(service_name, '\0', 64);
252         snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid);
253
254         SLOG(LOG_DEBUG, TAG_VCC, "service name is %s", service_name);
255
256         /* register our name on the bus, and check for errors */
257         ret = dbus_bus_request_name(g_conn_listener, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
258
259         if (dbus_error_is_set(&err)) {
260                 SLOG(LOG_ERROR, TAG_VCC, "Name Error (%s)", err.message);
261                 dbus_error_free(&err);
262         }
263
264         if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
265                 SLOG(LOG_ERROR, TAG_VCC, "fail dbus_bus_request_name()");
266                 __vc_dbus_connection_free();
267                 return -2;
268         }
269
270         if (NULL != g_fd_handler) {
271                 SLOG(LOG_WARN, TAG_VCC, "The handler already exists.");
272                 __vc_dbus_connection_free();
273                 return 0;
274         }
275
276         char rule[128] = {0, };
277         snprintf(rule, 128, "type='signal',interface='%s'", VC_CLIENT_SERVICE_INTERFACE);
278
279         /* add a rule for which messages we want to see */
280         dbus_bus_add_match(g_conn_listener, rule, &err);
281         dbus_connection_flush(g_conn_listener);
282
283         if (dbus_error_is_set(&err)) {
284                 SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message);
285                 dbus_error_free(&err);
286                 __vc_dbus_connection_free();
287                 return VC_ERROR_OPERATION_FAILED;
288         }
289
290         int fd = 0;
291         if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
292                 SLOG(LOG_ERROR, TAG_VCC, "fail to get fd from dbus ");
293                 __vc_dbus_connection_free();
294                 return VC_ERROR_OPERATION_FAILED;
295         } else {
296                 SLOG(LOG_DEBUG, TAG_VCC, "Get fd from dbus : %d", fd);
297         }
298
299         g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
300         if (NULL == g_fd_handler) {
301                 SLOG(LOG_ERROR, TAG_VCC, "fail to get fd handler from ecore ");
302                 __vc_dbus_connection_free();
303                 return VC_ERROR_OPERATION_FAILED;
304         }
305
306         return 0;
307 }
308
309 int vc_dbus_close_connection()
310 {
311         DBusError err;
312         dbus_error_init(&err);
313
314         if (NULL != g_fd_handler) {
315                 ecore_main_fd_handler_del(g_fd_handler);
316                 g_fd_handler = NULL;
317         }
318
319         int pid = getpid();
320
321         char service_name[64];
322         memset(service_name, '\0', 64);
323         snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid);
324
325         dbus_bus_release_name(g_conn_listener, service_name, &err);
326
327         if (dbus_error_is_set(&err)) {
328                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
329                 dbus_error_free(&err);
330         }
331
332         __vc_dbus_connection_free();
333
334         return 0;
335 }
336
337 int vc_dbus_reconnect()
338 {
339         if (!g_conn_sender || !g_conn_listener) {
340                 vc_dbus_close_connection();
341
342                 if (0 != vc_dbus_open_connection()) {
343                         SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect");
344                         return -1;
345                 }
346
347                 SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect");
348                 return 0;
349         }
350
351         bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
352         bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
353         SLOG(LOG_WARN, TAG_VCC, "[DBUS] Sender(%s) Listener(%s)",
354                  sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
355
356         if (false == sender_connected || false == listener_connected) {
357                 vc_dbus_close_connection();
358
359                 if (0 != vc_dbus_open_connection()) {
360                         SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect");
361                         return -1;
362                 }
363
364                 SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect");
365         }
366
367         return 0;
368 }
369
370 static int __dbus_check()
371 {
372         if (NULL == g_conn_sender) {
373                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection");
374                 return vc_dbus_reconnect();
375         }
376         return 0;
377 }
378
379 int vc_dbus_request_hello()
380 {
381         if (0 != __dbus_check()) {
382                 return VC_ERROR_OPERATION_FAILED;
383         }
384
385         DBusMessage* msg;
386
387         msg = dbus_message_new_method_call(
388                           VC_SERVER_SERVICE_NAME,
389                           VC_SERVER_SERVICE_OBJECT_PATH,
390                           VC_SERVER_SERVICE_INTERFACE,
391                           VC_METHOD_HELLO);
392
393         if (NULL == msg) {
394                 SLOG(LOG_ERROR, TAG_VCC, ">>>> Request vc hello : Fail to make message");
395                 return VC_ERROR_OPERATION_FAILED;
396         }
397
398         DBusError err;
399         dbus_error_init(&err);
400
401         DBusMessage* result_msg = NULL;
402         int result = 0;
403
404         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err);
405
406         if (dbus_error_is_set(&err)) {
407                 dbus_error_free(&err);
408         }
409
410         dbus_message_unref(msg);
411
412         if (NULL != result_msg) {
413                 dbus_message_unref(result_msg);
414                 result = 0;
415         } else {
416                 result = VC_ERROR_TIMED_OUT;
417         }
418
419         return result;
420 }
421
422
423 int vc_dbus_request_initialize(int pid, int* mgr_pid, int* service_state, int* daemon_pid)
424 {
425         if (0 != __dbus_check()) {
426                 return VC_ERROR_OPERATION_FAILED;
427         }
428
429         DBusMessage* msg;
430
431         msg = dbus_message_new_method_call(
432                           VC_SERVER_SERVICE_NAME,
433                           VC_SERVER_SERVICE_OBJECT_PATH,
434                           VC_SERVER_SERVICE_INTERFACE,
435                           VC_METHOD_INITIALIZE);
436
437         if (NULL == msg) {
438                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc initialize : Fail to make message ");
439                 return VC_ERROR_OPERATION_FAILED;
440         } else {
441                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc initialize : pid(%d)", pid);
442         }
443
444         dbus_message_append_args(msg,
445                         DBUS_TYPE_INT32, &pid,
446                         DBUS_TYPE_INVALID);
447
448         DBusError err;
449         dbus_error_init(&err);
450
451         DBusMessage* result_msg;
452         int result = VC_ERROR_OPERATION_FAILED;
453
454         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
455         dbus_message_unref(msg);
456
457         if (dbus_error_is_set(&err)) {
458                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
459                 dbus_error_free(&err);
460         }
461
462         if (NULL != result_msg) {
463                 int tmp = -1;
464                 int tmp_service_state = 0;
465                 int tmp_daemon_pid = 0;
466                 dbus_message_get_args(result_msg, &err,
467                         DBUS_TYPE_INT32, &result,
468                         DBUS_TYPE_INT32, &tmp,
469                         DBUS_TYPE_INT32, &tmp_service_state,
470                         DBUS_TYPE_INT32, &tmp_daemon_pid,
471                         DBUS_TYPE_INVALID);
472
473                 if (dbus_error_is_set(&err)) {
474                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
475                         dbus_error_free(&err);
476                         result = VC_ERROR_OPERATION_FAILED;
477                 }
478
479                 dbus_message_unref(result_msg);
480
481                 if (0 == result) {
482                         *mgr_pid = tmp;
483                         *service_state = tmp_service_state;
484                         *daemon_pid = tmp_daemon_pid;
485
486                         /* add a rule for daemon error */
487                         char rule_err[256] = {0, };
488                         snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE);
489                         dbus_bus_add_match(g_conn_listener, rule_err, &err);
490                         dbus_connection_flush(g_conn_listener);
491
492                         if (dbus_error_is_set(&err)) {
493                                 SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message);
494                                 dbus_error_free(&err);
495                                 return VC_ERROR_OPERATION_FAILED;
496                         }
497
498                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc initialize : result = %d mgr = %d service = %d daemon_pid = %d", result, *mgr_pid, *service_state, *daemon_pid);
499                 } else {
500                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc initialize : result = %d", result);
501                 }
502         } else {
503                 SLOG(LOG_ERROR, TAG_VCC, "<<<< Result message is NULL ");
504                 vc_dbus_reconnect();
505                 result = VC_ERROR_TIMED_OUT;
506         }
507
508         return result;
509 }
510
511 int vc_dbus_request_finalize(int pid)
512 {
513         DBusError err;
514         dbus_error_init(&err);
515
516         if (0 != __dbus_check()) {
517                 return VC_ERROR_OPERATION_FAILED;
518         }
519
520         /* remove a rule for daemon error */
521         char rule_err[256] = {0, };
522         snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE);
523         dbus_bus_remove_match(g_conn_listener, rule_err, &err);
524         dbus_connection_flush(g_conn_listener);
525
526         if (dbus_error_is_set(&err)) {
527                 SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message);
528                 dbus_error_free(&err);
529         }
530
531         DBusMessage* msg;
532
533         msg = dbus_message_new_method_call(
534                           VC_SERVER_SERVICE_NAME,
535                           VC_SERVER_SERVICE_OBJECT_PATH,
536                           VC_SERVER_SERVICE_INTERFACE,
537                           VC_METHOD_FINALIZE);
538
539         if (NULL == msg) {
540                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc finalize : Fail to make message ");
541                 return VC_ERROR_OPERATION_FAILED;
542         } else {
543                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc finalize : pid(%d)", pid);
544         }
545
546         dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
547
548         DBusMessage* result_msg;
549         int result = VC_ERROR_OPERATION_FAILED;
550
551         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
552         dbus_message_unref(msg);
553
554         if (dbus_error_is_set(&err)) {
555                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
556                 dbus_error_free(&err);
557         }
558
559         if (NULL != result_msg) {
560                 dbus_message_get_args(result_msg, &err,
561                                                           DBUS_TYPE_INT32, &result,
562                                                           DBUS_TYPE_INVALID);
563
564                 if (dbus_error_is_set(&err)) {
565                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
566                         dbus_error_free(&err);
567                         result = VC_ERROR_OPERATION_FAILED;
568                 }
569
570                 dbus_message_unref(result_msg);
571
572                 if (0 == result) {
573                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc finalize : result = %d", result);
574                 } else {
575                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc finalize : result = %d", result);
576                 }
577         } else {
578                 SLOG(LOG_ERROR, TAG_VCC, "<<<< Result message is NULL ");
579                 vc_dbus_reconnect();
580                 result = VC_ERROR_TIMED_OUT;
581         }
582
583         return result;
584 }
585
586 int vc_dbus_request_set_exclusive_command(int pid, bool value)
587 {
588         if (0 != __dbus_check()) {
589                 return VC_ERROR_OPERATION_FAILED;
590         }
591
592         DBusMessage* msg;
593
594         msg = dbus_message_new_method_call(
595                           VC_SERVER_SERVICE_NAME,
596                           VC_SERVER_SERVICE_OBJECT_PATH,
597                           VC_SERVER_SERVICE_INTERFACE,
598                           VC_METHOD_SET_EXCLUSIVE_CMD);
599
600         if (NULL == msg) {
601                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc set exclusive command : Fail to make message");
602                 return VC_ERROR_OPERATION_FAILED;
603         } else {
604                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc set exclusive command : pid(%d)", pid);
605         }
606
607         int temp = value;
608
609         dbus_message_append_args(msg,
610                                                          DBUS_TYPE_INT32, &pid,
611                                                          DBUS_TYPE_INT32, &temp,
612                                                          DBUS_TYPE_INVALID);
613
614         DBusError err;
615         dbus_error_init(&err);
616
617         DBusMessage* result_msg;
618         int result = VC_ERROR_OPERATION_FAILED;
619
620         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
621         dbus_message_unref(msg);
622
623         if (dbus_error_is_set(&err)) {
624                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
625                 dbus_error_free(&err);
626         }
627
628         if (NULL != result_msg) {
629                 dbus_message_get_args(result_msg, &err,
630                                                           DBUS_TYPE_INT32, &result,
631                                                           DBUS_TYPE_INVALID);
632
633                 if (dbus_error_is_set(&err)) {
634                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
635                         dbus_error_free(&err);
636                         result = VC_ERROR_OPERATION_FAILED;
637                 }
638                 dbus_message_unref(result_msg);
639
640                 if (0 == result) {
641                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc set exclusive command : result = %d", result);
642                 } else {
643                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc set exclusive command : result = %d", result);
644                 }
645         } else {
646                 SLOG(LOG_ERROR, TAG_VCC, "<<<< Result message is NULL");
647                 vc_dbus_reconnect();
648                 result = VC_ERROR_TIMED_OUT;
649         }
650
651         return result;
652 }
653
654 int vc_dbus_request_set_command(int pid, vc_cmd_type_e cmd_type)
655 {
656         if (0 != __dbus_check()) {
657                 return VC_ERROR_OPERATION_FAILED;
658         }
659
660         DBusMessage* msg;
661
662         msg = dbus_message_new_method_call(
663                           VC_SERVER_SERVICE_NAME,
664                           VC_SERVER_SERVICE_OBJECT_PATH,
665                           VC_SERVER_SERVICE_INTERFACE,
666                           VC_METHOD_SET_COMMAND);
667
668         if (NULL == msg) {
669                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc set command : Fail to make message");
670                 return VC_ERROR_OPERATION_FAILED;
671         } else {
672                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc set command : pid(%d)", pid);
673         }
674
675         dbus_message_append_args(msg,
676                                                          DBUS_TYPE_INT32, &pid,
677                                                          DBUS_TYPE_INT32, &cmd_type,
678                                                          DBUS_TYPE_INVALID);
679
680         DBusError err;
681         dbus_error_init(&err);
682
683         DBusMessage* result_msg;
684         int result = VC_ERROR_OPERATION_FAILED;
685
686         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
687         dbus_message_unref(msg);
688
689         if (dbus_error_is_set(&err)) {
690                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
691                 dbus_error_free(&err);
692         }
693
694         if (NULL != result_msg) {
695                 dbus_message_get_args(result_msg, &err,
696                                                           DBUS_TYPE_INT32, &result,
697                                                           DBUS_TYPE_INVALID);
698
699                 if (dbus_error_is_set(&err)) {
700                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
701                         dbus_error_free(&err);
702                         result = VC_ERROR_OPERATION_FAILED;
703                 }
704                 dbus_message_unref(result_msg);
705
706                 if (0 == result) {
707                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc set command : result = %d", result);
708                 } else {
709                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc set command : result = %d", result);
710                 }
711         } else {
712                 SLOG(LOG_ERROR, TAG_VCC, "<<<< Result message is NULL");
713                 vc_dbus_reconnect();
714                 result = VC_ERROR_TIMED_OUT;
715         }
716
717         return result;
718 }
719
720 int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type)
721 {
722         if (0 != __dbus_check()) {
723                 return VC_ERROR_OPERATION_FAILED;
724         }
725
726         DBusMessage* msg;
727
728         msg = dbus_message_new_method_call(
729                           VC_SERVER_SERVICE_NAME,
730                           VC_SERVER_SERVICE_OBJECT_PATH,
731                           VC_SERVER_SERVICE_INTERFACE,
732                           VC_METHOD_UNSET_COMMAND);
733
734         if (NULL == msg) {
735                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc unset command : Fail to make message");
736                 return VC_ERROR_OPERATION_FAILED;
737         } else {
738                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc unset command : pid(%d), type(%d)", pid, cmd_type);
739         }
740
741         dbus_message_append_args(msg,
742                                                          DBUS_TYPE_INT32, &pid,
743                                                          DBUS_TYPE_INT32, &cmd_type,
744                                                          DBUS_TYPE_INVALID);
745
746         DBusError err;
747         dbus_error_init(&err);
748
749         DBusMessage* result_msg;
750         int result = VC_ERROR_OPERATION_FAILED;
751
752         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
753         dbus_message_unref(msg);
754
755         if (dbus_error_is_set(&err)) {
756                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
757                 dbus_error_free(&err);
758         }
759
760         if (NULL != result_msg) {
761                 dbus_message_get_args(result_msg, &err,
762                                                           DBUS_TYPE_INT32, &result,
763                                                           DBUS_TYPE_INVALID);
764
765                 if (dbus_error_is_set(&err)) {
766                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
767                         dbus_error_free(&err);
768                         result = VC_ERROR_OPERATION_FAILED;
769                 }
770                 dbus_message_unref(result_msg);
771
772                 if (0 == result) {
773                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc unset command : result = %d", result);
774                 } else {
775                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc unset command : result = %d", result);
776                 }
777         } else {
778                 SLOG(LOG_ERROR, TAG_VCC, "<<<< Result message is NULL");
779                 vc_dbus_reconnect();
780                 result = VC_ERROR_TIMED_OUT;
781         }
782
783         return result;
784 }
785
786 int vc_dbus_set_foreground(int pid, bool value)
787 {
788         if (0 != __dbus_check()) {
789                 return VC_ERROR_OPERATION_FAILED;
790         }
791
792         DBusMessage* msg = NULL;
793         int tmp_value = 0;
794
795         tmp_value = (int)value;
796
797         msg = dbus_message_new_signal(
798                 VC_MANAGER_SERVICE_OBJECT_PATH,
799                 VC_MANAGER_SERVICE_INTERFACE,
800                 VCC_MANAGER_METHOD_SET_FOREGROUND);
801
802         if (NULL == msg) {
803                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc set foreground to manager : Fail to make message");
804                 return VC_ERROR_OPERATION_FAILED;
805         } else {
806                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc set foreground to manager : client pid(%d), value(%s)", pid, tmp_value ? "true" : "false");
807         }
808
809         dbus_message_append_args(msg,
810                 DBUS_TYPE_INT32, &pid,
811                 DBUS_TYPE_INT32, &tmp_value,
812                 DBUS_TYPE_INVALID);
813
814         if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
815                 SLOG(LOG_ERROR, TAG_VCC, "[Dbus ERROR] Fail to Send");
816                 return VC_ERROR_OPERATION_FAILED;
817         }
818
819         dbus_message_unref(msg);
820
821         msg = NULL;
822         msg = dbus_message_new_method_call(
823                 VC_SERVER_SERVICE_NAME,
824                 VC_SERVER_SERVICE_OBJECT_PATH,
825                 VC_SERVER_SERVICE_INTERFACE,
826                 VC_METHOD_SET_FOREGROUND);
827
828         if (NULL == msg) {
829                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc set foreground to daemon : Fail to make message");
830                 return VC_ERROR_OPERATION_FAILED;
831         } else {
832                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc set foreground to daemon : client pid(%d), value(%s)", pid, tmp_value ? "true" : "false");
833         }
834
835         dbus_message_append_args(msg,
836                 DBUS_TYPE_INT32, &pid,
837                 DBUS_TYPE_INT32, &tmp_value,
838                 DBUS_TYPE_INVALID);
839
840         dbus_message_set_no_reply(msg, TRUE);
841
842         if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
843                 SLOG(LOG_ERROR, TAG_VCC, "[Dbus ERROR] Fail to Send");
844                 return VC_ERROR_OPERATION_FAILED;
845         }
846
847         dbus_connection_flush(g_conn_sender);
848
849         dbus_message_unref(msg);
850
851         return 0;
852 }
853
854 int vc_dbus_request_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous)
855 {
856         if (NULL == g_conn_sender) {
857                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection");
858                 if (0 != vc_dbus_reconnect()) {
859                         SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect");
860                 }
861         }
862
863         DBusMessage* msg;
864         int tmp_continue = 0;
865
866         tmp_continue = (int)continuous;
867
868         msg = dbus_message_new_method_call(
869                 VC_SERVER_SERVICE_NAME,
870                 VC_SERVER_SERVICE_OBJECT_PATH,
871                 VC_SERVER_SERVICE_INTERFACE,
872                 VC_METHOD_DIALOG);
873
874         if (NULL == msg) {
875                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc request dialog to manager : Fail to make message");
876                 return VC_ERROR_OPERATION_FAILED;
877         } else {
878                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc request dialog to manager : client pid(%d), disp_text(%s), utt_text(%s), continuous(%d)", getpid(), disp_text, utt_text, continuous);
879         }
880
881         dbus_message_append_args(msg,
882                                 DBUS_TYPE_INT32, &pid,
883                                 DBUS_TYPE_STRING, &disp_text,
884                                 DBUS_TYPE_STRING, &utt_text,
885                                 DBUS_TYPE_INT32, &tmp_continue,
886                                 DBUS_TYPE_INVALID);
887
888         dbus_message_set_no_reply(msg, TRUE);
889
890         if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
891                 SLOG(LOG_ERROR, TAG_VCC, "[Dbus ERROR] Fail to Send");
892                 return VC_ERROR_OPERATION_FAILED;
893         } else {
894                 SLOG(LOG_DEBUG, TAG_VCC, "[Dbus DEBUG] Success to Send");
895                 dbus_connection_flush(g_conn_sender);
896         }
897
898         dbus_message_unref(msg);
899
900         return 0;
901
902 /*
903         DBusError err;
904         dbus_error_init(&err);
905
906         DBusMessage* result_msg;
907         int result = VC_ERROR_OPERATION_FAILED;
908
909         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
910         dbus_message_unref(msg);
911
912         if (dbus_error_is_set(&err)) {
913                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
914                 dbus_error_free(&err);
915         }
916
917         if (NULL != result_msg) {
918                 dbus_message_get_args(result_msg, &err,
919                                         DBUS_TYPE_INT32, &result,
920                                         DBUS_TYPE_INVALID);
921
922                 if (dbus_error_is_set(&err)) {
923                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
924                         dbus_error_free(&err);
925                         result = VC_ERROR_OPERATION_FAILED;
926                 }
927                 dbus_message_unref(result_msg);
928
929                 if (0 == result) {
930                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc set command : result = %d", result);
931                 } else {
932                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc set command : result = %d", result);
933                 }
934         } else {
935                 SLOG(LOG_ERROR, TAG_VCC, "<<<< Result message is NULL");
936                 vc_dbus_reconnect();
937                 result = VC_ERROR_TIMED_OUT;
938         }
939
940         return result;
941 */
942 }
943
944 int vc_dbus_request_is_system_command_valid(int pid, bool* is_sys_cmd_valid)
945 {
946         if (NULL == g_conn_sender) {
947                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection");
948                 if (0 != vc_dbus_reconnect()) {
949                         SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect");
950                 }
951         }
952
953         DBusMessage* msg;
954
955         msg = dbus_message_new_method_call(
956                           VC_SERVER_SERVICE_NAME,
957                           VC_SERVER_SERVICE_OBJECT_PATH,
958                           VC_SERVER_SERVICE_INTERFACE,
959                           VC_METHOD_IS_SYS_COMMAND_VALID);
960
961         if (NULL == msg) {
962                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc is system command valid : Fail to make message");
963                 return VC_ERROR_OPERATION_FAILED;
964         } else {
965                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc is system command valid : pid(%d)", pid);
966         }
967
968         dbus_message_append_args(msg,
969                                 DBUS_TYPE_INT32, &pid,
970                                 DBUS_TYPE_INVALID);
971
972         DBusError err;
973         dbus_error_init(&err);
974         int tmp_sys_cmd = 0;
975
976         DBusMessage* result_msg;
977         int result = VC_ERROR_OPERATION_FAILED;
978
979         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
980         dbus_message_unref(msg);
981
982         if (dbus_error_is_set(&err)) {
983                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
984                 dbus_error_free(&err);
985         }
986
987         if (NULL != result_msg) {
988                 dbus_message_get_args(result_msg, &err,
989                                         DBUS_TYPE_INT32, &result,
990                                         DBUS_TYPE_INT32, &tmp_sys_cmd,
991                                         DBUS_TYPE_INVALID);
992
993                 if (dbus_error_is_set(&err)) {
994                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
995                         dbus_error_free(&err);
996                         result = VC_ERROR_OPERATION_FAILED;
997                 }
998                 dbus_message_unref(result_msg);
999
1000                 if (0 == result) {
1001                         *is_sys_cmd_valid = (bool)tmp_sys_cmd;
1002                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc is system command valid : result = %d, is_sys_cmd_valid = %d", result, *is_sys_cmd_valid);
1003                 } else {
1004                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc is system command valid : result = %d", result);
1005                 }
1006         } else {
1007                 SLOG(LOG_ERROR, TAG_VCC, "<<<< Result message is NULL");
1008                 vc_dbus_reconnect();
1009                 result = VC_ERROR_TIMED_OUT;
1010         }
1011
1012         return result;
1013 }
1014
1015
1016 #if 0
1017 int vc_dbus_request_start(int pid, int silence)
1018 {
1019         DBusMessage* msg;
1020
1021         /* create a signal & check for errors */
1022         msg = dbus_message_new_method_call(
1023                           VC_SERVER_SERVICE_NAME,
1024                           VC_SERVER_SERVICE_OBJECT_PATH,
1025                           VC_SERVER_SERVICE_INTERFACE,
1026                           VC_METHOD_REQUEST_START);
1027
1028         if (NULL == msg) {
1029                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc start : Fail to make message ");
1030                 return VC_ERROR_OPERATION_FAILED;
1031         } else {
1032                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc start : pid(%d), silence(%d)", pid, silence);
1033         }
1034
1035         DBusMessageIter args;
1036         dbus_message_iter_init_append(msg, &args);
1037
1038         /* Append result*/
1039         dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(pid));
1040         dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(silence));
1041
1042         DBusError err;
1043         dbus_error_init(&err);
1044
1045         DBusMessage* result_msg;
1046         int result = VC_ERROR_OPERATION_FAILED;
1047
1048         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
1049         dbus_message_unref(msg);
1050
1051         if (dbus_error_is_set(&err)) {
1052                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
1053                 dbus_error_free(&err);
1054         }
1055
1056         if (NULL != result_msg) {
1057                 dbus_message_get_args(result_msg, &err,
1058                                                           DBUS_TYPE_INT32, &result,
1059                                                           DBUS_TYPE_INVALID);
1060
1061                 if (dbus_error_is_set(&err)) {
1062                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
1063                         dbus_error_free(&err);
1064                         result = VC_ERROR_OPERATION_FAILED;
1065                 }
1066                 dbus_message_unref(result_msg);
1067
1068                 if (0 == result) {
1069                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc start : result = %d", result);
1070                 } else {
1071                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc start : result = %d", result);
1072                 }
1073         } else {
1074                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< Result Message is NULL");
1075                 vc_dbus_reconnect();
1076                 result = VC_ERROR_TIMED_OUT;
1077         }
1078
1079         return result;
1080 }
1081
1082 int vc_dbus_request_stop(int pid)
1083 {
1084         DBusMessage* msg;
1085
1086         /* create a signal & check for errors */
1087         msg = dbus_message_new_method_call(
1088                           VC_SERVER_SERVICE_NAME,
1089                           VC_SERVER_SERVICE_OBJECT_PATH,
1090                           VC_SERVER_SERVICE_INTERFACE,
1091                           VC_METHOD_REQUEST_STOP);
1092
1093         if (NULL == msg) {
1094                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc stop : Fail to make message ");
1095                 return VC_ERROR_OPERATION_FAILED;
1096         } else {
1097                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc stop : pid(%d)", pid);
1098         }
1099
1100         dbus_message_append_args(msg,
1101                                                          DBUS_TYPE_INT32, &pid,
1102                                                          DBUS_TYPE_INVALID);
1103
1104         DBusError err;
1105         dbus_error_init(&err);
1106
1107         DBusMessage* result_msg;
1108         int result = VC_ERROR_OPERATION_FAILED;
1109
1110         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
1111         dbus_message_unref(msg);
1112
1113         if (dbus_error_is_set(&err)) {
1114                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
1115                 dbus_error_free(&err);
1116         }
1117
1118         if (NULL != result_msg) {
1119                 dbus_message_get_args(result_msg, &err,
1120                                                           DBUS_TYPE_INT32, &result,
1121                                                           DBUS_TYPE_INVALID);
1122
1123                 if (dbus_error_is_set(&err)) {
1124                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
1125                         dbus_error_free(&err);
1126                         result = VC_ERROR_OPERATION_FAILED;
1127                 }
1128                 dbus_message_unref(result_msg);
1129
1130                 if (0 == result) {
1131                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc stop : result = %d", result);
1132                 } else {
1133                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc stop : result = %d", result);
1134                 }
1135         } else {
1136                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< Result Message is NULL");
1137                 vc_dbus_reconnect();
1138                 result = VC_ERROR_TIMED_OUT;
1139         }
1140
1141         return result;
1142 }
1143
1144 int vc_dbus_request_cancel(int pid)
1145 {
1146         DBusMessage* msg;
1147
1148         /* create a signal & check for errors */
1149         msg = dbus_message_new_method_call(
1150                           VC_SERVER_SERVICE_NAME,
1151                           VC_SERVER_SERVICE_OBJECT_PATH,        /* object name of the signal */
1152                           VC_SERVER_SERVICE_INTERFACE,  /* interface name of the signal */
1153                           VC_METHOD_REQUEST_CANCEL);    /* name of the signal */
1154
1155         if (NULL == msg) {
1156                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc cancel : Fail to make message ");
1157                 return VC_ERROR_OPERATION_FAILED;
1158         } else {
1159                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc cancel : pid(%d)", pid);
1160         }
1161
1162         dbus_message_append_args(msg,
1163                                                          DBUS_TYPE_INT32, &pid,
1164                                                          DBUS_TYPE_INVALID);
1165
1166         DBusError err;
1167         dbus_error_init(&err);
1168
1169         DBusMessage* result_msg;
1170         int result = VC_ERROR_OPERATION_FAILED;
1171
1172         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
1173         dbus_message_unref(msg);
1174
1175         if (dbus_error_is_set(&err)) {
1176                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
1177                 dbus_error_free(&err);
1178         }
1179
1180         if (NULL != result_msg) {
1181                 dbus_message_get_args(result_msg, &err,
1182                                                           DBUS_TYPE_INT32, &result,
1183                                                           DBUS_TYPE_INVALID);
1184
1185                 if (dbus_error_is_set(&err)) {
1186                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
1187                         dbus_error_free(&err);
1188                         result = VC_ERROR_OPERATION_FAILED;
1189                 }
1190                 dbus_message_unref(result_msg);
1191
1192                 if (0 == result) {
1193                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc cancel : result = %d", result);
1194                 } else {
1195                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc cancel : result = %d", result);
1196                 }
1197         } else {
1198                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< Result Message is NULL");
1199                 vc_dbus_reconnect();
1200                 result = VC_ERROR_TIMED_OUT;
1201         }
1202
1203         return result;
1204 }
1205 #endif
1206
1207 /* Authority */
1208 int vc_dbus_request_auth_enable(int pid, int mgr_pid)
1209 {
1210         if (0 != __dbus_check()) {
1211                 return VC_ERROR_OPERATION_FAILED;
1212         }
1213
1214         DBusMessage* msg;
1215
1216         char service_name[64] = {0,};
1217         char object_path[64] = {0,};
1218         char target_if_name[128] = {0,};
1219
1220         snprintf(service_name, 64, "%s%d", VC_MANAGER_SERVICE_NAME, mgr_pid);
1221         snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH);
1222         snprintf(target_if_name, 128, "%s%d", VC_MANAGER_SERVICE_INTERFACE, mgr_pid);
1223
1224         /* create a signal & check for errors */
1225         msg = dbus_message_new_method_call(
1226                           service_name,
1227                           object_path,  /* object name of the signal */
1228                           target_if_name,       /* interface name of the signal */
1229                           VC_METHOD_AUTH_ENABLE);       /* name of the signal */
1230
1231         if (NULL == msg) {
1232                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc auth enable : Fail to make message ");
1233                 return VC_ERROR_OPERATION_FAILED;
1234         } else {
1235                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc auth enable : pid(%d)", pid);
1236         }
1237
1238         dbus_message_append_args(msg,
1239                                                          DBUS_TYPE_INT32, &pid,
1240                                                          DBUS_TYPE_INVALID);
1241
1242         DBusError err;
1243         dbus_error_init(&err);
1244
1245         DBusMessage* result_msg;
1246         int result = VC_ERROR_OPERATION_FAILED;
1247
1248         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
1249         dbus_message_unref(msg);
1250
1251         if (dbus_error_is_set(&err)) {
1252                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
1253                 dbus_error_free(&err);
1254         }
1255
1256         if (NULL != result_msg) {
1257                 dbus_message_get_args(result_msg, &err,
1258                                                           DBUS_TYPE_INT32, &result,
1259                                                           DBUS_TYPE_INVALID);
1260
1261                 if (dbus_error_is_set(&err)) {
1262                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
1263                         dbus_error_free(&err);
1264                         result = VC_ERROR_OPERATION_FAILED;
1265                 }
1266                 dbus_message_unref(result_msg);
1267
1268                 if (0 == result) {
1269                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc auth enable : result = %d", result);
1270                 } else {
1271                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc auth enable : result = %d", result);
1272                 }
1273         } else {
1274                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< Result Message is NULL");
1275                 vc_dbus_reconnect();
1276                 result = VC_ERROR_TIMED_OUT;
1277         }
1278
1279         return result;
1280 }
1281
1282 int vc_dbus_request_auth_disable(int pid, int mgr_pid)
1283 {
1284         if (0 != __dbus_check()) {
1285                 return VC_ERROR_OPERATION_FAILED;
1286         }
1287
1288         DBusMessage* msg;
1289
1290         char service_name[64] = {0,};
1291         char object_path[64] = {0,};
1292         char target_if_name[128] = {0,};
1293
1294         snprintf(service_name, 64, "%s%d", VC_MANAGER_SERVICE_NAME, mgr_pid);
1295         snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH);
1296         snprintf(target_if_name, 128, "%s%d", VC_MANAGER_SERVICE_INTERFACE, mgr_pid);
1297
1298         /* create a signal & check for errors */
1299         msg = dbus_message_new_method_call(
1300                           service_name,
1301                           object_path,  /* object name of the signal */
1302                           target_if_name,       /* interface name of the signal */
1303                           VC_METHOD_AUTH_DISABLE);      /* name of the signal */
1304
1305         if (NULL == msg) {
1306                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc auth disable : Fail to make message ");
1307                 return VC_ERROR_OPERATION_FAILED;
1308         } else {
1309                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc auth disable : pid(%d)", pid);
1310         }
1311
1312         dbus_message_append_args(msg,
1313                                                          DBUS_TYPE_INT32, &pid,
1314                                                          DBUS_TYPE_INVALID);
1315
1316         DBusError err;
1317         dbus_error_init(&err);
1318
1319         DBusMessage* result_msg;
1320         int result = VC_ERROR_OPERATION_FAILED;
1321
1322         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
1323         dbus_message_unref(msg);
1324
1325         if (dbus_error_is_set(&err)) {
1326                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
1327                 dbus_error_free(&err);
1328         }
1329
1330         if (NULL != result_msg) {
1331                 dbus_message_get_args(result_msg, &err,
1332                                                           DBUS_TYPE_INT32, &result,
1333                                                           DBUS_TYPE_INVALID);
1334
1335                 if (dbus_error_is_set(&err)) {
1336                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
1337                         dbus_error_free(&err);
1338                         result = VC_ERROR_OPERATION_FAILED;
1339                 }
1340                 dbus_message_unref(result_msg);
1341
1342                 if (0 == result) {
1343                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc auth disable : result = %d", result);
1344                 } else {
1345                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc auth disable : result = %d", result);
1346                 }
1347         } else {
1348                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< Result Message is NULL");
1349                 vc_dbus_reconnect();
1350                 result = VC_ERROR_TIMED_OUT;
1351         }
1352
1353         return result;
1354 }
1355
1356 int vc_dbus_request_auth_start(int pid, int mgr_pid)
1357 {
1358         if (0 != __dbus_check()) {
1359                 return VC_ERROR_OPERATION_FAILED;
1360         }
1361
1362         DBusMessage* msg;
1363
1364         char service_name[64] = {0,};
1365         char object_path[64] = {0,};
1366         char target_if_name[128] = {0,};
1367
1368         snprintf(service_name, 64, "%s%d", VC_MANAGER_SERVICE_NAME, mgr_pid);
1369         snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH);
1370         snprintf(target_if_name, 128, "%s%d", VC_MANAGER_SERVICE_INTERFACE, mgr_pid);
1371
1372         /* create a signal & check for errors */
1373         msg = dbus_message_new_method_call(
1374                           service_name,
1375                           object_path,
1376                           target_if_name,
1377                           VC_METHOD_AUTH_START);
1378
1379         if (NULL == msg) {
1380                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc auth start : Fail to make message ");
1381                 return VC_ERROR_OPERATION_FAILED;
1382         } else {
1383                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc auth start : pid(%d)", pid);
1384         }
1385
1386         DBusMessageIter args;
1387         dbus_message_iter_init_append(msg, &args);
1388
1389         /* Append result*/
1390         dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(pid));
1391
1392         DBusError err;
1393         dbus_error_init(&err);
1394
1395         DBusMessage* result_msg;
1396         int result = VC_ERROR_OPERATION_FAILED;
1397
1398         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
1399         dbus_message_unref(msg);
1400
1401         if (dbus_error_is_set(&err)) {
1402                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
1403                 dbus_error_free(&err);
1404         }
1405
1406         if (NULL != result_msg) {
1407                 dbus_message_get_args(result_msg, &err,
1408                                                           DBUS_TYPE_INT32, &result,
1409                                                           DBUS_TYPE_INVALID);
1410
1411                 if (dbus_error_is_set(&err)) {
1412                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
1413                         dbus_error_free(&err);
1414                         result = VC_ERROR_OPERATION_FAILED;
1415                 }
1416                 dbus_message_unref(result_msg);
1417
1418                 if (0 == result) {
1419                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc auth start : result = %d", result);
1420                 } else {
1421                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc auth start : result = %d", result);
1422                 }
1423         } else {
1424                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< Result Message is NULL");
1425                 vc_dbus_reconnect();
1426                 result = VC_ERROR_TIMED_OUT;
1427         }
1428
1429         return result;
1430 }
1431
1432 int vc_dbus_request_auth_stop(int pid, int mgr_pid)
1433 {
1434         if (0 != __dbus_check()) {
1435                 return VC_ERROR_OPERATION_FAILED;
1436         }
1437
1438         DBusMessage* msg;
1439
1440         char service_name[64] = {0,};
1441         char object_path[64] = {0,};
1442         char target_if_name[128] = {0,};
1443
1444         snprintf(service_name, 64, "%s%d", VC_MANAGER_SERVICE_NAME, mgr_pid);
1445         snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH);
1446         snprintf(target_if_name, 128, "%s%d", VC_MANAGER_SERVICE_INTERFACE, mgr_pid);
1447
1448         /* create a signal & check for errors */
1449         msg = dbus_message_new_method_call(
1450                           service_name,
1451                           object_path,
1452                           target_if_name,
1453                           VC_METHOD_AUTH_STOP);
1454
1455         if (NULL == msg) {
1456                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc auth stop : Fail to make message ");
1457                 return VC_ERROR_OPERATION_FAILED;
1458         } else {
1459                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc auth stop : pid(%d)", pid);
1460         }
1461
1462         dbus_message_append_args(msg,
1463                                                          DBUS_TYPE_INT32, &pid,
1464                                                          DBUS_TYPE_INVALID);
1465
1466         DBusError err;
1467         dbus_error_init(&err);
1468
1469         DBusMessage* result_msg;
1470         int result = VC_ERROR_OPERATION_FAILED;
1471
1472         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
1473         dbus_message_unref(msg);
1474
1475         if (dbus_error_is_set(&err)) {
1476                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
1477                 dbus_error_free(&err);
1478         }
1479
1480         if (NULL != result_msg) {
1481                 dbus_message_get_args(result_msg, &err,
1482                                                           DBUS_TYPE_INT32, &result,
1483                                                           DBUS_TYPE_INVALID);
1484
1485                 if (dbus_error_is_set(&err)) {
1486                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
1487                         dbus_error_free(&err);
1488                         result = VC_ERROR_OPERATION_FAILED;
1489                 }
1490                 dbus_message_unref(result_msg);
1491
1492                 if (0 == result) {
1493                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc auth stop : result = %d", result);
1494                 } else {
1495                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc auth stop : result = %d", result);
1496                 }
1497         } else {
1498                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< Result Message is NULL");
1499                 vc_dbus_reconnect();
1500                 result = VC_ERROR_TIMED_OUT;
1501         }
1502
1503         return result;
1504 }
1505
1506 int vc_dbus_request_auth_cancel(int pid, int mgr_pid)
1507 {
1508         if (0 != __dbus_check()) {
1509                 return VC_ERROR_OPERATION_FAILED;
1510         }
1511
1512         DBusMessage* msg;
1513
1514         char service_name[64] = {0,};
1515         char object_path[64] = {0,};
1516         char target_if_name[128] = {0,};
1517
1518         snprintf(service_name, 64, "%s%d", VC_MANAGER_SERVICE_NAME, mgr_pid);
1519         snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH);
1520         snprintf(target_if_name, 128, "%s%d", VC_MANAGER_SERVICE_INTERFACE, mgr_pid);
1521
1522         /* create a signal & check for errors */
1523         msg = dbus_message_new_method_call(
1524                           service_name,
1525                           object_path,  /* object name of the signal */
1526                           target_if_name,       /* interface name of the signal */
1527                           VC_METHOD_AUTH_CANCEL);       /* name of the signal */
1528
1529         if (NULL == msg) {
1530                 SLOG(LOG_ERROR, TAG_VCC, ">>>> vc auth cancel : Fail to make message ");
1531                 return VC_ERROR_OPERATION_FAILED;
1532         } else {
1533                 SLOG(LOG_DEBUG, TAG_VCC, ">>>> vc auth cancel : pid(%d)", pid);
1534         }
1535
1536         dbus_message_append_args(msg,
1537                                                          DBUS_TYPE_INT32, &pid,
1538                                                          DBUS_TYPE_INVALID);
1539
1540         DBusError err;
1541         dbus_error_init(&err);
1542
1543         DBusMessage* result_msg;
1544         int result = VC_ERROR_OPERATION_FAILED;
1545
1546         result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
1547         dbus_message_unref(msg);
1548
1549         if (dbus_error_is_set(&err)) {
1550                 SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Dbus Error (%s)", err.message);
1551                 dbus_error_free(&err);
1552         }
1553
1554         if (NULL != result_msg) {
1555                 dbus_message_get_args(result_msg, &err,
1556                                                           DBUS_TYPE_INT32, &result,
1557                                                           DBUS_TYPE_INVALID);
1558
1559                 if (dbus_error_is_set(&err)) {
1560                         SLOG(LOG_ERROR, TAG_VCC, "<<<< Get arguments error (%s)", err.message);
1561                         dbus_error_free(&err);
1562                         result = VC_ERROR_OPERATION_FAILED;
1563                 }
1564                 dbus_message_unref(result_msg);
1565
1566                 if (0 == result) {
1567                         SLOG(LOG_DEBUG, TAG_VCC, "<<<< vc auth cancel : result = %d", result);
1568                 } else {
1569                         SLOG(LOG_ERROR, TAG_VCC, "<<<< vc auth cancel : result = %d", result);
1570                 }
1571         } else {
1572                 SLOG(LOG_DEBUG, TAG_VCC, "<<<< Result Message is NULL");
1573                 vc_dbus_reconnect();
1574                 result = VC_ERROR_TIMED_OUT;
1575         }
1576
1577         return result;
1578 }