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