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