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