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