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