2 * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "vc_mgr_client.h"
20 #include "vc_mgr_dbus.h"
21 #include "vc_command.h"
24 static int g_m_waiting_time = 3000;
26 static Ecore_Fd_Handler* g_m_fd_handler = NULL;
28 static DBusConnection* g_m_conn_sender = NULL;
29 static DBusConnection* g_m_conn_listener = NULL;
31 static int g_volume_count = 0;
34 extern void __vc_mgr_cb_all_result(vc_result_type_e type);
36 extern void __vc_mgr_cb_pre_result(int event, const char* pre_result);
38 extern void __vc_mgr_cb_system_result();
40 extern void __vc_mgr_cb_speech_detected();
42 extern int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg);
44 extern int __vc_mgr_cb_set_volume(float volume);
46 extern int __vc_mgr_cb_service_state(int state);
48 extern int __vc_mgr_cb_set_foreground(int pid, bool value);
50 extern int __vc_mgr_cb_private_data_set(const char* key, const char* data);
52 extern int __vc_mgr_cb_private_data_requested(const char* key, char** data);
54 /* for TTS feedback */
55 extern int __vc_mgr_cb_feedback_audio_format(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type);
57 extern int __vc_mgr_cb_feedback_streaming(vc_feedback_event_e event, char* buffer, int len);
60 extern int __vc_mgr_request_auth_enable(int pid);
62 extern int __vc_mgr_request_auth_disable(int pid);
64 extern int __vc_mgr_request_auth_start(int pid);
66 extern int __vc_mgr_request_auth_stop(int pid);
68 extern int __vc_mgr_request_auth_cancel(int pid);
70 extern int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous);
72 extern void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result);
74 static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
76 if (NULL == g_m_conn_listener) return ECORE_CALLBACK_RENEW;
78 dbus_connection_read_write_dispatch(g_m_conn_listener, 50);
81 DBusMessage* msg = NULL;
82 msg = dbus_connection_pop_message(g_m_conn_listener);
84 /* loop again if we haven't read a message */
89 /* SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] Message is arrived"); */
92 dbus_error_init(&err);
94 char if_name[64] = {0, };
95 snprintf(if_name, 64, "%s", VC_MANAGER_SERVICE_INTERFACE);
97 if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_HELLO)) {
98 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get Hello");
102 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
103 if (dbus_error_is_set(&err)) {
104 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
105 dbus_error_free(&err);
109 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get hello : pid(%d) ", pid);
112 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get hello : invalid pid ");
115 DBusMessage *reply = NULL;
116 reply = dbus_message_new_method_return(msg);
119 dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
121 if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
122 SLOG(LOG_ERROR, TAG_VCM, "@@ vc get hello : fail to send reply");
124 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc get hello : result(%d)", response);
126 dbus_connection_flush(g_m_conn_listener);
127 dbus_message_unref(reply);
129 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get hello : fail to create reply message");
132 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
133 } /* VCD_METHOD_HELLO */
135 else if (dbus_message_is_signal(msg, if_name, VCD_MANAGER_METHOD_SET_VOLUME)) {
138 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &volume, DBUS_TYPE_INVALID);
140 if (dbus_error_is_set(&err)) {
141 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Get arguments error (%s)", err.message);
142 dbus_error_free(&err);
145 if (10 == g_volume_count) {
146 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set volume");
147 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set volume : volume(%f)", volume);
151 __vc_mgr_cb_set_volume(volume);
154 } /* VCD_MANAGER_METHOD_SET_VOLUME */
156 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SET_SERVICE_STATE)) {
159 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID);
160 if (dbus_error_is_set(&err)) {
161 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Get arguments error (%s)", err.message);
162 dbus_error_free(&err);
165 SLOG(LOG_DEBUG, TAG_VCM, "@@ state changed : %d", state);
167 __vc_mgr_cb_service_state(state);
169 } /* VCD_MANAGER_METHOD_SET_SERVICE_STATE */
171 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SPEECH_DETECTED)) {
172 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get Speech detected");
174 __vc_mgr_cb_speech_detected();
176 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
178 } /* VCD_MANAGER_METHOD_SPEECH_DETECTED */
180 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_ALL_RESULT)) {
181 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get All Result");
184 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &result_type, DBUS_TYPE_INVALID);
186 __vc_mgr_cb_all_result((vc_result_type_e)result_type);
188 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
190 } /* VCD_MANAGER_METHOD_ALL_RESULT */
192 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_PRE_RESULT)) {
193 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get Pre Result");
195 char* pre_result = NULL;
197 dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &event, DBUS_TYPE_STRING, &pre_result, DBUS_TYPE_INVALID);
199 if (NULL != pre_result) {
200 __vc_mgr_cb_pre_result((vc_pre_result_event_e)event, pre_result);
203 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
204 } /* VCD_MANAGER_METHOD_PRE_RESULT */
205 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT)) {
206 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get specific engine result");
207 char* engine_app_id = NULL;
211 dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &engine_app_id, DBUS_TYPE_STRING, &event, DBUS_TYPE_STRING, &result, DBUS_TYPE_INVALID);
213 if (NULL != result) {
214 __vc_mgr_cb_specific_engine_result(engine_app_id, event, result);
217 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
218 } /* VCD_MANAGER_METHOD_SPECIFIC_ENGINE_RESULT */
219 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_RESULT)) {
220 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get System Result");
222 __vc_mgr_cb_system_result();
224 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
226 } /* VCD_MANAGER_METHOD_RESULT */
228 else if (dbus_message_is_signal(msg, if_name, VCC_MANAGER_METHOD_SET_FOREGROUND)) {
229 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set foreground");
233 dbus_message_get_args(msg, &err,
234 DBUS_TYPE_INT32, &pid,
235 DBUS_TYPE_INT32, &value,
237 if (dbus_error_is_set(&err)) {
238 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Get arguments error (%s)", err.message);
239 dbus_error_free(&err);
242 SLOG(LOG_DEBUG, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false");
244 __vc_mgr_cb_set_foreground(pid, (bool)value);
245 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
246 } /* VCC_MANAGER_METHOD_SET_FOREGROUND */
248 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_DIALOG)) {
249 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Request Dialog");
251 char* disp_text = NULL;
252 char* utt_text = NULL;
255 dbus_message_get_args(msg, &err,
256 DBUS_TYPE_INT32, &pid,
257 DBUS_TYPE_STRING, &disp_text,
258 DBUS_TYPE_STRING, &utt_text,
259 DBUS_TYPE_INT32, &tmp_continue,
262 if (!strcmp(disp_text, "#NULL"))
264 if (!strcmp(utt_text, "#NULL"))
267 __vc_mgr_cb_dialog(pid, disp_text, utt_text, (bool)tmp_continue);
269 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
271 } /* VCD_MANAGER_METHOD_ALL_RESULT */
273 else if (dbus_message_is_signal(msg, if_name, VCD_MANAGER_METHOD_ERROR)) {
274 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get Error");
277 char* err_msg = NULL;
279 dbus_message_get_args(msg, &err,
280 DBUS_TYPE_INT32, &reason,
281 DBUS_TYPE_INT32, &daemon_pid,
282 DBUS_TYPE_STRING, &err_msg,
285 if (dbus_error_is_set(&err)) {
286 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : Get arguments error (%s)", err.message);
287 dbus_error_free(&err);
289 char* temp_msg = NULL;
290 if (NULL != err_msg && strcmp("#NULL", err_msg)) {
291 temp_msg = strdup(err_msg);
293 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr Get Error message : reason(%d), daemon_pid(%d), msg(%s)", reason, daemon_pid, temp_msg);
294 __vc_mgr_cb_error(reason, daemon_pid, temp_msg);
295 if (NULL != temp_msg) {
301 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
302 } /* VCD_MANAGER_METHOD_ERROR */
304 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SET_PRIVATE_DATA)) {
305 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request set private data");
309 char* private_data = NULL;
311 dbus_message_get_args(msg, &err,
312 DBUS_TYPE_INT32, &pid,
313 DBUS_TYPE_STRING, &key,
314 DBUS_TYPE_STRING, &private_data,
317 if (dbus_error_is_set(&err)) {
318 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
319 dbus_error_free(&err);
323 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get request set private data : pid(%d) ", pid);
324 ret = __vc_mgr_cb_private_data_set(key, private_data);
326 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get requset set private data : invalid pid ");
329 DBusMessage *reply = NULL;
330 reply = dbus_message_new_method_return(msg);
333 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
335 if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
336 SLOG(LOG_ERROR, TAG_VCM, "@@ vc get request set private data : fail to send reply");
338 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc get request set private data : result(%d)", ret);
340 dbus_connection_flush(g_m_conn_listener);
341 dbus_message_unref(reply);
343 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request set private data : fail to create reply message");
346 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
347 } /* VCD_MANAGER_METHOD_SET_PRIVATE_DATA */
349 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_GET_PRIVATE_DATA)) {
350 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request get private data");
356 dbus_message_get_args(msg, &err,
357 DBUS_TYPE_INT32, &pid,
358 DBUS_TYPE_STRING, &key,
361 if (dbus_error_is_set(&err)) {
362 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
363 dbus_error_free(&err);
367 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get request get private data : pid(%d) ", pid);
368 ret = __vc_mgr_cb_private_data_requested(key, &temp);
370 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request get private data : invalid pid ");
373 DBusMessage *reply = NULL;
374 reply = dbus_message_new_method_return(msg);
377 dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID);
379 if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
380 SLOG(LOG_ERROR, TAG_VCM, "@@ vc get request get private data : fail to send reply");
382 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc get request get private data : result(%d)", ret);
384 dbus_connection_flush(g_m_conn_listener);
385 dbus_message_unref(reply);
387 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request get private data : fail to create reply message");
390 if (NULL != temp) free(temp);
392 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
393 } /* VCD_MANAGER_METHOD_GET_PRIVATE_DATA */
395 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT)) {
396 SLOG(LOG_INFO, TAG_VCM, "@@@ Get TTS feedback audio format");
398 vc_audio_channel_e channel;
399 vc_audio_type_e audio_type;
401 dbus_message_get_args(msg, &err,
402 DBUS_TYPE_INT32, &rate,
403 DBUS_TYPE_INT32, &channel,
404 DBUS_TYPE_INT32, &audio_type,
407 __vc_mgr_cb_feedback_audio_format(rate, channel, audio_type);
409 SLOG(LOG_INFO, TAG_VCM, "@@@");
410 } /* VCD_MANAGER_METHOD_FEEDBACK_AUDIO_FORMAT */
412 else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_FEEDBACK_STREAMING)) {
413 SLOG(LOG_INFO, TAG_VCM, "@@@ Get TTS feedback streaming");
414 vc_feedback_event_e event;
418 dbus_message_get_args(msg, &err,
419 DBUS_TYPE_INT32, &event,
420 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
424 __vc_mgr_cb_feedback_streaming(event, buffer, len);
426 SLOG(LOG_INFO, TAG_VCM, "@@@");
427 } /* VCD_MANAGER_METHOD_FEEDBACK_STREAMING */
430 else if (dbus_message_is_method_call(msg, if_name, VC_METHOD_AUTH_ENABLE)) {
431 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth enable");
435 dbus_message_get_args(msg, &err,
436 DBUS_TYPE_INT32, &pid,
439 if (dbus_error_is_set(&err)) {
440 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth enable : Get arguments error (%s)", err.message);
441 dbus_error_free(&err);
443 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth enable : pid(%d)", pid);
444 ret = __vc_mgr_request_auth_enable(pid);
447 DBusMessage *reply = NULL;
448 reply = dbus_message_new_method_return(msg);
451 dbus_message_append_args(reply,
452 DBUS_TYPE_INT32, &ret,
454 if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
455 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth enable : fail to send reply");
457 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth enable : ret(%d)", ret);
458 dbus_connection_flush(g_m_conn_listener);
459 dbus_message_unref(reply);
461 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth enable : fail to create reply message");
464 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
465 } /* VC_METHOD_AUTH_ENABLE */
467 else if (dbus_message_is_method_call(msg, if_name, VC_METHOD_AUTH_DISABLE)) {
468 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth disable");
472 dbus_message_get_args(msg, &err,
473 DBUS_TYPE_INT32, &pid,
476 if (dbus_error_is_set(&err)) {
477 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth disable : Get arguments error (%s)", err.message);
478 dbus_error_free(&err);
480 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth disable : pid(%d)", pid);
481 ret = __vc_mgr_request_auth_disable(pid);
484 DBusMessage *reply = NULL;
485 reply = dbus_message_new_method_return(msg);
488 dbus_message_append_args(reply,
489 DBUS_TYPE_INT32, &ret,
491 if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
492 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth disable : fail to send reply");
494 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth disable : ret(%d)", ret);
495 dbus_connection_flush(g_m_conn_listener);
496 dbus_message_unref(reply);
498 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth disable : fail to create reply message");
501 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
502 } /* VC_METHOD_AUTH_DISABLE */
504 else if (dbus_message_is_method_call(msg, if_name, VC_METHOD_AUTH_START)) {
505 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth start");
509 dbus_message_get_args(msg, &err,
510 DBUS_TYPE_INT32, &pid,
513 if (dbus_error_is_set(&err)) {
514 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth start : Get arguments error (%s)", err.message);
515 dbus_error_free(&err);
517 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth start : pid(%d)", pid);
518 ret = __vc_mgr_request_auth_start(pid);
521 DBusMessage *reply = NULL;
522 reply = dbus_message_new_method_return(msg);
525 dbus_message_append_args(reply,
526 DBUS_TYPE_INT32, &ret,
528 if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
529 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth start : fail to send reply");
531 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth start : ret(%d)", ret);
532 dbus_connection_flush(g_m_conn_listener);
533 dbus_message_unref(reply);
535 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth start : fail to create reply message");
538 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
539 } /* VC_METHOD_AUTH_START */
541 else if (dbus_message_is_method_call(msg, if_name, VC_METHOD_AUTH_STOP)) {
542 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth stop");
546 dbus_message_get_args(msg, &err,
547 DBUS_TYPE_INT32, &pid,
550 if (dbus_error_is_set(&err)) {
551 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth stop : Get arguments error (%s)", err.message);
552 dbus_error_free(&err);
554 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth stop : pid(%d)", pid);
555 ret = __vc_mgr_request_auth_stop(pid);
558 DBusMessage *reply = NULL;
559 reply = dbus_message_new_method_return(msg);
562 dbus_message_append_args(reply,
563 DBUS_TYPE_INT32, &ret,
565 if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
566 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth stop : fail to send reply");
568 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth stop : ret(%d)", ret);
569 dbus_connection_flush(g_m_conn_listener);
570 dbus_message_unref(reply);
572 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth stop : fail to create reply message");
575 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
576 } /* VC_METHOD_AUTH_STOP */
578 else if (dbus_message_is_method_call(msg, if_name, VC_METHOD_AUTH_CANCEL)) {
579 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get request auth cancel");
583 dbus_message_get_args(msg, &err,
584 DBUS_TYPE_INT32, &pid,
587 if (dbus_error_is_set(&err)) {
588 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth cancel : Get arguments error (%s)", err.message);
589 dbus_error_free(&err);
591 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr request auth cancel : pid(%d)", pid);
592 ret = __vc_mgr_request_auth_cancel(pid);
595 DBusMessage *reply = NULL;
596 reply = dbus_message_new_method_return(msg);
599 dbus_message_append_args(reply,
600 DBUS_TYPE_INT32, &ret,
602 if (!dbus_connection_send(g_m_conn_listener, reply, NULL))
603 SLOG(LOG_ERROR, TAG_VCM, "@@ vc request auth cancel : fail to send reply");
605 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc request auth cancel : ret(%d)", ret);
606 dbus_connection_flush(g_m_conn_listener);
607 dbus_message_unref(reply);
609 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr request auth cancel : fail to create reply message");
612 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
613 } /* VC_METHOD_AUTH_CANCEL */
615 else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) {
616 SLOG(LOG_DEBUG, TAG_VCM, "@@@ Owner Changed");
617 /* remove a rule for daemon error */
619 /* initialise the error value */
620 dbus_error_init(&err);
621 char rule_err[256] = {0, };
622 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);
623 dbus_bus_remove_match(g_m_conn_listener, rule_err, &err);
624 dbus_connection_flush(g_m_conn_listener);
626 if (dbus_error_is_set(&err)) {
627 SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message);
628 dbus_error_free(&err);
630 __vc_mgr_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset");
631 SLOG(LOG_DEBUG, TAG_VCM, "@@@");
632 } /* NameOwnerChanged */
635 SLOG(LOG_DEBUG, TAG_VCM, "Message is NOT valid");
636 dbus_message_unref(msg);
640 /* free the message */
641 dbus_message_unref(msg);
644 return ECORE_CALLBACK_PASS_ON;
647 static void __vc_mgr_dbus_connection_free()
649 if (NULL != g_m_conn_listener) {
650 dbus_connection_close(g_m_conn_listener);
651 dbus_connection_unref(g_m_conn_listener);
652 g_m_conn_listener = NULL;
654 if (NULL != g_m_conn_sender) {
655 dbus_connection_close(g_m_conn_sender);
656 dbus_connection_unref(g_m_conn_sender);
657 g_m_conn_sender = NULL;
661 int vc_mgr_dbus_open_connection()
663 if (NULL != g_m_conn_sender && NULL != g_m_conn_listener) {
664 SLOG(LOG_WARN, TAG_VCM, "already existed connection ");
671 /* initialise the error value */
672 dbus_error_init(&err);
674 /* connect to the DBUS system bus, and check for errors */
675 g_m_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
677 if (dbus_error_is_set(&err)) {
678 SLOG(LOG_ERROR, TAG_VCM, "Dbus Connection Error (%s)", err.message);
679 dbus_error_free(&err);
682 if (NULL == g_m_conn_sender) {
683 SLOG(LOG_ERROR, TAG_VCM, "Fail to get dbus connection ");
684 return VC_ERROR_OPERATION_FAILED;
687 dbus_connection_set_exit_on_disconnect(g_m_conn_sender, false);
689 /* connect to the DBUS system bus, and check for errors */
690 g_m_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
692 if (dbus_error_is_set(&err)) {
693 SLOG(LOG_ERROR, TAG_VCM, "Dbus Connection Error (%s)", err.message);
694 dbus_error_free(&err);
697 if (NULL == g_m_conn_listener) {
698 SLOG(LOG_ERROR, TAG_VCM, "Fail to get dbus connection ");
699 __vc_mgr_dbus_connection_free();
700 return VC_ERROR_OPERATION_FAILED;
703 dbus_connection_set_exit_on_disconnect(g_m_conn_listener, false);
705 SLOG(LOG_DEBUG, TAG_VCM, "service name is %s", VC_MANAGER_SERVICE_NAME);
707 /* register our name on the bus, and check for errors */
708 ret = dbus_bus_request_name(g_m_conn_listener, VC_MANAGER_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
710 if (dbus_error_is_set(&err)) {
711 SLOG(LOG_ERROR, TAG_VCM, "Name Error (%s)", err.message);
712 dbus_error_free(&err);
715 if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
716 SLOG(LOG_ERROR, TAG_VCM, "fail dbus_bus_request_name()");
717 __vc_mgr_dbus_connection_free();
721 if (NULL != g_m_fd_handler) {
722 SLOG(LOG_WARN, TAG_VCM, "The handler already exists.");
723 __vc_mgr_dbus_connection_free();
727 char rule[128] = {0, };
728 snprintf(rule, 128, "type='signal',interface='%s'", VC_MANAGER_SERVICE_INTERFACE);
730 /* add a rule for which messages we want to see */
731 dbus_bus_add_match(g_m_conn_listener, rule, &err);
733 if (dbus_error_is_set(&err)) {
734 SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message);
735 dbus_error_free(&err);
736 __vc_mgr_dbus_connection_free();
737 return VC_ERROR_OPERATION_FAILED;
741 if (1 != dbus_connection_get_unix_fd(g_m_conn_listener, &fd)) {
742 SLOG(LOG_ERROR, TAG_VCM, "fail to get fd from dbus ");
743 __vc_mgr_dbus_connection_free();
744 return VC_ERROR_OPERATION_FAILED;
746 SLOG(LOG_DEBUG, TAG_VCM, "Get fd from dbus : %d", fd);
749 g_m_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)vc_mgr_listener_event_callback, g_m_conn_listener, NULL, NULL);
751 if (NULL == g_m_fd_handler) {
752 SLOG(LOG_ERROR, TAG_VCM, "fail to get fd handler from ecore ");
753 __vc_mgr_dbus_connection_free();
754 return VC_ERROR_OPERATION_FAILED;
760 int vc_mgr_dbus_close_connection()
763 dbus_error_init(&err);
765 if (NULL != g_m_fd_handler) {
766 ecore_main_fd_handler_del(g_m_fd_handler);
767 g_m_fd_handler = NULL;
770 if (NULL != g_m_conn_listener) {
773 char service_name[64];
774 memset(service_name, '\0', 64);
775 snprintf(service_name, 64, "%s%d", VC_MANAGER_SERVICE_NAME, pid);
777 dbus_bus_release_name(g_m_conn_listener, service_name, &err);
779 if (dbus_error_is_set(&err)) {
780 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
781 dbus_error_free(&err);
785 __vc_mgr_dbus_connection_free();
790 int vc_mgr_dbus_reconnect()
792 if (!g_m_conn_sender || !g_m_conn_listener) {
793 vc_mgr_dbus_close_connection();
795 if (0 != vc_mgr_dbus_open_connection()) {
796 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to reconnect");
800 SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect");
804 bool sender_connected = dbus_connection_get_is_connected(g_m_conn_sender);
805 bool listener_connected = dbus_connection_get_is_connected(g_m_conn_listener);
807 SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Sender(%s) Listener(%s)",
808 sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
810 if (false == sender_connected || false == listener_connected) {
811 vc_mgr_dbus_close_connection();
813 if (0 != vc_mgr_dbus_open_connection()) {
814 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to reconnect");
818 SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect");
824 int vc_mgr_dbus_request_hello()
828 msg = dbus_message_new_method_call(
829 VC_SERVER_SERVICE_NAME,
830 VC_SERVER_SERVICE_OBJECT_PATH,
831 VC_SERVER_SERVICE_INTERFACE,
835 SLOG(LOG_ERROR, TAG_VCM, "@@ Request vc hello : Fail to make message");
836 return VC_ERROR_OPERATION_FAILED;
840 dbus_error_init(&err);
842 DBusMessage* result_msg = NULL;
845 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, -1, &err);
847 if (dbus_error_is_set(&err)) {
848 SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
849 dbus_error_free(&err);
852 dbus_message_unref(msg);
854 if (NULL != result_msg) {
855 dbus_message_unref(result_msg);
858 result = VC_ERROR_TIMED_OUT;
864 static int __dbus_restore_daemon()
869 ret = vc_mgr_dbus_request_hello();
871 if (VC_ERROR_TIMED_OUT != ret) {
872 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
875 SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry restore daemon");
878 if (VC_RETRY_COUNT == count) {
879 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request");
884 SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] restore daemon");
890 int vc_mgr_dbus_request_initialize(int pid, int* service_state, int* foreground, int* daemon_pid)
893 dbus_error_init(&err);
895 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
896 if (dbus_error_is_set(&err)) {
897 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
898 dbus_error_free(&err);
902 if (false == exist) {
903 ret = __dbus_restore_daemon();
904 if (VC_ERROR_NONE != ret) {
905 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
906 return VC_ERROR_TIMED_OUT;
908 return VC_ERROR_OPERATION_FAILED;
913 msg = dbus_message_new_method_call(
914 VC_SERVER_SERVICE_NAME,
915 VC_SERVER_SERVICE_OBJECT_PATH,
916 VC_SERVER_SERVICE_INTERFACE,
917 VC_MANAGER_METHOD_INITIALIZE);
920 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr initialize : Fail to make message ");
921 return VC_ERROR_OPERATION_FAILED;
923 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr initialize : pid(%d)", pid);
926 dbus_message_append_args(msg,
927 DBUS_TYPE_INT32, &pid,
930 DBusMessage* result_msg;
931 int result = VC_ERROR_OPERATION_FAILED;
933 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
934 dbus_message_unref(msg);
936 if (dbus_error_is_set(&err)) {
937 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
938 dbus_error_free(&err);
941 if (NULL != result_msg) {
942 int tmp_service_state = 0;
943 int tmp_foreground = 0;
944 int tmp_daemon_pid = 0;
945 dbus_message_get_args(result_msg, &err,
946 DBUS_TYPE_INT32, &result,
947 DBUS_TYPE_INT32, &tmp_service_state,
948 DBUS_TYPE_INT32, &tmp_foreground,
949 DBUS_TYPE_INT32, &tmp_daemon_pid,
952 if (dbus_error_is_set(&err)) {
953 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
954 dbus_error_free(&err);
955 result = VC_ERROR_OPERATION_FAILED;
958 dbus_message_unref(result_msg);
961 *service_state = tmp_service_state;
962 *foreground = tmp_foreground;
963 *daemon_pid = tmp_daemon_pid;
965 /* add a rule for daemon error */
966 char rule_err[256] = {0, };
967 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);
968 dbus_bus_add_match(g_m_conn_listener, rule_err, &err);
970 if (dbus_error_is_set(&err)) {
971 SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message);
972 dbus_error_free(&err);
975 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr initialize : result = %d, service state = %d, foreground = %d, daemon_pid = %d",
976 result, *service_state, *foreground, *daemon_pid);
978 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr initialize : result = %d", result);
981 SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL ");
982 vc_mgr_dbus_reconnect();
983 result = VC_ERROR_TIMED_OUT;
989 int vc_mgr_dbus_request_finalize(int pid)
992 dbus_error_init(&err);
994 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
995 if (dbus_error_is_set(&err)) {
996 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
997 dbus_error_free(&err);
1001 if (false == exist) {
1002 ret = __dbus_restore_daemon();
1003 if (VC_ERROR_NONE != ret) {
1004 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1005 return VC_ERROR_TIMED_OUT;
1007 return VC_ERROR_OPERATION_FAILED;
1010 /* remove a rule for daemon error */
1011 char rule_err[256] = {0, };
1012 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);
1013 dbus_bus_remove_match(g_m_conn_listener, rule_err, &err);
1014 dbus_connection_flush(g_m_conn_listener);
1016 if (dbus_error_is_set(&err)) {
1017 SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message);
1018 dbus_error_free(&err);
1019 return VC_ERROR_OPERATION_FAILED;
1024 msg = dbus_message_new_method_call(
1025 VC_SERVER_SERVICE_NAME,
1026 VC_SERVER_SERVICE_OBJECT_PATH,
1027 VC_SERVER_SERVICE_INTERFACE,
1028 VC_MANAGER_METHOD_FINALIZE);
1031 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr finalize : Fail to make message ");
1032 return VC_ERROR_OPERATION_FAILED;
1034 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr finalize : pid(%d)", pid);
1037 dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INVALID);
1039 DBusMessage* result_msg;
1040 int result = VC_ERROR_OPERATION_FAILED;
1042 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1043 dbus_message_unref(msg);
1045 if (dbus_error_is_set(&err)) {
1046 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1047 dbus_error_free(&err);
1050 if (NULL != result_msg) {
1051 dbus_message_get_args(result_msg, &err,
1052 DBUS_TYPE_INT32, &result,
1055 if (dbus_error_is_set(&err)) {
1056 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1057 dbus_error_free(&err);
1058 result = VC_ERROR_OPERATION_FAILED;
1061 dbus_message_unref(result_msg);
1064 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr finalize : result = %d", result);
1066 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr finalize : result = %d", result);
1069 SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL ");
1070 vc_mgr_dbus_reconnect();
1071 result = VC_ERROR_TIMED_OUT;
1077 int vc_mgr_dbus_request_set_command(int pid)
1080 dbus_error_init(&err);
1082 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1083 if (dbus_error_is_set(&err)) {
1084 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1085 dbus_error_free(&err);
1089 if (false == exist) {
1090 ret = __dbus_restore_daemon();
1091 if (VC_ERROR_NONE != ret) {
1092 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1093 return VC_ERROR_TIMED_OUT;
1095 return VC_ERROR_OPERATION_FAILED;
1100 msg = dbus_message_new_method_call(
1101 VC_SERVER_SERVICE_NAME,
1102 VC_SERVER_SERVICE_OBJECT_PATH,
1103 VC_SERVER_SERVICE_INTERFACE,
1104 VC_MANAGER_METHOD_SET_COMMAND);
1107 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set command : Fail to make message");
1108 return VC_ERROR_OPERATION_FAILED;
1110 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set command : pid(%d)", pid);
1113 dbus_message_append_args(msg,
1114 DBUS_TYPE_INT32, &pid,
1117 DBusMessage* result_msg;
1118 int result = VC_ERROR_OPERATION_FAILED;
1120 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1121 dbus_message_unref(msg);
1123 if (dbus_error_is_set(&err)) {
1124 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1125 dbus_error_free(&err);
1128 if (NULL != result_msg) {
1129 dbus_message_get_args(result_msg, &err,
1130 DBUS_TYPE_INT32, &result,
1133 if (dbus_error_is_set(&err)) {
1134 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1135 dbus_error_free(&err);
1136 result = VC_ERROR_OPERATION_FAILED;
1138 dbus_message_unref(result_msg);
1141 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set command : result = %d", result);
1143 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set command : result = %d", result);
1146 SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL");
1147 vc_mgr_dbus_reconnect();
1148 result = VC_ERROR_TIMED_OUT;
1154 int vc_mgr_dbus_request_unset_command(int pid)
1157 dbus_error_init(&err);
1159 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1160 if (dbus_error_is_set(&err)) {
1161 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1162 dbus_error_free(&err);
1166 if (false == exist) {
1167 ret = __dbus_restore_daemon();
1168 if (VC_ERROR_NONE != ret) {
1169 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1170 return VC_ERROR_TIMED_OUT;
1172 return VC_ERROR_OPERATION_FAILED;
1177 msg = dbus_message_new_method_call(
1178 VC_SERVER_SERVICE_NAME,
1179 VC_SERVER_SERVICE_OBJECT_PATH,
1180 VC_SERVER_SERVICE_INTERFACE,
1181 VC_MANAGER_METHOD_UNSET_COMMAND);
1184 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr unset command : Fail to make message");
1185 return VC_ERROR_OPERATION_FAILED;
1187 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr unset command : pid(%d)", pid);
1190 dbus_message_append_args(msg,
1191 DBUS_TYPE_INT32, &pid,
1194 DBusMessage* result_msg;
1195 int result = VC_ERROR_OPERATION_FAILED;
1197 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1198 dbus_message_unref(msg);
1200 if (dbus_error_is_set(&err)) {
1201 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1202 dbus_error_free(&err);
1205 if (NULL != result_msg) {
1206 dbus_message_get_args(result_msg, &err,
1207 DBUS_TYPE_INT32, &result,
1210 if (dbus_error_is_set(&err)) {
1211 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1212 dbus_error_free(&err);
1213 result = VC_ERROR_OPERATION_FAILED;
1215 dbus_message_unref(result_msg);
1218 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr unset command : result = %d", result);
1220 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr unset command : result = %d", result);
1223 SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL");
1224 vc_mgr_dbus_reconnect();
1225 result = VC_ERROR_TIMED_OUT;
1231 int vc_mgr_dbus_request_demandable_client(int pid)
1234 dbus_error_init(&err);
1236 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1237 if (dbus_error_is_set(&err)) {
1238 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1239 dbus_error_free(&err);
1243 if (false == exist) {
1244 ret = __dbus_restore_daemon();
1245 if (VC_ERROR_NONE != ret) {
1246 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1247 return VC_ERROR_TIMED_OUT;
1249 return VC_ERROR_OPERATION_FAILED;
1254 msg = dbus_message_new_method_call(
1255 VC_SERVER_SERVICE_NAME,
1256 VC_SERVER_SERVICE_OBJECT_PATH,
1257 VC_SERVER_SERVICE_INTERFACE,
1258 VC_MANAGER_METHOD_SET_DEMANDABLE);
1261 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set demandable client : Fail to make message");
1262 return VC_ERROR_OPERATION_FAILED;
1264 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set demandable client : pid(%d)", pid);
1267 dbus_message_append_args(msg,
1268 DBUS_TYPE_INT32, &pid,
1271 DBusMessage* result_msg;
1272 int result = VC_ERROR_OPERATION_FAILED;
1274 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1275 dbus_message_unref(msg);
1277 if (dbus_error_is_set(&err)) {
1278 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1279 dbus_error_free(&err);
1282 if (NULL != result_msg) {
1283 dbus_message_get_args(result_msg, &err,
1284 DBUS_TYPE_INT32, &result,
1287 if (dbus_error_is_set(&err)) {
1288 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1289 dbus_error_free(&err);
1290 result = VC_ERROR_OPERATION_FAILED;
1292 dbus_message_unref(result_msg);
1295 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set demandable client : result = %d", result);
1297 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set demandable client : result = %d", result);
1300 SLOG(LOG_ERROR, TAG_VCM, "@@ Result message is NULL");
1301 vc_mgr_dbus_reconnect();
1302 result = VC_ERROR_TIMED_OUT;
1308 int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type)
1311 dbus_error_init(&err);
1313 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1314 if (dbus_error_is_set(&err)) {
1315 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1316 dbus_error_free(&err);
1320 if (false == exist) {
1321 ret = __dbus_restore_daemon();
1322 if (VC_ERROR_NONE != ret) {
1323 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1324 return VC_ERROR_TIMED_OUT;
1326 return VC_ERROR_OPERATION_FAILED;
1331 /* create a signal & check for errors */
1332 msg = dbus_message_new_method_call(
1333 VC_SERVER_SERVICE_NAME,
1334 VC_SERVER_SERVICE_OBJECT_PATH,
1335 VC_SERVER_SERVICE_INTERFACE,
1336 VC_MANAGER_METHOD_SET_AUDIO_TYPE);
1339 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set audio type : Fail to make message ");
1340 return VC_ERROR_OPERATION_FAILED;
1342 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set audio type : pid(%d), audio type(%s)", pid, audio_type);
1345 dbus_message_append_args(msg,
1346 DBUS_TYPE_INT32, &pid,
1347 DBUS_TYPE_STRING, &(audio_type),
1350 DBusMessage* result_msg;
1351 int result = VC_ERROR_OPERATION_FAILED;
1353 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1354 dbus_message_unref(msg);
1356 if (dbus_error_is_set(&err)) {
1357 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1358 dbus_error_free(&err);
1361 if (NULL != result_msg) {
1362 dbus_message_get_args(result_msg, &err,
1363 DBUS_TYPE_INT32, &result,
1366 if (dbus_error_is_set(&err)) {
1367 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1368 dbus_error_free(&err);
1369 result = VC_ERROR_OPERATION_FAILED;
1371 dbus_message_unref(result_msg);
1374 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set audio type : result = %d", result);
1376 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set audio type : result = %d", result);
1379 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
1380 vc_mgr_dbus_reconnect();
1381 result = VC_ERROR_TIMED_OUT;
1387 int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type)
1390 dbus_error_init(&err);
1392 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1393 if (dbus_error_is_set(&err)) {
1394 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1395 dbus_error_free(&err);
1399 if (false == exist) {
1400 ret = __dbus_restore_daemon();
1401 if (VC_ERROR_NONE != ret) {
1402 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1403 return VC_ERROR_TIMED_OUT;
1405 return VC_ERROR_OPERATION_FAILED;
1410 /* create a signal & check for errors */
1411 msg = dbus_message_new_method_call(
1412 VC_SERVER_SERVICE_NAME,
1413 VC_SERVER_SERVICE_OBJECT_PATH,
1414 VC_SERVER_SERVICE_INTERFACE,
1415 VC_MANAGER_METHOD_GET_AUDIO_TYPE);
1418 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get audio type : Fail to make message ");
1419 return VC_ERROR_OPERATION_FAILED;
1421 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get audio type : pid(%d)", pid);
1424 dbus_message_append_args(msg,
1425 DBUS_TYPE_INT32, &pid,
1429 DBusMessage* result_msg;
1430 int result = VC_ERROR_OPERATION_FAILED;
1433 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1434 dbus_message_unref(msg);
1436 if (dbus_error_is_set(&err)) {
1437 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1438 dbus_error_free(&err);
1441 if (NULL != result_msg) {
1442 dbus_message_get_args(result_msg, &err,
1443 DBUS_TYPE_INT32, &result,
1444 DBUS_TYPE_STRING, &temp,
1447 if (dbus_error_is_set(&err)) {
1448 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1449 dbus_error_free(&err);
1450 result = VC_ERROR_OPERATION_FAILED;
1452 dbus_message_unref(result_msg);
1455 if (NULL != audio_type && NULL != temp) {
1456 *audio_type = strdup(temp);
1458 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get audio type : result = %d audio type = %s", result, temp);
1460 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get audio type : result = %d", result);
1463 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
1464 vc_mgr_dbus_reconnect();
1465 result = VC_ERROR_TIMED_OUT;
1471 int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* data)
1475 /* create a signal & check for errors */
1476 msg = dbus_message_new_method_call(
1477 VC_SERVER_SERVICE_NAME,
1478 VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
1479 VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */
1480 VC_MANAGER_METHOD_SET_PRIVATE_DATA); /* name of the signal */
1483 SLOG(LOG_ERROR, TAG_VCM, "@@ vc set private data : Fail to make message ");
1484 return VC_ERROR_OPERATION_FAILED;
1486 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc set private data : pid(%d), data(%s)", pid, data);
1489 dbus_message_append_args(msg,
1490 DBUS_TYPE_INT32, &pid,
1491 DBUS_TYPE_STRING, &key,
1492 DBUS_TYPE_STRING, &data,
1495 dbus_message_set_no_reply(msg, TRUE);
1497 /* send the message and flush the connection */
1498 if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) {
1499 SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to send private data");
1500 dbus_message_unref(msg);
1501 return VC_ERROR_OPERATION_FAILED;
1503 SLOG(LOG_ERROR, TAG_VCM, "[Dbus] Success to send private data");
1504 dbus_connection_flush(g_m_conn_sender);
1507 dbus_message_unref(msg);
1509 return VC_ERROR_NONE;
1512 int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data)
1516 /* create a signal & check for errors */
1517 msg = dbus_message_new_method_call(
1518 VC_SERVER_SERVICE_NAME,
1519 VC_SERVER_SERVICE_OBJECT_PATH,
1520 VC_SERVER_SERVICE_INTERFACE,
1521 VC_MANAGER_METHOD_GET_PRIVATE_DATA);
1524 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get private data : Fail to make message ");
1525 return VC_ERROR_OPERATION_FAILED;
1527 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get private data : pid(%d), key(%s)", pid, key);
1530 dbus_message_append_args(msg,
1531 DBUS_TYPE_INT32, &pid,
1532 DBUS_TYPE_STRING, &key,
1536 dbus_error_init(&err);
1538 DBusMessage* result_msg;
1539 int result = VC_ERROR_OPERATION_FAILED;
1542 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1543 dbus_message_unref(msg);
1545 if (dbus_error_is_set(&err)) {
1546 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1547 dbus_error_free(&err);
1550 if (NULL != result_msg) {
1551 dbus_message_get_args(result_msg, &err,
1552 DBUS_TYPE_INT32, &result,
1553 DBUS_TYPE_STRING, &temp,
1556 if (dbus_error_is_set(&err)) {
1557 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1558 dbus_error_free(&err);
1559 result = VC_ERROR_OPERATION_FAILED;
1561 dbus_message_unref(result_msg);
1564 if (NULL != data && NULL != temp) {
1565 *data = strdup(temp);
1567 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get private data : result = %d private data = %s", result, *data);
1570 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get private data : result = %d", result);
1573 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
1574 vc_mgr_dbus_reconnect();
1575 result = VC_ERROR_TIMED_OUT;
1581 int vc_mgr_dbus_request_set_client_info(int pid)
1584 dbus_error_init(&err);
1586 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1587 if (dbus_error_is_set(&err)) {
1588 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1589 dbus_error_free(&err);
1593 if (false == exist) {
1594 ret = __dbus_restore_daemon();
1595 if (VC_ERROR_NONE != ret) {
1596 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1597 return VC_ERROR_TIMED_OUT;
1599 return VC_ERROR_OPERATION_FAILED;
1604 /* create a signal & check for errors */
1605 msg = dbus_message_new_method_call(
1606 VC_SERVER_SERVICE_NAME,
1607 VC_SERVER_SERVICE_OBJECT_PATH,
1608 VC_SERVER_SERVICE_INTERFACE,
1609 VC_MANAGER_METHOD_SET_CLIENT_INFO);
1612 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set client info : Fail to make message ");
1613 return VC_ERROR_OPERATION_FAILED;
1615 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set client info : pid(%d)", pid);
1618 dbus_message_append_args(msg,
1619 DBUS_TYPE_INT32, &pid,
1622 DBusMessage* result_msg;
1623 int result = VC_ERROR_OPERATION_FAILED;
1625 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1626 dbus_message_unref(msg);
1628 if (dbus_error_is_set(&err)) {
1629 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1630 dbus_error_free(&err);
1633 if (NULL != result_msg) {
1634 dbus_message_get_args(result_msg, &err,
1635 DBUS_TYPE_INT32, &result,
1638 if (dbus_error_is_set(&err)) {
1639 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1640 dbus_error_free(&err);
1641 result = VC_ERROR_OPERATION_FAILED;
1643 dbus_message_unref(result_msg);
1646 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set client info : result = %d", result);
1648 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr set client info : result = %d", result);
1651 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
1652 vc_mgr_dbus_reconnect();
1653 result = VC_ERROR_TIMED_OUT;
1659 int vc_mgr_dbus_request_set_domain(int pid, const char* domain)
1663 /* create a signal & check for errors */
1664 msg = dbus_message_new_method_call(
1665 VC_SERVER_SERVICE_NAME,
1666 VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
1667 VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */
1668 VC_MANAGER_METHOD_SET_DOMAIN); /* name of the signal */
1671 SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : Fail to make message ");
1672 return VC_ERROR_OPERATION_FAILED;
1674 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc set domain : pid(%d), domain(%s)", pid, domain);
1677 dbus_message_append_args(msg,
1678 DBUS_TYPE_INT32, &pid,
1679 DBUS_TYPE_STRING, &domain,
1683 dbus_error_init(&err);
1685 DBusMessage* result_msg;
1686 int result = VC_ERROR_OPERATION_FAILED;
1688 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1689 dbus_message_unref(msg);
1691 if (dbus_error_is_set(&err)) {
1692 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1693 dbus_error_free(&err);
1696 if (NULL != result_msg) {
1697 dbus_message_get_args(result_msg, &err,
1698 DBUS_TYPE_INT32, &result,
1701 if (dbus_error_is_set(&err)) {
1702 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1703 dbus_error_free(&err);
1704 result = VC_ERROR_OPERATION_FAILED;
1706 dbus_message_unref(result_msg);
1709 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc set domain : result = %d", result);
1711 SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : result = %d", result);
1714 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
1715 vc_mgr_dbus_reconnect();
1716 result = VC_ERROR_TIMED_OUT;
1722 int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send_event)
1726 /* create a signal & check for errors */
1727 msg = dbus_message_new_method_call(
1728 VC_SERVER_SERVICE_NAME,
1729 VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
1730 VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */
1731 VC_MANAGER_METHOD_DO_ACTION); /* name of the signal */
1734 SLOG(LOG_ERROR, TAG_VCM, "@@ vc set domain : Fail to make message ");
1735 return VC_ERROR_OPERATION_FAILED;
1737 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc set domain : pid(%d), type(%d), send_event(%s)", pid, type, send_event);
1740 dbus_message_append_args(msg,
1741 DBUS_TYPE_INT32, &pid,
1742 DBUS_TYPE_INT32, &type,
1743 DBUS_TYPE_STRING, &send_event,
1746 dbus_message_set_no_reply(msg, TRUE);
1748 if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) {
1749 SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send");
1752 SLOG(LOG_DEBUG, TAG_VCM, "[Dbus] SUCCESS Send");
1753 dbus_connection_flush(g_m_conn_sender);
1759 int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client)
1762 dbus_error_init(&err);
1764 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1765 if (dbus_error_is_set(&err)) {
1766 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1767 dbus_error_free(&err);
1771 if (false == exist) {
1772 ret = __dbus_restore_daemon();
1773 if (VC_ERROR_NONE != ret) {
1774 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1775 return VC_ERROR_TIMED_OUT;
1777 return VC_ERROR_OPERATION_FAILED;
1782 /* create a signal & check for errors */
1783 msg = dbus_message_new_method_call(
1784 VC_SERVER_SERVICE_NAME,
1785 VC_SERVER_SERVICE_OBJECT_PATH,
1786 VC_SERVER_SERVICE_INTERFACE,
1787 VC_MANAGER_METHOD_START);
1790 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr start : Fail to make message ");
1791 return VC_ERROR_OPERATION_FAILED;
1793 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr start : pid(%d), recognition_mode(%d) exclusive(%d) start by client(%d)",
1794 pid, recognition_mode, exclusive_command_option, start_by_client);
1797 int exclusive = (int)exclusive_command_option;
1798 int by = (int)start_by_client;
1800 dbus_message_append_args(msg,
1801 DBUS_TYPE_INT32, &pid,
1802 DBUS_TYPE_INT32, &(recognition_mode),
1803 DBUS_TYPE_INT32, &(exclusive),
1804 DBUS_TYPE_INT32, &(by),
1807 DBusMessage* result_msg;
1808 int result = VC_ERROR_OPERATION_FAILED;
1810 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1811 dbus_message_unref(msg);
1813 if (dbus_error_is_set(&err)) {
1814 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1815 dbus_error_free(&err);
1818 if (NULL != result_msg) {
1819 dbus_message_get_args(result_msg, &err,
1820 DBUS_TYPE_INT32, &result,
1823 if (dbus_error_is_set(&err)) {
1824 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1825 dbus_error_free(&err);
1826 result = VC_ERROR_OPERATION_FAILED;
1828 dbus_message_unref(result_msg);
1831 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr start : result = %d", result);
1833 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr start : result = %d", result);
1836 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
1837 vc_mgr_dbus_reconnect();
1838 result = VC_ERROR_TIMED_OUT;
1844 int vc_mgr_dbus_request_stop(int pid)
1847 dbus_error_init(&err);
1849 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1850 if (dbus_error_is_set(&err)) {
1851 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1852 dbus_error_free(&err);
1856 if (false == exist) {
1857 ret = __dbus_restore_daemon();
1858 if (VC_ERROR_NONE != ret) {
1859 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1860 return VC_ERROR_TIMED_OUT;
1862 return VC_ERROR_OPERATION_FAILED;
1867 /* create a signal & check for errors */
1868 msg = dbus_message_new_method_call(
1869 VC_SERVER_SERVICE_NAME,
1870 VC_SERVER_SERVICE_OBJECT_PATH,
1871 VC_SERVER_SERVICE_INTERFACE,
1872 VC_MANAGER_METHOD_STOP);
1875 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr stop : Fail to make message ");
1876 return VC_ERROR_OPERATION_FAILED;
1878 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr stop : pid(%d)", pid);
1881 dbus_message_append_args(msg,
1882 DBUS_TYPE_INT32, &pid,
1885 DBusMessage* result_msg;
1886 int result = VC_ERROR_OPERATION_FAILED;
1888 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1889 dbus_message_unref(msg);
1891 if (dbus_error_is_set(&err)) {
1892 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1893 dbus_error_free(&err);
1896 if (NULL != result_msg) {
1897 dbus_message_get_args(result_msg, &err,
1898 DBUS_TYPE_INT32, &result,
1901 if (dbus_error_is_set(&err)) {
1902 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1903 dbus_error_free(&err);
1904 result = VC_ERROR_OPERATION_FAILED;
1906 dbus_message_unref(result_msg);
1909 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr stop : result = %d", result);
1911 SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr stop : result = %d", result);
1914 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
1915 vc_mgr_dbus_reconnect();
1916 result = VC_ERROR_TIMED_OUT;
1922 int vc_mgr_dbus_request_cancel(int pid)
1925 dbus_error_init(&err);
1927 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
1928 if (dbus_error_is_set(&err)) {
1929 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1930 dbus_error_free(&err);
1934 if (false == exist) {
1935 ret = __dbus_restore_daemon();
1936 if (VC_ERROR_NONE != ret) {
1937 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
1938 return VC_ERROR_TIMED_OUT;
1940 return VC_ERROR_OPERATION_FAILED;
1945 /* create a signal & check for errors */
1946 msg = dbus_message_new_method_call(
1947 VC_SERVER_SERVICE_NAME,
1948 VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
1949 VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */
1950 VC_MANAGER_METHOD_CANCEL); /* name of the signal */
1953 SLOG(LOG_ERROR, TAG_VCM, "@@ vc cancel : Fail to make message ");
1954 return VC_ERROR_OPERATION_FAILED;
1956 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc cancel : pid(%d)", pid);
1959 dbus_message_append_args(msg,
1960 DBUS_TYPE_INT32, &pid,
1963 DBusMessage* result_msg;
1964 int result = VC_ERROR_OPERATION_FAILED;
1966 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
1967 dbus_message_unref(msg);
1969 if (dbus_error_is_set(&err)) {
1970 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
1971 dbus_error_free(&err);
1974 if (NULL != result_msg) {
1975 dbus_message_get_args(result_msg, &err,
1976 DBUS_TYPE_INT32, &result,
1979 if (dbus_error_is_set(&err)) {
1980 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
1981 dbus_error_free(&err);
1982 result = VC_ERROR_OPERATION_FAILED;
1984 dbus_message_unref(result_msg);
1987 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc cancel : result = %d", result);
1989 SLOG(LOG_ERROR, TAG_VCM, "@@ vc cancel : result = %d", result);
1992 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
1993 vc_mgr_dbus_reconnect();
1994 result = VC_ERROR_TIMED_OUT;
2000 int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type)
2003 dbus_error_init(&err);
2005 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
2006 if (dbus_error_is_set(&err)) {
2007 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
2008 dbus_error_free(&err);
2012 if (false == exist) {
2013 ret = __dbus_restore_daemon();
2014 if (VC_ERROR_NONE != ret) {
2015 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
2016 return VC_ERROR_TIMED_OUT;
2018 return VC_ERROR_OPERATION_FAILED;
2023 /* create a signal & check for errors */
2024 msg = dbus_message_new_method_call(
2025 VC_SERVER_SERVICE_NAME,
2026 VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
2027 VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */
2028 VC_MANAGER_METHOD_ENABLE_COMMAND_TYPE); /* name of the signal */
2031 SLOG(LOG_ERROR, TAG_VCM, "@@ vc enable command type : Fail to make message ");
2032 return VC_ERROR_OPERATION_FAILED;
2034 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc enable command type : pid(%d) type(%d)", pid, cmd_type);
2037 dbus_message_append_args(msg,
2038 DBUS_TYPE_INT32, &pid,
2039 DBUS_TYPE_INT32, &cmd_type,
2042 DBusMessage* result_msg;
2043 int result = VC_ERROR_OPERATION_FAILED;
2045 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
2046 dbus_message_unref(msg);
2048 if (dbus_error_is_set(&err)) {
2049 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
2050 dbus_error_free(&err);
2053 if (NULL != result_msg) {
2054 dbus_message_get_args(result_msg, &err,
2055 DBUS_TYPE_INT32, &result,
2058 if (dbus_error_is_set(&err)) {
2059 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
2060 dbus_error_free(&err);
2061 result = VC_ERROR_OPERATION_FAILED;
2063 dbus_message_unref(result_msg);
2066 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc enable command type : result = %d", result);
2068 SLOG(LOG_ERROR, TAG_VCM, "@@ vc enable command type : result = %d", result);
2071 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
2072 vc_mgr_dbus_reconnect();
2073 result = VC_ERROR_TIMED_OUT;
2079 int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type)
2082 dbus_error_init(&err);
2084 bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err);
2085 if (dbus_error_is_set(&err)) {
2086 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
2087 dbus_error_free(&err);
2091 if (false == exist) {
2092 ret = __dbus_restore_daemon();
2093 if (VC_ERROR_NONE != ret) {
2094 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon");
2095 return VC_ERROR_TIMED_OUT;
2097 return VC_ERROR_OPERATION_FAILED;
2102 /* create a signal & check for errors */
2103 msg = dbus_message_new_method_call(
2104 VC_SERVER_SERVICE_NAME,
2105 VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
2106 VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */
2107 VC_MANAGER_METHOD_DISABLE_COMMAND_TYPE); /* name of the signal */
2110 SLOG(LOG_ERROR, TAG_VCM, "@@ vc disable command type : Fail to make message ");
2111 return VC_ERROR_OPERATION_FAILED;
2113 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc disable command type : pid(%d) type(%d)", pid, cmd_type);
2116 dbus_message_append_args(msg,
2117 DBUS_TYPE_INT32, &pid,
2118 DBUS_TYPE_INT32, &cmd_type,
2121 DBusMessage* result_msg;
2122 int result = VC_ERROR_OPERATION_FAILED;
2124 result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err);
2125 dbus_message_unref(msg);
2127 if (dbus_error_is_set(&err)) {
2128 SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message);
2129 dbus_error_free(&err);
2132 if (NULL != result_msg) {
2133 dbus_message_get_args(result_msg, &err,
2134 DBUS_TYPE_INT32, &result,
2137 if (dbus_error_is_set(&err)) {
2138 SLOG(LOG_ERROR, TAG_VCM, "@@ Get arguments error (%s)", err.message);
2139 dbus_error_free(&err);
2140 result = VC_ERROR_OPERATION_FAILED;
2142 dbus_message_unref(result_msg);
2145 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc disable command type : result = %d", result);
2147 SLOG(LOG_ERROR, TAG_VCM, "@@ vc disable command type : result = %d", result);
2150 SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL");
2151 vc_mgr_dbus_reconnect();
2152 result = VC_ERROR_TIMED_OUT;
2158 static DBusMessage* __get_message(int pid, const char* method, int type)
2160 char service_name[64];
2161 char object_path[64];
2162 char target_if_name[128];
2164 memset(service_name, '\0', 64);
2165 memset(object_path, '\0', 64);
2166 memset(target_if_name, '\0', 128);
2168 if (VC_COMMAND_TYPE_FOREGROUND == type || VC_COMMAND_TYPE_BACKGROUND == type) {
2169 snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid);
2170 snprintf(object_path, 64, "%s", VC_CLIENT_SERVICE_OBJECT_PATH);
2171 snprintf(target_if_name, 128, "%s%d", VC_CLIENT_SERVICE_NAME, pid);
2172 } else if (VC_COMMAND_TYPE_WIDGET == type) {
2173 snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid);
2174 snprintf(object_path, 64, "%s", VC_WIDGET_SERVICE_OBJECT_PATH);
2175 snprintf(target_if_name, 128, "%s%d", VC_WIDGET_SERVICE_INTERFACE, pid);
2180 SLOG(LOG_DEBUG, TAG_VCM, "[Dbus] Service(%s) object(%s) if(%s)", service_name, object_path, target_if_name);
2182 return dbus_message_new_method_call(service_name, object_path, target_if_name, method);
2185 int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id)
2187 DBusMessage* msg = NULL;
2190 case VC_COMMAND_TYPE_FOREGROUND:
2191 case VC_COMMAND_TYPE_BACKGROUND:
2192 msg = __get_message(pid, VCD_METHOD_RESULT, cmd_type);
2194 case VC_COMMAND_TYPE_WIDGET:
2195 msg = __get_message(pid, VCD_WIDGET_METHOD_RESULT, cmd_type);
2198 SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type);
2203 SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Message is NULL");
2205 dbus_message_append_args(msg, DBUS_TYPE_INT32, &result_id, DBUS_TYPE_INVALID);
2207 dbus_message_set_no_reply(msg, TRUE);
2209 /* send the message and flush the connection */
2210 if (!dbus_connection_send(g_m_conn_sender, msg, NULL)) {
2211 SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to send result message");
2213 SLOG(LOG_DEBUG, TAG_VCM, "[Dbus] Success to send result");
2215 dbus_connection_flush(g_m_conn_sender);
2218 dbus_message_unref(msg);
2223 int vc_mgr_dbus_send_result_selection(int pid)
2227 /* create a signal & check for errors */
2228 msg = dbus_message_new_method_call(
2229 VC_SERVER_SERVICE_NAME,
2230 VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
2231 VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */
2232 VC_MANAGER_METHOD_RESULT_SELECTION); /* name of the signal */
2235 SLOG(LOG_ERROR, TAG_VCM, "@@ vc result selection : Fail to make message ");
2236 return VC_ERROR_OPERATION_FAILED;
2238 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc result selection : pid(%d)", pid);
2241 dbus_message_append_args(msg,
2242 DBUS_TYPE_INT32, &pid,
2245 dbus_message_set_no_reply(msg, TRUE);
2247 if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) {
2248 SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send");
2251 SLOG(LOG_DEBUG, TAG_VCM, "[Dbus] SUCCESS Send");
2252 dbus_connection_flush(g_m_conn_sender);
2258 int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request)
2262 /* create a signal & check for errors */
2263 msg = dbus_message_new_method_call(
2264 VC_SERVER_SERVICE_NAME,
2265 VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */
2266 VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */
2267 VC_MANAGER_METHOD_SPECIFIC_ENGINE_REQUEST); /* name of the signal */
2270 SLOG(LOG_ERROR, TAG_VCM, "@@ vc send specific engine : Fail to make message");
2271 return VC_ERROR_OPERATION_FAILED;
2273 SLOG(LOG_DEBUG, TAG_VCM, "@@ vc send specific engine : pid(%d), engine_app_id(%s), event(%s), request(%s)", pid, engine_app_id, event, request);
2276 dbus_message_append_args(msg,
2277 DBUS_TYPE_INT32, &pid,
2278 DBUS_TYPE_STRING, &engine_app_id,
2279 DBUS_TYPE_STRING, &event,
2280 DBUS_TYPE_STRING, &request,
2283 dbus_message_set_no_reply(msg, TRUE);
2285 if (1 != dbus_connection_send(g_m_conn_sender, msg, NULL)) {
2286 SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to Send");
2289 SLOG(LOG_DEBUG, TAG_VCM, "[Dbus] SUCCESS Send");
2290 dbus_connection_flush(g_m_conn_sender);