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