Init commit from tizen 2.4
[platform/core/uifw/voice-control.git] / client / vc_widget_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_main.h"
19 #include "vc_widget_client.h"
20 #include "vc_widget_dbus.h"
21
22
23 static int g_w_waiting_time = 3000;
24
25 static Ecore_Fd_Handler* g_w_fd_handler = NULL;
26
27 static DBusConnection* g_w_conn = NULL;
28
29
30 extern int __vc_widget_cb_error(int pid, int reason);
31
32 extern void __vc_widget_cb_show_tooltip(int pid, bool show);
33
34 extern void __vc_widget_cb_result();
35
36
37 static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
38 {
39         DBusConnection* conn = (DBusConnection*)data;
40         DBusMessage* msg = NULL;
41         DBusMessage *reply = NULL;
42
43         if (NULL == conn)
44                 return ECORE_CALLBACK_RENEW;
45
46         dbus_connection_read_write_dispatch(conn, 50);
47
48         msg = dbus_connection_pop_message(conn);
49
50         /* loop again if we haven't read a message */
51         if (NULL == msg) { 
52                 return ECORE_CALLBACK_RENEW;
53         }
54
55         DBusError err;
56         dbus_error_init(&err);
57
58         char if_name[64];
59         snprintf(if_name, 64, "%s%d", VC_WIDGET_SERVICE_INTERFACE, getpid());
60
61         if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_HELLO)) {
62                 SLOG(LOG_DEBUG, TAG_VCW, "===== Get widget hello");
63                 int pid = 0;
64                 int response = -1;
65
66                 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
67                 
68                 if (dbus_error_is_set(&err)) {
69                         SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
70                         dbus_error_free(&err);
71                 }
72
73                 if (pid > 0) {
74                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget get hello : pid(%d) ", pid);
75                         response = 1;
76                 } else {
77                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget get hello : invalid pid ");
78                 }
79
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(conn, reply, NULL))
86                                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget get hello : fail to send reply");
87                         else 
88                                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget get hello : result(%d)", response);
89
90                         dbus_connection_flush(conn);
91                         dbus_message_unref(reply); 
92                 } else {
93                         SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget get hello : fail to create reply message");
94                 }
95                 
96                 SLOG(LOG_DEBUG, TAG_VCW, "=====");
97                 SLOG(LOG_DEBUG, TAG_VCW, " ");
98         } /* VCD_WIDGET_METHOD_HELLO */
99
100         else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_SHOW_TOOLTIP)) {
101                 SLOG(LOG_DEBUG, TAG_VCW, "===== Show / Hide tooltip");
102                 int pid = 0;
103                 int show = 0;
104
105                 dbus_message_get_args(msg, &err, 
106                         DBUS_TYPE_INT32, &pid, 
107                         DBUS_TYPE_INT32, &show,
108                         DBUS_TYPE_INVALID);
109
110                 if (dbus_error_is_set(&err)) {
111                         SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
112                         dbus_error_free(&err);
113                 }
114
115                 if (pid > 0) {
116                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget show tooltip : pid(%d), show(%d)", pid, show);
117
118                         __vc_widget_cb_show_tooltip(pid, (bool)show);
119                 } else {
120                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget show tooltip : invalid pid");
121                 }
122
123                 /*
124                 reply = dbus_message_new_method_return(msg);
125
126                 if (NULL != reply) {
127                         if (!dbus_connection_send(conn, reply, NULL))
128                                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget show tooltip : fail to send reply");
129                         else 
130                                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget show tooltip");
131
132                         dbus_connection_flush(conn);
133                         dbus_message_unref(reply); 
134                 } else {
135                         SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget show tooltip : fail to create reply message");
136                 }
137                 */
138
139                 SLOG(LOG_DEBUG, TAG_VCW, "=====");
140                 SLOG(LOG_DEBUG, TAG_VCW, " ");
141         } /* VCD_WIDGET_METHOD_SHOW_TOOLTIP */
142
143         else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_RESULT)) {
144                 SLOG(LOG_DEBUG, TAG_VCW, "===== Get widget result");
145
146                 __vc_widget_cb_result();
147
148                 /*
149                 reply = dbus_message_new_method_return(msg);
150
151                 if (NULL != reply) {
152                         if (!dbus_connection_send(conn, reply, NULL))
153                                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget get result : fail to send reply");
154                         else 
155                                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget get result");
156
157                         dbus_connection_flush(conn);
158                         dbus_message_unref(reply); 
159                 } else {
160                         SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget get result : fail to create reply message");
161                 
162                 */
163
164                 SLOG(LOG_DEBUG, TAG_VCW, "=====");
165                 SLOG(LOG_DEBUG, TAG_VCW, " ");
166
167         } /* VCD_WIDGET_METHOD_RESULT */
168
169         else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_ERROR)) {
170                 SLOG(LOG_DEBUG, TAG_VCW, "===== Get widget error");
171                 int pid;
172                 int reason;
173                 char* err_msg;
174
175                 dbus_message_get_args(msg, &err,
176                         DBUS_TYPE_INT32, &pid,
177                         DBUS_TYPE_INT32, &reason,
178                         DBUS_TYPE_STRING, &err_msg,
179                         DBUS_TYPE_INVALID);
180
181                 if (dbus_error_is_set(&err)) { 
182                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget get error message : Get arguments error (%s)", err.message);
183                         dbus_error_free(&err); 
184                 } else {
185                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget get error message : pid(%d), reason(%d), msg(%s)", pid, reason, err_msg);
186                         __vc_widget_cb_error(pid, reason);
187                 }
188
189                 /*
190                 reply = dbus_message_new_method_return(msg);
191
192                 if (NULL != reply) {
193                         if (!dbus_connection_send(conn, reply, NULL))
194                                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget error message : fail to send reply");
195                         else 
196                                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget error message");
197
198                         dbus_connection_flush(conn);
199                         dbus_message_unref(reply); 
200                 } else {
201                         SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget error message : fail to create reply message");
202                 }
203                 */
204
205                 SLOG(LOG_DEBUG, TAG_VCW, "=====");
206                 SLOG(LOG_DEBUG, TAG_VCW, " ");
207         } /* VCD_WIDGET_METHOD_ERROR */
208
209         /* free the message */
210         dbus_message_unref(msg);
211
212         return ECORE_CALLBACK_PASS_ON;
213 }
214
215 int vc_widget_dbus_open_connection()
216 {
217         if (NULL != g_w_conn) {
218                 SLOG(LOG_WARN, TAG_VCW, "Already existed connection ");
219                 return 0;
220         }
221
222         DBusError err;
223         int ret;
224
225         /* initialise the error value */
226         dbus_error_init(&err);
227
228         /* connect to the DBUS system bus, and check for errors */
229         g_w_conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
230
231         if (dbus_error_is_set(&err)) { 
232                 SLOG(LOG_ERROR, TAG_VCW, "Dbus Connection Error (%s)", err.message); 
233                 dbus_error_free(&err); 
234         }
235
236         if (NULL == g_w_conn) {
237                 SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection ");
238                 return VC_ERROR_OPERATION_FAILED; 
239         }
240
241         int pid = getpid();
242
243         char service_name[64];
244         memset(service_name, '\0', 64);
245         snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid);
246
247         SLOG(LOG_DEBUG, TAG_VCW, "service name is %s", service_name);
248
249         /* register our name on the bus, and check for errors */
250         ret = dbus_bus_request_name(g_w_conn, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
251
252         if (dbus_error_is_set(&err)) {
253                 SLOG(LOG_ERROR, TAG_VCW, "Name Error (%s)", err.message); 
254                 dbus_error_free(&err); 
255         }
256
257         if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
258                 SLOG(LOG_ERROR, TAG_VCW, "fail dbus_bus_request_name()");
259                 return -2;
260         }
261
262         if( NULL != g_w_fd_handler ) {
263                 SLOG(LOG_WARN, TAG_VCW, "The handler already exists.");
264                 return 0;
265         }
266
267         char rule[128];
268         snprintf(rule, 128, "type='signal',interface='%s%d'", VC_WIDGET_SERVICE_INTERFACE, pid);
269
270         /* add a rule for which messages we want to see */
271         dbus_bus_add_match(g_w_conn, rule, &err); 
272         dbus_connection_flush(g_w_conn);
273
274         if (dbus_error_is_set(&err)) 
275         { 
276                 SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message);
277                 dbus_error_free(&err);
278                 return VC_ERROR_OPERATION_FAILED; 
279         }
280
281         int fd = 0;
282         if (1 != dbus_connection_get_unix_fd(g_w_conn, &fd)) {
283                 SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus ");
284                 return VC_ERROR_OPERATION_FAILED;
285         } else {
286                 SLOG(LOG_DEBUG, TAG_VCW, "Get fd from dbus : %d", fd);
287         }
288
289         g_w_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)widget_listener_event_callback, g_w_conn, NULL, NULL);
290
291         if (NULL == g_w_fd_handler) {
292                 SLOG(LOG_ERROR, TAG_VCW, "fail to get fd handler from ecore ");
293                 return VC_ERROR_OPERATION_FAILED;
294         }
295
296         return 0;
297 }
298
299 int vc_widget_dbus_close_connection()
300 {
301         DBusError err;
302         dbus_error_init(&err);
303
304         int pid = getpid();
305
306         char service_name[64];
307         memset(service_name, '\0', 64);
308         snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid);
309
310         dbus_bus_release_name (g_w_conn, service_name, &err);
311
312         if (dbus_error_is_set(&err)) {
313                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
314                 dbus_error_free(&err);
315         }
316
317         dbus_connection_close(g_w_conn);
318
319         g_w_fd_handler = NULL;
320         g_w_conn = NULL;
321
322         return 0;
323 }
324
325 int vc_widget_dbus_reconnect()
326 {
327         bool connected = dbus_connection_get_is_connected(g_w_conn);
328         SECURE_SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] %s", connected ? "Connected" : "Not connected");
329
330         if (false == connected) {
331                 vc_widget_dbus_close_connection();
332
333                 if (0 != vc_widget_dbus_open_connection()) {
334                         SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to reconnect");
335                         return -1;
336                 }
337
338                 SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Reconnect");
339         }
340         return 0;
341 }
342
343 int vc_widget_dbus_request_hello()
344 {
345         DBusMessage* msg;
346
347         msg = dbus_message_new_method_call(
348                 VC_SERVER_SERVICE_NAME, 
349                 VC_SERVER_SERVICE_OBJECT_PATH, 
350                 VC_SERVER_SERVICE_INTERFACE, 
351                 VC_METHOD_HELLO);
352
353         if (NULL == msg) { 
354                 SLOG(LOG_ERROR, TAG_VCW, ">>>> Request vc hello : Fail to make message"); 
355                 return VC_ERROR_OPERATION_FAILED;
356         } 
357
358         DBusError err;
359         dbus_error_init(&err);
360
361         DBusMessage* result_msg = NULL;
362         int result = 0;
363
364         result_msg = dbus_connection_send_with_reply_and_block(g_w_conn, msg, 500, &err);
365
366         if (dbus_error_is_set(&err)) {
367                 dbus_error_free(&err);
368         }
369
370         dbus_message_unref(msg);
371
372         if (NULL != result_msg) {
373                 dbus_message_unref(result_msg);
374                 result = 0;
375         } else {
376                 result = VC_ERROR_TIMED_OUT;
377         }
378
379         return result;
380 }
381
382
383 int vc_widget_dbus_request_initialize(int pid)
384 {
385         DBusMessage* msg;
386
387         msg = dbus_message_new_method_call(
388                 VC_SERVER_SERVICE_NAME, 
389                 VC_SERVER_SERVICE_OBJECT_PATH, 
390                 VC_SERVER_SERVICE_INTERFACE, 
391                 VC_WIDGET_METHOD_INITIALIZE);
392
393         if (NULL == msg) { 
394                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget initialize : Fail to make message "); 
395                 return VC_ERROR_OPERATION_FAILED;
396         } else {
397                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget initialize : pid(%d)", pid);
398         }
399
400         dbus_message_append_args( msg, 
401                 DBUS_TYPE_INT32, &pid,
402                 DBUS_TYPE_INVALID);
403
404         DBusError err;
405         dbus_error_init(&err);
406
407         DBusMessage* result_msg;
408         int result = VC_ERROR_OPERATION_FAILED;
409
410         result_msg = dbus_connection_send_with_reply_and_block(g_w_conn, msg, g_w_waiting_time, &err);
411         dbus_message_unref(msg);
412
413         if (dbus_error_is_set(&err)) {
414                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
415                 dbus_error_free(&err);
416         }
417
418         if (NULL != result_msg) {
419                 dbus_message_get_args(result_msg, &err, 
420                         DBUS_TYPE_INT32, &result, 
421                         DBUS_TYPE_INVALID);
422
423                 if (dbus_error_is_set(&err)) { 
424                         SLOG(LOG_ERROR, TAG_VCW, "<<<< Get arguments error (%s)", err.message);
425                         dbus_error_free(&err); 
426                         result = VC_ERROR_OPERATION_FAILED;
427                 }
428
429                 dbus_message_unref(result_msg);
430
431                 if (0 == result) {
432                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget initialize : result = %d", result);
433                 } else {
434                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget initialize : result = %d", result);
435                 }
436         } else {
437                 SLOG(LOG_ERROR, TAG_VCW, "<<<< Result message is NULL ");
438                 vc_widget_dbus_reconnect();
439                 result = VC_ERROR_TIMED_OUT;
440         }
441
442         return result;
443 }
444
445 int vc_widget_dbus_request_finalize(int pid)
446 {
447         DBusMessage* msg;
448
449         msg = dbus_message_new_method_call(
450                 VC_SERVER_SERVICE_NAME, 
451                 VC_SERVER_SERVICE_OBJECT_PATH, 
452                 VC_SERVER_SERVICE_INTERFACE, 
453                 VC_WIDGET_METHOD_FINALIZE);
454
455         if (NULL == msg) { 
456                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget finalize : Fail to make message "); 
457                 return VC_ERROR_OPERATION_FAILED;
458         } else {
459                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget finalize : pid(%d)", pid);
460         }
461
462         dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
463
464         DBusError err;
465         dbus_error_init(&err);
466
467         DBusMessage* result_msg;
468         int result = VC_ERROR_OPERATION_FAILED;
469
470         result_msg = dbus_connection_send_with_reply_and_block(g_w_conn, msg, g_w_waiting_time, &err);
471         dbus_message_unref(msg);
472
473         if (dbus_error_is_set(&err)) {
474                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
475                 dbus_error_free(&err);
476         }
477
478         if (NULL != result_msg) {
479                 dbus_message_get_args(result_msg, &err, 
480                                 DBUS_TYPE_INT32, &result,
481                                 DBUS_TYPE_INVALID);
482
483                 if (dbus_error_is_set(&err)) { 
484                         SLOG(LOG_ERROR, TAG_VCW, "<<<< Get arguments error (%s)", err.message);
485                         dbus_error_free(&err); 
486                         result = VC_ERROR_OPERATION_FAILED;
487                 }
488
489                 dbus_message_unref(result_msg);
490
491                 if (0 == result) {
492                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget finalize : result = %d", result);
493                 } else {
494                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget finalize : result = %d", result);
495                 }
496         } else {
497                 SLOG(LOG_ERROR, TAG_VCW, "<<<< Result message is NULL ");
498                 vc_widget_dbus_reconnect();
499                 result = VC_ERROR_TIMED_OUT;
500         }
501
502         return result;
503 }
504
505 int vc_widget_dbus_request_start_recording(int pid, bool command)
506 {
507         DBusMessage* msg;
508
509         msg = dbus_message_new_method_call(
510                 VC_SERVER_SERVICE_NAME, 
511                 VC_SERVER_SERVICE_OBJECT_PATH, 
512                 VC_SERVER_SERVICE_INTERFACE, 
513                 VC_WIDGET_METHOD_START_RECORDING);
514
515         if (NULL == msg) { 
516                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget start recording : Fail to make message"); 
517                 return VC_ERROR_OPERATION_FAILED;
518         } else {
519                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget start recording : pid(%d)", pid);
520         }
521
522         int temp = (int)command;
523
524         dbus_message_append_args(msg, 
525                 DBUS_TYPE_INT32, &pid, 
526                 DBUS_TYPE_INT32, &temp, 
527                 DBUS_TYPE_INVALID);
528
529         DBusError err;
530         dbus_error_init(&err);
531
532         DBusMessage* result_msg;
533         int result = VC_ERROR_OPERATION_FAILED;
534
535         result_msg = dbus_connection_send_with_reply_and_block(g_w_conn, msg, g_w_waiting_time, &err);
536         dbus_message_unref(msg);
537
538         if (dbus_error_is_set(&err)) {
539                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
540                 dbus_error_free(&err);
541         }
542
543         if (NULL != result_msg) {
544                 dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
545
546                 if (dbus_error_is_set(&err)) { 
547                         SLOG(LOG_ERROR, TAG_VCW, "<<<< Get arguments error (%s)", err.message);
548                         dbus_error_free(&err); 
549                         result = VC_ERROR_OPERATION_FAILED;
550                 }
551                 dbus_message_unref(result_msg);
552
553                 if (0 == result) {
554                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget start recording : result = %d", result);
555                 } else {
556                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget start recording : result = %d", result);
557                 }
558         } else {
559                 SLOG(LOG_ERROR, TAG_VCW, "<<<< Result message is NULL");
560                 vc_widget_dbus_reconnect();
561                 result = VC_ERROR_TIMED_OUT;
562         }
563
564         return result;
565 }
566
567 int vc_widget_dbus_request_start(int pid, int silence)
568 {
569         DBusMessage* msg;
570
571         /* create a signal & check for errors */
572         msg = dbus_message_new_method_call(
573                 VC_SERVER_SERVICE_NAME,
574                 VC_SERVER_SERVICE_OBJECT_PATH,  
575                 VC_SERVER_SERVICE_INTERFACE,    
576                 VC_WIDGET_METHOD_START);                
577
578         if (NULL == msg) { 
579                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget start : Fail to make message "); 
580                 return VC_ERROR_OPERATION_FAILED;
581         } else {
582                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget start : pid(%d), silence(%d)", pid, silence);
583         }
584
585         DBusMessageIter args;
586         dbus_message_iter_init_append(msg, &args);
587
588         /* Append result*/
589         dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(pid));
590         dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(silence));
591
592         DBusError err;
593         dbus_error_init(&err);
594
595         DBusMessage* result_msg;
596         int result = VC_ERROR_OPERATION_FAILED;
597
598         result_msg = dbus_connection_send_with_reply_and_block(g_w_conn, msg, g_w_waiting_time, &err);
599         dbus_message_unref(msg);
600
601         if (dbus_error_is_set(&err)) {
602                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
603                 dbus_error_free(&err);
604         }
605
606         if (NULL != result_msg) {
607                 dbus_message_get_args(result_msg, &err,
608                         DBUS_TYPE_INT32, &result,
609                         DBUS_TYPE_INVALID);
610
611                 if (dbus_error_is_set(&err)) { 
612                         SLOG(LOG_ERROR, TAG_VCW, "<<<< Get arguments error (%s)", err.message);
613                         dbus_error_free(&err); 
614                         result = VC_ERROR_OPERATION_FAILED;
615                 }
616                 dbus_message_unref(result_msg);
617
618                 if (0 == result) {
619                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget start : result = %d", result);
620                 } else {
621                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget start : result = %d", result);
622                 }
623         } else {
624                 SLOG(LOG_DEBUG, TAG_VCW, "<<<< Result Message is NULL");
625                 vc_widget_dbus_reconnect();
626                 result = VC_ERROR_TIMED_OUT;
627         }
628
629         return result;
630 }
631
632 int vc_widget_dbus_request_stop(int pid)
633 {
634         DBusMessage* msg;
635
636         /* create a signal & check for errors */
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_WIDGET_METHOD_STOP);
642
643         if (NULL == msg) { 
644                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget stop : Fail to make message "); 
645                 return VC_ERROR_OPERATION_FAILED;
646         } else {
647                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget stop : pid(%d)", pid);
648         }
649
650         dbus_message_append_args(msg, 
651                 DBUS_TYPE_INT32, &pid, 
652                 DBUS_TYPE_INVALID);
653
654         DBusError err;
655         dbus_error_init(&err);
656
657         DBusMessage* result_msg;
658         int result = VC_ERROR_OPERATION_FAILED;
659
660         result_msg = dbus_connection_send_with_reply_and_block(g_w_conn, msg, g_w_waiting_time, &err);
661         dbus_message_unref(msg);
662
663         if (dbus_error_is_set(&err)) {
664                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
665                 dbus_error_free(&err);
666         }
667
668         if (NULL != result_msg) {
669                 dbus_message_get_args(result_msg, &err,
670                         DBUS_TYPE_INT32, &result,
671                         DBUS_TYPE_INVALID);
672
673                 if (dbus_error_is_set(&err)) { 
674                         SLOG(LOG_ERROR, TAG_VCW, "<<<< Get arguments error (%s)", err.message);
675                         dbus_error_free(&err); 
676                         result = VC_ERROR_OPERATION_FAILED;
677                 }
678                 dbus_message_unref(result_msg);
679
680                 if (0 == result) {
681                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget stop : result = %d", result);
682                 } else {
683                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget stop : result = %d", result);
684                 }
685         } else {
686                 SLOG(LOG_DEBUG, TAG_VCW, "<<<< Result Message is NULL");
687                 vc_widget_dbus_reconnect();
688                 result = VC_ERROR_TIMED_OUT;
689         }
690
691         return result;
692 }
693
694 int vc_widget_dbus_request_cancel(int pid)
695 {
696         DBusMessage* msg;
697
698         /* create a signal & check for errors */
699         msg = dbus_message_new_method_call(
700                 VC_SERVER_SERVICE_NAME,
701                 VC_SERVER_SERVICE_OBJECT_PATH,  /* object name of the signal */
702                 VC_SERVER_SERVICE_INTERFACE,    /* interface name of the signal */
703                 VC_WIDGET_METHOD_CANCEL);       /* name of the signal */
704
705         if (NULL == msg) { 
706                 SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget cancel : Fail to make message "); 
707                 return VC_ERROR_OPERATION_FAILED;
708         } else {
709                 SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget cancel : pid(%d)", pid);
710         }
711
712         dbus_message_append_args(msg, 
713                 DBUS_TYPE_INT32, &pid, 
714                 DBUS_TYPE_INVALID);
715
716         DBusError err;
717         dbus_error_init(&err);
718
719         DBusMessage* result_msg;
720         int result = VC_ERROR_OPERATION_FAILED;
721
722         result_msg = dbus_connection_send_with_reply_and_block(g_w_conn, msg, g_w_waiting_time, &err);
723         dbus_message_unref(msg);
724
725         if (dbus_error_is_set(&err)) {
726                 SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message);
727                 dbus_error_free(&err);
728         }
729
730         if (NULL != result_msg) {
731                 dbus_message_get_args(result_msg, &err,
732                         DBUS_TYPE_INT32, &result,
733                         DBUS_TYPE_INVALID);
734
735                 if (dbus_error_is_set(&err)) { 
736                         SLOG(LOG_ERROR, TAG_VCW, "<<<< Get arguments error (%s)", err.message);
737                         dbus_error_free(&err); 
738                         result = VC_ERROR_OPERATION_FAILED;
739                 }
740                 dbus_message_unref(result_msg);
741
742                 if (0 == result) {
743                         SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget cancel : result = %d", result);
744                 } else {
745                         SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget cancel : result = %d", result);
746                 }
747         } else {
748                 SLOG(LOG_DEBUG, TAG_VCW, "<<<< Result Message is NULL");
749                 vc_widget_dbus_reconnect();
750                 result = VC_ERROR_TIMED_OUT;
751         }
752
753         return result;
754 }