From a08434760f199addc89f3556489ae2a6097e4a05 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 18 Jul 2019 21:09:30 +0900 Subject: [PATCH 01/16] Migration from DBUS to GDBUS Change-Id: I1ecec2666f93fca6e6dcbba0a789b5a184e0a018 --- CMakeLists.txt | 16 +- client/CMakeLists.txt | 4 + client/vc.c | 6 +- client/vc_dbus.c | 493 +++++++++++- client/vc_mgr.c | 4 +- client/vc_mgr_dbus.c | 865 ++++++++++++++++++++- client/vc_setting.c | 0 client/vc_setting_dbus.c | 111 +++ client/vc_setting_dbus.h | 0 client/vc_widget_dbus.c | 324 +++++++- common/vc_config_mgr.c | 0 common/vc_defs.h | 12 +- common/vc_regex_rule.h | 0 include/voice_control_command_expand.h | 0 include/voice_control_setting.h | 0 ...ver.service => org.tizen.voice.vcdaemon.service | 2 +- ....service => org.tizen.voice.vcdaemon.tv.service | 2 +- org.tizen.voice.voice-control.gdbus.xml | 360 +++++++++ packaging/voice-control.spec | 6 +- server/CMakeLists.txt | 1 + server/vcd_config.c | 0 server/vcd_config.h | 0 server/vcd_dbus.c | 405 +++++++++- server/vcd_dbus_server.c | 697 +++++++++++++++++ server/vcd_dbus_server.h | 154 ++++ server/vce.c | 4 + vc-server.conf => vc-service.conf | 4 +- 27 files changed, 3400 insertions(+), 70 deletions(-) mode change 100755 => 100644 client/vc_setting.c mode change 100755 => 100644 client/vc_setting_dbus.c mode change 100755 => 100644 client/vc_setting_dbus.h mode change 100755 => 100644 common/vc_config_mgr.c mode change 100755 => 100644 common/vc_regex_rule.h mode change 100755 => 100644 include/voice_control_command_expand.h mode change 100755 => 100644 include/voice_control_setting.h rename org.tizen.voice.vcserver.service => org.tizen.voice.vcdaemon.service (87%) rename org.tizen.voice.vcserver.tv.service => org.tizen.voice.vcdaemon.tv.service (75%) create mode 100644 org.tizen.voice.voice-control.gdbus.xml mode change 100755 => 100644 server/vcd_config.c mode change 100755 => 100644 server/vcd_config.h rename vc-server.conf => vc-service.conf (85%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2b603d..cbc716f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,14 @@ ADD_DEFINITIONS("-Werror") # for the use of ecore_wl2 ADD_DEFINITIONS("-DEFL_BETA_API_SUPPORT") +FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen) +EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS "\\ + --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/common/vc_gdbus \\ + --c-namespace GDBus\\ + --interface-prefix org.tizen.voice. \\ + ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.voice.voice-control.gdbus.xml \\ + ") + # pkg config tool INCLUDE(FindPkgConfig) @@ -47,12 +55,12 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include") INCLUDE(FindPkgConfig) IF("${_TV_PRODUCT}" STREQUAL "TRUE") pkg_check_modules(pkgs REQUIRED - aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 + aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 gio-2.0 gio-unix-2.0 capi-network-bluetooth capi-network-bluetooth-tv capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libgum libtzplatform-config libxml-2.0 sqlite3 vconf msfapi farfield-voice-api ) ELSE() pkg_check_modules(pkgs REQUIRED - aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 + aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 gio-2.0 gio-unix-2.0 capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libgum libtzplatform-config libxml-2.0 sqlite3 vconf ) ENDIF() @@ -75,9 +83,9 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/voice-control.info DESTINATION ${TZ_SYS_RO_SHA ## config ## INSTALL(FILES ${CMAKE_SOURCE_DIR}/vc-config.xml DESTINATION ${TZ_SYS_RO_SHARE}/voice/vc/1.0) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.voice.vcserver.service DESTINATION ${TZ_SYS_RO_SHARE}/dbus-1/services) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.voice.vcdaemon.service DESTINATION ${TZ_SYS_RO_SHARE}/dbus-1/services) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/vc-server.conf DESTINATION /etc/dbus-1/session.d) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/vc-service.conf DESTINATION /etc/dbus-1/session.d) ## vc_getengine ## IF("${ARCH}" MATCHES "^arm.*") diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 29a1049..a874dd2 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -10,6 +10,7 @@ SET(SRCS ../common/vc_config_parser.c ../common/vc_info_parser.c ../common/vc_json_parser.c + ../common/vc_gdbus.c ) SET(SETTING_SRCS @@ -17,6 +18,7 @@ SET(SETTING_SRCS vc_setting.c ../common/vc_config_mgr.c ../common/vc_config_parser.c + ../common/vc_gdbus.c ) SET(WIDGET_SRCS @@ -30,6 +32,7 @@ SET(WIDGET_SRCS ../common/vc_config_parser.c ../common/vc_info_parser.c ../common/vc_json_parser.c + ../common/vc_gdbus.c ) SET(MANAGER_SRCS @@ -45,6 +48,7 @@ SET(MANAGER_SRCS ../common/vc_config_parser.c ../common/vc_info_parser.c ../common/vc_json_parser.c + ../common/vc_gdbus.c ) #INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) diff --git a/client/vc.c b/client/vc.c index b510170..4e17f19 100644 --- a/client/vc.c +++ b/client/vc.c @@ -309,6 +309,10 @@ static Eina_Bool __focus_changed_cb(void *data, int type, void *event) int vc_initialize(void) { + if (!ecore_main_loop_glib_integrate()) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail ecore_main_loop_glib_integrate()"); + } + if (0 != __vc_get_feature_enabled()) { return VC_ERROR_NOT_SUPPORTED; } @@ -1666,7 +1670,7 @@ static void __vc_notify_error(void *data) } } -int __vc_cb_error(int reason, int daemon_pid, char* msg) +int __vc_cb_error(int reason, int daemon_pid, const char* msg) { vc_state_e state; if (0 != vc_client_get_client_state(g_vc, &state)) { diff --git a/client/vc_dbus.c b/client/vc_dbus.c index c78d5db..8408cbe 100644 --- a/client/vc_dbus.c +++ b/client/vc_dbus.c @@ -18,18 +18,17 @@ #include "vc_dbus.h" #include "vc_main.h" -static pthread_mutex_t g_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; +#define USE_GDBUS -static int g_waiting_time = 3000; -static int g_waiting_short_time = 200; -static bool g_is_connection_opened = false; +#ifdef USE_GDBUS +#include "vc_gdbus.h" -static Ecore_Fd_Handler* g_fd_handler = NULL; - -static DBusConnection* g_conn_sender = NULL; -static DBusConnection* g_conn_listener = NULL; +static GDBusConnection* g_connection = NULL; +static GDBusVcdaemon *g_daemon_proxy = NULL; +static int g_own_name_id = 0; +static guint g_name_owner_changed_subscription_id = 0; -extern int __vc_cb_error(int reason, int daemon_pid, char* msg); +extern int __vc_cb_error(int reason, int daemon_pid, const char* msg); extern void __vc_cb_result(); @@ -40,8 +39,19 @@ extern int __vc_cb_manager_pid(int manager_pid); extern int __vc_cb_tts_streaming(int utt_id, vc_feedback_event_e event, char* buffer, int len); extern int __vc_cb_utterance_status(int utt_id, int utt_status); +#else +static pthread_mutex_t g_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; +static bool g_is_connection_opened = false; +static int g_waiting_time = 3000; +static int g_waiting_short_time = 200; +static Ecore_Fd_Handler* g_fd_handler = NULL; +static DBusConnection* g_conn_listener = NULL; +static DBusConnection* g_conn_sender = NULL; + +#endif //LCOV_EXCL_START +#ifndef USE_GDBUS static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW; @@ -249,9 +259,208 @@ static void __vc_dbus_connection_free() g_conn_sender = NULL; } } +#endif + +#ifdef USE_GDBUS +static GDBusVcmanager* get_manager_proxy() { + char service_name[64] = {0,}; + char object_path[64] = {0,}; + + snprintf(service_name, 64, "%s", VC_MANAGER_SERVICE_NAME); + snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH); + + GError *error = NULL; + GDBusVcmanager *proxy = gdbus_vcmanager_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + service_name, object_path, NULL, &error); + + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", + proxy, service_name, object_path, error->message); + g_error_free(error); + } + + return proxy; +} + +gboolean vcd_client_method_hello(GDBusVcclient *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int response = -1; + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc get hello : pid(%d) ", pid); + response = 1; + } else { + SLOG(LOG_ERROR, TAG_VCC, "@@ vc get hello : invalid pid "); + } + gdbus_vcclient_complete_vcd_client_method_hello(service, invocation, response); + return TRUE; +} + +gboolean vcd_client_method_result(GDBusVcclient *service, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + __vc_cb_result(); + gdbus_vcclient_complete_vcd_client_method_result(service, invocation); + return TRUE; +} + +gboolean vcd_client_method_feedback_streaming(GDBusVcclient *service, GDBusMethodInvocation *invocation, + gint utt_id, gint event, guint size, GVariant* buffer, gpointer user_data) +{ + int len = 0; + GVariantIter *iter; + guchar uc; + + char *data = NULL; + data = malloc(size); + if (!data) return FALSE; + + g_variant_get(buffer, "ay", &iter); + while (g_variant_iter_loop(iter, "y", &uc)) { + if (len < size) { + data[len++] = uc; + } else { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] max size reached : %d", len); + } + } + g_variant_iter_free(iter); + + int ret = __vc_cb_tts_streaming(utt_id, event, data, len); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to send_audio_streaming"); + } + + gdbus_vcclient_complete_vcd_client_method_feedback_streaming(service, invocation); + + free(data); + return ret; +} + +gboolean vcm_client_method_utterance_status(GDBusVcclient *service, GDBusMethodInvocation *invocation, + gint utt_id, gint utt_status, gpointer user_data) +{ + SLOG(LOG_INFO, TAG_VCC, "@@@ Get TTS utterance status streaming"); + __vc_cb_utterance_status(utt_id, utt_status); + gdbus_vcclient_complete_vcm_client_method_utterance_status(service, invocation); + return TRUE; +} + +static void +on_name_acquired(GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCC, "Name acquired : %s", name); + + GDBusVcclient *service; + GError *error = NULL; + + service = gdbus_vcclient_skeleton_new(); + + /* vc daemon methods */ + g_signal_connect(service, "handle-vcd-client-method-hello", + G_CALLBACK(vcd_client_method_hello), NULL); + g_signal_connect(service, "handle-vcd-client-method-result", + G_CALLBACK(vcd_client_method_result), NULL); + g_signal_connect(service, "handle-vcd-client-method-feedback-streaming", + G_CALLBACK(vcd_client_method_feedback_streaming), NULL); + + /* vc manager methods */ + g_signal_connect(service, "handle-vcm-client-method-utterance-status", + G_CALLBACK(vcm_client_method_utterance_status), NULL); + + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), + connection, VC_CLIENT_SERVICE_OBJECT_PATH, &error); + if (error) { + SLOG(LOG_DEBUG, TAG_VCC, "Error : %s\n", error->message); + g_error_free(error); + } +} + +static void vcd_signal_set_service_state(GDBusVcdaemon* proxy, + gint state, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCC, "@@ state changed : %d", state); + __vc_cb_service_state(state); +} + +static void vcd_client_signal_send_error(GDBusVcdaemon* proxy, + gint reason, gint daemon_pid, const gchar* err_msg, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCC, "@@ vc Get Error message : reason(%d), daemon_pid(%d), msg(%s)", + reason, daemon_pid, err_msg); + __vc_cb_error(reason, daemon_pid, err_msg); +} + +static void vcd_client_signal_send_manager_pid(GDBusVcdaemon* proxy, + gint manager_pid, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCC, "@@ manager pid is changed : %d", manager_pid); + __vc_cb_manager_pid(manager_pid); +} + +static void _on_name_owner_changed(GDBusConnection *connection, + const gchar *sender_name, const gchar *object_path, + const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) +{ + gchar *name; + gchar *old_owner; + gchar *new_owner; + + g_variant_get(parameters, + "(sss)", + &name, + &old_owner, + &new_owner); + + if (g_name_owner_changed_subscription_id > 0) { + g_dbus_connection_signal_unsubscribe(connection, g_name_owner_changed_subscription_id); + g_name_owner_changed_subscription_id = 0; + } + + SLOG(LOG_ERROR, TAG_VCC, "name_owner_changed(%s: %s -> %s) interface %s sender %s object %s", + name, old_owner, new_owner, interface_name, sender_name, object_path); + __vc_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); + + g_free(name); + g_free(old_owner); + g_free(new_owner); +} +#endif int vc_dbus_open_connection() { +#ifdef USE_GDBUS + GError* error = NULL; + g_connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); + int pid = getpid(); + + char service_name[64]; + memset(service_name, '\0', 64); + snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid); + g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, + service_name, G_BUS_NAME_OWNER_FLAGS_REPLACE, NULL, on_name_acquired, NULL, NULL, NULL); + SLOG(LOG_DEBUG, TAG_VCC, "service_name : %s, %d", service_name, g_own_name_id); + + g_daemon_proxy = gdbus_vcdaemon_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + VC_DAEMON_SERVICE_NAME, VC_DAEMON_SERVICE_OBJECT_PATH, NULL, &error); + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + g_error_free(error); + } else { + /* vc common signals */ + g_signal_connect(g_daemon_proxy, "vcd-signal-set-service-state", + G_CALLBACK(vcd_signal_set_service_state), NULL); + + /* vc daemon signals */ + g_signal_connect(g_daemon_proxy, "vcd-client-signal-send-error", + G_CALLBACK(vcd_client_signal_send_error), NULL); + g_signal_connect(g_daemon_proxy, "vcd-client-signal-send-manager-pid", + G_CALLBACK(vcd_client_signal_send_manager_pid), NULL); + } +#else pthread_mutex_lock(&g_dbus_mutex); if (NULL != g_conn_sender && NULL != g_conn_listener) { @@ -365,12 +574,26 @@ int vc_dbus_open_connection() pthread_mutex_unlock(&g_dbus_mutex); SLOG(LOG_INFO, TAG_VCC, "[INFO] vc client dbus connection is opened"); - +#endif return VC_ERROR_NONE; } int vc_dbus_close_connection() { +#ifdef USE_GDBUS + if (g_daemon_proxy) { + g_object_unref(g_daemon_proxy); + g_daemon_proxy = NULL; + } + if (g_own_name_id) { + g_bus_unown_name(g_own_name_id); + g_own_name_id = 0; + } + if (g_connection != NULL) { + g_object_unref(g_connection); + g_connection = NULL; + } +#else pthread_mutex_lock(&g_dbus_mutex); DBusError err; @@ -403,12 +626,25 @@ int vc_dbus_close_connection() pthread_mutex_unlock(&g_dbus_mutex); SLOG(LOG_INFO, TAG_VCC, "[INFO] vc client dbus connection is closed"); - +#endif return 0; } int vc_dbus_reconnect() { +#ifdef USE_GDBUS + if (!g_own_name_id || !g_daemon_proxy) { + vc_dbus_close_connection(); + + if (0 != vc_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect"); //LCOV_EXCL_LINE + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect"); //LCOV_EXCL_LINE + return 0; + } +#else if (!g_conn_sender || !g_conn_listener) { vc_dbus_close_connection(); @@ -436,16 +672,24 @@ int vc_dbus_reconnect() SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect"); //LCOV_EXCL_LINE } - +#endif return 0; } static int __dbus_check() { +#ifdef USE_GDBUS + SLOG(LOG_DEBUG, TAG_VCC, "%d %p", g_own_name_id, g_daemon_proxy); //LCOV_EXCL_LINE + if (0 == g_own_name_id || NULL == g_daemon_proxy) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE + return vc_dbus_reconnect(); + } +#else if (NULL == g_conn_sender || NULL == g_conn_listener) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE return vc_dbus_reconnect(); } +#endif return 0; } @@ -455,6 +699,20 @@ int vc_dbus_request_hello() return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vc_method_hello_sync(g_daemon_proxy, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Request vc hello"); //LCOV_EXCL_LINE DBusMessage* msg; @@ -493,6 +751,7 @@ int vc_dbus_request_hello() } return result; +#endif } @@ -502,6 +761,26 @@ int vc_dbus_request_initialize(int pid, int* mgr_pid, int* service_state, int* d return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vcc_daemon_method_initialize_sync(g_daemon_proxy, + pid, &result, mgr_pid, service_state, daemon_pid, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + if (0 == result && NULL != g_connection) { + g_name_owner_changed_subscription_id = g_dbus_connection_signal_subscribe(g_connection, + "org.freedesktop.DBus", "org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus", + VC_DAEMON_SERVICE_NAME, G_DBUS_SIGNAL_FLAGS_NONE, _on_name_owner_changed, NULL, NULL); + } + return result; +#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -589,10 +868,35 @@ int vc_dbus_request_initialize(int pid, int* mgr_pid, int* service_state, int* d } return result; +#endif } int vc_dbus_request_finalize(int pid) { +#ifdef USE_GDBUS + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + if (g_name_owner_changed_subscription_id > 0) { + g_dbus_connection_signal_unsubscribe(g_connection, g_name_owner_changed_subscription_id); + g_name_owner_changed_subscription_id = 0; + } + + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vcc_daemon_method_finalize_sync(g_daemon_proxy, pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + + return result; +#else DBusError err; dbus_error_init(&err); @@ -664,6 +968,7 @@ int vc_dbus_request_finalize(int pid) } return result; +#endif } //LCOV_EXCL_START @@ -673,6 +978,20 @@ int vc_dbus_request_set_exclusive_command(int pid, bool value) return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vcc_daemon_method_set_exclusive_cmd_sync(g_daemon_proxy, pid, value, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -733,6 +1052,7 @@ int vc_dbus_request_set_exclusive_command(int pid, bool value) } return result; +#endif } //LCOV_EXCL_STOP @@ -742,6 +1062,20 @@ int vc_dbus_request_set_command(int pid, vc_cmd_type_e cmd_type) return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vcc_daemon_method_set_command_sync(g_daemon_proxy, pid, cmd_type, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -800,6 +1134,7 @@ int vc_dbus_request_set_command(int pid, vc_cmd_type_e cmd_type) } return result; +#endif } int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type) @@ -808,6 +1143,20 @@ int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type) return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + GError *error = NULL; + gint result = 0; + if (!gdbus_vcdaemon_call_vcc_daemon_method_unset_command_sync(g_daemon_proxy, pid, cmd_type, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -866,6 +1215,7 @@ int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type) } return result; +#endif } int vc_dbus_set_foreground(int pid, bool value) @@ -874,6 +1224,16 @@ int vc_dbus_set_foreground(int pid, bool value) return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcc_manager_method_set_foreground(proxy, + pid, value, NULL, NULL, NULL); + if (proxy) g_object_unref(proxy); + + gdbus_vcdaemon_call_vcc_daemon_method_set_foreground(g_daemon_proxy, + pid, value, NULL, NULL, NULL); + return 0; +#else DBusMessage* msg = NULL; int tmp_value = 0; @@ -936,11 +1296,26 @@ int vc_dbus_set_foreground(int pid, bool value) dbus_message_unref(msg); return 0; +#endif } //LCOV_EXCL_START int vc_dbus_set_server_dialog(int pid, const char* app_id, const char* credential) { +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vcc_daemon_method_set_server_dialog_sync(g_daemon_proxy, pid, app_id, credential, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); if (0 != vc_dbus_reconnect()) { @@ -1006,11 +1381,17 @@ int vc_dbus_set_server_dialog(int pid, const char* app_id, const char* credentia } return result; +#endif } //LCOV_EXCL_STOP int vc_dbus_request_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous) { +#ifdef USE_GDBUS + int result = 0; + gdbus_vcdaemon_call_vcc_daemon_method_dialog(g_daemon_proxy, pid, disp_text, utt_text, continuous, NULL, NULL, NULL); + return result; +#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE if (0 != vc_dbus_reconnect()) { @@ -1100,10 +1481,28 @@ int vc_dbus_request_dialog(int pid, const char* disp_text, const char* utt_text, return result; */ //LCOV_EXCL_STOP +#endif } int vc_dbus_request_is_system_command_valid(int pid, bool* is_sys_cmd_valid) { +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + gboolean valid = FALSE; + if (!gdbus_vcdaemon_call_vcc_daemon_method_is_system_command_valid_sync(g_daemon_proxy, pid, &result, &valid, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } else { + if (is_sys_cmd_valid) *is_sys_cmd_valid = valid; + } + return result; +#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE if (0 != vc_dbus_reconnect()) { @@ -1171,6 +1570,7 @@ int vc_dbus_request_is_system_command_valid(int pid, bool* is_sys_cmd_valid) } return result; +#endif } //LCOV_EXCL_START @@ -1370,6 +1770,9 @@ int vc_dbus_request_cancel(int pid) /* Authority */ int vc_dbus_request_auth_enable(int pid, int mgr_pid) { +#ifdef USE_GDBUS + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1440,10 +1843,14 @@ int vc_dbus_request_auth_enable(int pid, int mgr_pid) } return result; +#endif } int vc_dbus_request_auth_disable(int pid, int mgr_pid) { +#ifdef USE_GDBUS + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1514,10 +1921,14 @@ int vc_dbus_request_auth_disable(int pid, int mgr_pid) } return result; +#endif } int vc_dbus_request_auth_start(int pid, int mgr_pid) { +#ifdef USE_GDBUS + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1590,10 +2001,14 @@ int vc_dbus_request_auth_start(int pid, int mgr_pid) } return result; +#endif } int vc_dbus_request_auth_stop(int pid, int mgr_pid) { +#ifdef USE_GDBUS + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1664,10 +2079,14 @@ int vc_dbus_request_auth_stop(int pid, int mgr_pid) } return result; +#endif } int vc_dbus_request_auth_cancel(int pid, int mgr_pid) { +#ifdef USE_GDBUS + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1738,11 +2157,26 @@ int vc_dbus_request_auth_cancel(int pid, int mgr_pid) } return result; +#endif } //LCOV_EXCL_STOP int vc_dbus_request_tts(int pid, const char* text, const char* language, bool to_vcm, int* utt_id) { +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vcc_daemon_method_request_tts_sync(g_daemon_proxy, pid, text, language, to_vcm, &result, utt_id, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); if (0 != vc_dbus_reconnect()) { @@ -1818,10 +2252,25 @@ int vc_dbus_request_tts(int pid, const char* text, const char* language, bool to return result; return 0; +#endif } int vc_dbus_cancel_tts(int pid, int utt_id) { +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vcc_daemon_method_cancel_tts_sync(g_daemon_proxy, pid, utt_id, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); if (0 != vc_dbus_reconnect()) { @@ -1889,10 +2338,29 @@ int vc_dbus_cancel_tts(int pid, int utt_id) return result; return 0; +#endif } int vc_dbus_get_tts_audio_format(int pid, int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type) { +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + gint out_channel, out_audio_type; + if (!gdbus_vcdaemon_call_vcc_daemon_method_get_tts_audio_format_sync(g_daemon_proxy, pid, &result, rate, &out_channel, &out_audio_type, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } else { + if (channel) *channel = out_channel; + if (audio_type) *audio_type = out_audio_type; + } + return result; +#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); if (0 != vc_dbus_reconnect()) { @@ -1969,5 +2437,6 @@ int vc_dbus_get_tts_audio_format(int pid, int* rate, vc_audio_channel_e* channel return result; return 0; +#endif } diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 657afd2..df81eee 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -83,7 +83,7 @@ static Eina_Bool __vc_mgr_notify_state_changed(void *data); static void __vc_mgr_notify_error(void *data); static Eina_Bool __vc_mgr_notify_result(void *data); -int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg); +int __vc_mgr_cb_error(int reason, int daemon_pid, const char* msg); static const char* __vc_mgr_get_error_code(vc_error_e err) @@ -2950,7 +2950,7 @@ static void __vc_mgr_notify_error(void *data) } } -int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg) +int __vc_mgr_cb_error(int reason, int daemon_pid, const char* msg) { vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index aa20c13..e4f39ca 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -20,20 +20,32 @@ #include "vc_mgr_dbus.h" #include "vc_command.h" +#define USE_GDBUS +#ifdef USE_GDBUS +#include "vc_gdbus.h" + +static GDBusConnection* g_connection = NULL; +static GDBusVcdaemon *g_daemon_proxy = NULL; +static int g_own_name_id = 0; +static guint g_watch_id = 0; +static guint g_name_owner_changed_subscription_id = 0; +static bool g_daemon_name_appeared = false; + +static int g_volume_count = 0; +#else static pthread_mutex_t g_m_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; +static Ecore_Fd_Handler* g_m_fd_handler = NULL; -static int g_m_waiting_time = 3000; -static int g_m_waiting_short_time = 200; static bool g_is_connection_opened = false; -static Ecore_Fd_Handler* g_m_fd_handler = NULL; +static int g_m_waiting_time = 3000; +static int g_m_waiting_short_time = 200; static DBusConnection* g_m_conn_sender = NULL; static DBusConnection* g_m_conn_listener = NULL; -static int g_volume_count = 0; - +#endif extern void __vc_mgr_cb_all_result(vc_result_type_e type); @@ -43,7 +55,7 @@ extern void __vc_mgr_cb_system_result(); extern void __vc_mgr_cb_speech_detected(); -extern int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg); +extern int __vc_mgr_cb_error(int reason, int daemon_pid, const char* msg); extern int __vc_mgr_cb_set_volume(float volume); @@ -75,6 +87,7 @@ extern int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_te extern void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result); +#ifndef USE_GDBUS static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_m_conn_listener) return ECORE_CALLBACK_RENEW; @@ -654,8 +667,323 @@ static void __vc_mgr_dbus_connection_free() } } +#endif + +#ifdef USE_GDBUS +gboolean vcd_manager_method_hello(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int response = -1; + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get hello : pid(%d) ", pid); + response = 1; + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get hello : invalid pid "); + } + gdbus_vcmanager_complete_vcd_manager_method_hello(service, invocation, response); + return TRUE; +} + +gboolean vcd_manager_method_speech_detected(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get Speech detected"); + __vc_mgr_cb_speech_detected(); + gdbus_vcmanager_complete_vcd_manager_method_speech_detected(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_all_result(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gint result_type, gpointer user_data) +{ + __vc_mgr_cb_all_result((vc_result_type_e)result_type); + gdbus_vcmanager_complete_vcd_manager_method_all_result(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_pre_result(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gint event, const gchar* pre_result, gpointer user_data) +{ + if (NULL != pre_result) { + __vc_mgr_cb_pre_result((vc_pre_result_event_e)event, pre_result); + } + gdbus_vcmanager_complete_vcd_manager_method_pre_result(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_result(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + __vc_mgr_cb_system_result(); + gdbus_vcmanager_complete_vcd_manager_method_result(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_set_volume(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gint volume, gpointer user_data) +{ + if (10 == g_volume_count) { + SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set volume"); + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set volume : volume(%d)", volume); + g_volume_count = 0; + } + + __vc_mgr_cb_set_volume(volume); + g_volume_count++; + gdbus_vcmanager_complete_vcd_manager_method_set_volume(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_dialog(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gint pid, const gchar* disp_text, const gchar* utt_text, gboolean continuous, gpointer user_data) +{ + __vc_mgr_cb_dialog(pid, disp_text, utt_text, continuous); + gdbus_vcmanager_complete_vcd_manager_method_dialog(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_set_private_data(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gint pid, const gchar* key, const gchar* data, gpointer user_data) +{ + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get request set private data : pid(%d) ", pid); + __vc_mgr_cb_private_data_set(key, data); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request set private data : invalid pid "); + } + gdbus_vcmanager_complete_vcd_manager_method_set_private_data(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_get_private_data(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + int pid, const gchar* key, gpointer user_data) +{ + gint ret = 0; + gchar* value = NULL; + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get request get private data : pid(%d) ", pid); + ret = __vc_mgr_cb_private_data_requested(key, &value); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request get private data : invalid pid "); + } + gdbus_vcmanager_complete_vcd_manager_method_get_private_data(service, invocation, ret, value); + return TRUE; +} + +gboolean vcd_manager_method_specific_engine_result(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + const gchar* engine_app_id, const gchar* event, const gchar* result, gpointer user_data) +{ + if (NULL != result) { + __vc_mgr_cb_specific_engine_result(engine_app_id, event, result); + } + gdbus_vcmanager_complete_vcd_manager_method_specific_engine_result(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_feedback_audio_format(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gint rate, gint channel, gint audio_type, gpointer user_data) +{ + __vc_mgr_cb_feedback_audio_format(rate, channel, audio_type); + gdbus_vcmanager_complete_vcd_manager_method_feedback_audio_format(service, invocation); + return TRUE; +} + +gboolean vcd_manager_method_feedback_streaming(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + gint pid, gint utt_id, gint event, guint size, GVariant* buffer, gpointer user_data) +{ + int index = 0; + GVariantIter *iter; + guchar uc; + + char *data = NULL; + data = malloc(size); + if (!data) return FALSE; + + g_variant_get(buffer, "ay", &iter); + while (g_variant_iter_loop(iter, "y", &uc)) { + if (index < size) { + data[index++] = uc; + } else { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] max size reached : %d", index); + } + } + g_variant_iter_free(iter); + + __vc_mgr_cb_feedback_streaming(pid, utt_id, event, data, size); + + gdbus_vcmanager_complete_vcd_manager_method_feedback_streaming(service, invocation); + + free(data); + return TRUE; +} + +gboolean vcc_manager_method_set_foreground(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + int pid, gboolean value, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false"); + + __vc_mgr_cb_set_foreground(pid, value); + gdbus_vcmanager_complete_vcc_manager_method_set_foreground(service, invocation); + return TRUE; +} + +gboolean vcw_manager_method_set_foreground(GDBusVcmanager *service, GDBusMethodInvocation *invocation, + int pid, gboolean value, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false"); + + __vc_mgr_cb_set_foreground(pid, value); + gdbus_vcmanager_complete_vcw_manager_method_set_foreground(service, invocation); + return TRUE; +} + +static void +on_name_acquired(GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCM, "Name acquired : %s", name); + + GDBusVcmanager *service; + GError *error = NULL; + + service = gdbus_vcmanager_skeleton_new(); + + /* vc client methods */ + g_signal_connect(service, "handle-vcc-manager-method-set-foreground", + G_CALLBACK(vcc_manager_method_set_foreground), NULL); + + /* vc daemon methods */ + g_signal_connect(service, "handle-vcd-manager-method-hello", + G_CALLBACK(vcd_manager_method_hello), NULL); + g_signal_connect(service, "handle-vcd-manager-method-speech-detected", + G_CALLBACK(vcd_manager_method_speech_detected), NULL); + g_signal_connect(service, "handle-vcd-manager-method-all-result", + G_CALLBACK(vcd_manager_method_all_result), NULL); + + g_signal_connect(service, "handle-vcd-manager-method-pre-result", + G_CALLBACK(vcd_manager_method_pre_result), NULL); + g_signal_connect(service, "handle-vcd-manager-method-result", + G_CALLBACK(vcd_manager_method_result), NULL); + g_signal_connect(service, "handle-vcd-manager-method-set-volume", + G_CALLBACK(vcd_manager_method_set_volume), NULL); + g_signal_connect(service, "handle-vcd-manager-method-dialog", + G_CALLBACK(vcd_manager_method_dialog), NULL); + g_signal_connect(service, "handle-vcd-manager-method-set-private-data", + G_CALLBACK(vcd_manager_method_set_private_data), NULL); + g_signal_connect(service, "handle-vcd-manager-method-get-private-data", + G_CALLBACK(vcd_manager_method_get_private_data), NULL); + g_signal_connect(service, "handle-vcd-manager-method-specific-engine-result", + G_CALLBACK(vcd_manager_method_specific_engine_result), NULL); + g_signal_connect(service, "handle-vcd-manager-method-feedback-audio-format", + G_CALLBACK(vcd_manager_method_feedback_audio_format), NULL); + g_signal_connect(service, "handle-vcd-manager-method-feedback-streaming", + G_CALLBACK(vcd_manager_method_feedback_streaming), NULL); + + /* vc widget methods */ + g_signal_connect(service, "handle-vcw-manager-method-set-foreground", + G_CALLBACK(vcw_manager_method_set_foreground), NULL); + + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), + connection, VC_MANAGER_SERVICE_OBJECT_PATH, &error); + if (error) { + SLOG(LOG_DEBUG, TAG_VCM, "Error : %s\n", error->message); + g_error_free(error); + } +} + +static void _on_name_owner_changed(GDBusConnection *connection, + const gchar *sender_name, const gchar *object_path, + const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) +{ + gchar *name; + gchar *old_owner; + gchar *new_owner; + + g_variant_get(parameters, + "(sss)", + &name, + &old_owner, + &new_owner); + + if (g_name_owner_changed_subscription_id > 0) { + g_dbus_connection_signal_unsubscribe(connection, g_name_owner_changed_subscription_id); + g_name_owner_changed_subscription_id = 0; + } + + SLOG(LOG_ERROR, TAG_VCM, "name_owner_changed(%s: %s -> %s) interface %s sender %s object %s", + name, old_owner, new_owner, interface_name, sender_name, object_path); + __vc_mgr_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); + + g_free(name); + g_free(old_owner); + g_free(new_owner); +} + +static void name_appeared_handler(GDBusConnection *connection, + const gchar *name, const gchar *name_owner, gpointer user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@ Name appeared : name %s owner %s", name, name_owner); + g_daemon_name_appeared = true; +} + +static void name_vanished_handler(GDBusConnection *connection, + const gchar *name, gpointer user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@ Name vanished : name %s", name); + g_daemon_name_appeared = false; +} + +#endif + +static void vcd_signal_set_service_state(GDBusVcdaemon* proxy, + gint state, gpointer user_data) +{ + SLOG(LOG_INFO, TAG_VCM, "@@ state changed : %d", state); + + __vc_mgr_cb_service_state(state); +} + +static void vcd_manager_signal_send_error(GDBusVcdaemon* proxy, + gint reason, gint daemon_pid, const gchar* err_msg, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCM, "Error Signal : reason(%d), daemon_pid(%d), err_msg(%s)", + reason, daemon_pid, err_msg); +} + int vc_mgr_dbus_open_connection() { +#ifdef USE_GDBUS + GError* error = NULL; + g_connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); + g_watch_id = g_bus_watch_name_on_connection(g_connection, VC_DAEMON_SERVICE_NAME, 0, + name_appeared_handler, + name_vanished_handler, + NULL, NULL); + + char service_name[64]; + memset(service_name, '\0', 64); + snprintf(service_name, 64, "%s", VC_MANAGER_SERVICE_NAME); + g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, + service_name, 0, NULL, on_name_acquired, NULL, NULL, NULL); + SLOG(LOG_DEBUG, TAG_VCM, "service_name : %s, %d", service_name, g_own_name_id); + + g_daemon_proxy = gdbus_vcdaemon_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + VC_DAEMON_SERVICE_NAME, VC_DAEMON_SERVICE_OBJECT_PATH, NULL, &error); + if (error) { + SLOG(LOG_DEBUG, TAG_VCM, "Error : %s", error->message); + g_error_free(error); + } else { + /* vc common signals */ + g_signal_connect(g_daemon_proxy, "vcd-signal-set-service-state", + G_CALLBACK(vcd_signal_set_service_state), NULL); + + /* vc manager signals */ + g_signal_connect(g_daemon_proxy, "vcd-manager-signal-send-error", + G_CALLBACK(vcd_manager_signal_send_error), NULL); + } +#else pthread_mutex_lock(&g_m_dbus_mutex); if (NULL != g_m_conn_sender && NULL != g_m_conn_listener) { @@ -765,12 +1093,30 @@ int vc_mgr_dbus_open_connection() pthread_mutex_unlock(&g_m_dbus_mutex); SLOG(LOG_INFO, TAG_VCM, "[INFO] manager dbus connection is opened"); - +#endif return VC_ERROR_NONE; } int vc_mgr_dbus_close_connection() { +#ifdef USE_GDBUS + if (g_daemon_proxy) { + g_object_unref(g_daemon_proxy); + g_daemon_proxy = NULL; + } + if (g_own_name_id) { + g_bus_unown_name(g_own_name_id); + g_own_name_id = 0; + } + if (g_watch_id) { + g_bus_unwatch_name(g_watch_id); + g_watch_id = 0; + } + if (g_connection != NULL) { + g_object_unref(g_connection); + g_connection = NULL; + } +#else pthread_mutex_lock(&g_m_dbus_mutex); DBusError err; @@ -803,12 +1149,25 @@ int vc_mgr_dbus_close_connection() pthread_mutex_unlock(&g_m_dbus_mutex); SLOG(LOG_INFO, TAG_VCM, "[INFO] manager dbus connection is closed"); - +#endif return VC_ERROR_NONE; } int vc_mgr_dbus_reconnect() { +#ifdef USE_GDBUS + if (!g_own_name_id || !g_daemon_proxy) { + vc_mgr_dbus_close_connection(); + + if (0 != vc_mgr_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to reconnect"); //LCOV_EXCL_LINE + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect"); //LCOV_EXCL_LINE + return 0; + } +#else if (!g_m_conn_sender || !g_m_conn_listener) { vc_mgr_dbus_close_connection(); @@ -837,16 +1196,24 @@ int vc_mgr_dbus_reconnect() SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect"); } - +#endif return 0; } static int __dbus_check() { +#ifdef USE_GDBUS + SLOG(LOG_DEBUG, TAG_VCM, "%d %p", g_own_name_id, g_daemon_proxy); //LCOV_EXCL_LINE + if (0 == g_own_name_id || NULL == g_daemon_proxy) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NULL connection"); //LCOV_EXCL_LINE + return vc_mgr_dbus_reconnect(); + } +#else if (NULL == g_m_conn_sender || NULL == g_m_conn_listener) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NULL connection"); //LCOV_EXCL_LINE return vc_mgr_dbus_reconnect(); } +#endif return 0; } @@ -855,7 +1222,20 @@ int vc_mgr_dbus_request_hello() if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vc_method_hello_sync(g_daemon_proxy, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -892,6 +1272,7 @@ int vc_mgr_dbus_request_hello() } return result; +#endif } static int __dbus_restore_daemon() @@ -899,19 +1280,15 @@ static int __dbus_restore_daemon() int ret = -1; int count = 0; while (0 != ret) { + usleep(100000); + SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] requesting hello : %d", count); ret = vc_mgr_dbus_request_hello(); if (0 != ret) { - if (VC_ERROR_TIMED_OUT != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry restore daemon"); + count++; + if (VC_RETRY_COUNT == count) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry restore daemon"); - usleep(10000); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); - break; - } } } else { SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] restore daemon"); @@ -925,7 +1302,34 @@ int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* servi if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + } + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vcm_daemon_method_initialize_sync(g_daemon_proxy, + pid, audio_streaming_mode, &result, service_state, foreground, daemon_pid, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + if (0 == result && NULL != g_connection && 0 == g_name_owner_changed_subscription_id) { + g_name_owner_changed_subscription_id = g_dbus_connection_signal_subscribe(g_connection, + "org.freedesktop.DBus", "org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus", + VC_DAEMON_SERVICE_NAME, G_DBUS_SIGNAL_FLAGS_NONE, _on_name_owner_changed, NULL, NULL); + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -1026,14 +1430,39 @@ int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* servi } return result; +#endif } int vc_mgr_dbus_request_finalize(int pid) { - if (0 != __dbus_check()) { +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } return VC_ERROR_OPERATION_FAILED; } + GError *error = NULL; + gint result; + if (g_name_owner_changed_subscription_id > 0) { + g_dbus_connection_signal_unsubscribe(g_connection, g_name_owner_changed_subscription_id); + g_name_owner_changed_subscription_id = 0; + } + if (!gdbus_vcdaemon_call_vcm_daemon_method_finalize_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -1116,7 +1545,7 @@ int vc_mgr_dbus_request_finalize(int pid) vc_mgr_dbus_reconnect(); result = VC_ERROR_TIMED_OUT; } - +#endif return result; } @@ -1125,7 +1554,30 @@ int vc_mgr_dbus_request_set_command(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_set_command_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -1199,6 +1651,7 @@ int vc_mgr_dbus_request_set_command(int pid) } return result; +#endif } int vc_mgr_dbus_request_unset_command(int pid) @@ -1206,7 +1659,30 @@ int vc_mgr_dbus_request_unset_command(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_unset_command_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -1280,6 +1756,7 @@ int vc_mgr_dbus_request_unset_command(int pid) } return result; +#endif } int vc_mgr_dbus_request_demandable_client(int pid) @@ -1287,7 +1764,30 @@ int vc_mgr_dbus_request_demandable_client(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_set_demandable_client_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -1361,6 +1861,7 @@ int vc_mgr_dbus_request_demandable_client(int pid) } return result; +#endif } int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) @@ -1369,6 +1870,30 @@ int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_set_audio_type_sync(g_daemon_proxy, + pid, audio_type, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -1444,6 +1969,7 @@ int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) } return result; +#endif } int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) @@ -1451,7 +1977,34 @@ int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + GError *error = NULL; + gint result; + gchar *temp = NULL; + if (!gdbus_vcdaemon_call_vcm_daemon_method_get_audio_type_sync(g_daemon_proxy, + pid, &result, &temp, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + if (NULL != audio_type && NULL != temp) { + *audio_type = strdup(temp); + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -1532,10 +2085,16 @@ int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) } return result; +#endif } int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* data) { +#ifdef USE_GDBUS + gdbus_vcdaemon_call_vcm_daemon_method_set_private_data(g_daemon_proxy, + pid, key, data, NULL, NULL, NULL); + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1577,10 +2136,30 @@ int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* d dbus_message_unref(msg); return VC_ERROR_NONE; +#endif } int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data) { +#ifdef USE_GDBUS + GError *error = NULL; + gint result = 0; + gchar *temp = NULL; + if (!gdbus_vcdaemon_call_vcm_daemon_method_get_private_data_sync(g_daemon_proxy, + pid, key, &result, &temp, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + if (NULL != data && NULL != temp) { + *data = strdup(temp); + } + return result; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1651,6 +2230,7 @@ int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data) } return result; +#endif } int vc_mgr_dbus_request_set_client_info(int pid) @@ -1658,6 +2238,33 @@ int vc_mgr_dbus_request_set_client_info(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_set_client_info_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } DBusError err; dbus_error_init(&err); @@ -1733,10 +2340,26 @@ int vc_mgr_dbus_request_set_client_info(int pid) } return result; +#endif } int vc_mgr_dbus_request_set_domain(int pid, const char* domain) { +#ifdef USE_GDBUS + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_set_domain_sync(g_daemon_proxy, + pid, domain, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1800,10 +2423,16 @@ int vc_mgr_dbus_request_set_domain(int pid, const char* domain) } return result; +#endif } int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send_event) { +#ifdef USE_GDBUS + gdbus_vcdaemon_call_vcm_daemon_method_do_action(g_daemon_proxy, + pid, type, send_event, NULL, NULL, NULL); + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1843,6 +2472,7 @@ int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send dbus_message_unref(msg); return 0; +#endif } int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client) @@ -1850,6 +2480,33 @@ int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_comm if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_request_start_sync(g_daemon_proxy, + pid, recognition_mode, exclusive_command_option, start_by_client, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } DBusError err; dbus_error_init(&err); @@ -1932,6 +2589,7 @@ int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_comm } return result; +#endif } int vc_mgr_dbus_request_stop(int pid) @@ -1939,7 +2597,30 @@ int vc_mgr_dbus_request_stop(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_request_stop_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -2014,6 +2695,7 @@ int vc_mgr_dbus_request_stop(int pid) } return result; +#endif } int vc_mgr_dbus_request_cancel(int pid) @@ -2021,7 +2703,30 @@ int vc_mgr_dbus_request_cancel(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_request_cancel_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -2096,6 +2801,7 @@ int vc_mgr_dbus_request_cancel(int pid) } return result; +#endif } int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type) @@ -2103,7 +2809,30 @@ int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_enable_command_type_sync(g_daemon_proxy, + pid, cmd_type, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else DBusError err; dbus_error_init(&err); @@ -2179,6 +2908,7 @@ int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type) } return result; +#endif } int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type) @@ -2186,6 +2916,33 @@ int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_disable_command_type_sync(g_daemon_proxy, + pid, cmd_type, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } DBusError err; dbus_error_init(&err); @@ -2262,8 +3019,10 @@ int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type) } return result; +#endif } +#ifndef USE_GDBUS static DBusMessage* __get_message(int pid, const char* method, int type) { char service_name[64]; @@ -2290,9 +3049,13 @@ static DBusMessage* __get_message(int pid, const char* method, int type) return dbus_message_new_method_call(service_name, object_path, target_if_name, method); } +#endif int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) { +#ifdef USE_GDBUS + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2331,10 +3094,16 @@ int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) dbus_message_unref(msg); return 0; +#endif } int vc_mgr_dbus_send_result_selection(int pid) { +#ifdef USE_GDBUS + gdbus_vcdaemon_call_vcm_daemon_method_result_selection(g_daemon_proxy, + pid, NULL, NULL, NULL); + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2370,10 +3139,16 @@ int vc_mgr_dbus_send_result_selection(int pid) } return 0; +#endif } int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request) { +#ifdef USE_GDBUS + gdbus_vcdaemon_call_vcm_daemon_method_specific_engine_request(g_daemon_proxy, + pid, engine_app_id, event, request, NULL, NULL, NULL); + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2414,10 +3189,17 @@ int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, dbus_message_unref(msg); return 0; +#endif } int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status) { +#ifdef USE_GDBUS + /* To Client */ + //gdbus_vcdaemon_call_vcm_daemon_method_utterance_status(g_daemon_proxy, + // utt_id, utt_status, NULL, NULL, NULL); + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2450,10 +3232,20 @@ int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status) dbus_message_unref(msg); return 0; +#endif } int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) { +#ifdef USE_GDBUS + GVariant *variant = g_variant_new_from_data(G_VARIANT_TYPE ("ay"), + buffer, len, TRUE, NULL, NULL); + + gdbus_vcdaemon_call_vcm_daemon_method_send_audio_streaming(g_daemon_proxy, + pid, event, len, variant, NULL, NULL, NULL); + + return 0; +#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2492,6 +3284,7 @@ int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, dbus_message_unref(msg); return 0; +#endif } int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_event) @@ -2499,6 +3292,33 @@ int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_ev if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } +#ifdef USE_GDBUS + if (false == g_daemon_name_appeared) { + int ret = __dbus_restore_daemon(); + if (VC_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); + return VC_ERROR_TIMED_OUT; + } + return VC_ERROR_OPERATION_FAILED; + } + + GError *error = NULL; + gint result; + if (!gdbus_vcdaemon_call_vcm_daemon_method_change_system_volume_sync(g_daemon_proxy, + pid, volume_event, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); + } + } + return result; +#else + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } DBusError err; dbus_error_init(&err); @@ -2576,5 +3396,6 @@ int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_ev } return result; +#endif } diff --git a/client/vc_setting.c b/client/vc_setting.c old mode 100755 new mode 100644 diff --git a/client/vc_setting_dbus.c b/client/vc_setting_dbus.c old mode 100755 new mode 100644 index c249d40..a28d700 --- a/client/vc_setting_dbus.c +++ b/client/vc_setting_dbus.c @@ -17,7 +17,15 @@ #include "vc_setting_dbus.h" #include "vc_main.h" +#define USE_GDBUS +#ifdef USE_GDBUS +#include "vc_gdbus.h" + +static GDBusVcdaemon *g_daemon_proxy = NULL; +static int g_own_name_id = 0; + +#else static int g_s_waiting_time = 3000; static Ecore_Fd_Handler* g_s_fd_handler = NULL; @@ -25,7 +33,9 @@ static Ecore_Fd_Handler* g_s_fd_handler = NULL; static DBusConnection* g_s_conn_sender = NULL; static DBusConnection* g_s_conn_listener = NULL; +#endif +#ifndef USE_GDBUS static Eina_Bool listener_setting_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_s_conn_listener) return ECORE_CALLBACK_RENEW; @@ -112,9 +122,52 @@ static void __vc_setting_dbus_connection_free() g_s_conn_sender = NULL; } } +#endif + +#ifdef USE_GDBUS +static void +on_name_acquired(GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCS, "Name acquired : %s", name); + + GDBusVcsetting *service; + GError *error = NULL; + + service = gdbus_vcsetting_skeleton_new(); + + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), + connection, VC_SETTING_SERVICE_OBJECT_PATH, &error); + if (error) { + SLOG(LOG_DEBUG, TAG_VCS, "Error : %s\n", error->message); + g_error_free(error); + } +} + +#endif int vc_setting_dbus_open_connection() { +#ifdef USE_GDBUS + int pid = getpid(); + + char service_name[64]; + memset(service_name, '\0', 64); + snprintf(service_name, 64, "%s%d", VC_SETTING_SERVICE_NAME, pid); + g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, + service_name, 0, NULL, on_name_acquired, NULL, NULL, NULL); + SLOG(LOG_DEBUG, TAG_VCS, "service_name : %s, %d", service_name, g_own_name_id); + + GError *error = NULL; + g_daemon_proxy = gdbus_vcdaemon_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + VC_DAEMON_SERVICE_NAME, VC_DAEMON_SERVICE_OBJECT_PATH, NULL, &error); + if (error) { + SLOG(LOG_DEBUG, TAG_VCS, "Error : %s", error->message); + g_error_free(error); + } + return 0; +#else if (NULL != g_s_conn_sender && NULL != g_s_conn_listener) { SLOG(LOG_WARN, TAG_VCS, "already existed connection "); return 0; @@ -210,10 +263,22 @@ int vc_setting_dbus_open_connection() } return 0; +#endif } int vc_setting_dbus_close_connection() { +#ifdef USE_GDBUS + if (g_daemon_proxy) { + g_object_unref(g_daemon_proxy); + g_daemon_proxy = NULL; + } + if (g_own_name_id) { + g_bus_unown_name(g_own_name_id); + g_own_name_id = 0; + } + return 0; +#else DBusError err; dbus_error_init(&err); @@ -242,10 +307,24 @@ int vc_setting_dbus_close_connection() __vc_setting_dbus_connection_free(); return 0; +#endif } int vc_setting_dbus_reconnect() { +#ifdef USE_GDBUS + if (!g_own_name_id || !g_daemon_proxy) { + vc_setting_dbus_close_connection(); + + if (0 != vc_setting_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCS, "[ERROR] Fail to reconnect"); //LCOV_EXCL_LINE + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCS, "[DBUS] Reconnect"); //LCOV_EXCL_LINE + } + return 0; +#else if (!g_s_conn_sender || !g_s_conn_listener) { vc_setting_dbus_close_connection(); @@ -275,10 +354,25 @@ int vc_setting_dbus_reconnect() } return 0; +#endif } int vc_setting_dbus_request_hello() { +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vc_method_hello_sync(g_daemon_proxy, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCS, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCS, "Failed without explicit error"); + } + } + return result; +#else if (NULL == g_s_conn_sender) { return VC_ERROR_OPERATION_FAILED; } @@ -318,10 +412,26 @@ int vc_setting_dbus_request_hello() } return result; +#endif } int vc_setting_dbus_request_set_language(int pid, const char* language) { +#ifdef USE_GDBUS + GError *error = NULL; + int result; + if (!gdbus_vcdaemon_call_vcs_daemon_method_set_language_sync(g_daemon_proxy, + pid, language, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCS, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCS, "Failed without explicit error"); + } + } + return result; +#else if (NULL == g_s_conn_sender) { SLOG(LOG_ERROR, TAG_VCS, "[ERROR] Dbus does not open"); return VC_ERROR_OPERATION_FAILED; @@ -381,4 +491,5 @@ int vc_setting_dbus_request_set_language(int pid, const char* language) } return result; +#endif } diff --git a/client/vc_setting_dbus.h b/client/vc_setting_dbus.h old mode 100755 new mode 100644 diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index eddeb77..1108085 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -21,18 +21,27 @@ #include "vc_widget_client.h" #include "vc_widget_dbus.h" +#define USE_GDBUS -static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; +#ifdef USE_GDBUS +#include "vc_gdbus.h" + +static GDBusVcdaemon *g_daemon_proxy = NULL; +static int g_own_name_id = 0; +#else static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; static int g_w_waiting_time = 3000; static int g_w_waiting_short_time = 200; + static bool g_is_connection_opened = false; static Ecore_Fd_Handler* g_w_fd_handler = NULL; -static DBusConnection* g_w_conn_sender = NULL; static DBusConnection* g_w_conn_listener = NULL; +static DBusConnection* g_w_conn_sender = NULL; +#endif extern int __vc_widget_cb_error(int reason, int daemon_pid, char* msg); @@ -44,7 +53,7 @@ extern bool __vc_widget_cb_asr_result(int event, const char* asr_result); extern int __vc_widget_cb_service_state(int state); - +#ifndef USE_GDBUS static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_w_conn_listener) return ECORE_CALLBACK_RENEW; @@ -280,9 +289,113 @@ static void __vc_widget_dbus_connection_free() g_w_conn_sender = NULL; } } +#endif + +#ifdef USE_GDBUS + +gboolean vcd_widget_method_hello(GDBusVcwidget *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int response = -1; + + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : pid(%d) ", pid); + response = 1; + } else { + SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : invalid pid "); + } + + gdbus_vcwidget_complete_vcd_widget_method_hello(service, invocation, response); + return TRUE; +} + +gboolean vcd_widget_method_show_tooltip(GDBusVcwidget *service, GDBusMethodInvocation *invocation, + int pid, gboolean show, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget show tooltip : pid(%d), show(%d)", pid, show); + __vc_widget_cb_show_tooltip(pid, show); + + gdbus_vcwidget_complete_vcd_widget_method_show_tooltip(service, invocation); + return TRUE; +} + +gboolean vcd_widget_method_result(GDBusVcwidget *service, GDBusMethodInvocation *invocation, + int pid, gboolean show, gpointer user_data) +{ + __vc_widget_cb_result(); + + gdbus_vcwidget_complete_vcd_widget_method_result(service, invocation); + return TRUE; +} + + +gboolean vcd_widget_method_asr_result(GDBusVcwidget *service, GDBusMethodInvocation *invocation, + int event, const gchar* asr_result, gpointer user_data) +{ + int ret = 0; + + if (false == __vc_widget_cb_asr_result(event, asr_result)) + ret = 0; + else + ret = 1; + + SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get asr result, event(%d), asr_result(%s), consumed(%d)", event, asr_result, ret); + gdbus_vcwidget_complete_vcd_widget_method_asr_result(service, invocation, ret); + return TRUE; +} + +static void +on_name_acquired(GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCW, "Name acquired : %s", name); + + GDBusVcwidget *service; + GError *error = NULL; + + service = gdbus_vcwidget_skeleton_new(); + + /* vc daemon methods */ + g_signal_connect(service, "handle-vcd-widget-method-hello", + G_CALLBACK(vcd_widget_method_hello), NULL); + g_signal_connect(service, "handle-vcd-widget-method-result", + G_CALLBACK(vcd_widget_method_result), NULL); + g_signal_connect(service, "handle-vcd-widget-method-asr-result", + G_CALLBACK(vcd_widget_method_asr_result), NULL); + g_signal_connect(service, "handle-vcd-widget-method-show-tooltip", + G_CALLBACK(vcd_widget_method_show_tooltip), NULL); + + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), + connection, VC_WIDGET_SERVICE_OBJECT_PATH, &error); + if (error) { + SLOG(LOG_DEBUG, TAG_VCW, "Error : %s\n", error->message); + g_error_free(error); + } +} +#endif int vc_widget_dbus_open_connection() { +#ifdef USE_GDBUS + int pid = getpid(); + + char service_name[64]; + memset(service_name, '\0', 64); + snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); + g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, + service_name, 0, NULL, on_name_acquired, NULL, NULL, NULL); + SLOG(LOG_DEBUG, TAG_VCW, "service_name : %s, %d", service_name, g_own_name_id); + + GError *error = NULL; + g_daemon_proxy = gdbus_vcdaemon_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + VC_DAEMON_SERVICE_NAME, VC_DAEMON_SERVICE_OBJECT_PATH, NULL, &error); + if (error) { + SLOG(LOG_DEBUG, TAG_VCW, "Error : %s", error->message); + g_error_free(error); + } + return 0; +#else pthread_mutex_lock(&g_w_dbus_mutex); if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) { @@ -398,19 +511,31 @@ int vc_widget_dbus_open_connection() SLOG(LOG_INFO, TAG_VCW, "[INFO] widget dbus connection is opened"); - return 0; +return 0; +#endif } int vc_widget_dbus_close_connection() { +#ifdef USE_GDBUS + if (g_daemon_proxy) { + g_object_unref(g_daemon_proxy); + g_daemon_proxy = NULL; + } + if (g_own_name_id) { + g_bus_unown_name(g_own_name_id); + g_own_name_id = 0; + } + return 0; +#else pthread_mutex_lock(&g_w_dbus_mutex); DBusError err; dbus_error_init(&err); if (NULL != g_w_fd_handler) { - ecore_main_fd_handler_del(g_w_fd_handler); - g_w_fd_handler = NULL; + ecore_main_fd_handler_del(g_w_fd_handler); + g_w_fd_handler = NULL; } if (NULL != g_w_conn_listener) { @@ -437,10 +562,24 @@ int vc_widget_dbus_close_connection() SLOG(LOG_INFO, TAG_VCW, "[INFO] widget dbus connection is closed"); return 0; +#endif } int vc_widget_dbus_reconnect() { +#ifdef USE_GDBUS + if (!g_own_name_id || !g_daemon_proxy) { + vc_widget_dbus_close_connection(); + + if (0 != vc_widget_dbus_open_connection()) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect"); //LCOV_EXCL_LINE + return -1; + } + + SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect"); //LCOV_EXCL_LINE + } + return 0; +#else if (!g_w_conn_sender || !g_w_conn_listener) { vc_widget_dbus_close_connection(); @@ -470,15 +609,45 @@ int vc_widget_dbus_reconnect() } return 0; +#endif } static int __dbus_check() { +#ifdef USE_GDBUS + SLOG(LOG_DEBUG, TAG_VCW, "%d %p", g_own_name_id, g_daemon_proxy); //LCOV_EXCL_LINE + if (0 == g_own_name_id || NULL == g_daemon_proxy) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); //LCOV_EXCL_LINE + return vc_widget_dbus_reconnect(); + } + return 0; +#else if (NULL == g_w_conn_sender || NULL == g_w_conn_listener) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); return vc_widget_dbus_reconnect(); } return 0; +#endif +} + +static GDBusVcmanager* get_manager_proxy() { + char service_name[64] = {0,}; + char object_path[64] = {0,}; + + snprintf(service_name, 64, "%s", VC_MANAGER_SERVICE_NAME); + snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH); + + GError *error = NULL; + GDBusVcmanager *proxy = gdbus_vcmanager_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + service_name, object_path, NULL, &error); + + if (error) { + SLOG(LOG_ERROR, TAG_VCC, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", + proxy, service_name, object_path, error->message); + g_error_free(error); + } + + return proxy; } int vc_widget_dbus_request_hello() @@ -486,7 +655,20 @@ int vc_widget_dbus_request_hello() if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - +#ifdef USE_GDBUS + GError *error = NULL; + int result = 0; + if (!gdbus_vcdaemon_call_vc_method_hello_sync(g_daemon_proxy, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCW, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -524,11 +706,27 @@ int vc_widget_dbus_request_hello() } return result; +#endif } int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid) { +#ifdef USE_GDBUS + GError *error = NULL; + int result; + if (!gdbus_vcdaemon_call_vcw_daemon_method_initialize_sync(g_daemon_proxy, + pid, &result, service_state, daemon_pid, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else pthread_mutex_lock(&g_w_init_mutex); if (0 != __dbus_check()) { pthread_mutex_unlock(&g_w_init_mutex); @@ -619,10 +817,26 @@ int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_p pthread_mutex_unlock(&g_w_init_mutex); return result; +#endif } int vc_widget_dbus_request_finalize(int pid) { +#ifdef USE_GDBUS + GError *error = NULL; + int result; + if (!gdbus_vcdaemon_call_vcw_daemon_method_finalize_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else pthread_mutex_lock(&g_w_init_mutex); if (0 != __dbus_check()) { pthread_mutex_unlock(&g_w_init_mutex); @@ -700,6 +914,7 @@ int vc_widget_dbus_request_finalize(int pid) pthread_mutex_unlock(&g_w_init_mutex); return result; +#endif } int vc_widget_dbus_request_start_recording(int pid, bool command) @@ -707,7 +922,21 @@ int vc_widget_dbus_request_start_recording(int pid, bool command) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - +#ifdef USE_GDBUS + GError *error = NULL; + int result; + if (!gdbus_vcdaemon_call_vcw_daemon_method_start_recording_sync(g_daemon_proxy, + pid, command, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -766,6 +995,7 @@ int vc_widget_dbus_request_start_recording(int pid, bool command) } return result; +#endif } int vc_widget_dbus_set_foreground(int pid, bool value) @@ -773,7 +1003,14 @@ int vc_widget_dbus_set_foreground(int pid, bool value) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - +#ifdef USE_GDBUS + /* To Manager */ + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcw_manager_method_set_foreground(proxy, + pid, value, NULL, NULL, NULL); + if (proxy) g_object_unref(proxy); + return 0; +#else DBusMessage* msg = NULL; int tmp_value = 0; @@ -836,6 +1073,7 @@ int vc_widget_dbus_set_foreground(int pid, bool value) dbus_message_unref(msg); return 0; +#endif } int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) @@ -843,7 +1081,21 @@ int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - +#ifdef USE_GDBUS + GError *error = NULL; + int result; + if (!gdbus_vcdaemon_call_vcw_daemon_method_start_recording_sync(g_daemon_proxy, + pid, enable, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; /* create a signal & check for errors */ @@ -908,6 +1160,7 @@ int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) } return result; +#endif } int vc_widget_dbus_request_start(int pid, int silence) @@ -915,7 +1168,21 @@ int vc_widget_dbus_request_start(int pid, int silence) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - +#ifdef USE_GDBUS + GError *error = NULL; + int result; + if (!gdbus_vcdaemon_call_vcw_daemon_method_start_sync(g_daemon_proxy, + pid, silence, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; /* create a signal & check for errors */ @@ -977,6 +1244,7 @@ int vc_widget_dbus_request_start(int pid, int silence) } return result; +#endif } int vc_widget_dbus_request_stop(int pid) @@ -984,7 +1252,21 @@ int vc_widget_dbus_request_stop(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - +#ifdef USE_GDBUS + GError *error = NULL; + int result; + if (!gdbus_vcdaemon_call_vcw_daemon_method_stop_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; /* create a signal & check for errors */ @@ -1043,6 +1325,7 @@ int vc_widget_dbus_request_stop(int pid) } return result; +#endif } int vc_widget_dbus_request_cancel(int pid) @@ -1050,7 +1333,21 @@ int vc_widget_dbus_request_cancel(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - +#ifdef USE_GDBUS + GError *error = NULL; + int result; + if (!gdbus_vcdaemon_call_vcw_daemon_method_cancel_sync(g_daemon_proxy, + pid, &result, NULL, &error)) { + if (error) { + SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); + result = VC_ERROR_OPERATION_FAILED; + g_error_free(error); + } else { + SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); + } + } + return result; +#else DBusMessage* msg; /* create a signal & check for errors */ @@ -1109,4 +1406,5 @@ int vc_widget_dbus_request_cancel(int pid) } return result; +#endif } diff --git a/common/vc_config_mgr.c b/common/vc_config_mgr.c old mode 100755 new mode 100644 diff --git a/common/vc_defs.h b/common/vc_defs.h index 1686581..a3a62dc 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -30,7 +30,7 @@ extern "C" { *******************************************************************************************/ #define VC_CLIENT_SERVICE_NAME "org.tizen.voice.vcclient" -#define VC_CLIENT_SERVICE_OBJECT_PATH "/org/tize/voice/vcclient" +#define VC_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/voice/vcclient" #define VC_CLIENT_SERVICE_INTERFACE "org.tizen.voice.vcclient" #define VC_WIDGET_SERVICE_NAME "org.tizen.voice.vcwidget" @@ -38,15 +38,15 @@ extern "C" { #define VC_WIDGET_SERVICE_INTERFACE "org.tizen.voice.vcwidget" #define VC_MANAGER_SERVICE_NAME "org.tizen.voice.vcmanager" -#define VC_MANAGER_SERVICE_OBJECT_PATH "/org/tize/voice/vcmanager" +#define VC_MANAGER_SERVICE_OBJECT_PATH "/org/tizen/voice/vcmanager" #define VC_MANAGER_SERVICE_INTERFACE "org.tizen.voice.vcmanager" -#define VC_SERVER_SERVICE_NAME "org.tizen.voice.vcserver" -#define VC_SERVER_SERVICE_OBJECT_PATH "/org/tizen/voice/vcserver" -#define VC_SERVER_SERVICE_INTERFACE "org.tizen.voice.vcserver" +#define VC_DAEMON_SERVICE_NAME "org.tizen.voice.vcdaemon" +#define VC_DAEMON_SERVICE_OBJECT_PATH "/org/tizen/voice/vcdaemon" +#define VC_DAEMON_SERVICE_INTERFACE "org.tizen.voice.vcdaemon" #define VC_SETTING_SERVICE_NAME "org.tizen.voice.vcsetting" -#define VC_SETTING_SERVICE_OBJECT_PATH "/org/tize/voice/vcsetting" +#define VC_SETTING_SERVICE_OBJECT_PATH "/org/tizen/voice/vcsetting" #define VC_SETTING_SERVICE_INTERFACE "org.tizen.voice.vcsetting" /****************************************************************************************** diff --git a/common/vc_regex_rule.h b/common/vc_regex_rule.h old mode 100755 new mode 100644 diff --git a/include/voice_control_command_expand.h b/include/voice_control_command_expand.h old mode 100755 new mode 100644 diff --git a/include/voice_control_setting.h b/include/voice_control_setting.h old mode 100755 new mode 100644 diff --git a/org.tizen.voice.vcserver.service b/org.tizen.voice.vcdaemon.service similarity index 87% rename from org.tizen.voice.vcserver.service rename to org.tizen.voice.vcdaemon.service index aa51fd1..4c73109 100644 --- a/org.tizen.voice.vcserver.service +++ b/org.tizen.voice.vcdaemon.service @@ -1,5 +1,5 @@ [D-BUS Service] -Name=org.tizen.voice.vcserver +Name=org.tizen.voice.vcdaemon #Exec=/usr/bin/vc-daemon #Exec=/bin/sh -c "launch_app org.tizen.vc-engine-default" Exec=/bin/sh -c "vc_getengine get system db/voice/vc/engine/default | awk '{print$5}' | xargs -t -i launch_app {}" diff --git a/org.tizen.voice.vcserver.tv.service b/org.tizen.voice.vcdaemon.tv.service similarity index 75% rename from org.tizen.voice.vcserver.tv.service rename to org.tizen.voice.vcdaemon.tv.service index 22b0781..33ae340 100644 --- a/org.tizen.voice.vcserver.tv.service +++ b/org.tizen.voice.vcdaemon.tv.service @@ -1,4 +1,4 @@ [D-BUS Service] -Name=org.tizen.voice.vcserver +Name=org.tizen.voice.vcdaemon #Exec=/usr/bin/vc-daemon Exec=/bin/sh -c "launch_app org.tizen.voice-client" diff --git a/org.tizen.voice.voice-control.gdbus.xml b/org.tizen.voice.voice-control.gdbus.xml new file mode 100644 index 0000000..b424ee6 --- /dev/null +++ b/org.tizen.voice.voice-control.gdbus.xml @@ -0,0 +1,360 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index d7ceb5a..8872f45 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -33,6 +33,8 @@ BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(pkgmgr-installer) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(gio-unix-2.0) %if "%{tizen_profile_name}" == "tv" BuildRequires: pkgconfig(capi-network-bluetooth) BuildRequires: pkgconfig(capi-network-bluetooth-tv) @@ -131,7 +133,7 @@ find . -name '*.gcno' -exec cp '{}' gcov-obj ';' rm -rf %{buildroot} %if "%{tizen_profile_name}" == "tv" -mv -f org.tizen.voice.vcserver.tv.service org.tizen.voice.vcserver.service +mv -f org.tizen.voice.vcdaemon.tv.service org.tizen.voice.vcdaemon.service %endif %make_install @@ -162,7 +164,7 @@ mkdir -p %{_libdir}/voice/vc %{TZ_SYS_RO_SHARE}/dbus-1/services/org.tizen.voice* %{TZ_SYS_RO_SHARE}/parser-plugins/voice-control.info %{TZ_SYS_RO_ETC}/package-manager/parserlib/metadata/libvc-engine-parser.so* -/etc/dbus-1/session.d/vc-server.conf +/etc/dbus-1/session.d/vc-service.conf %files devel %manifest %{name}-devel.manifest diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 778f56d..98a5c30 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -6,6 +6,7 @@ SET(SRCS ../common/vc_config_parser.c ../common/vc_info_parser.c ../common/vc_json_parser.c + ../common/vc_gdbus.c vcd_client_data.c vcd_server_data.cpp vcd_config.c diff --git a/server/vcd_config.c b/server/vcd_config.c old mode 100755 new mode 100644 diff --git a/server/vcd_config.h b/server/vcd_config.h old mode 100755 new mode 100644 diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 462f1a6..a61912d 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -20,17 +20,84 @@ #include "vcd_dbus_server.h" #include "vcd_main.h" +#define USE_GDBUS +#ifdef USE_GDBUS +#include "vc_gdbus.h" +static GDBusVcdaemon *g_daemon = NULL; +static int g_own_name_id = 0; +#else +static Ecore_Fd_Handler* g_dbus_fd_handler = NULL; static DBusConnection* g_conn_sender = NULL; static DBusConnection* g_conn_listener = NULL; -static Ecore_Fd_Handler* g_dbus_fd_handler = NULL; - static int g_waiting_time = 3000; +#endif + static int g_volume_count = 0; +#ifdef USE_GDBUS +static GDBusVcmanager* get_manager_proxy() { + char service_name[64] = {0,}; + char object_path[64] = {0,}; + + snprintf(service_name, 64, "%s", VC_MANAGER_SERVICE_NAME); + snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH); + + GError *error = NULL; + GDBusVcmanager *proxy = gdbus_vcmanager_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + service_name, object_path, NULL, &error); + + if (error) { + SLOG(LOG_ERROR, TAG_VCD, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", + proxy, service_name, object_path, error->message); + g_error_free(error); + } + + return proxy; +} + +static GDBusVcclient* get_client_proxy(int pid) { + char service_name[64] = {0,}; + char object_path[64] = {0,}; + + snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid); + snprintf(object_path, 64, "%s", VC_CLIENT_SERVICE_OBJECT_PATH); + + GError *error = NULL; + GDBusVcclient *proxy = gdbus_vcclient_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + service_name, object_path, NULL, &error); + + if (error) { + SLOG(LOG_ERROR, TAG_VCD, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", + proxy, service_name, object_path, error->message); + g_error_free(error); + } + + return proxy; +} + +static GDBusVcwidget* get_widget_proxy(int pid) { + char service_name[64] = {0,}; + char object_path[64] = {0,}; + + snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); + snprintf(object_path, 64, "%s", VC_WIDGET_SERVICE_OBJECT_PATH); + + GError *error = NULL; + GDBusVcwidget *proxy = gdbus_vcwidget_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, + service_name, object_path, NULL, &error); + + if (error) { + SLOG(LOG_ERROR, TAG_VCD, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", + proxy, service_name, object_path, error->message); + g_error_free(error); + } + return proxy; +} +#else static DBusMessage* __get_message(int pid, const char* method, vcd_client_type_e type) { char service_name[64] = {0,}; @@ -158,9 +225,17 @@ int vcdc_send_hello(int pid, vcd_client_type_e type) return result; } +#endif int vcdc_send_show_tooltip(int pid, bool show) { +#ifdef USE_GDBUS + GDBusVcwidget* proxy = get_widget_proxy(pid); + gdbus_vcwidget_call_vcd_widget_method_show_tooltip(proxy, + pid, show, NULL, NULL, NULL); + g_object_unref(proxy); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -214,10 +289,25 @@ int vcdc_send_show_tooltip(int pid, bool show) dbus_message_unref(msg); return 0; +#endif } int vcdc_send_set_volume(int manger_pid, float volume) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_set_volume(proxy, + volume, NULL, NULL, NULL); + g_object_unref(proxy); + + if (10 == g_volume_count) { + SLOG(LOG_DEBUG, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manger_pid, volume); + g_volume_count = 0; + } + g_volume_count++; + + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -256,10 +346,49 @@ int vcdc_send_set_volume(int manger_pid, float volume) dbus_message_unref(msg); return 0; +#endif } int vcdc_send_result(int pid, int manager_pid, int cmd_type) { +#ifdef USE_GDBUS + SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Result command type(%d)", cmd_type); + + switch (cmd_type) { + case VC_COMMAND_TYPE_FOREGROUND: + case VC_COMMAND_TYPE_BACKGROUND: + if (pid == manager_pid) { + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_result(proxy, NULL, NULL, NULL); + g_object_unref(proxy); + } else { + GDBusVcclient* proxy = get_client_proxy(pid); + gdbus_vcclient_call_vcd_client_method_result(proxy, NULL, NULL, NULL); + g_object_unref(proxy); + } + break; + case VC_COMMAND_TYPE_WIDGET: { + GDBusVcwidget* proxy = get_widget_proxy(pid); + gdbus_vcwidget_call_vcd_widget_method_result(proxy, NULL, NULL, NULL); + g_object_unref(proxy); + } + break; + case VC_COMMAND_TYPE_SYSTEM: + case VC_COMMAND_TYPE_SYSTEM_BACKGROUND: + case VC_COMMAND_TYPE_EXCLUSIVE: { + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_result(proxy, NULL, NULL, NULL); + g_object_unref(proxy); + } + break; + + default: + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); + return -1; + } + + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -309,10 +438,24 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) dbus_message_unref(msg); return 0; +#endif } int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed) { +#ifdef USE_GDBUS + GError *error = NULL; + gint result = 0; + GDBusVcwidget* proxy = get_widget_proxy(pid); + gdbus_vcwidget_call_vcd_widget_method_asr_result_sync(proxy, + event, asr_result, &result, NULL, &error); + if (error) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Dbus Error (%s)", error->message); + g_error_free(error); + } + g_object_unref(proxy); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -370,10 +513,18 @@ int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_typ SLOG(LOG_ERROR, TAG_VCD, "@@ Result message is NULL "); return VCD_ERROR_OPERATION_FAILED; } +#endif } int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_pre_result(proxy, + event, pre_result, NULL, NULL, NULL); + g_object_unref(proxy); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -403,10 +554,18 @@ int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_ } return 0; +#endif } int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_specific_engine_result(proxy, + engine_app_id, event, result, NULL, NULL, NULL); + g_object_unref(proxy); + return 0; +#else SLOG(LOG_DEBUG, TAG_VCD, "[VCDC] send specific engine result to manager, mgr pid(%d), engine app id(%s), event(%s), result(%s),", manager_pid, engine_app_id, event, result); @@ -439,10 +598,19 @@ int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* eng } return 0; +#endif } int vcdc_send_result_to_manager(int manger_pid, int result_type) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] send result : result type(%d)", result_type); + gdbus_vcmanager_call_vcd_manager_method_all_result(proxy, + result_type, NULL, NULL, NULL); + g_object_unref(proxy); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -476,10 +644,18 @@ int vcdc_send_result_to_manager(int manger_pid, int result_type) dbus_message_unref(msg); return 0; +#endif } int vcdc_send_speech_detected(int manger_pid) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_speech_detected(proxy, + NULL, NULL, NULL); + g_object_unref(proxy); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -510,10 +686,15 @@ int vcdc_send_speech_detected(int manger_pid) dbus_message_unref(msg); return 0; +#endif } int vcdc_send_service_state(vcd_state_e state) { +#ifdef USE_GDBUS + gdbus_vcdaemon_emit_vcd_signal_set_service_state(g_daemon, state); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -595,10 +776,14 @@ int vcdc_send_service_state(vcd_state_e state) dbus_message_unref(msg); return 0; +#endif } int vcdc_send_manager_pid(int manager_pid) { +#ifdef USE_GDBUS + gdbus_vcdaemon_emit_vcd_client_signal_send_manager_pid(g_daemon, manager_pid); +#else DBusError err; dbus_error_init(&err); @@ -626,12 +811,19 @@ int vcdc_send_manager_pid(int manager_pid) } dbus_message_unref(msg); - +#endif return 0; } int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_dialog(proxy, + pid, disp_text, utt_text, continuous, NULL, NULL, NULL); + g_object_unref(proxy); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -693,10 +885,16 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* } return ret; +#endif } int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg) { +#ifdef USE_GDBUS + int daemon_pid = getpid(); + gdbus_vcdaemon_emit_vcd_manager_signal_send_error(g_daemon, reason, daemon_pid, err_msg); + return 0; +#else SLOG(LOG_ERROR, TAG_VCD, "@@ Send error signal to manager"); if (0 != __dbus_check()) { @@ -749,10 +947,18 @@ int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg } return 0; +#endif } int vcdc_send_error_signal(int reason, char *err_msg) { +#ifdef USE_GDBUS + int daemon_pid = getpid(); + gdbus_vcdaemon_emit_vcd_client_signal_send_error(g_daemon, reason, daemon_pid, err_msg); + gdbus_vcdaemon_emit_vcd_manager_signal_send_error(g_daemon, reason, daemon_pid, err_msg); + gdbus_vcdaemon_emit_vcd_widget_signal_send_error(g_daemon, reason, daemon_pid, err_msg); + return 0; +#else SLOG(LOG_ERROR, TAG_VCD, "@@ Send error signal"); if (NULL == err_msg) { @@ -840,10 +1046,18 @@ int vcdc_send_error_signal(int reason, char *err_msg) dbus_message_unref(msg); return 0; +#endif } int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_set_private_data(proxy, + pid, key, data, NULL, NULL, NULL); + g_object_unref(proxy); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -875,10 +1089,28 @@ int vcdc_send_request_set_private_data(int pid, const char* key, const char* dat dbus_message_unref(msg); return VCD_ERROR_NONE; +#endif } int vcdc_send_request_get_private_data(int pid, const char* key, char** data) { +#ifdef USE_GDBUS + GError *error = NULL; + gint result = 0; + gchar* value = NULL; + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_get_private_data_sync(proxy, + pid, key, &result, &value, NULL, &error); + if (error) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Dbus Error (%s)", error->message); + g_error_free(error); + } + if (NULL != data && NULL != value) { + *data = strdup(value); + } + g_object_unref(proxy); + return 0; +#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -936,10 +1168,18 @@ int vcdc_send_request_get_private_data(int pid, const char* key, char** data) } return result; +#endif } int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + gdbus_vcmanager_call_vcd_manager_method_feedback_audio_format(proxy, + rate, channel, audio_type, NULL, NULL, NULL); + g_object_unref(proxy); + return 0; +#else SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback audio format : manager_pid(%d), rate(%d), audio channel(%d), audio type(%d)", manager_pid, rate, channel, audio_type); if (0 != __dbus_check()) { @@ -978,10 +1218,22 @@ int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_aud dbus_message_unref(msg); return ret; +#endif } int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) { +#ifdef USE_GDBUS + GDBusVcmanager* proxy = get_manager_proxy(); + GVariant *variant = g_variant_new_from_data(G_VARIANT_TYPE ("ay"), + buffer, len, TRUE, NULL, NULL); + + gdbus_vcmanager_call_vcd_manager_method_feedback_streaming(proxy, + pid, utt_id, event, len, variant, NULL, NULL, NULL); + + g_object_unref(proxy); + return 0; +#else SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : manager_pid(%d), pid(%d), utt_id(%d) feedback event(%d), buffer(%p), length(%d)", manager_pid, pid, utt_id, event, buffer, len); if (0 != __dbus_check()) { @@ -1022,10 +1274,22 @@ int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id dbus_message_unref(msg); return ret; +#endif } int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) { +#ifdef USE_GDBUS + GDBusVcclient* proxy = get_client_proxy(pid); + GVariant *variant = g_variant_new_from_data(G_VARIANT_TYPE ("ay"), + buffer, len, TRUE, NULL, NULL); + + gdbus_vcclient_call_vcd_client_method_feedback_streaming(proxy, + utt_id, event, len, variant, NULL, NULL, NULL); + + g_object_unref(proxy); + return 0; +#else SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : pid(%d), utt_id(%d), feedback event(%d), buffer(%p), length(%d)", pid, utt_id, event, buffer, len); if (0 != __dbus_check()) { @@ -1065,8 +1329,10 @@ int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, dbus_message_unref(msg); return ret; +#endif } +#ifndef USE_GDBUS static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW; @@ -1261,9 +1527,129 @@ static void __vcd_dbus_connection_free() g_conn_sender = NULL; } } +#endif + +#ifdef USE_GDBUS +static void +on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "Name acquired : %s", name); + + GError *error = NULL; + + g_daemon = gdbus_vcdaemon_skeleton_new(); + + /* vc common methods */ + g_signal_connect(g_daemon, "handle-vc-method-hello", + G_CALLBACK(vc_method_hello), NULL); + + /* vc client methods */ + g_signal_connect(g_daemon, "handle-vcc-daemon-method-initialize", + G_CALLBACK(vcc_daemon_method_initialize), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-finalize", + G_CALLBACK(vcc_daemon_method_finalize), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-set-exclusive-cmd", + G_CALLBACK(vcc_daemon_method_set_exclusive_cmd), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-set-command", + G_CALLBACK(vcc_daemon_method_set_command), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-unset-command", + G_CALLBACK(vcc_daemon_method_unset_command), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-set-foreground", + G_CALLBACK(vcc_daemon_method_set_foreground), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-set-server-dialog", + G_CALLBACK(vcc_daemon_method_set_server_dialog), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-dialog", + G_CALLBACK(vcc_daemon_method_dialog), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-is-system-command-valid", + G_CALLBACK(vcc_daemon_method_is_system_command_valid), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-request-tts", + G_CALLBACK(vcc_daemon_method_request_tts), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-cancel-tts", + G_CALLBACK(vcc_daemon_method_cancel_tts), NULL); + g_signal_connect(g_daemon, "handle-vcc-daemon-method-get-tts-audio-format", + G_CALLBACK(vcc_daemon_method_get_tts_audio_format), NULL); + + /* vc widget methods */ + g_signal_connect(g_daemon, "handle-vcw-daemon-method-initialize", + G_CALLBACK(vcw_daemon_method_initialize), NULL); + g_signal_connect(g_daemon, "handle-vcw-daemon-method-finalize", + G_CALLBACK(vcw_daemon_method_finalize), NULL); + g_signal_connect(g_daemon, "handle-vcw-daemon-method-start-recording", + G_CALLBACK(vcw_daemon_method_start_recording), NULL); + g_signal_connect(g_daemon, "handle-vcw-daemon-method-enable-asr-result", + G_CALLBACK(vcw_daemon_method_enable_asr_result), NULL); + g_signal_connect(g_daemon, "handle-vcw-daemon-method-start", + G_CALLBACK(vcw_daemon_method_start), NULL); + g_signal_connect(g_daemon, "handle-vcw-daemon-method-stop", + G_CALLBACK(vcw_daemon_method_stop), NULL); + g_signal_connect(g_daemon, "handle-vcw-daemon-method-cancel", + G_CALLBACK(vcw_daemon_method_cancel), NULL); + + /* vc manager methods */ + g_signal_connect(g_daemon, "handle-vcm-daemon-method-initialize", + G_CALLBACK(vcm_daemon_method_initialize), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-finalize", + G_CALLBACK(vcm_daemon_method_finalize), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-command", + G_CALLBACK(vcm_daemon_method_set_command), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-unset-command", + G_CALLBACK(vcm_daemon_method_unset_command), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-demandable-client", + G_CALLBACK(vcm_daemon_method_set_demandable_client), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-audio-type", + G_CALLBACK(vcm_daemon_method_set_audio_type), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-get-audio-type", + G_CALLBACK(vcm_daemon_method_get_audio_type), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-client-info", + G_CALLBACK(vcm_daemon_method_set_client_info), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-private-data", + G_CALLBACK(vcm_daemon_method_set_private_data), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-get-private-data", + G_CALLBACK(vcm_daemon_method_get_private_data), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-enable-command-type", + G_CALLBACK(vcm_daemon_method_enable_command_type), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-disable-command-type", + G_CALLBACK(vcm_daemon_method_disable_command_type), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-request-start", + G_CALLBACK(vcm_daemon_method_request_start), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-request-stop", + G_CALLBACK(vcm_daemon_method_request_stop), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-request-cancel", + G_CALLBACK(vcm_daemon_method_request_cancel), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-result-selection", + G_CALLBACK(vcm_daemon_method_result_selection), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-domain", + G_CALLBACK(vcm_daemon_method_set_domain), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-do-action", + G_CALLBACK(vcm_daemon_method_do_action), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-specific-engine-request", + G_CALLBACK(vcm_daemon_method_specific_engine_request), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-send-audio-streaming", + G_CALLBACK(vcm_daemon_method_send_audio_streaming), NULL); + g_signal_connect(g_daemon, "handle-vcm-daemon-method-change-system-volume", + G_CALLBACK(vcm_daemon_method_change_system_volume), NULL); + + /* vc setting methods */ + g_signal_connect(g_daemon, "handle-vcs-daemon-method-set-language", + G_CALLBACK(vcs_daemon_method_set_language), NULL); + + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(g_daemon), + connection, VC_DAEMON_SERVICE_OBJECT_PATH, &error); + + if (error) { + SLOG(LOG_ERROR, TAG_VCD, "Exporting interface error : %s", error->message); + g_error_free(error); + } +} +#endif int vcd_dbus_open_connection() { +#ifdef USE_GDBUS + g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, + VC_DAEMON_SERVICE_NAME, G_BUS_NAME_OWNER_FLAGS_REPLACE, NULL, on_name_acquired, NULL, NULL, NULL); + SLOG(LOG_DEBUG, TAG_VCD, "g_bus_own_name returned %d", g_own_name_id); +#else DBusError err; dbus_error_init(&err); @@ -1356,12 +1742,22 @@ int vcd_dbus_open_connection() } SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to open dbus connection"); - +#endif return 0; } int vcd_dbus_close_connection() { +#ifdef USE_GDBUS + if (g_daemon) { + g_object_unref(g_daemon); + g_daemon = NULL; + } + if (g_own_name_id) { + g_bus_unown_name(g_own_name_id); + g_own_name_id = 0; + } +#else DBusError err; dbus_error_init(&err); @@ -1378,6 +1774,7 @@ int vcd_dbus_close_connection() } __vcd_dbus_connection_free(); +#endif return 0; } diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index b1affc8..421280b 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -22,6 +22,702 @@ #include "vcd_server.h" #include "vcd_config.h" +#define USE_GDBUS + +#ifdef USE_GDBUS +gboolean vc_method_hello(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[ENTER]"); + gdbus_vcdaemon_complete_vc_method_hello(service, invocation); + return TRUE; +} + +gboolean vcc_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_initialize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize"); + } + + int service_state = vcd_server_get_service_state(); + int daemon_pid = getpid(); + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd initialize : pid(%d) daemon_pid(%d)", pid, daemon_pid); + + int mgr_pid = vcd_client_manager_get_pid(); + + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + gdbus_vcdaemon_complete_vcc_daemon_method_initialize(service, invocation, + ret, mgr_pid, service_state, daemon_pid); + + return TRUE; +} + +gboolean vcc_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_mgr_finalize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd finalize : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcc_daemon_method_finalize(service, invocation, ret); + + return TRUE; +} + +gboolean vcc_daemon_method_set_exclusive_cmd(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean value, gpointer user_data) +{ + /* + int ret = vcd_server_set_exclusive_command(pid, value); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_exclusive_cmd"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_exclusive_cmd : pid(%d), exclusive(%d)", pid, value); + + gdbus_vcdaemon_complete_vcc_daemon_method_set_exclusive_cmd(service, invocation, ret); + */ + return TRUE; +} + +gboolean vcc_daemon_method_set_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int cmd_type, gpointer user_data) +{ + int ret = vcd_server_set_command(pid, (vc_cmd_type_e)cmd_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_command"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_command : pid(%d), cmd_type(%d)", pid, cmd_type); + + gdbus_vcdaemon_complete_vcc_daemon_method_set_command(service, invocation, ret); + + return TRUE; +} + +gboolean vcc_daemon_method_unset_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int cmd_type, gpointer user_data) +{ + int ret = vcd_server_unset_command(pid, (vc_cmd_type_e)cmd_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to unset_command"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd unset_command : pid(%d), cmd_type(%d)", pid, cmd_type); + + gdbus_vcdaemon_complete_vcc_daemon_method_unset_command(service, invocation, ret); + + return TRUE; +} + +gboolean vcc_daemon_method_set_foreground(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean value, gpointer user_data) +{ + int ret = vcd_server_set_foreground(pid, value); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_foreground"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_foreground : pid(%d), value(%d)", pid, value); + + gdbus_vcdaemon_complete_vcc_daemon_method_set_foreground(service, invocation); + + return TRUE; +} + +gboolean vcc_daemon_method_set_server_dialog(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* app_id, const gchar* credential, gpointer user_data) +{ + int ret = vcd_server_set_server_dialog(pid, app_id, credential); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_server_dialog"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_server_dialog : pid(%d), app_id(%s)", pid, app_id); + + gdbus_vcdaemon_complete_vcc_daemon_method_set_server_dialog(service, invocation, ret); + + return TRUE; +} + +gboolean vcc_daemon_method_dialog(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* disp_text, const gchar* utt_text, gboolean continuous, gpointer user_data) +{ + int ret = vcd_server_dialog(pid, disp_text, utt_text, continuous); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to dialog"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd dialog : pid(%d), disp_text(%s), utt_text(%s)", pid, disp_text, utt_text); + + gdbus_vcdaemon_complete_vcc_daemon_method_dialog(service, invocation); + + return TRUE; +} + +gboolean vcc_daemon_method_is_system_command_valid(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int is_sys_cmd_valid; + int ret = vcd_server_is_system_command_valid(pid, &is_sys_cmd_valid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to is_system_command_valid"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd is_system_command_valid : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcc_daemon_method_is_system_command_valid(service, invocation, + ret, is_sys_cmd_valid); + + return TRUE; +} + +gboolean vcc_daemon_method_request_tts(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* text, const gchar* language, gboolean to_vcm, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd request tts : pid(%d), text(%s), language(%s), to_vcm(%d)", + pid, text, language, to_vcm); + + int utt_id = -1; + int ret = vcd_server_request_tts(pid, text, language, to_vcm, &utt_id); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to request_tts"); + } + + gdbus_vcdaemon_complete_vcc_daemon_method_request_tts(service, invocation, ret, utt_id); + + return TRUE; +} + +gboolean vcc_daemon_method_cancel_tts(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int utt_id, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd cancel tts : pid(%d), utt_id(%d)", pid, utt_id); + + int ret = vcd_server_cancel_tts(pid, utt_id); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to cancel_tts"); + } + + gdbus_vcdaemon_complete_vcc_daemon_method_cancel_tts(service, invocation, ret); + + return TRUE; +} + +gboolean vcc_daemon_method_get_tts_audio_format(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd get tts audio format : pid(%d)", pid); + + int rate; + int channel; + int audio_type; + int ret = vcd_server_get_tts_audio_format(pid, &rate, &channel, &audio_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get_tts_audio_format"); + } + + gdbus_vcdaemon_complete_vcc_daemon_method_get_tts_audio_format(service, invocation, + ret, rate, channel, audio_type); + + return TRUE; +} + +gboolean vcw_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_widget_initialize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to widget_initialize"); + } + int service_state = vcd_server_get_service_state(); + int daemon_pid = getpid(); + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget initialize : pid(%d) daemon_pid(%d)", pid, daemon_pid); + + gdbus_vcdaemon_complete_vcw_daemon_method_initialize(service, invocation, + ret, service_state, daemon_pid); + + return TRUE; +} + +gboolean vcw_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget finalize : pid(%d)", pid); + + int ret = vcd_server_widget_finalize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to widget_finalize"); + } + + gdbus_vcdaemon_complete_vcw_daemon_method_finalize(service, invocation, ret); + + return TRUE; +} + +gboolean vcw_daemon_method_start_recording(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int widget_command, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget start recording : pid(%d)", pid); + + int ret = vcd_server_widget_start_recording(pid, widget_command); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start_recording"); + } + + gdbus_vcdaemon_complete_vcw_daemon_method_start_recording(service, invocation, ret); + + return TRUE; +} + +gboolean vcw_daemon_method_enable_asr_result(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean enable, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget enable asr result : pid(%d) enable(%d)", pid, enable); + + int ret = vcd_server_widget_enable_asr_result(pid, enable); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to enable_asr_result"); + } + + gdbus_vcdaemon_complete_vcw_daemon_method_enable_asr_result(service, invocation, ret); + + return TRUE; +} + +gboolean vcw_daemon_method_start(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean silence, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget start : pid(%d), silence(%d)", pid, silence); + + int ret = vcd_server_widget_start(pid, silence); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start"); + } + + gdbus_vcdaemon_complete_vcw_daemon_method_start(service, invocation, ret); + + return TRUE; +} + +gboolean vcw_daemon_method_stop(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget stop : pid(%d)", pid); + + int ret = vcd_server_widget_stop(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop"); + } + + gdbus_vcdaemon_complete_vcw_daemon_method_stop(service, invocation, ret); + + return TRUE; +} + +gboolean vcw_daemon_method_cancel(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget cancel : pid(%d)", pid); + + int ret = vcd_server_widget_cancel(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to cancel"); + } + + gdbus_vcdaemon_complete_vcw_daemon_method_cancel(service, invocation, ret); + + return TRUE; +} + +gboolean vcw_daemon_method_set_foreground(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean value, gpointer user_data) +{ + int ret = vcd_server_set_foreground(pid, value); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_foreground"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_foreground : pid(%d), value(%d)", pid, value); + + gdbus_vcdaemon_complete_vcw_daemon_method_set_foreground(service, invocation); + + return TRUE; +} + +gboolean vcm_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int streaming_mode, gpointer user_data) +{ + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)streaming_mode); + int ret = vcd_server_mgr_initialize(pid); + int service_state = vcd_server_get_service_state(); + int foreground = vcd_server_get_foreground(); + int daemon_pid = getpid(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr initialize : pid(%d) service state(%d) foreground(%d) daemon_pid(%d)", pid, service_state, foreground, daemon_pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_initialize(service, invocation, + ret, service_state, foreground, daemon_pid); + + return TRUE; +} + +gboolean vcm_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_mgr_finalize(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_finalize(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_set_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_mgr_set_command(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_command"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_set_command(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_unset_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_mgr_unset_command(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to unset_command"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_unset_command(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_set_demandable_client(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_mgr_set_demandable_client(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_demandable_client"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_set_demandable_client(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_set_audio_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* audio_type, gpointer user_data) +{ + int ret = vcd_server_mgr_set_audio_type(pid, audio_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_audio_type"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); + + gdbus_vcdaemon_complete_vcm_daemon_method_set_audio_type(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_get_audio_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + char* audio_type = NULL; + int ret = vcd_server_mgr_get_audio_type(pid, &audio_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_audio_type"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr get audio type : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_get_audio_type(service, invocation, ret, audio_type); + + return TRUE; +} + +gboolean vcm_daemon_method_set_client_info(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_mgr_set_client_info(pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_client_info"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_set_client_info(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_set_private_data(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* key, const gchar* data, gpointer user_data) +{ + int ret = vcd_server_mgr_set_private_data(pid, key, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_private_data"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data); + + gdbus_vcdaemon_complete_vcm_daemon_method_set_private_data(service, invocation); + + return TRUE; +} + +gboolean vcm_daemon_method_get_private_data(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* key, gpointer user_data) +{ + char* data = NULL; + int ret = vcd_server_mgr_get_private_data(pid, key, &data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get_private_data"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key); + + gdbus_vcdaemon_complete_vcm_daemon_method_get_private_data(service, invocation, ret, data); + + return TRUE; +} + +gboolean vcm_daemon_method_enable_command_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int cmd_type, gpointer user_data) +{ + int ret = vcd_server_mgr_enable_command_type(pid, cmd_type); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to enable_command_type"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr enable command type : pid(%d), cmd_type(%d)", pid, cmd_type); + + gdbus_vcdaemon_complete_vcm_daemon_method_enable_command_type(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_disable_command_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int cmd_type, gpointer user_data) +{ + int ret = vcd_server_mgr_disable_command_type(pid, cmd_type); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to disable_command_type"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr disable command type : pid(%d), cmd_type(%d)", pid, cmd_type); + + gdbus_vcdaemon_complete_vcm_daemon_method_disable_command_type(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_request_start(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int recognition_mode, gboolean exclusive, gboolean start_by_client, gpointer user_data) +{ + int ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, exclusive, start_by_client); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to request_start"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr start : pid(%d) recognition_mode(%d) exclusive(%d) start by client(%d)", pid, recognition_mode, exclusive, start_by_client); + + gdbus_vcdaemon_complete_vcm_daemon_method_request_start(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_request_stop(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_mgr_stop(); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to request_stop"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_request_stop(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_request_cancel(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + int ret = vcd_server_mgr_cancel(); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to request_cancel"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_request_cancel(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_result_selection(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data) +{ + vcd_server_mgr_result_select(); + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid); + + gdbus_vcdaemon_complete_vcm_daemon_method_result_selection(service, invocation); + + return TRUE; +} + +gboolean vcm_daemon_method_set_domain(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* domain, gpointer user_data) +{ + int ret = vcd_server_mgr_set_domain(pid, domain); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to disable_command_type"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain); + + gdbus_vcdaemon_complete_vcm_daemon_method_set_domain(service, invocation, ret); + + return TRUE; +} + +gboolean vcm_daemon_method_do_action(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int type, const gchar* send_event, gpointer user_data) +{ + int ret = vcd_server_mgr_do_action(pid, type, send_event); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to disable_command_type"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event); + + gdbus_vcdaemon_complete_vcm_daemon_method_do_action(service, invocation); + + return TRUE; +} + +gboolean vcm_daemon_method_specific_engine_request(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* engine_app_id, const gchar* event, const gchar* request, gpointer user_data) +{ + int ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, request); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to specific_engine_request"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr specific engine request : pid(%d), engine_app_id(%s), event(%s), request(%s), ret(%d)", pid, engine_app_id, event, request, ret); + + gdbus_vcdaemon_complete_vcm_daemon_method_specific_engine_request(service, invocation); + + return TRUE; +} + +gboolean vcm_daemon_method_send_audio_streaming(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int event, GVariant *buffer, gpointer user_data) +{ + int len = 0; + GVariantIter *iter; + guchar uc; + const int MAX_STREAMING_DATA_SIZE = 4096; + unsigned char data[MAX_STREAMING_DATA_SIZE]; + + gdbus_vcdaemon_complete_vcm_daemon_method_send_audio_streaming(service, invocation); + + g_variant_get(buffer, "ay", &iter); + while (g_variant_iter_loop(iter, "y", &uc)) { + if (len < MAX_STREAMING_DATA_SIZE) { + data[len++] = uc; + } else { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] max size reached : %d", len); + } + } + g_variant_iter_free(iter); + + int ret = vcd_server_mgr_send_audio_streaming(pid, event, data, len); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send_audio_streaming"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, data, len); + + return TRUE; +} + +gboolean vcm_daemon_method_change_system_volume(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int volume_event, gpointer user_data) +{ + int ret = vcd_server_mgr_change_system_volume(pid, volume_event); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to change_system_volume"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr change system volume: pid(%d), volume_event(%d)", pid, volume_event); + + gdbus_vcdaemon_complete_vcm_daemon_method_change_system_volume(service, invocation, ret); + + return TRUE; +} + +gboolean vcs_daemon_method_set_language(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* language, gpointer user_data) +{ + int ret = vcd_server_set_language(language); + + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_language"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd server set language : language(%s)", language); + + gdbus_vcdaemon_complete_vcs_daemon_method_set_language(service, invocation, ret); + + return TRUE; +} +#else int __dbus_error_return(DBusConnection* conn, DBusMessage* msg, int ret) { DBusMessage* reply; @@ -2375,3 +3071,4 @@ int vcd_dbus_server_get_tts_audio_format(DBusConnection* conn, DBusMessage* msg) return 0; } +#endif \ No newline at end of file diff --git a/server/vcd_dbus_server.h b/server/vcd_dbus_server.h index 6182697..bebf860 100644 --- a/server/vcd_dbus_server.h +++ b/server/vcd_dbus_server.h @@ -25,6 +25,159 @@ extern "C" { #endif +#define USE_GDBUS + +#ifdef USE_GDBUS +#include "vc_gdbus.h" + +/* +* Dbus Common Server functions +*/ +gboolean vc_method_hello(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + gpointer user_data); + +/* +* Dbus Server functions for client +*/ +gboolean vcc_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcc_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcc_daemon_method_set_exclusive_cmd(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean value, gpointer user_data); + +gboolean vcc_daemon_method_set_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int cmd_type, gpointer user_data); + +gboolean vcc_daemon_method_unset_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int cmd_type, gpointer user_data); + +gboolean vcc_daemon_method_set_foreground(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean value, gpointer user_data); + +gboolean vcc_daemon_method_set_server_dialog(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* app_id, const gchar* credential, gpointer user_data); + +gboolean vcc_daemon_method_dialog(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* disp_text, const gchar* utt_text, gboolean continuous, gpointer user_data); + +gboolean vcc_daemon_method_is_system_command_valid(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcc_daemon_method_request_tts(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* text, const gchar* language, gboolean to_vcm, gpointer user_data); + +gboolean vcc_daemon_method_cancel_tts(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int utt_id, gpointer user_data); + +gboolean vcc_daemon_method_get_tts_audio_format(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +/* +* Dbus Server functions for widget +*/ + +gboolean vcw_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcw_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcw_daemon_method_start_recording(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int widget_command, gpointer user_data); + +gboolean vcw_daemon_method_enable_asr_result(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean enable, gpointer user_data); + +gboolean vcw_daemon_method_start(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean silence, gpointer user_data); + +gboolean vcw_daemon_method_stop(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcw_daemon_method_cancel(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcw_daemon_method_set_foreground(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gboolean value, gpointer user_data); + +/* +* Dbus Server functions for manager +*/ + +gboolean vcm_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int streaming_mode, gpointer user_data); + +gboolean vcm_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_set_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_unset_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_set_demandable_client(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_set_audio_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* audio_type, gpointer user_data); + +gboolean vcm_daemon_method_get_audio_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_set_client_info(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_set_private_data(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* key, const gchar* data, gpointer user_data); + +gboolean vcm_daemon_method_get_private_data(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* key, gpointer user_data); + +gboolean vcm_daemon_method_enable_command_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int cmd_type, gpointer user_data); + +gboolean vcm_daemon_method_disable_command_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int cmd_type, gpointer user_data); + +gboolean vcm_daemon_method_request_start(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int recognition_mode, gboolean exclusive, gboolean start_by_client, gpointer user_data); + +gboolean vcm_daemon_method_request_stop(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_request_cancel(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_result_selection(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, gpointer user_data); + +gboolean vcm_daemon_method_set_domain(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* domain, gpointer user_data); + +gboolean vcm_daemon_method_do_action(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int type, const gchar* send_event, gpointer user_data); + +gboolean vcm_daemon_method_specific_engine_request(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* engine_app_id, const gchar* event, const gchar* request, gpointer user_data); + +gboolean vcm_daemon_method_send_audio_streaming(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int event, GVariant *buffer, gpointer user_data); + +gboolean vcm_daemon_method_change_system_volume(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, int volume_event, gpointer user_data); + +/* +* Dbus Server functions for setting +*/ + +gboolean vcs_daemon_method_set_language(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, + int pid, const gchar* language, gpointer user_data); + +#else int vcd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg); /* @@ -137,6 +290,7 @@ int vcd_dbus_server_cancel_tts(DBusConnection* conn, DBusMessage* msg); int vcd_dbus_server_get_tts_audio_format(DBusConnection* conn, DBusMessage* msg); +#endif #ifdef __cplusplus } diff --git a/server/vce.c b/server/vce.c index 7a9bf97..1cd3c2b 100644 --- a/server/vce.c +++ b/server/vce.c @@ -150,6 +150,10 @@ int vce_main(int argc, char** argv, vce_request_callback_s *callback) SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_init()"); return VCE_ERROR_OPERATION_FAILED; } + if (!ecore_main_loop_glib_integrate()) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_main_loop_glib_integrate()"); + return VCE_ERROR_OPERATION_FAILED; + } // if (0 != vcd_dbus_open_connection()) { // SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection"); diff --git a/vc-server.conf b/vc-service.conf similarity index 85% rename from vc-server.conf rename to vc-service.conf index 60a1d1b..e7d601f 100644 --- a/vc-server.conf +++ b/vc-service.conf @@ -13,7 +13,7 @@ - - + + -- 2.7.4 From bfd06ef00407ac3bb44833d14485d2eb79555ead Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Fri, 23 Aug 2019 15:11:22 +0900 Subject: [PATCH 02/16] Added mutex for widget list Change-Id: I14fdcdf7e68383c8a6f3bfa5ee1b46b21482f8cd Signed-off-by: sungrae jo --- client/vc_widget_client.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/client/vc_widget_client.c b/client/vc_widget_client.c index e2415a6..27ee57d 100644 --- a/client/vc_widget_client.c +++ b/client/vc_widget_client.c @@ -27,6 +27,8 @@ static int g_allocated_handle = 0; /* widget list */ static GSList *g_widget_list = NULL; +static pthread_mutex_t g_widget_list_mutex = PTHREAD_MUTEX_INITIALIZER; + vc_widget_s* widget_get(vc_h vc) { if (vc == NULL) { @@ -34,6 +36,8 @@ vc_widget_s* widget_get(vc_h vc) return NULL; } + pthread_mutex_lock(&g_widget_list_mutex); + vc_widget_s *data = NULL; int count = g_slist_length(g_widget_list); @@ -44,6 +48,7 @@ vc_widget_s* widget_get(vc_h vc) if (NULL != data) { if (vc->handle == data->vc->handle) { + pthread_mutex_unlock(&g_widget_list_mutex); return data; } } @@ -51,6 +56,7 @@ vc_widget_s* widget_get(vc_h vc) SLOG(LOG_DEBUG, TAG_VCW, "[DEBUG] Fail to get widget by vc"); + pthread_mutex_unlock(&g_widget_list_mutex); return NULL; } @@ -112,7 +118,9 @@ int vc_widget_client_create(vc_h* vc) widget->cb_ref_count = 0; + pthread_mutex_lock(&g_widget_list_mutex); g_widget_list = g_slist_append(g_widget_list, widget); + pthread_mutex_unlock(&g_widget_list_mutex); *vc = temp; @@ -128,6 +136,7 @@ int vc_widget_client_destroy(vc_h vc) vc_widget_s *data = NULL; + pthread_mutex_lock(&g_widget_list_mutex); int count = g_slist_length(g_widget_list); int i; @@ -147,6 +156,7 @@ int vc_widget_client_destroy(vc_h vc) data = NULL; vc = NULL; + pthread_mutex_unlock(&g_widget_list_mutex); return 0; } } @@ -154,12 +164,16 @@ int vc_widget_client_destroy(vc_h vc) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] widget Not found"); + pthread_mutex_unlock(&g_widget_list_mutex); return -1; } GSList* vc_widget_client_get_client_list() { - return g_widget_list; + pthread_mutex_lock(&g_widget_list_mutex); + GSList *ret = g_widget_list; + pthread_mutex_unlock(&g_widget_list_mutex); + return ret; } bool vc_widget_client_is_valid(vc_h vc) @@ -179,6 +193,7 @@ bool vc_widget_client_is_valid_by_uid(int uid) { vc_widget_s *data = NULL; + pthread_mutex_lock(&g_widget_list_mutex); int count = g_slist_length(g_widget_list); int i; @@ -186,13 +201,16 @@ bool vc_widget_client_is_valid_by_uid(int uid) data = g_slist_nth_data(g_widget_list, i); if (NULL != data) { - if (uid == data->vc->handle) + if (uid == data->vc->handle) { + pthread_mutex_unlock(&g_widget_list_mutex); return true; + } } } SLOG(LOG_DEBUG, TAG_VCW, "[DEBUG] Fail to get widget by vc"); + pthread_mutex_unlock(&g_widget_list_mutex); return false; } @@ -200,6 +218,7 @@ int vc_widget_client_get_handle(int uid, vc_h* vc) { vc_widget_s *data = NULL; + pthread_mutex_lock(&g_widget_list_mutex); int count = g_slist_length(g_widget_list); int i; @@ -209,11 +228,13 @@ int vc_widget_client_get_handle(int uid, vc_h* vc) if (NULL != data) { if (uid == data->vc->handle) { *vc = data->vc; + pthread_mutex_unlock(&g_widget_list_mutex); return 0; } } } + pthread_mutex_unlock(&g_widget_list_mutex); return -1; } @@ -528,6 +549,7 @@ int vc_widget_client_get_state_by_uid(int uid, vc_state_e* state) { vc_widget_s *data = NULL; + pthread_mutex_lock(&g_widget_list_mutex); int count = g_slist_length(g_widget_list); int i; @@ -537,11 +559,13 @@ int vc_widget_client_get_state_by_uid(int uid, vc_state_e* state) if (NULL != data) { if (uid == data->vc->handle) { *state = data->current_state; + pthread_mutex_unlock(&g_widget_list_mutex); return 0; } } } + pthread_mutex_unlock(&g_widget_list_mutex); return -1; } @@ -639,7 +663,10 @@ int vc_widget_client_get_show_tooltip(vc_h vc, bool* show) int vc_widget_client_get_count() { - return g_slist_length(g_widget_list); + pthread_mutex_lock(&g_widget_list_mutex); + int ret = g_slist_length(g_widget_list); + pthread_mutex_unlock(&g_widget_list_mutex); + return ret; } int vc_widget_client_use_callback(vc_h vc) -- 2.7.4 From 28cd4f626fd8f2409e8e5ed8a810e09b347c2ded Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Tue, 17 Sep 2019 14:45:39 +0900 Subject: [PATCH 03/16] Fixed coverity issue. Change-Id: Ide3e1362f2db573710fc2de37f393232c2d88b6e Signed-off-by: sungrae jo --- common/vc_cmd_db.c | 8 ++++++++ common/vc_config_mgr.c | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index c866247..7823832 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -201,6 +201,8 @@ static int __vc_db_delete_commands(sqlite3* db_handle, int pid, vc_cmd_type_e ty SLOG(LOG_WARN, vc_db_tag(), "[WARNING] There is no table (%s) (%d). Make a table", VC_INFO_TABLE, ret); if (VC_DB_ERROR_NONE != __vc_db_create_table(db_handle, VC_INFO_TABLE)) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create table(%s), %d", VC_INFO_TABLE, ret); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } } else { @@ -409,6 +411,8 @@ static int __vc_db_get_commands(sqlite3* db_handle, int pid, vc_cmd_type_e type, SLOG(LOG_WARN, vc_db_tag(), "[WARNING] There is no table (%s) (%d). Make a table", VC_INFO_TABLE, ret); if (VC_DB_ERROR_NONE != __vc_db_create_table(db_handle, VC_INFO_TABLE)) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create table(%s), %d", VC_INFO_TABLE, ret); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } } else { @@ -856,6 +860,8 @@ static int __vc_db_get_result(sqlite3* db_handle, char** result_text, int* event SLOG(LOG_WARN, vc_db_tag(), "[WARNING] There is no table (%s) (%d). Make a table", VC_RESULT_TABLE, ret); if (VC_DB_ERROR_NONE != __vc_db_create_table(db_handle, VC_RESULT_TABLE)) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create table(%s), %d", VC_RESULT_TABLE, ret); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } } else { @@ -1432,6 +1438,8 @@ static int __vc_db_create_table(sqlite3* db_handle, const char* table) } SLOG(LOG_WARN, vc_db_tag(), "[SQL] %s", sql); + free(sql); + sql = NULL; return VC_DB_ERROR_NONE; } diff --git a/common/vc_config_mgr.c b/common/vc_config_mgr.c index 35acf5d..4edf45b 100644 --- a/common/vc_config_mgr.c +++ b/common/vc_config_mgr.c @@ -1454,7 +1454,7 @@ int vc_config_mgr_set_engine(const char* engine) } /* Check engine id is valid */ - if (0 != strcmp(engine, engine_info->uuid)) { + if (NULL == engine_info->uuid || 0 != strcmp(engine, engine_info->uuid)) { iter = g_slist_next(iter); continue; } @@ -1463,8 +1463,8 @@ int vc_config_mgr_set_engine(const char* engine) free(g_config_info->engine_id); g_config_info->engine_id = NULL; } - if (engine_info->uuid) - g_config_info->engine_id = strdup(engine_info->uuid); + + g_config_info->engine_id = strdup(engine_info->uuid); /* Engine is valid*/ -- 2.7.4 From 8ed9a78df842c19843c053a56ee4909e3bc0e39d Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Tue, 17 Sep 2019 15:13:03 +0900 Subject: [PATCH 04/16] Fixed savce dereferenced issue. Change-Id: I4da395f6999ea662fb2c823b449be17710e50fee Signed-off-by: sungrae jo --- common/vc_cmd_db.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 7823832..74087db 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1605,13 +1605,13 @@ int vc_db_initialize(void) int ret = sqlite3_exec(g_db_handle, "pragma integrity_check", __vc_db_integrity_check_cb, NULL, NULL); if (true == is_db_corrupted || SQLITE_CORRUPT == ret) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open DB"); - if (g_db_handle) { - ret = db_util_close(g_db_handle); - if (ret != SQLITE_OK) { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to close db, ret %d: %s", ret, sqlite3_errmsg(g_db_handle)); - } - g_db_handle = NULL; + + ret = db_util_close(g_db_handle); + if (ret != SQLITE_OK) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to close db, ret %d: %s", ret, sqlite3_errmsg(g_db_handle)); } + g_db_handle = NULL; + if (0 != remove(g_path)) { SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_path); g_db_cnt = (g_db_cnt + 1) % 1000; -- 2.7.4 From 2c625f8f00a1468136397a42e2d70833b00dd079 Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Thu, 19 Sep 2019 18:31:58 +0900 Subject: [PATCH 05/16] Added new feature for vc_mgr Change-Id: I11b7616e3827fb1389744d78506c3efe55cbe09b Signed-off-by: sungrae jo --- client/vc_mgr.c | 2 +- common/vc_defs.h | 1 + doc/uix_vc_mgr_doc.h | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index df81eee..35f272c 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -133,7 +133,7 @@ static int __vc_mgr_get_feature_enabled() } else if (-1 == g_feature_enabled) { bool vc_supported = false; bool mic_supported = false; - if (0 == system_info_get_platform_bool(VC_FEATURE_PATH, &vc_supported)) { + if (0 == system_info_get_platform_bool(VC_MGR_FEATURE_PATH, &vc_supported)) { if (0 == system_info_get_platform_bool(VC_MIC_FEATURE_PATH, &mic_supported)) { if (false == vc_supported || false == mic_supported) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Voice control feature NOT supported"); diff --git a/common/vc_defs.h b/common/vc_defs.h index a3a62dc..b3db152 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -233,6 +233,7 @@ extern "C" { #define VC_CONNECTION_RETRY_COUNT 10 #define VC_FEATURE_PATH "tizen.org/feature/speech.control" +#define VC_MGR_FEATURE_PATH "tizen.org/feature/speech.control_manager" #define VC_MIC_FEATURE_PATH "tizen.org/feature/microphone" #define VC_PRIVILEGE "http://tizen.org/privilege/recorder" diff --git a/doc/uix_vc_mgr_doc.h b/doc/uix_vc_mgr_doc.h index 04c96a1..08c30cf 100644 --- a/doc/uix_vc_mgr_doc.h +++ b/doc/uix_vc_mgr_doc.h @@ -276,7 +276,7 @@ * @section CAPI_UIX_VOICE_CONTROL_MANAGER_MODULE_FEATURES Related Features * This API is related with the following features:
* - http://tizen.org/feature/microphone
- * - http://tizen.org/feature/speech.control
+ * - http://tizen.org/feature/speech.control_manager
* It is recommended to design feature related codes in your application for reliability.
* You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.
* To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
-- 2.7.4 From fb15d2963c0388cab0d35dcea7dc9cb4de9073e0 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Wed, 4 Sep 2019 20:44:49 +0900 Subject: [PATCH 06/16] [ACR-1450] Add to request vc-tts Change-Id: Ic14941e62a511140fb5e2e5ce030fa6201e47dee --- client/vc.c | 8 +- include/voice_control.h | 200 +++++++++++++++++++++++++++++++++------ include/voice_control_common.h | 52 +++++++++- include/voice_control_internal.h | 172 --------------------------------- 4 files changed, 227 insertions(+), 205 deletions(-) diff --git a/client/vc.c b/client/vc.c index d4aa48c..677713e 100644 --- a/client/vc.c +++ b/client/vc.c @@ -2994,7 +2994,7 @@ int __vc_cb_tts_streaming(int utt_id, vc_tts_event_e event, char* buffer, int le return ret; } -int vc_tts_request(const char* text, const char* language, bool to_vcm, int* utt_id) +int vc_tts_request(const char* text, const char* language, bool to_vc_manager, int* utt_id) { vc_state_e state; int ret = -1; @@ -3031,12 +3031,12 @@ int vc_tts_request(const char* text, const char* language, bool to_vcm, int* utt return VC_ERROR_INVALID_STATE; } - SLOG(LOG_DEBUG, TAG_VCC, "@@@ tts request, pid(%d), text(%s), language(%s), to_vcm(%d)", pid, text, language, to_vcm); + SLOG(LOG_DEBUG, TAG_VCC, "@@@ tts request, pid(%d), text(%s), language(%s), to_vc_manager(%d)", pid, text, language, to_vc_manager); int count = 0; bool is_prepared = false; do { - ret = vc_dbus_request_tts(pid, text, language, to_vcm, utt_id); + ret = vc_dbus_request_tts(pid, text, language, to_vc_manager, utt_id); if (0 != ret) { if (VC_ERROR_INVALID_PARAMETER == ret && false == is_prepared) { vc_client_set_client_state(g_vc, VC_STATE_INITIALIZED); @@ -3277,7 +3277,7 @@ int __vc_cb_utterance_status(int utt_id, int utt_status) SLOG(LOG_DEBUG, TAG_VCC, "Utterance status callback is called"); vc_client_use_callback(g_vc); - callback(utt_id, (vc_tts_utterance_status_e)utt_status); + callback(utt_id, (vc_tts_utterance_status_e)utt_status, user_data); vc_client_not_use_callback(g_vc); return 0; diff --git a/include/voice_control.h b/include/voice_control.h index f46b5c0..c37d991 100644 --- a/include/voice_control.h +++ b/include/voice_control.h @@ -86,8 +86,8 @@ extern "C" * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @remarks If the function succeeds, @a vc must be released with vc_deinitialize(). - * @return @c 0 on success, + * @remarks If the function succeeds, vc must be released with vc_deinitialize(). + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_OUT_OF_MEMORY Out of memory @@ -105,14 +105,14 @@ int vc_initialize(void); * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_STATE Invalid state * @retval #VC_ERROR_OPERATION_FAILED Operation failure * @retval #VC_ERROR_PERMISSION_DENIED Permission denied * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * @see vc_deinitialize() + * @see vc_initialize() */ int vc_deinitialize(void); @@ -122,7 +122,7 @@ int vc_deinitialize(void); * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_STATE Invalid state @@ -141,7 +141,7 @@ int vc_prepare(void); * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_STATE Invalid state @@ -161,7 +161,7 @@ int vc_unprepare(void); * @privilege %http://tizen.org/privilege/recorder * @param[in] callback Callback function to invoke * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -182,11 +182,11 @@ int vc_foreach_supported_languages(vc_supported_language_cb callback, void* user * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @remark If the function succeeds, @a language must be released with free() by you when you no longer need it. + * @remarks If the function succeeds, @a language must be released with free() by you when you no longer need it. * @param[out] language A language is specified as an ISO 3166 alpha-2 two letter country-code * followed by ISO 639-1 for the two-letter language code. * For example, "ko_KR" for Korean, "en_US" for American English - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -207,7 +207,7 @@ int vc_get_current_language(char** language); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[out] state The current state - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -225,7 +225,7 @@ int vc_get_state(vc_state_e* state); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[out] state The current state - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -250,7 +250,7 @@ int vc_get_service_state(vc_service_state_e* state); * Therefore, the user can not set any commands same with the system commands. * The @a vc_sys_cmd_list must be released using free() when it is no longer required. * @param[out] vc_sys_cmd_list System command list handle - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -275,7 +275,7 @@ int vc_get_system_command_list(vc_cmd_list_h* vc_sys_cmd_list); * If the current language is "ja_JP"(Japanese) and the invocation name is "en_US", the invocation name will not be recognized. * This function should be called before vc_set_command_list(). * @param[in] name Invocation name that an application wants to be invoked by - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -346,7 +346,7 @@ int vc_unset_server_dialog(const char* app_id); * @param[in] disp_text Text to be displayed on the screen * @param[in] utt_text Text to be spoken * @param[in] auto_start A variable for setting whether the dialog session will be restarted automatically or not - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -367,7 +367,7 @@ int vc_request_dialog(const char* disp_text, const char* utt_text, bool auto_sta * The matched commands of command list should be set and they should include type and command text at least. * @param[in] vc_cmd_list Command list handle * @param[in] type Command type - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -386,7 +386,7 @@ int vc_set_command_list(vc_cmd_list_h vc_cmd_list, int type); * @privlevel public * @privilege %http://tizen.org/privilege/recorder * @param[in] type Command type - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -406,7 +406,7 @@ int vc_unset_command_list(int type); * @privilege %http://tizen.org/privilege/recorder * @param[in] callback Callback function to get recognition result * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -425,7 +425,7 @@ int vc_get_result(vc_result_cb callback, void* user_data); * @privilege %http://tizen.org/privilege/recorder * @param[in] callback Callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -444,7 +444,7 @@ int vc_set_result_cb(vc_result_cb callback, void* user_data); * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_STATE Invalid state @@ -462,7 +462,7 @@ int vc_unset_result_cb(void); * @privilege %http://tizen.org/privilege/recorder * @param[in] callback Callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -481,7 +481,7 @@ int vc_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_STATE Invalid state @@ -500,7 +500,7 @@ int vc_unset_service_state_changed_cb(void); * @privilege %http://tizen.org/privilege/recorder * @param[in] callback Callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -519,7 +519,7 @@ int vc_set_state_changed_cb(vc_state_changed_cb callback, void* user_data); * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_STATE Invalid state @@ -538,7 +538,7 @@ int vc_unset_state_changed_cb(void); * @privilege %http://tizen.org/privilege/recorder * @param[in] callback Callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -557,7 +557,7 @@ int vc_set_current_language_changed_cb(vc_current_language_changed_cb callback, * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_STATE Invalid state @@ -576,7 +576,7 @@ int vc_unset_current_language_changed_cb(void); * @privilege %http://tizen.org/privilege/recorder * @param[in] callback Callback function to register * @param[in] user_data The user data to be passed to the callback function - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter @@ -595,7 +595,7 @@ int vc_set_error_cb(vc_error_cb callback, void* user_data); * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif * @privlevel public * @privilege %http://tizen.org/privilege/recorder - * @return @c 0 on success, + * @return @c 0 on success, * otherwise a negative error value * @retval #VC_ERROR_NONE Successful * @retval #VC_ERROR_INVALID_STATE Invalid state @@ -607,6 +607,152 @@ int vc_set_error_cb(vc_error_cb callback, void* user_data); int vc_unset_error_cb(void); +/** + * @brief Requests to send TTS streaming data, asynchronously. + * @details Using this function, the developer can request text to speech to the framework. + * When the developer requests the TTS with @a language, VC engine will send PCM data which is synthesized using VC engine's own persona. + * If @a to_vc_manager is true, the synthesized PCM data will be delivered to the VC manager, otherwise it will be delivered to the VC client + * For example, if @a text is "Alarm is set as 7 PM" and @a to_vc_manager is true, the PCM data corresponding "Alarm is set as 7 PM" will be delivered to VC manager client, + * and then it will be spoken in VC manager. If @a to_vc_manager is false, you will receive PCM data through the vc_tts_streaming_cb() callback function if it was set using vc_tts_set_streaming_cb(). + * This function is executed asynchronously, so if there is an error while synthesizing, vc_error_cb() will be called. + * @since_tizen 5.5 + * @privlevel @partner + * @privilege %http://tizen.org/privilege/voicecontrol.tts + * @param[in] text The text to be requested for TTS + * @param[in] language The language is specified as an ISO 3166 alpha-2 two-letter country code + * followed by ISO 639-1 for the two-letter language code. + * For example, "ko_KR" for Korean, "en_US" for American English + * @param[in] to_vc_manager The value for selection between VC client and VC manager\n + * If @c true, the synthesized PCM data will be delivered to the VC manager, otherwise it will be delivered to the VC client + * @param[out] utt_id The utterance id + * @return @c 0 on success, + * otherwise a negative error value + * @retval #VC_ERROR_NONE Successful + * @retval #VC_ERROR_NOT_SUPPORTED Not supported + * @retval #VC_ERROR_PERMISSION_DENIED Permission denied + * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #VC_ERROR_INVALID_STATE Invalid state + * @retval #VC_ERROR_OPERATION_FAILED Operation failure + * @pre The state should be #VC_STATE_READY. + * @see vc_tts_cancel() + */ +int vc_tts_request(const char* text, const char* language, bool to_vc_manager, int* utt_id); + + +/** + * @brief Requests to cancel TTS streaming data. + * @since_tizen 5.5 + * @privlevel @partner + * @privilege %http://tizen.org/privilege/voicecontrol.tts + * @param[in] utt_id The utterance id + * @return @c 0 on success, + * otherwise a negative error value + * @retval #VC_ERROR_NONE Successful + * @retval #VC_ERROR_NOT_SUPPORTED Not supported + * @retval #VC_ERROR_PERMISSION_DENIED Permission denied + * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #VC_ERROR_INVALID_STATE Invalid state + * @pre The state should be #VC_STATE_READY. + * @see vc_tts_request() + */ +int vc_tts_cancel(int utt_id); + + +/** + * @brief Gets the TTS audio details. + * @details Using this function, the developer can get details of synthesized audio data which is requested by vc_tts_request() function. + * @since_tizen 5.5 + * @privlevel @partner + * @privilege %http://tizen.org/privilege/voicecontrol.tts + * @param[out] rate The audio sampling rate + * @param[out] channel The audio channel + * @param[out] audio_type The audio type + * @return @c 0 on success, + * otherwise a negative error value + * @retval #VC_ERROR_NONE Successful + * @retval #VC_ERROR_NOT_SUPPORTED Not supported + * @retval #VC_ERROR_PERMISSION_DENIED Permission denied + * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #VC_ERROR_INVALID_STATE Invalid state + * @pre The state should be #VC_STATE_READY. + */ +int vc_tts_get_synthesized_audio_details(int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type); + + +/** + * @brief Sets the TTS streaming callback function. + * @since_tizen 5.5 + * @privlevel @partner + * @privilege %http://tizen.org/privilege/voicecontrol.tts + * @param[in] callback The callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #VC_ERROR_NONE Successful + * @retval #VC_ERROR_NOT_SUPPORTED Not supported + * @retval #VC_ERROR_PERMISSION_DENIED Permission denied + * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #VC_ERROR_INVALID_STATE Invalid state + * @pre The state should be #VC_STATE_INITIALIZED. + */ +int vc_tts_set_streaming_cb(vc_tts_streaming_cb callback, void* user_data); + + +/** + * @brief Unsets the TTS streaming callback function. + * @since_tizen 5.5 + * @privlevel @partner + * @privilege %http://tizen.org/privilege/voicecontrol.tts + * @return @c 0 on success, + * otherwise a negative error value + * @retval #VC_ERROR_NONE Successful + * @retval #VC_ERROR_NOT_SUPPORTED Not supported + * @retval #VC_ERROR_PERMISSION_DENIED Permission denied + * @retval #VC_ERROR_INVALID_STATE Invalid state + * @pre The state should be #VC_STATE_INITIALIZED. + */ +int vc_tts_unset_streaming_cb(void); + + +/** + * @brief Sets the TTS utterance status callback function. + * @details Using this function, the developer can set the utterance status callback to be called + * when the VC manager client starts or stops playing TTS PCM data which was requested to be synthesized with the vc_tts_request() function. + * This function is called when @a to_vc_manager in the vc_tts_request() function call is true. + * @since_tizen 5.5 + * @privlevel @partner + * @privilege %http://tizen.org/privilege/voicecontrol.tts + * @param[in] callback The callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #VC_ERROR_NONE Successful + * @retval #VC_ERROR_NOT_SUPPORTED Not supported + * @retval #VC_ERROR_PERMISSION_DENIED Permission denied + * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #VC_ERROR_INVALID_STATE Invalid state + * @retval #VC_ERROR_OPERATION_FAILED Operation failure + * @pre The state should be #VC_STATE_INITIALIZED. + */ +int vc_tts_set_utterance_status_cb(vc_tts_utterance_status_cb callback, void* user_data); + + +/** + * @brief Unsets the TTS utterance status callback function. + * @since_tizen 5.5 + * @privlevel @partner + * @privilege %http://tizen.org/privilege/voicecontrol.tts + * @return @c 0 on success, + * otherwise a negative error value + * @retval #VC_ERROR_NONE Successful + * @retval #VC_ERROR_NOT_SUPPORTED Not supported + * @retval #VC_ERROR_PERMISSION_DENIED Permission denied + * @retval #VC_ERROR_INVALID_STATE Invalid state + * @pre The state should be #VC_STATE_INITIALIZED. + */ +int vc_tts_unset_utterance_status_cb(void); + + #ifdef __cplusplus } #endif diff --git a/include/voice_control_common.h b/include/voice_control_common.h index 4bf4ba1..136e628 100644 --- a/include/voice_control_common.h +++ b/include/voice_control_common.h @@ -103,7 +103,7 @@ typedef enum { } vc_audio_type_e; /** - * @brief Enumerations for audio channels + * @brief Enumerations for audio channels. * @since_tizen 5.0 */ typedef enum { @@ -112,7 +112,7 @@ typedef enum { } vc_audio_channel_e; /** - * @brief Enumeration for TTS feedback events + * @brief Enumeration for TTS feedback events. * @since_tizen 5.0 */ typedef enum { @@ -122,6 +122,27 @@ typedef enum { VC_FEEDBACK_EVENT_FINISH = 3 /**< Finish event */ } vc_feedback_event_e; +/** + * @brief Enumeration for requested TTS events. + * @since_tizen 5.5 + */ +typedef enum { + VC_TTS_EVENT_FAIL = -1, /**< Failed */ + VC_TTS_EVENT_START = 1, /**< Start event */ + VC_TTS_EVENT_CONTINUE = 2, /**< Continue event */ + VC_TTS_EVENT_FINISH = 3 /**< Finish event */ +} vc_tts_event_e; + +/** + * @brief Enumeration for requested TTS utterance status events. + * @since_tizen 5.5 + */ +typedef enum { + VC_TTS_UTTERANCE_NONE = -1, /**< None */ + VC_TTS_UTTERANCE_STARTED = 1, /**< Utterance started */ + VC_TTS_UTTERANCE_COMPLETED = 2, /**< Utterance completed */ + VC_TTS_UTTERANCE_CANCELED = 3 /**< Utterance canceled */ +} vc_tts_utterance_status_e; /** * @brief Called when client gets the recognition result. @@ -200,6 +221,33 @@ typedef void (*vc_service_state_changed_cb)(vc_service_state_e previous, vc_serv typedef void (*vc_error_cb)(vc_error_e reason, void *user_data); +/** + * @brief Called when the client receives TTS streaming data from the VC engine service. + * @since_tizen 5.5 + * @remarks The @a buffer must be released with free() by you when you no longer need it. + * @param[in] event The TTS event + * @param[in] buffer The TTS streaming data + * @param[in] len The length of the TTS streaming data + * @param[in] utt_id The utterance id + * @param[in] user_data The user data passed from the callback registration function + * @pre The application registers the callback function using vc_tts_set_streaming_cb(). + * @see vc_tts_set_streaming_cb() + */ +typedef void (*vc_tts_streaming_cb)(vc_tts_event_e event, char* buffer, int len, int utt_id, void *user_data); + + +/** + * @brief Called when the client receives the TTS utterance status. + * @since_tizen 5.5 + * @param[in] utt_id The utterance id + * @param[in] status The new TTS utterance status (e.g. #VC_TTS_UTTERANCE_STARTED, #VC_TTS_UTTERANCE_COMPLETED, and so on) + * @param[in] user_data The user data passed from the callback registration function + * @pre The application registers the callback function using vc_tts_set_utterance_status_cb(). + * @see vc_tts_set_utterance_status_cb() + */ +typedef void (*vc_tts_utterance_status_cb)(int utt_id, vc_tts_utterance_status_e status, void *user_data); + + #ifdef __cplusplus } #endif diff --git a/include/voice_control_internal.h b/include/voice_control_internal.h index 131c7e5..2e117b7 100644 --- a/include/voice_control_internal.h +++ b/include/voice_control_internal.h @@ -26,20 +26,6 @@ extern "C" { #endif -typedef enum { - VC_TTS_EVENT_FAIL = -1, /**< Failed */ - VC_TTS_EVENT_START = 1, /**< Start event */ - VC_TTS_EVENT_CONTINUE = 2, /**< Continue event */ - VC_TTS_EVENT_FINISH = 3 /**< Finish event */ -} vc_tts_event_e; - -typedef enum { - VC_TTS_UTTERANCE_NONE = -1, - VC_TTS_UTTERANCE_STARTED = 1, - VC_TTS_UTTERANCE_COMPLETED = 2, - VC_TTS_UTTERANCE_CANCELED = 3 -} vc_tts_utterance_status_e; - /** * @brief Called when client gets the asr recognition result from vc-daemon. @@ -58,39 +44,6 @@ typedef enum { typedef bool (*vc_asr_result_cb)(vc_result_event_e event, const char* result, void *user_data); /** - * @brief Called when client gets TTS streaming data from vc engine service. - * @since_tizen 4.0 - * - * @remarks The @a buffer must be released with free() by you when you no longer need it. - * - * @param[in] event The TTS event - * @param[in] buffer The TTS streaming data - * @param[in] len The length of the TTS streaming data - * @param[in] utt_id The utterance id - * @param[in] user_data The user data passed from the callback registration function - * - * @pre An application registers callback function using vc_tts_set_streaming_cb(). - * - * @see vc_tts_set_streaming_cb() - * @see vc_tts_unset_streaming_cb() - */ -typedef void (*vc_tts_streaming_cb)(vc_tts_event_e event, char* buffer, int len, int utt_id, void *user_data); - -/** - * @brief Called when client gets TTS utterance status. - * @since_tizen 4.0 - * - * @param[in] utt_id The utterance id - * @param[in] status The TTS utterance status (e.g. #VC_TTS_UTTERANCE_STARTED, #VC_TTS_UTTERANCE_COMPLETED, and so on) - * - * @pre An application registers callback function using vc_tts_set_utterance_status_cb(). - * - * @see vc_tts_set_utterance_status_cb() - * @see vc_tts_unset_utterance_status_cb() - */ -typedef void (*vc_tts_utterance_status_cb)(int utt_id, vc_tts_utterance_status_e status); - -/** * @brief Sets command list from file. * @since_tizen 3.0 * @privlevel public @@ -134,131 +87,6 @@ int vc_set_command_list_from_file(const char* file_path, int type); */ int vc_prepare_sync(void); -/** - * @brief Requests to send TTS streaming data. - * @since_tizen 4.0 - * - * @param[in] text The text to be requested for TTS - * @param[in] language The language for TTS - * @param[in] to_vcm A value whether the TTS request is from vc client or vc manager - * @param[in] utt_id The utterance id - * - * @return 0 on success, otherwise a negative error value - * @retval #VC_ERROR_NONE Successful - * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #VC_ERROR_INVALID_STATE Invalid state - * @retval #VC_ERROR_PERMISSION_DENIED Permission denied - * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * - * @pre The state should be #VC_STATE_READY. - * - * @see vc_tts_cancel() - */ -int vc_tts_request(const char* text, const char* language, bool to_vcm, int* utt_id); - -/** - * @brief Requests to cancel TTS streaming data. - * @since_tizen 4.0 - * - * @param[in] utt_id The utterance id - * - * @return 0 on success, otherwise a negative error value - * @retval #VC_ERROR_NONE Successful - * @retval #VC_ERROR_INVALID_STATE Invalid state - * @retval #VC_ERROR_PERMISSION_DENIED Permission denied - * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * - * @pre The state should be #VC_STATE_READY. - * - * @see vc_tts_request() - */ -int vc_tts_cancel(int utt_id); - -/** - * @brief Gets TTS audio format. - * @since_tizen 4.0 - * - * @param[out] rate The audio sampling rate - * @param[out] channel The audio channel - * @param[out] audio_type The audio type - * - * @return 0 on success, otherwise a negative error value - * @retval #VC_ERROR_NONE Successful - * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #VC_ERROR_INVALID_STATE Invalid state - * @retval #VC_ERROR_PERMISSION_DENIED Permission denied - * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * - * @pre The state should be #VC_STATE_READY. - */ -int vc_tts_get_audio_format(int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type); - -/** - * @brief Sets TTS streaming callback function. - * @since_tizen 4.0 - * - * @param[in] callback The callback function - * @param[in] user_data The user data to be passed to the callback function - * - * @return 0 on success, otherwise a negative error value - * @retval #VC_ERROR_NONE Successful - * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #VC_ERROR_INVALID_STATE Invalid state - * @retval #VC_ERROR_PERMISSION_DENIED Permission denied - * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * - * @pre The state should be #VC_STATE_INITIALIZED. - */ -int vc_tts_set_streaming_cb(vc_tts_streaming_cb callback, void* user_data); - -/** - * @brief Unsets TTS streaming callback function. - * @since_tizen 4.0 - * - * @return 0 on success, otherwise a negative error value - * @retval #VC_ERROR_NONE Successful - * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #VC_ERROR_INVALID_STATE Invalid state - * @retval #VC_ERROR_PERMISSION_DENIED Permission denied - * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * - * @pre The state should be #VC_STATE_INITIALIZED. - */ -int vc_tts_unset_streaming_cb(void); - -/** - * @brief Sets TTS utterance status callback function. - * @since_tizen 4.0 - * - * @param[in] callback The callback function - * @param[in] user_data The user data to be passed to the callback function - * - * @return 0 on success, otherwise a negative error value - * @retval #VC_ERROR_NONE Successful - * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #VC_ERROR_INVALID_STATE Invalid state - * @retval #VC_ERROR_PERMISSION_DENIED Permission denied - * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * - * @pre The state should be #VC_STATE_INITIALIZED. - */ -int vc_tts_set_utterance_status_cb(vc_tts_utterance_status_cb callback, void* user_data); - -/** - * @brief Unsets TTS utterance status callback function. - * @since_tizen 4.0 - * - * @return 0 on success, otherwise a negative error value - * @retval #VC_ERROR_NONE Successful - * @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #VC_ERROR_INVALID_STATE Invalid state - * @retval #VC_ERROR_PERMISSION_DENIED Permission denied - * @retval #VC_ERROR_NOT_SUPPORTED Not supported - * - * @pre The state should be #VC_STATE_INITIALIZED. - */ -int vc_tts_unset_utterance_status_cb(void); - #ifdef __cplusplus } -- 2.7.4 From e2b63eab5bfb38312544bb44f397b6f3bd1fc0af Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Fri, 20 Sep 2019 23:30:08 +0900 Subject: [PATCH 07/16] Update DB tolerance logic Change-Id: I7ba1e8870cc763a218cf2dea38592ae1f6435b46 --- common/vc_cmd_db.c | 241 +++++++++++++++++++++++++++++++++++++++++++--------- common/vc_cmd_db.h | 2 + server/vcd_server.c | 2 +- 3 files changed, 204 insertions(+), 41 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 74087db..37726a9 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -61,7 +61,7 @@ static sqlite3* g_db_backup_handle = NULL; static char* g_path = NULL; static char* g_backup_path = NULL; static int g_ref_cnt = 0; -static bool is_db_corrupted = false; + int g_fpid = -1; int g_db_cnt = 0; int g_backup_db_cnt = 0; @@ -1443,7 +1443,7 @@ static int __vc_db_create_table(sqlite3* db_handle, const char* table) return VC_DB_ERROR_NONE; } -int __vc_db_open_db(char** path, sqlite3** db_handle) +int __vc_db_open_db_for_daemon(char** path, sqlite3** db_handle) { struct stat stat; int ret = db_util_open(*path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD); @@ -1508,53 +1508,97 @@ int __vc_db_open_db(char** path, sqlite3** db_handle) int ret = sqlite3_exec(*db_handle, sql, NULL, NULL, &err_msg); if (ret != SQLITE_OK) { SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_exec returned %d: %s", ret, err_msg); + return VC_DB_ERROR_OPERATION_FAILED; } } return VC_DB_ERROR_NONE; } -static int __vc_db_integrity_check_cb(void *NotUsed, int argc, char **argv, char **azColName) +static int __vc_db_restore_table(sqlite3* db_handle, const char* table) { - SLOG(LOG_INFO, vc_db_tag(), "integrity check cb is called"); - - char *check_str = "ok"; - if (0 != strncmp(argv[0], check_str, strlen(check_str))) { - SLOG(LOG_ERROR, vc_db_tag(), "db integrity result : %s", argv[0]); - is_db_corrupted = true; - return -1; + /* check whether there is a vc_info table or not */ + bool is_exist = false; + int ret = __vc_db_check_table(db_handle, table, &is_exist); + if (VC_DB_ERROR_NONE != ret || false == is_exist) { + SLOG(LOG_WARN, vc_db_tag(), "[WARNING] There is no table (%s) (%d). Make a table", table, ret); + if (VC_DB_ERROR_NONE != __vc_db_create_table(db_handle, table)) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create table(%s), %d", table, ret); + return VC_DB_ERROR_OPERATION_FAILED; + } + } else { + SLOG(LOG_INFO, vc_db_tag(), "[INFO] There is the table (%s)", table); } - - SLOG(LOG_INFO, vc_db_tag(), "db integrity result : %s", argv[0]); - return 0; + return VC_DB_ERROR_NONE; } -bool __vc_db_connect_db(char** path, sqlite3** db_handle) +bool __vc_db_connect_db_for_daemon(char** path, sqlite3** db_handle) { bool is_connect = false; - int ret = __vc_db_open_db(path, db_handle); + int ret = __vc_db_open_db_for_daemon(path, db_handle); if (0 != ret) { int cnt = 0; while (cnt <= 5) { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open DB"); + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open DB for daemon"); usleep(100000); - if (0 == __vc_db_open_db(path, db_handle)) { - SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to open DB"); + if (0 == __vc_db_open_db_for_daemon(path, db_handle)) { + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to open DB for daemon"); is_connect = true; break; } cnt++; } } else { - SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to open DB"); + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to open DB for daemon"); is_connect = true; } return is_connect; } -int vc_db_initialize(void) +static int __vc_db_integrity_check_cb(void *NotUsed, int argc, char **argv, char **azColName) +{ + SLOG(LOG_INFO, vc_db_tag(), "integrity check cb is called"); + + int ret; + char *check_str = "ok"; + if (0 != strncmp(argv[0], check_str, strlen(check_str))) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Doesn't have integrity(%s), retry to connect after removing", argv[0]); + if (0 != remove(g_path)) { + SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed for daemon", g_path); + g_db_cnt = (g_db_cnt + 1) % 1000; + snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt); + } + bool is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_handle); + if (true == is_connect) { + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect main DB for daemon"); + ret = __vc_db_restore_table(g_db_handle, VC_INFO_TABLE); + if (0 != ret) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create table (%s)", VC_INFO_TABLE); + } + ret = __vc_db_restore_table(g_db_handle, VC_RESULT_TABLE); + if (0 != ret) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create table (%s)", VC_RESULT_TABLE); + } + is_connect = __vc_db_connect_db_for_daemon(&g_backup_path, &g_db_backup_handle); + if (true == is_connect) { + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB for daemon"); + if (0 != vc_db_restore_command()) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to restore command"); + } + } + } else { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB for daemon"); + return VC_DB_ERROR_OPERATION_FAILED; + } + } + + SLOG(LOG_INFO, vc_db_tag(), "db integrity result : %s", argv[0]); + return VC_DB_ERROR_NONE; +} + +int vc_db_initialize_for_daemon(void) { - SLOG(LOG_INFO, vc_db_tag(), "DB initialization"); + SLOG(LOG_INFO, vc_db_tag(), "DB on initialization for daemon"); if (0 < g_ref_cnt) { g_ref_cnt++; @@ -1578,41 +1622,159 @@ int vc_db_initialize(void) } snprintf(g_backup_path, 256, "%s/.vc_backup.db", VC_RUNTIME_INFO_ROOT); - bool is_connect = __vc_db_connect_db(&g_path, &g_db_handle); + bool is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_handle); if (false == is_connect) { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB, retry to connect after removing file"); + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB, retry to connect after removing"); if (0 != remove(g_path)) { - SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_path); + SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed for daemon", g_path); g_db_cnt = (g_db_cnt + 1) % 1000; snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt); } - is_connect = __vc_db_connect_db(&g_path, &g_db_handle); + is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_handle); if (true == is_connect) { - SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect main DB"); - is_connect = __vc_db_connect_db(&g_backup_path, &g_db_backup_handle); + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect main DB for daemon"); + is_connect = __vc_db_connect_db_for_daemon(&g_backup_path, &g_db_backup_handle); if (true == is_connect) { - SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB"); + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB for daemon"); if (0 != vc_db_restore_command()) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to restore command"); } } } else { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB"); + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB for daemon"); return VC_DB_ERROR_OPERATION_FAILED; } } int ret = sqlite3_exec(g_db_handle, "pragma integrity_check", __vc_db_integrity_check_cb, NULL, NULL); - if (true == is_db_corrupted || SQLITE_CORRUPT == ret) { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open DB"); + if (SQLITE_CORRUPT == ret) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open DB for daemon"); ret = db_util_close(g_db_handle); if (ret != SQLITE_OK) { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to close db, ret %d: %s", ret, sqlite3_errmsg(g_db_handle)); + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to close db, ret %d: %s for daemon", ret, sqlite3_errmsg(g_db_handle)); } g_db_handle = NULL; if (0 != remove(g_path)) { + SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed for daemon", g_path); + g_db_cnt = (g_db_cnt + 1) % 1000; + snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt); + } + is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_handle); + if (true == is_connect) { + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect main DB for daemon"); + is_connect = __vc_db_connect_db_for_daemon(&g_backup_path, &g_db_backup_handle); + if (true == is_connect) { + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB for daemon"); + if (0 != vc_db_restore_command()) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to restore command for daemon"); + } + } + } else { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB for daemon"); + return VC_DB_ERROR_OPERATION_FAILED; + } + + g_ref_cnt++; + SLOG(LOG_INFO, vc_db_tag(), "[SUCCESS] DB initialization after restore for daemon"); + return 0; + } + + is_connect = __vc_db_connect_db_for_daemon(&g_backup_path, &g_db_backup_handle); + if (false == is_connect) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open backup DB, retry to connect after removing file for daemon"); + if (0 != remove(g_backup_path)) { + g_backup_db_cnt = (g_backup_db_cnt + 1) % 1000; + SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_backup_path); + snprintf(g_backup_path, 256, "%s/.vc_backup_%d.db", VC_RUNTIME_INFO_ROOT, g_backup_db_cnt); + } + is_connect = __vc_db_connect_db_for_daemon(&g_path, &g_db_backup_handle); + if (true == is_connect) { + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB for daemon"); + if (0 != vc_db_restore_command()) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to restore command for daemon"); + } + } + } + + g_ref_cnt++; + + SLOG(LOG_INFO, vc_db_tag(), "[SUCCESS] DB initialization for daemon"); + return VC_DB_ERROR_NONE; +} + +int __vc_db_open_db(char** path, sqlite3** db_handle) +{ + int ret = db_util_open(*path, db_handle, DB_UTIL_REGISTER_HOOK_METHOD); + if (ret != SQLITE_OK) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open db for daemon, path = %s, ret %d: %s", *path, ret, sqlite3_errmsg(*db_handle)); + if (*db_handle) { + db_util_close(*db_handle); + *db_handle = NULL; + } + + free(*path); + *path = NULL; + return VC_DB_ERROR_OPERATION_FAILED; + } + return VC_DB_ERROR_NONE; +} + +bool __vc_db_connect_db(char** path, sqlite3** db_handle) +{ + bool is_connect = false; + int ret = __vc_db_open_db(path, db_handle); + if (0 != ret) { + int cnt = 0; + while (cnt <= 5) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to open DB"); + + usleep(100000); + if (0 == __vc_db_open_db(path, db_handle)) { + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to open DB"); + is_connect = true; + break; + } + cnt++; + } + } else { + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to open DB"); + is_connect = true; + } + return is_connect; +} + +int vc_db_initialize(void) +{ + SLOG(LOG_INFO, vc_db_tag(), "DB on initialization"); + + if (0 < g_ref_cnt) { + g_ref_cnt++; + return VC_DB_ERROR_NONE; + } + + /* For voice control DB */ + g_path = (char*)calloc(256, sizeof(char)); + if (NULL == g_path) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory"); + return VC_DB_ERROR_OUT_OF_MEMORY; + } + /* This should be changed to general DB space - TZ_USER_DB */ + snprintf(g_path, 256, "%s/.vc_info.db", VC_RUNTIME_INFO_ROOT); + + /* For Backup DB */ + g_backup_path = (char*)calloc(256, sizeof(char)); + if (NULL == g_backup_path) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory"); + return VC_DB_ERROR_OUT_OF_MEMORY; + } + snprintf(g_backup_path, 256, "%s/.vc_backup.db", VC_RUNTIME_INFO_ROOT); + + bool is_connect = __vc_db_connect_db(&g_path, &g_db_handle); + if (false == is_connect) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB, retry to connect after removing"); + if (0 != remove(g_path)) { SLOG(LOG_ERROR, vc_db_tag(), "[Error] remove file(%s) is failed", g_path); g_db_cnt = (g_db_cnt + 1) % 1000; snprintf(g_path, 256, "%s/.vc_info_%d.db", VC_RUNTIME_INFO_ROOT, g_db_cnt); @@ -1631,10 +1793,6 @@ int vc_db_initialize(void) SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to connect main DB"); return VC_DB_ERROR_OPERATION_FAILED; } - - g_ref_cnt++; - SLOG(LOG_INFO, vc_db_tag(), "[SUCCESS] DB initialization after restore"); - return 0; } is_connect = __vc_db_connect_db(&g_backup_path, &g_db_backup_handle); @@ -1647,7 +1805,7 @@ int vc_db_initialize(void) } is_connect = __vc_db_connect_db(&g_path, &g_db_backup_handle); if (true == is_connect) { - SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup DB"); + SLOG(LOG_ERROR, vc_db_tag(), "[INFO] Success to connect backup"); if (0 != vc_db_restore_command()) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to restore command"); } @@ -2044,9 +2202,12 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ int vc_db_insert_command(int pid, vc_cmd_type_e type, vc_cmd_s* cmd, bool skip_invocation) { - int ret = __vc_db_insert_command(g_db_handle, pid, type, cmd, skip_invocation); - if (0 != ret) { - SLOG(LOG_DEBUG, vc_db_tag(), "[ERROR] Fail to insert command, %d", ret); + int cnt = 0; + int ret = -1; + while (cnt < 5 && (ret = __vc_db_insert_command(g_db_handle, pid, type, cmd, skip_invocation))) { + usleep(100000); + SLOG(LOG_DEBUG, vc_db_tag(), "[ERROR] Fail to insert command(%d), retry cnt(%d)", ret, cnt); + cnt++; } return ret; } diff --git a/common/vc_cmd_db.h b/common/vc_cmd_db.h index 0a4f76a..87376e5 100644 --- a/common/vc_cmd_db.h +++ b/common/vc_cmd_db.h @@ -50,6 +50,8 @@ typedef struct _deactivated_app_s { char* appid; } vc_deactivated_app_s; +int vc_db_initialize_for_daemon(void); + int vc_db_initialize(void); int vc_db_finalize(void); diff --git a/server/vcd_server.c b/server/vcd_server.c index c640d82..c4425d0 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1222,7 +1222,7 @@ int vcd_initialize(vce_request_callback_s *callback) SLOG(LOG_ERROR, TAG_VCD, "[Server WARNING] Fail to initialize config."); } - ret = vc_db_initialize(); + ret = vc_db_initialize_for_daemon(); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize DB : %d", ret); return ret; -- 2.7.4 From 6aeed18c1d8f5762ab6858719cf19124415a4e05 Mon Sep 17 00:00:00 2001 From: Sungwook Park Date: Tue, 24 Sep 2019 13:53:13 +0900 Subject: [PATCH 08/16] Fix issues that detected by static analysis tool Change-Id: Ib78994b2c910e05d5e19fedce613ae1cf62e21bf Signed-off-by: Sungwook Park --- client/vc.c | 4 +++- client/vc_dbus.c | 5 +++-- client/vc_mgr_dbus.c | 1 + client/vc_widget.c | 4 +++- common/vc_cmd_db.c | 2 ++ server/vcd_dbus.c | 2 ++ server/vcd_dbus_server.c | 7 +++++-- 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/client/vc.c b/client/vc.c index 677713e..458ece8 100644 --- a/client/vc.c +++ b/client/vc.c @@ -547,7 +547,9 @@ static Eina_Bool __vc_connect_daemon(void *data) ecore_thread_main_loop_end(); char appid[1024] = {'\0',}; - aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1); + ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1); + if (ret != AUL_R_OK) + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get aul_app_get_appid_bypid : %d", ret); int status = aul_app_get_status(appid); if (STATUS_FOCUS == status) { diff --git a/client/vc_dbus.c b/client/vc_dbus.c index 8408cbe..cb0c7b6 100644 --- a/client/vc_dbus.c +++ b/client/vc_dbus.c @@ -355,6 +355,7 @@ on_name_acquired(GDBusConnection *connection, GDBusVcclient *service; GError *error = NULL; + gboolean ret = FALSE; service = gdbus_vcclient_skeleton_new(); @@ -370,9 +371,9 @@ on_name_acquired(GDBusConnection *connection, g_signal_connect(service, "handle-vcm-client-method-utterance-status", G_CALLBACK(vcm_client_method_utterance_status), NULL); - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), + ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), connection, VC_CLIENT_SERVICE_OBJECT_PATH, &error); - if (error) { + if (ret == FALSE || error) { SLOG(LOG_DEBUG, TAG_VCC, "Error : %s\n", error->message); g_error_free(error); } diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index e4f39ca..f071430 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -3244,6 +3244,7 @@ int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, gdbus_vcdaemon_call_vcm_daemon_method_send_audio_streaming(g_daemon_proxy, pid, event, len, variant, NULL, NULL, NULL); + g_variant_ref(variant); return 0; #else if (0 != __dbus_check()) { diff --git a/client/vc_widget.c b/client/vc_widget.c index a40506c..950f7fc 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -440,7 +440,9 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) /* Get app focus and set foreground */ char appid[1024] = {'\0',}; - aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1); + ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1); + if (ret != AUL_R_OK) + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get aul_app_get_appid_bypid : %d", ret); int status = aul_app_get_status(appid); if (status == STATUS_FOCUS) { diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 37726a9..f3889d5 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1434,6 +1434,8 @@ static int __vc_db_create_table(sqlite3* db_handle, const char* table) int ret = __vc_db_exec_query(db_handle, sql); if (ret != VC_DB_ERROR_NONE) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to create table(%s), %d", table, ret); + free(sql); + sql = NULL; return VC_DB_ERROR_OPERATION_FAILED; } SLOG(LOG_WARN, vc_db_tag(), "[SQL] %s", sql); diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index a61912d..853a26e 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -1232,6 +1232,7 @@ int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id pid, utt_id, event, len, variant, NULL, NULL, NULL); g_object_unref(proxy); + g_variant_ref(variant); return 0; #else SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : manager_pid(%d), pid(%d), utt_id(%d) feedback event(%d), buffer(%p), length(%d)", manager_pid, pid, utt_id, event, buffer, len); @@ -1288,6 +1289,7 @@ int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, utt_id, event, len, variant, NULL, NULL, NULL); g_object_unref(proxy); + g_variant_ref(variant); return 0; #else SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : pid(%d), utt_id(%d), feedback event(%d), buffer(%p), length(%d)", pid, utt_id, event, buffer, len); diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index 421280b..f880201 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -464,7 +464,10 @@ gboolean vcm_daemon_method_get_audio_type(GDBusVcdaemon *service, GDBusMethodInv SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr get audio type : pid(%d)", pid); gdbus_vcdaemon_complete_vcm_daemon_method_get_audio_type(service, invocation, ret, audio_type); - + if (audio_type) { + free (audio_type); + audio_type = NULL; + } return TRUE; } @@ -3071,4 +3074,4 @@ int vcd_dbus_server_get_tts_audio_format(DBusConnection* conn, DBusMessage* msg) return 0; } -#endif \ No newline at end of file +#endif -- 2.7.4 From 1446f4e1a0211185975e80986d2f3258e51b60a6 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Wed, 25 Sep 2019 14:49:51 +0900 Subject: [PATCH 09/16] Change function to vc_tts_get_synthesized_audio_details Change-Id: If6273314a49397bb0f33eca45ccea7ed867916cd --- client/vc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/vc.c b/client/vc.c index 458ece8..c446137 100644 --- a/client/vc.c +++ b/client/vc.c @@ -3141,7 +3141,7 @@ int vc_tts_cancel(int utt_id) return ret; } -int vc_tts_get_audio_format(int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type) +int vc_tts_get_synthesized_audio_details(int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type) { vc_state_e state; int ret = -1; -- 2.7.4 From 0a72541b5fc5277405dc0cabcb2008fb413b465f Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 30 Sep 2019 18:53:22 +0900 Subject: [PATCH 10/16] Revert "Merge "Migration from DBUS to GDBUS" into tizen" This reverts commit a148c1f3b344f4ea8654b12a6571e6b27b49dde8, reversing changes made to bfd06ef00407ac3bb44833d14485d2eb79555ead. Change-Id: I4149d1183bec408fd04e2c434ebd41569d6e5d6d --- CMakeLists.txt | 16 +- client/CMakeLists.txt | 4 - client/vc.c | 6 +- client/vc_dbus.c | 494 +----------- client/vc_mgr.c | 4 +- client/vc_mgr_dbus.c | 866 +-------------------- client/vc_setting_dbus.c | 111 --- client/vc_widget_dbus.c | 324 +------- common/vc_defs.h | 12 +- ...mon.service => org.tizen.voice.vcserver.service | 2 +- ....service => org.tizen.voice.vcserver.tv.service | 2 +- org.tizen.voice.voice-control.gdbus.xml | 360 --------- packaging/voice-control.spec | 6 +- server/CMakeLists.txt | 1 - server/vcd_dbus.c | 407 +--------- server/vcd_dbus_server.c | 700 ----------------- server/vcd_dbus_server.h | 154 ---- server/vce.c | 4 - vc-service.conf => vc-server.conf | 4 +- 19 files changed, 70 insertions(+), 3407 deletions(-) rename org.tizen.voice.vcdaemon.service => org.tizen.voice.vcserver.service (87%) rename org.tizen.voice.vcdaemon.tv.service => org.tizen.voice.vcserver.tv.service (75%) delete mode 100644 org.tizen.voice.voice-control.gdbus.xml rename vc-service.conf => vc-server.conf (85%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbc716f..c2b603d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,14 +36,6 @@ ADD_DEFINITIONS("-Werror") # for the use of ecore_wl2 ADD_DEFINITIONS("-DEFL_BETA_API_SUPPORT") -FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen) -EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS "\\ - --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/common/vc_gdbus \\ - --c-namespace GDBus\\ - --interface-prefix org.tizen.voice. \\ - ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.voice.voice-control.gdbus.xml \\ - ") - # pkg config tool INCLUDE(FindPkgConfig) @@ -55,12 +47,12 @@ INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include") INCLUDE(FindPkgConfig) IF("${_TV_PRODUCT}" STREQUAL "TRUE") pkg_check_modules(pkgs REQUIRED - aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 gio-2.0 gio-unix-2.0 + aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 capi-network-bluetooth capi-network-bluetooth-tv capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libgum libtzplatform-config libxml-2.0 sqlite3 vconf msfapi farfield-voice-api ) ELSE() pkg_check_modules(pkgs REQUIRED - aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 gio-2.0 gio-unix-2.0 + aul buxton2 capi-appfw-app-control capi-appfw-app-manager capi-base-common capi-media-audio-io capi-media-sound-manager ecore-wl2 capi-system-info cynara-client cynara-session dbus-1 db-util dlog ecore glib-2.0 json-glib-1.0 libgum libtzplatform-config libxml-2.0 sqlite3 vconf ) ENDIF() @@ -83,9 +75,9 @@ INSTALL(FILES ${CMAKE_SOURCE_DIR}/voice-control.info DESTINATION ${TZ_SYS_RO_SHA ## config ## INSTALL(FILES ${CMAKE_SOURCE_DIR}/vc-config.xml DESTINATION ${TZ_SYS_RO_SHARE}/voice/vc/1.0) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.voice.vcdaemon.service DESTINATION ${TZ_SYS_RO_SHARE}/dbus-1/services) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.voice.vcserver.service DESTINATION ${TZ_SYS_RO_SHARE}/dbus-1/services) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/vc-service.conf DESTINATION /etc/dbus-1/session.d) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/vc-server.conf DESTINATION /etc/dbus-1/session.d) ## vc_getengine ## IF("${ARCH}" MATCHES "^arm.*") diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index a874dd2..29a1049 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -10,7 +10,6 @@ SET(SRCS ../common/vc_config_parser.c ../common/vc_info_parser.c ../common/vc_json_parser.c - ../common/vc_gdbus.c ) SET(SETTING_SRCS @@ -18,7 +17,6 @@ SET(SETTING_SRCS vc_setting.c ../common/vc_config_mgr.c ../common/vc_config_parser.c - ../common/vc_gdbus.c ) SET(WIDGET_SRCS @@ -32,7 +30,6 @@ SET(WIDGET_SRCS ../common/vc_config_parser.c ../common/vc_info_parser.c ../common/vc_json_parser.c - ../common/vc_gdbus.c ) SET(MANAGER_SRCS @@ -48,7 +45,6 @@ SET(MANAGER_SRCS ../common/vc_config_parser.c ../common/vc_info_parser.c ../common/vc_json_parser.c - ../common/vc_gdbus.c ) #INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) diff --git a/client/vc.c b/client/vc.c index c446137..f63e842 100644 --- a/client/vc.c +++ b/client/vc.c @@ -309,10 +309,6 @@ static Eina_Bool __focus_changed_cb(void *data, int type, void *event) int vc_initialize(void) { - if (!ecore_main_loop_glib_integrate()) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail ecore_main_loop_glib_integrate()"); - } - if (0 != __vc_get_feature_enabled()) { return VC_ERROR_NOT_SUPPORTED; } @@ -1672,7 +1668,7 @@ static void __vc_notify_error(void *data) } } -int __vc_cb_error(int reason, int daemon_pid, const char* msg) +int __vc_cb_error(int reason, int daemon_pid, char* msg) { vc_state_e state; if (0 != vc_client_get_client_state(g_vc, &state)) { diff --git a/client/vc_dbus.c b/client/vc_dbus.c index cb0c7b6..c78d5db 100644 --- a/client/vc_dbus.c +++ b/client/vc_dbus.c @@ -18,17 +18,18 @@ #include "vc_dbus.h" #include "vc_main.h" -#define USE_GDBUS +static pthread_mutex_t g_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; -#ifdef USE_GDBUS -#include "vc_gdbus.h" +static int g_waiting_time = 3000; +static int g_waiting_short_time = 200; +static bool g_is_connection_opened = false; -static GDBusConnection* g_connection = NULL; -static GDBusVcdaemon *g_daemon_proxy = NULL; -static int g_own_name_id = 0; -static guint g_name_owner_changed_subscription_id = 0; +static Ecore_Fd_Handler* g_fd_handler = NULL; + +static DBusConnection* g_conn_sender = NULL; +static DBusConnection* g_conn_listener = NULL; -extern int __vc_cb_error(int reason, int daemon_pid, const char* msg); +extern int __vc_cb_error(int reason, int daemon_pid, char* msg); extern void __vc_cb_result(); @@ -39,19 +40,8 @@ extern int __vc_cb_manager_pid(int manager_pid); extern int __vc_cb_tts_streaming(int utt_id, vc_feedback_event_e event, char* buffer, int len); extern int __vc_cb_utterance_status(int utt_id, int utt_status); -#else -static pthread_mutex_t g_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; -static bool g_is_connection_opened = false; -static int g_waiting_time = 3000; -static int g_waiting_short_time = 200; -static Ecore_Fd_Handler* g_fd_handler = NULL; -static DBusConnection* g_conn_listener = NULL; -static DBusConnection* g_conn_sender = NULL; - -#endif //LCOV_EXCL_START -#ifndef USE_GDBUS static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW; @@ -259,209 +249,9 @@ static void __vc_dbus_connection_free() g_conn_sender = NULL; } } -#endif - -#ifdef USE_GDBUS -static GDBusVcmanager* get_manager_proxy() { - char service_name[64] = {0,}; - char object_path[64] = {0,}; - - snprintf(service_name, 64, "%s", VC_MANAGER_SERVICE_NAME); - snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH); - - GError *error = NULL; - GDBusVcmanager *proxy = gdbus_vcmanager_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - service_name, object_path, NULL, &error); - - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", - proxy, service_name, object_path, error->message); - g_error_free(error); - } - - return proxy; -} - -gboolean vcd_client_method_hello(GDBusVcclient *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int response = -1; - if (pid > 0) { - SLOG(LOG_DEBUG, TAG_VCC, "@@ vc get hello : pid(%d) ", pid); - response = 1; - } else { - SLOG(LOG_ERROR, TAG_VCC, "@@ vc get hello : invalid pid "); - } - gdbus_vcclient_complete_vcd_client_method_hello(service, invocation, response); - return TRUE; -} - -gboolean vcd_client_method_result(GDBusVcclient *service, GDBusMethodInvocation *invocation, - gpointer user_data) -{ - __vc_cb_result(); - gdbus_vcclient_complete_vcd_client_method_result(service, invocation); - return TRUE; -} - -gboolean vcd_client_method_feedback_streaming(GDBusVcclient *service, GDBusMethodInvocation *invocation, - gint utt_id, gint event, guint size, GVariant* buffer, gpointer user_data) -{ - int len = 0; - GVariantIter *iter; - guchar uc; - - char *data = NULL; - data = malloc(size); - if (!data) return FALSE; - - g_variant_get(buffer, "ay", &iter); - while (g_variant_iter_loop(iter, "y", &uc)) { - if (len < size) { - data[len++] = uc; - } else { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] max size reached : %d", len); - } - } - g_variant_iter_free(iter); - - int ret = __vc_cb_tts_streaming(utt_id, event, data, len); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to send_audio_streaming"); - } - - gdbus_vcclient_complete_vcd_client_method_feedback_streaming(service, invocation); - - free(data); - return ret; -} - -gboolean vcm_client_method_utterance_status(GDBusVcclient *service, GDBusMethodInvocation *invocation, - gint utt_id, gint utt_status, gpointer user_data) -{ - SLOG(LOG_INFO, TAG_VCC, "@@@ Get TTS utterance status streaming"); - __vc_cb_utterance_status(utt_id, utt_status); - gdbus_vcclient_complete_vcm_client_method_utterance_status(service, invocation); - return TRUE; -} - -static void -on_name_acquired(GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCC, "Name acquired : %s", name); - - GDBusVcclient *service; - GError *error = NULL; - gboolean ret = FALSE; - - service = gdbus_vcclient_skeleton_new(); - - /* vc daemon methods */ - g_signal_connect(service, "handle-vcd-client-method-hello", - G_CALLBACK(vcd_client_method_hello), NULL); - g_signal_connect(service, "handle-vcd-client-method-result", - G_CALLBACK(vcd_client_method_result), NULL); - g_signal_connect(service, "handle-vcd-client-method-feedback-streaming", - G_CALLBACK(vcd_client_method_feedback_streaming), NULL); - - /* vc manager methods */ - g_signal_connect(service, "handle-vcm-client-method-utterance-status", - G_CALLBACK(vcm_client_method_utterance_status), NULL); - - ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), - connection, VC_CLIENT_SERVICE_OBJECT_PATH, &error); - if (ret == FALSE || error) { - SLOG(LOG_DEBUG, TAG_VCC, "Error : %s\n", error->message); - g_error_free(error); - } -} - -static void vcd_signal_set_service_state(GDBusVcdaemon* proxy, - gint state, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCC, "@@ state changed : %d", state); - __vc_cb_service_state(state); -} - -static void vcd_client_signal_send_error(GDBusVcdaemon* proxy, - gint reason, gint daemon_pid, const gchar* err_msg, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCC, "@@ vc Get Error message : reason(%d), daemon_pid(%d), msg(%s)", - reason, daemon_pid, err_msg); - __vc_cb_error(reason, daemon_pid, err_msg); -} - -static void vcd_client_signal_send_manager_pid(GDBusVcdaemon* proxy, - gint manager_pid, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCC, "@@ manager pid is changed : %d", manager_pid); - __vc_cb_manager_pid(manager_pid); -} - -static void _on_name_owner_changed(GDBusConnection *connection, - const gchar *sender_name, const gchar *object_path, - const gchar *interface_name, const gchar *signal_name, - GVariant *parameters, gpointer user_data) -{ - gchar *name; - gchar *old_owner; - gchar *new_owner; - - g_variant_get(parameters, - "(sss)", - &name, - &old_owner, - &new_owner); - - if (g_name_owner_changed_subscription_id > 0) { - g_dbus_connection_signal_unsubscribe(connection, g_name_owner_changed_subscription_id); - g_name_owner_changed_subscription_id = 0; - } - - SLOG(LOG_ERROR, TAG_VCC, "name_owner_changed(%s: %s -> %s) interface %s sender %s object %s", - name, old_owner, new_owner, interface_name, sender_name, object_path); - __vc_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); - - g_free(name); - g_free(old_owner); - g_free(new_owner); -} -#endif int vc_dbus_open_connection() { -#ifdef USE_GDBUS - GError* error = NULL; - g_connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); - int pid = getpid(); - - char service_name[64]; - memset(service_name, '\0', 64); - snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid); - g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, - service_name, G_BUS_NAME_OWNER_FLAGS_REPLACE, NULL, on_name_acquired, NULL, NULL, NULL); - SLOG(LOG_DEBUG, TAG_VCC, "service_name : %s, %d", service_name, g_own_name_id); - - g_daemon_proxy = gdbus_vcdaemon_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - VC_DAEMON_SERVICE_NAME, VC_DAEMON_SERVICE_OBJECT_PATH, NULL, &error); - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - g_error_free(error); - } else { - /* vc common signals */ - g_signal_connect(g_daemon_proxy, "vcd-signal-set-service-state", - G_CALLBACK(vcd_signal_set_service_state), NULL); - - /* vc daemon signals */ - g_signal_connect(g_daemon_proxy, "vcd-client-signal-send-error", - G_CALLBACK(vcd_client_signal_send_error), NULL); - g_signal_connect(g_daemon_proxy, "vcd-client-signal-send-manager-pid", - G_CALLBACK(vcd_client_signal_send_manager_pid), NULL); - } -#else pthread_mutex_lock(&g_dbus_mutex); if (NULL != g_conn_sender && NULL != g_conn_listener) { @@ -575,26 +365,12 @@ int vc_dbus_open_connection() pthread_mutex_unlock(&g_dbus_mutex); SLOG(LOG_INFO, TAG_VCC, "[INFO] vc client dbus connection is opened"); -#endif + return VC_ERROR_NONE; } int vc_dbus_close_connection() { -#ifdef USE_GDBUS - if (g_daemon_proxy) { - g_object_unref(g_daemon_proxy); - g_daemon_proxy = NULL; - } - if (g_own_name_id) { - g_bus_unown_name(g_own_name_id); - g_own_name_id = 0; - } - if (g_connection != NULL) { - g_object_unref(g_connection); - g_connection = NULL; - } -#else pthread_mutex_lock(&g_dbus_mutex); DBusError err; @@ -627,25 +403,12 @@ int vc_dbus_close_connection() pthread_mutex_unlock(&g_dbus_mutex); SLOG(LOG_INFO, TAG_VCC, "[INFO] vc client dbus connection is closed"); -#endif + return 0; } int vc_dbus_reconnect() { -#ifdef USE_GDBUS - if (!g_own_name_id || !g_daemon_proxy) { - vc_dbus_close_connection(); - - if (0 != vc_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect"); //LCOV_EXCL_LINE - return -1; - } - - SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect"); //LCOV_EXCL_LINE - return 0; - } -#else if (!g_conn_sender || !g_conn_listener) { vc_dbus_close_connection(); @@ -673,24 +436,16 @@ int vc_dbus_reconnect() SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect"); //LCOV_EXCL_LINE } -#endif + return 0; } static int __dbus_check() { -#ifdef USE_GDBUS - SLOG(LOG_DEBUG, TAG_VCC, "%d %p", g_own_name_id, g_daemon_proxy); //LCOV_EXCL_LINE - if (0 == g_own_name_id || NULL == g_daemon_proxy) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE - return vc_dbus_reconnect(); - } -#else if (NULL == g_conn_sender || NULL == g_conn_listener) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE return vc_dbus_reconnect(); } -#endif return 0; } @@ -700,20 +455,6 @@ int vc_dbus_request_hello() return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vc_method_hello_sync(g_daemon_proxy, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Request vc hello"); //LCOV_EXCL_LINE DBusMessage* msg; @@ -752,7 +493,6 @@ int vc_dbus_request_hello() } return result; -#endif } @@ -762,26 +502,6 @@ int vc_dbus_request_initialize(int pid, int* mgr_pid, int* service_state, int* d return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vcc_daemon_method_initialize_sync(g_daemon_proxy, - pid, &result, mgr_pid, service_state, daemon_pid, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - if (0 == result && NULL != g_connection) { - g_name_owner_changed_subscription_id = g_dbus_connection_signal_subscribe(g_connection, - "org.freedesktop.DBus", "org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus", - VC_DAEMON_SERVICE_NAME, G_DBUS_SIGNAL_FLAGS_NONE, _on_name_owner_changed, NULL, NULL); - } - return result; -#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -869,35 +589,10 @@ int vc_dbus_request_initialize(int pid, int* mgr_pid, int* service_state, int* d } return result; -#endif } int vc_dbus_request_finalize(int pid) { -#ifdef USE_GDBUS - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } - - if (g_name_owner_changed_subscription_id > 0) { - g_dbus_connection_signal_unsubscribe(g_connection, g_name_owner_changed_subscription_id); - g_name_owner_changed_subscription_id = 0; - } - - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vcc_daemon_method_finalize_sync(g_daemon_proxy, pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - - return result; -#else DBusError err; dbus_error_init(&err); @@ -969,7 +664,6 @@ int vc_dbus_request_finalize(int pid) } return result; -#endif } //LCOV_EXCL_START @@ -979,20 +673,6 @@ int vc_dbus_request_set_exclusive_command(int pid, bool value) return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vcc_daemon_method_set_exclusive_cmd_sync(g_daemon_proxy, pid, value, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -1053,7 +733,6 @@ int vc_dbus_request_set_exclusive_command(int pid, bool value) } return result; -#endif } //LCOV_EXCL_STOP @@ -1063,20 +742,6 @@ int vc_dbus_request_set_command(int pid, vc_cmd_type_e cmd_type) return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vcc_daemon_method_set_command_sync(g_daemon_proxy, pid, cmd_type, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -1135,7 +800,6 @@ int vc_dbus_request_set_command(int pid, vc_cmd_type_e cmd_type) } return result; -#endif } int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type) @@ -1144,20 +808,6 @@ int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type) return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - gint result = 0; - if (!gdbus_vcdaemon_call_vcc_daemon_method_unset_command_sync(g_daemon_proxy, pid, cmd_type, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else DBusMessage* msg; msg = dbus_message_new_method_call( @@ -1216,7 +866,6 @@ int vc_dbus_request_unset_command(int pid, vc_cmd_type_e cmd_type) } return result; -#endif } int vc_dbus_set_foreground(int pid, bool value) @@ -1225,16 +874,6 @@ int vc_dbus_set_foreground(int pid, bool value) return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcc_manager_method_set_foreground(proxy, - pid, value, NULL, NULL, NULL); - if (proxy) g_object_unref(proxy); - - gdbus_vcdaemon_call_vcc_daemon_method_set_foreground(g_daemon_proxy, - pid, value, NULL, NULL, NULL); - return 0; -#else DBusMessage* msg = NULL; int tmp_value = 0; @@ -1297,26 +936,11 @@ int vc_dbus_set_foreground(int pid, bool value) dbus_message_unref(msg); return 0; -#endif } //LCOV_EXCL_START int vc_dbus_set_server_dialog(int pid, const char* app_id, const char* credential) { -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vcc_daemon_method_set_server_dialog_sync(g_daemon_proxy, pid, app_id, credential, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); if (0 != vc_dbus_reconnect()) { @@ -1382,17 +1006,11 @@ int vc_dbus_set_server_dialog(int pid, const char* app_id, const char* credentia } return result; -#endif } //LCOV_EXCL_STOP int vc_dbus_request_dialog(int pid, const char* disp_text, const char* utt_text, bool continuous) { -#ifdef USE_GDBUS - int result = 0; - gdbus_vcdaemon_call_vcc_daemon_method_dialog(g_daemon_proxy, pid, disp_text, utt_text, continuous, NULL, NULL, NULL); - return result; -#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE if (0 != vc_dbus_reconnect()) { @@ -1482,28 +1100,10 @@ int vc_dbus_request_dialog(int pid, const char* disp_text, const char* utt_text, return result; */ //LCOV_EXCL_STOP -#endif } int vc_dbus_request_is_system_command_valid(int pid, bool* is_sys_cmd_valid) { -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - gboolean valid = FALSE; - if (!gdbus_vcdaemon_call_vcc_daemon_method_is_system_command_valid_sync(g_daemon_proxy, pid, &result, &valid, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } else { - if (is_sys_cmd_valid) *is_sys_cmd_valid = valid; - } - return result; -#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE if (0 != vc_dbus_reconnect()) { @@ -1571,7 +1171,6 @@ int vc_dbus_request_is_system_command_valid(int pid, bool* is_sys_cmd_valid) } return result; -#endif } //LCOV_EXCL_START @@ -1771,9 +1370,6 @@ int vc_dbus_request_cancel(int pid) /* Authority */ int vc_dbus_request_auth_enable(int pid, int mgr_pid) { -#ifdef USE_GDBUS - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1844,14 +1440,10 @@ int vc_dbus_request_auth_enable(int pid, int mgr_pid) } return result; -#endif } int vc_dbus_request_auth_disable(int pid, int mgr_pid) { -#ifdef USE_GDBUS - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -1922,14 +1514,10 @@ int vc_dbus_request_auth_disable(int pid, int mgr_pid) } return result; -#endif } int vc_dbus_request_auth_start(int pid, int mgr_pid) { -#ifdef USE_GDBUS - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2002,14 +1590,10 @@ int vc_dbus_request_auth_start(int pid, int mgr_pid) } return result; -#endif } int vc_dbus_request_auth_stop(int pid, int mgr_pid) { -#ifdef USE_GDBUS - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2080,14 +1664,10 @@ int vc_dbus_request_auth_stop(int pid, int mgr_pid) } return result; -#endif } int vc_dbus_request_auth_cancel(int pid, int mgr_pid) { -#ifdef USE_GDBUS - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2158,26 +1738,11 @@ int vc_dbus_request_auth_cancel(int pid, int mgr_pid) } return result; -#endif } //LCOV_EXCL_STOP int vc_dbus_request_tts(int pid, const char* text, const char* language, bool to_vcm, int* utt_id) { -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vcc_daemon_method_request_tts_sync(g_daemon_proxy, pid, text, language, to_vcm, &result, utt_id, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); if (0 != vc_dbus_reconnect()) { @@ -2253,25 +1818,10 @@ int vc_dbus_request_tts(int pid, const char* text, const char* language, bool to return result; return 0; -#endif } int vc_dbus_cancel_tts(int pid, int utt_id) { -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vcc_daemon_method_cancel_tts_sync(g_daemon_proxy, pid, utt_id, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); if (0 != vc_dbus_reconnect()) { @@ -2339,29 +1889,10 @@ int vc_dbus_cancel_tts(int pid, int utt_id) return result; return 0; -#endif } int vc_dbus_get_tts_audio_format(int pid, int* rate, vc_audio_channel_e* channel, vc_audio_type_e* audio_type) { -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - gint out_channel, out_audio_type; - if (!gdbus_vcdaemon_call_vcc_daemon_method_get_tts_audio_format_sync(g_daemon_proxy, pid, &result, rate, &out_channel, &out_audio_type, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } else { - if (channel) *channel = out_channel; - if (audio_type) *audio_type = out_audio_type; - } - return result; -#else if (NULL == g_conn_sender) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); if (0 != vc_dbus_reconnect()) { @@ -2438,6 +1969,5 @@ int vc_dbus_get_tts_audio_format(int pid, int* rate, vc_audio_channel_e* channel return result; return 0; -#endif } diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 35f272c..cee3254 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -83,7 +83,7 @@ static Eina_Bool __vc_mgr_notify_state_changed(void *data); static void __vc_mgr_notify_error(void *data); static Eina_Bool __vc_mgr_notify_result(void *data); -int __vc_mgr_cb_error(int reason, int daemon_pid, const char* msg); +int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg); static const char* __vc_mgr_get_error_code(vc_error_e err) @@ -2950,7 +2950,7 @@ static void __vc_mgr_notify_error(void *data) } } -int __vc_mgr_cb_error(int reason, int daemon_pid, const char* msg) +int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg) { vc_state_e state; if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index f071430..aa20c13 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -20,32 +20,20 @@ #include "vc_mgr_dbus.h" #include "vc_command.h" -#define USE_GDBUS -#ifdef USE_GDBUS -#include "vc_gdbus.h" - -static GDBusConnection* g_connection = NULL; -static GDBusVcdaemon *g_daemon_proxy = NULL; -static int g_own_name_id = 0; -static guint g_watch_id = 0; -static guint g_name_owner_changed_subscription_id = 0; -static bool g_daemon_name_appeared = false; - -static int g_volume_count = 0; -#else static pthread_mutex_t g_m_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; -static Ecore_Fd_Handler* g_m_fd_handler = NULL; - -static bool g_is_connection_opened = false; static int g_m_waiting_time = 3000; static int g_m_waiting_short_time = 200; +static bool g_is_connection_opened = false; + +static Ecore_Fd_Handler* g_m_fd_handler = NULL; static DBusConnection* g_m_conn_sender = NULL; static DBusConnection* g_m_conn_listener = NULL; -#endif +static int g_volume_count = 0; + extern void __vc_mgr_cb_all_result(vc_result_type_e type); @@ -55,7 +43,7 @@ extern void __vc_mgr_cb_system_result(); extern void __vc_mgr_cb_speech_detected(); -extern int __vc_mgr_cb_error(int reason, int daemon_pid, const char* msg); +extern int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg); extern int __vc_mgr_cb_set_volume(float volume); @@ -87,7 +75,6 @@ extern int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_te extern void __vc_mgr_cb_specific_engine_result(const char* engine_app_id, const char* event, const char* result); -#ifndef USE_GDBUS static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_m_conn_listener) return ECORE_CALLBACK_RENEW; @@ -667,323 +654,8 @@ static void __vc_mgr_dbus_connection_free() } } -#endif - -#ifdef USE_GDBUS -gboolean vcd_manager_method_hello(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int response = -1; - if (pid > 0) { - SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get hello : pid(%d) ", pid); - response = 1; - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get hello : invalid pid "); - } - gdbus_vcmanager_complete_vcd_manager_method_hello(service, invocation, response); - return TRUE; -} - -gboolean vcd_manager_method_speech_detected(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCM, "@@@ Get Speech detected"); - __vc_mgr_cb_speech_detected(); - gdbus_vcmanager_complete_vcd_manager_method_speech_detected(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_all_result(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gint result_type, gpointer user_data) -{ - __vc_mgr_cb_all_result((vc_result_type_e)result_type); - gdbus_vcmanager_complete_vcd_manager_method_all_result(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_pre_result(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gint event, const gchar* pre_result, gpointer user_data) -{ - if (NULL != pre_result) { - __vc_mgr_cb_pre_result((vc_pre_result_event_e)event, pre_result); - } - gdbus_vcmanager_complete_vcd_manager_method_pre_result(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_result(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gpointer user_data) -{ - __vc_mgr_cb_system_result(); - gdbus_vcmanager_complete_vcd_manager_method_result(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_set_volume(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gint volume, gpointer user_data) -{ - if (10 == g_volume_count) { - SLOG(LOG_DEBUG, TAG_VCM, "@@@ Set volume"); - SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr set volume : volume(%d)", volume); - g_volume_count = 0; - } - - __vc_mgr_cb_set_volume(volume); - g_volume_count++; - gdbus_vcmanager_complete_vcd_manager_method_set_volume(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_dialog(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gint pid, const gchar* disp_text, const gchar* utt_text, gboolean continuous, gpointer user_data) -{ - __vc_mgr_cb_dialog(pid, disp_text, utt_text, continuous); - gdbus_vcmanager_complete_vcd_manager_method_dialog(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_set_private_data(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gint pid, const gchar* key, const gchar* data, gpointer user_data) -{ - if (pid > 0) { - SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get request set private data : pid(%d) ", pid); - __vc_mgr_cb_private_data_set(key, data); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request set private data : invalid pid "); - } - gdbus_vcmanager_complete_vcd_manager_method_set_private_data(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_get_private_data(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - int pid, const gchar* key, gpointer user_data) -{ - gint ret = 0; - gchar* value = NULL; - if (pid > 0) { - SLOG(LOG_DEBUG, TAG_VCM, "@@ vc mgr get request get private data : pid(%d) ", pid); - ret = __vc_mgr_cb_private_data_requested(key, &value); - } else { - SLOG(LOG_ERROR, TAG_VCM, "@@ vc mgr get request get private data : invalid pid "); - } - gdbus_vcmanager_complete_vcd_manager_method_get_private_data(service, invocation, ret, value); - return TRUE; -} - -gboolean vcd_manager_method_specific_engine_result(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - const gchar* engine_app_id, const gchar* event, const gchar* result, gpointer user_data) -{ - if (NULL != result) { - __vc_mgr_cb_specific_engine_result(engine_app_id, event, result); - } - gdbus_vcmanager_complete_vcd_manager_method_specific_engine_result(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_feedback_audio_format(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gint rate, gint channel, gint audio_type, gpointer user_data) -{ - __vc_mgr_cb_feedback_audio_format(rate, channel, audio_type); - gdbus_vcmanager_complete_vcd_manager_method_feedback_audio_format(service, invocation); - return TRUE; -} - -gboolean vcd_manager_method_feedback_streaming(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - gint pid, gint utt_id, gint event, guint size, GVariant* buffer, gpointer user_data) -{ - int index = 0; - GVariantIter *iter; - guchar uc; - - char *data = NULL; - data = malloc(size); - if (!data) return FALSE; - - g_variant_get(buffer, "ay", &iter); - while (g_variant_iter_loop(iter, "y", &uc)) { - if (index < size) { - data[index++] = uc; - } else { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] max size reached : %d", index); - } - } - g_variant_iter_free(iter); - - __vc_mgr_cb_feedback_streaming(pid, utt_id, event, data, size); - - gdbus_vcmanager_complete_vcd_manager_method_feedback_streaming(service, invocation); - - free(data); - return TRUE; -} - -gboolean vcc_manager_method_set_foreground(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - int pid, gboolean value, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false"); - - __vc_mgr_cb_set_foreground(pid, value); - gdbus_vcmanager_complete_vcc_manager_method_set_foreground(service, invocation); - return TRUE; -} - -gboolean vcw_manager_method_set_foreground(GDBusVcmanager *service, GDBusMethodInvocation *invocation, - int pid, gboolean value, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCM, "@@ foreground changed : pid(%d) value(%s)", pid, value ? "true" : "false"); - - __vc_mgr_cb_set_foreground(pid, value); - gdbus_vcmanager_complete_vcw_manager_method_set_foreground(service, invocation); - return TRUE; -} - -static void -on_name_acquired(GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCM, "Name acquired : %s", name); - - GDBusVcmanager *service; - GError *error = NULL; - - service = gdbus_vcmanager_skeleton_new(); - - /* vc client methods */ - g_signal_connect(service, "handle-vcc-manager-method-set-foreground", - G_CALLBACK(vcc_manager_method_set_foreground), NULL); - - /* vc daemon methods */ - g_signal_connect(service, "handle-vcd-manager-method-hello", - G_CALLBACK(vcd_manager_method_hello), NULL); - g_signal_connect(service, "handle-vcd-manager-method-speech-detected", - G_CALLBACK(vcd_manager_method_speech_detected), NULL); - g_signal_connect(service, "handle-vcd-manager-method-all-result", - G_CALLBACK(vcd_manager_method_all_result), NULL); - - g_signal_connect(service, "handle-vcd-manager-method-pre-result", - G_CALLBACK(vcd_manager_method_pre_result), NULL); - g_signal_connect(service, "handle-vcd-manager-method-result", - G_CALLBACK(vcd_manager_method_result), NULL); - g_signal_connect(service, "handle-vcd-manager-method-set-volume", - G_CALLBACK(vcd_manager_method_set_volume), NULL); - g_signal_connect(service, "handle-vcd-manager-method-dialog", - G_CALLBACK(vcd_manager_method_dialog), NULL); - g_signal_connect(service, "handle-vcd-manager-method-set-private-data", - G_CALLBACK(vcd_manager_method_set_private_data), NULL); - g_signal_connect(service, "handle-vcd-manager-method-get-private-data", - G_CALLBACK(vcd_manager_method_get_private_data), NULL); - g_signal_connect(service, "handle-vcd-manager-method-specific-engine-result", - G_CALLBACK(vcd_manager_method_specific_engine_result), NULL); - g_signal_connect(service, "handle-vcd-manager-method-feedback-audio-format", - G_CALLBACK(vcd_manager_method_feedback_audio_format), NULL); - g_signal_connect(service, "handle-vcd-manager-method-feedback-streaming", - G_CALLBACK(vcd_manager_method_feedback_streaming), NULL); - - /* vc widget methods */ - g_signal_connect(service, "handle-vcw-manager-method-set-foreground", - G_CALLBACK(vcw_manager_method_set_foreground), NULL); - - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), - connection, VC_MANAGER_SERVICE_OBJECT_PATH, &error); - if (error) { - SLOG(LOG_DEBUG, TAG_VCM, "Error : %s\n", error->message); - g_error_free(error); - } -} - -static void _on_name_owner_changed(GDBusConnection *connection, - const gchar *sender_name, const gchar *object_path, - const gchar *interface_name, const gchar *signal_name, - GVariant *parameters, gpointer user_data) -{ - gchar *name; - gchar *old_owner; - gchar *new_owner; - - g_variant_get(parameters, - "(sss)", - &name, - &old_owner, - &new_owner); - - if (g_name_owner_changed_subscription_id > 0) { - g_dbus_connection_signal_unsubscribe(connection, g_name_owner_changed_subscription_id); - g_name_owner_changed_subscription_id = 0; - } - - SLOG(LOG_ERROR, TAG_VCM, "name_owner_changed(%s: %s -> %s) interface %s sender %s object %s", - name, old_owner, new_owner, interface_name, sender_name, object_path); - __vc_mgr_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); - - g_free(name); - g_free(old_owner); - g_free(new_owner); -} - -static void name_appeared_handler(GDBusConnection *connection, - const gchar *name, const gchar *name_owner, gpointer user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@ Name appeared : name %s owner %s", name, name_owner); - g_daemon_name_appeared = true; -} - -static void name_vanished_handler(GDBusConnection *connection, - const gchar *name, gpointer user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@ Name vanished : name %s", name); - g_daemon_name_appeared = false; -} - -#endif - -static void vcd_signal_set_service_state(GDBusVcdaemon* proxy, - gint state, gpointer user_data) -{ - SLOG(LOG_INFO, TAG_VCM, "@@ state changed : %d", state); - - __vc_mgr_cb_service_state(state); -} - -static void vcd_manager_signal_send_error(GDBusVcdaemon* proxy, - gint reason, gint daemon_pid, const gchar* err_msg, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCM, "Error Signal : reason(%d), daemon_pid(%d), err_msg(%s)", - reason, daemon_pid, err_msg); -} - int vc_mgr_dbus_open_connection() { -#ifdef USE_GDBUS - GError* error = NULL; - g_connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); - g_watch_id = g_bus_watch_name_on_connection(g_connection, VC_DAEMON_SERVICE_NAME, 0, - name_appeared_handler, - name_vanished_handler, - NULL, NULL); - - char service_name[64]; - memset(service_name, '\0', 64); - snprintf(service_name, 64, "%s", VC_MANAGER_SERVICE_NAME); - g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, - service_name, 0, NULL, on_name_acquired, NULL, NULL, NULL); - SLOG(LOG_DEBUG, TAG_VCM, "service_name : %s, %d", service_name, g_own_name_id); - - g_daemon_proxy = gdbus_vcdaemon_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - VC_DAEMON_SERVICE_NAME, VC_DAEMON_SERVICE_OBJECT_PATH, NULL, &error); - if (error) { - SLOG(LOG_DEBUG, TAG_VCM, "Error : %s", error->message); - g_error_free(error); - } else { - /* vc common signals */ - g_signal_connect(g_daemon_proxy, "vcd-signal-set-service-state", - G_CALLBACK(vcd_signal_set_service_state), NULL); - - /* vc manager signals */ - g_signal_connect(g_daemon_proxy, "vcd-manager-signal-send-error", - G_CALLBACK(vcd_manager_signal_send_error), NULL); - } -#else pthread_mutex_lock(&g_m_dbus_mutex); if (NULL != g_m_conn_sender && NULL != g_m_conn_listener) { @@ -1093,30 +765,12 @@ int vc_mgr_dbus_open_connection() pthread_mutex_unlock(&g_m_dbus_mutex); SLOG(LOG_INFO, TAG_VCM, "[INFO] manager dbus connection is opened"); -#endif + return VC_ERROR_NONE; } int vc_mgr_dbus_close_connection() { -#ifdef USE_GDBUS - if (g_daemon_proxy) { - g_object_unref(g_daemon_proxy); - g_daemon_proxy = NULL; - } - if (g_own_name_id) { - g_bus_unown_name(g_own_name_id); - g_own_name_id = 0; - } - if (g_watch_id) { - g_bus_unwatch_name(g_watch_id); - g_watch_id = 0; - } - if (g_connection != NULL) { - g_object_unref(g_connection); - g_connection = NULL; - } -#else pthread_mutex_lock(&g_m_dbus_mutex); DBusError err; @@ -1149,25 +803,12 @@ int vc_mgr_dbus_close_connection() pthread_mutex_unlock(&g_m_dbus_mutex); SLOG(LOG_INFO, TAG_VCM, "[INFO] manager dbus connection is closed"); -#endif + return VC_ERROR_NONE; } int vc_mgr_dbus_reconnect() { -#ifdef USE_GDBUS - if (!g_own_name_id || !g_daemon_proxy) { - vc_mgr_dbus_close_connection(); - - if (0 != vc_mgr_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to reconnect"); //LCOV_EXCL_LINE - return -1; - } - - SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect"); //LCOV_EXCL_LINE - return 0; - } -#else if (!g_m_conn_sender || !g_m_conn_listener) { vc_mgr_dbus_close_connection(); @@ -1196,24 +837,16 @@ int vc_mgr_dbus_reconnect() SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect"); } -#endif + return 0; } static int __dbus_check() { -#ifdef USE_GDBUS - SLOG(LOG_DEBUG, TAG_VCM, "%d %p", g_own_name_id, g_daemon_proxy); //LCOV_EXCL_LINE - if (0 == g_own_name_id || NULL == g_daemon_proxy) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NULL connection"); //LCOV_EXCL_LINE - return vc_mgr_dbus_reconnect(); - } -#else if (NULL == g_m_conn_sender || NULL == g_m_conn_listener) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NULL connection"); //LCOV_EXCL_LINE return vc_mgr_dbus_reconnect(); } -#endif return 0; } @@ -1222,20 +855,7 @@ int vc_mgr_dbus_request_hello() if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vc_method_hello_sync(g_daemon_proxy, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -1272,7 +892,6 @@ int vc_mgr_dbus_request_hello() } return result; -#endif } static int __dbus_restore_daemon() @@ -1280,15 +899,19 @@ static int __dbus_restore_daemon() int ret = -1; int count = 0; while (0 != ret) { - usleep(100000); - SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] requesting hello : %d", count); ret = vc_mgr_dbus_request_hello(); if (0 != ret) { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry restore daemon"); - count++; - if (VC_RETRY_COUNT == count) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); + if (VC_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); break; + } else { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry restore daemon"); + usleep(10000); + count++; + if (VC_RETRY_COUNT == count) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); + break; + } } } else { SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] restore daemon"); @@ -1302,34 +925,7 @@ int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* servi if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - } - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vcm_daemon_method_initialize_sync(g_daemon_proxy, - pid, audio_streaming_mode, &result, service_state, foreground, daemon_pid, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - if (0 == result && NULL != g_connection && 0 == g_name_owner_changed_subscription_id) { - g_name_owner_changed_subscription_id = g_dbus_connection_signal_subscribe(g_connection, - "org.freedesktop.DBus", "org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus", - VC_DAEMON_SERVICE_NAME, G_DBUS_SIGNAL_FLAGS_NONE, _on_name_owner_changed, NULL, NULL); - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -1430,39 +1026,14 @@ int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* servi } return result; -#endif } int vc_mgr_dbus_request_finalize(int pid) { -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } + if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } - GError *error = NULL; - gint result; - if (g_name_owner_changed_subscription_id > 0) { - g_dbus_connection_signal_unsubscribe(g_connection, g_name_owner_changed_subscription_id); - g_name_owner_changed_subscription_id = 0; - } - if (!gdbus_vcdaemon_call_vcm_daemon_method_finalize_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -1545,7 +1116,7 @@ int vc_mgr_dbus_request_finalize(int pid) vc_mgr_dbus_reconnect(); result = VC_ERROR_TIMED_OUT; } -#endif + return result; } @@ -1554,30 +1125,7 @@ int vc_mgr_dbus_request_set_command(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_set_command_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -1651,7 +1199,6 @@ int vc_mgr_dbus_request_set_command(int pid) } return result; -#endif } int vc_mgr_dbus_request_unset_command(int pid) @@ -1659,30 +1206,7 @@ int vc_mgr_dbus_request_unset_command(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_unset_command_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -1756,7 +1280,6 @@ int vc_mgr_dbus_request_unset_command(int pid) } return result; -#endif } int vc_mgr_dbus_request_demandable_client(int pid) @@ -1764,30 +1287,7 @@ int vc_mgr_dbus_request_demandable_client(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_set_demandable_client_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -1861,7 +1361,6 @@ int vc_mgr_dbus_request_demandable_client(int pid) } return result; -#endif } int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) @@ -1870,30 +1369,6 @@ int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_set_audio_type_sync(g_daemon_proxy, - pid, audio_type, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -1969,7 +1444,6 @@ int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) } return result; -#endif } int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) @@ -1977,34 +1451,7 @@ int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - GError *error = NULL; - gint result; - gchar *temp = NULL; - if (!gdbus_vcdaemon_call_vcm_daemon_method_get_audio_type_sync(g_daemon_proxy, - pid, &result, &temp, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - if (NULL != audio_type && NULL != temp) { - *audio_type = strdup(temp); - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -2085,16 +1532,10 @@ int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) } return result; -#endif } int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* data) { -#ifdef USE_GDBUS - gdbus_vcdaemon_call_vcm_daemon_method_set_private_data(g_daemon_proxy, - pid, key, data, NULL, NULL, NULL); - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2136,30 +1577,10 @@ int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* d dbus_message_unref(msg); return VC_ERROR_NONE; -#endif } int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data) { -#ifdef USE_GDBUS - GError *error = NULL; - gint result = 0; - gchar *temp = NULL; - if (!gdbus_vcdaemon_call_vcm_daemon_method_get_private_data_sync(g_daemon_proxy, - pid, key, &result, &temp, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - if (NULL != data && NULL != temp) { - *data = strdup(temp); - } - return result; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2230,7 +1651,6 @@ int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data) } return result; -#endif } int vc_mgr_dbus_request_set_client_info(int pid) @@ -2238,33 +1658,6 @@ int vc_mgr_dbus_request_set_client_info(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_set_client_info_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } DBusError err; dbus_error_init(&err); @@ -2340,26 +1733,10 @@ int vc_mgr_dbus_request_set_client_info(int pid) } return result; -#endif } int vc_mgr_dbus_request_set_domain(int pid, const char* domain) { -#ifdef USE_GDBUS - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_set_domain_sync(g_daemon_proxy, - pid, domain, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2423,16 +1800,10 @@ int vc_mgr_dbus_request_set_domain(int pid, const char* domain) } return result; -#endif } int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send_event) { -#ifdef USE_GDBUS - gdbus_vcdaemon_call_vcm_daemon_method_do_action(g_daemon_proxy, - pid, type, send_event, NULL, NULL, NULL); - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -2472,7 +1843,6 @@ int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send dbus_message_unref(msg); return 0; -#endif } int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client) @@ -2480,33 +1850,6 @@ int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_comm if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_request_start_sync(g_daemon_proxy, - pid, recognition_mode, exclusive_command_option, start_by_client, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } DBusError err; dbus_error_init(&err); @@ -2589,7 +1932,6 @@ int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_comm } return result; -#endif } int vc_mgr_dbus_request_stop(int pid) @@ -2597,30 +1939,7 @@ int vc_mgr_dbus_request_stop(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_request_stop_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -2695,7 +2014,6 @@ int vc_mgr_dbus_request_stop(int pid) } return result; -#endif } int vc_mgr_dbus_request_cancel(int pid) @@ -2703,30 +2021,7 @@ int vc_mgr_dbus_request_cancel(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_request_cancel_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -2801,7 +2096,6 @@ int vc_mgr_dbus_request_cancel(int pid) } return result; -#endif } int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type) @@ -2809,30 +2103,7 @@ int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_enable_command_type_sync(g_daemon_proxy, - pid, cmd_type, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else DBusError err; dbus_error_init(&err); @@ -2908,7 +2179,6 @@ int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type) } return result; -#endif } int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type) @@ -2916,33 +2186,6 @@ int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_disable_command_type_sync(g_daemon_proxy, - pid, cmd_type, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } DBusError err; dbus_error_init(&err); @@ -3019,10 +2262,8 @@ int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type) } return result; -#endif } -#ifndef USE_GDBUS static DBusMessage* __get_message(int pid, const char* method, int type) { char service_name[64]; @@ -3049,13 +2290,9 @@ static DBusMessage* __get_message(int pid, const char* method, int type) return dbus_message_new_method_call(service_name, object_path, target_if_name, method); } -#endif int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) { -#ifdef USE_GDBUS - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -3094,16 +2331,10 @@ int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) dbus_message_unref(msg); return 0; -#endif } int vc_mgr_dbus_send_result_selection(int pid) { -#ifdef USE_GDBUS - gdbus_vcdaemon_call_vcm_daemon_method_result_selection(g_daemon_proxy, - pid, NULL, NULL, NULL); - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -3139,16 +2370,10 @@ int vc_mgr_dbus_send_result_selection(int pid) } return 0; -#endif } int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request) { -#ifdef USE_GDBUS - gdbus_vcdaemon_call_vcm_daemon_method_specific_engine_request(g_daemon_proxy, - pid, engine_app_id, event, request, NULL, NULL, NULL); - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -3189,17 +2414,10 @@ int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, dbus_message_unref(msg); return 0; -#endif } int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status) { -#ifdef USE_GDBUS - /* To Client */ - //gdbus_vcdaemon_call_vcm_daemon_method_utterance_status(g_daemon_proxy, - // utt_id, utt_status, NULL, NULL, NULL); - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -3232,21 +2450,10 @@ int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status) dbus_message_unref(msg); return 0; -#endif } int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) { -#ifdef USE_GDBUS - GVariant *variant = g_variant_new_from_data(G_VARIANT_TYPE ("ay"), - buffer, len, TRUE, NULL, NULL); - - gdbus_vcdaemon_call_vcm_daemon_method_send_audio_streaming(g_daemon_proxy, - pid, event, len, variant, NULL, NULL, NULL); - - g_variant_ref(variant); - return 0; -#else if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } @@ -3285,7 +2492,6 @@ int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, dbus_message_unref(msg); return 0; -#endif } int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_event) @@ -3293,33 +2499,6 @@ int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_ev if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - if (false == g_daemon_name_appeared) { - int ret = __dbus_restore_daemon(); - if (VC_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to restore daemon"); - return VC_ERROR_TIMED_OUT; - } - return VC_ERROR_OPERATION_FAILED; - } - - GError *error = NULL; - gint result; - if (!gdbus_vcdaemon_call_vcm_daemon_method_change_system_volume_sync(g_daemon_proxy, - pid, volume_event, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCM, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCM, "Failed without explicit error"); - } - } - return result; -#else - if (0 != __dbus_check()) { - return VC_ERROR_OPERATION_FAILED; - } DBusError err; dbus_error_init(&err); @@ -3397,6 +2576,5 @@ int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_ev } return result; -#endif } diff --git a/client/vc_setting_dbus.c b/client/vc_setting_dbus.c index a28d700..c249d40 100644 --- a/client/vc_setting_dbus.c +++ b/client/vc_setting_dbus.c @@ -17,15 +17,7 @@ #include "vc_setting_dbus.h" #include "vc_main.h" -#define USE_GDBUS -#ifdef USE_GDBUS -#include "vc_gdbus.h" - -static GDBusVcdaemon *g_daemon_proxy = NULL; -static int g_own_name_id = 0; - -#else static int g_s_waiting_time = 3000; static Ecore_Fd_Handler* g_s_fd_handler = NULL; @@ -33,9 +25,7 @@ static Ecore_Fd_Handler* g_s_fd_handler = NULL; static DBusConnection* g_s_conn_sender = NULL; static DBusConnection* g_s_conn_listener = NULL; -#endif -#ifndef USE_GDBUS static Eina_Bool listener_setting_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_s_conn_listener) return ECORE_CALLBACK_RENEW; @@ -122,52 +112,9 @@ static void __vc_setting_dbus_connection_free() g_s_conn_sender = NULL; } } -#endif - -#ifdef USE_GDBUS -static void -on_name_acquired(GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCS, "Name acquired : %s", name); - - GDBusVcsetting *service; - GError *error = NULL; - - service = gdbus_vcsetting_skeleton_new(); - - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), - connection, VC_SETTING_SERVICE_OBJECT_PATH, &error); - if (error) { - SLOG(LOG_DEBUG, TAG_VCS, "Error : %s\n", error->message); - g_error_free(error); - } -} - -#endif int vc_setting_dbus_open_connection() { -#ifdef USE_GDBUS - int pid = getpid(); - - char service_name[64]; - memset(service_name, '\0', 64); - snprintf(service_name, 64, "%s%d", VC_SETTING_SERVICE_NAME, pid); - g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, - service_name, 0, NULL, on_name_acquired, NULL, NULL, NULL); - SLOG(LOG_DEBUG, TAG_VCS, "service_name : %s, %d", service_name, g_own_name_id); - - GError *error = NULL; - g_daemon_proxy = gdbus_vcdaemon_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - VC_DAEMON_SERVICE_NAME, VC_DAEMON_SERVICE_OBJECT_PATH, NULL, &error); - if (error) { - SLOG(LOG_DEBUG, TAG_VCS, "Error : %s", error->message); - g_error_free(error); - } - return 0; -#else if (NULL != g_s_conn_sender && NULL != g_s_conn_listener) { SLOG(LOG_WARN, TAG_VCS, "already existed connection "); return 0; @@ -263,22 +210,10 @@ int vc_setting_dbus_open_connection() } return 0; -#endif } int vc_setting_dbus_close_connection() { -#ifdef USE_GDBUS - if (g_daemon_proxy) { - g_object_unref(g_daemon_proxy); - g_daemon_proxy = NULL; - } - if (g_own_name_id) { - g_bus_unown_name(g_own_name_id); - g_own_name_id = 0; - } - return 0; -#else DBusError err; dbus_error_init(&err); @@ -307,24 +242,10 @@ int vc_setting_dbus_close_connection() __vc_setting_dbus_connection_free(); return 0; -#endif } int vc_setting_dbus_reconnect() { -#ifdef USE_GDBUS - if (!g_own_name_id || !g_daemon_proxy) { - vc_setting_dbus_close_connection(); - - if (0 != vc_setting_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCS, "[ERROR] Fail to reconnect"); //LCOV_EXCL_LINE - return -1; - } - - SLOG(LOG_DEBUG, TAG_VCS, "[DBUS] Reconnect"); //LCOV_EXCL_LINE - } - return 0; -#else if (!g_s_conn_sender || !g_s_conn_listener) { vc_setting_dbus_close_connection(); @@ -354,25 +275,10 @@ int vc_setting_dbus_reconnect() } return 0; -#endif } int vc_setting_dbus_request_hello() { -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vc_method_hello_sync(g_daemon_proxy, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCS, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCS, "Failed without explicit error"); - } - } - return result; -#else if (NULL == g_s_conn_sender) { return VC_ERROR_OPERATION_FAILED; } @@ -412,26 +318,10 @@ int vc_setting_dbus_request_hello() } return result; -#endif } int vc_setting_dbus_request_set_language(int pid, const char* language) { -#ifdef USE_GDBUS - GError *error = NULL; - int result; - if (!gdbus_vcdaemon_call_vcs_daemon_method_set_language_sync(g_daemon_proxy, - pid, language, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCS, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCS, "Failed without explicit error"); - } - } - return result; -#else if (NULL == g_s_conn_sender) { SLOG(LOG_ERROR, TAG_VCS, "[ERROR] Dbus does not open"); return VC_ERROR_OPERATION_FAILED; @@ -491,5 +381,4 @@ int vc_setting_dbus_request_set_language(int pid, const char* language) } return result; -#endif } diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index 1108085..eddeb77 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -21,27 +21,18 @@ #include "vc_widget_client.h" #include "vc_widget_dbus.h" -#define USE_GDBUS -#ifdef USE_GDBUS -#include "vc_gdbus.h" - -static GDBusVcdaemon *g_daemon_proxy = NULL; -static int g_own_name_id = 0; -#else -static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t g_w_init_mutex = PTHREAD_MUTEX_INITIALIZER; static int g_w_waiting_time = 3000; static int g_w_waiting_short_time = 200; - static bool g_is_connection_opened = false; static Ecore_Fd_Handler* g_w_fd_handler = NULL; -static DBusConnection* g_w_conn_listener = NULL; static DBusConnection* g_w_conn_sender = NULL; -#endif +static DBusConnection* g_w_conn_listener = NULL; extern int __vc_widget_cb_error(int reason, int daemon_pid, char* msg); @@ -53,7 +44,7 @@ extern bool __vc_widget_cb_asr_result(int event, const char* asr_result); extern int __vc_widget_cb_service_state(int state); -#ifndef USE_GDBUS + static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_w_conn_listener) return ECORE_CALLBACK_RENEW; @@ -289,113 +280,9 @@ static void __vc_widget_dbus_connection_free() g_w_conn_sender = NULL; } } -#endif - -#ifdef USE_GDBUS - -gboolean vcd_widget_method_hello(GDBusVcwidget *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int response = -1; - - if (pid > 0) { - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get hello : pid(%d) ", pid); - response = 1; - } else { - SLOG(LOG_ERROR, TAG_VCW, "@@ vc widget get hello : invalid pid "); - } - - gdbus_vcwidget_complete_vcd_widget_method_hello(service, invocation, response); - return TRUE; -} - -gboolean vcd_widget_method_show_tooltip(GDBusVcwidget *service, GDBusMethodInvocation *invocation, - int pid, gboolean show, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget show tooltip : pid(%d), show(%d)", pid, show); - __vc_widget_cb_show_tooltip(pid, show); - - gdbus_vcwidget_complete_vcd_widget_method_show_tooltip(service, invocation); - return TRUE; -} - -gboolean vcd_widget_method_result(GDBusVcwidget *service, GDBusMethodInvocation *invocation, - int pid, gboolean show, gpointer user_data) -{ - __vc_widget_cb_result(); - - gdbus_vcwidget_complete_vcd_widget_method_result(service, invocation); - return TRUE; -} - - -gboolean vcd_widget_method_asr_result(GDBusVcwidget *service, GDBusMethodInvocation *invocation, - int event, const gchar* asr_result, gpointer user_data) -{ - int ret = 0; - - if (false == __vc_widget_cb_asr_result(event, asr_result)) - ret = 0; - else - ret = 1; - - SLOG(LOG_DEBUG, TAG_VCW, "@@ vc widget get asr result, event(%d), asr_result(%s), consumed(%d)", event, asr_result, ret); - gdbus_vcwidget_complete_vcd_widget_method_asr_result(service, invocation, ret); - return TRUE; -} - -static void -on_name_acquired(GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCW, "Name acquired : %s", name); - - GDBusVcwidget *service; - GError *error = NULL; - - service = gdbus_vcwidget_skeleton_new(); - - /* vc daemon methods */ - g_signal_connect(service, "handle-vcd-widget-method-hello", - G_CALLBACK(vcd_widget_method_hello), NULL); - g_signal_connect(service, "handle-vcd-widget-method-result", - G_CALLBACK(vcd_widget_method_result), NULL); - g_signal_connect(service, "handle-vcd-widget-method-asr-result", - G_CALLBACK(vcd_widget_method_asr_result), NULL); - g_signal_connect(service, "handle-vcd-widget-method-show-tooltip", - G_CALLBACK(vcd_widget_method_show_tooltip), NULL); - - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(service), - connection, VC_WIDGET_SERVICE_OBJECT_PATH, &error); - if (error) { - SLOG(LOG_DEBUG, TAG_VCW, "Error : %s\n", error->message); - g_error_free(error); - } -} -#endif int vc_widget_dbus_open_connection() { -#ifdef USE_GDBUS - int pid = getpid(); - - char service_name[64]; - memset(service_name, '\0', 64); - snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); - g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, - service_name, 0, NULL, on_name_acquired, NULL, NULL, NULL); - SLOG(LOG_DEBUG, TAG_VCW, "service_name : %s, %d", service_name, g_own_name_id); - - GError *error = NULL; - g_daemon_proxy = gdbus_vcdaemon_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - VC_DAEMON_SERVICE_NAME, VC_DAEMON_SERVICE_OBJECT_PATH, NULL, &error); - if (error) { - SLOG(LOG_DEBUG, TAG_VCW, "Error : %s", error->message); - g_error_free(error); - } - return 0; -#else pthread_mutex_lock(&g_w_dbus_mutex); if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) { @@ -511,31 +398,19 @@ int vc_widget_dbus_open_connection() SLOG(LOG_INFO, TAG_VCW, "[INFO] widget dbus connection is opened"); -return 0; -#endif + return 0; } int vc_widget_dbus_close_connection() { -#ifdef USE_GDBUS - if (g_daemon_proxy) { - g_object_unref(g_daemon_proxy); - g_daemon_proxy = NULL; - } - if (g_own_name_id) { - g_bus_unown_name(g_own_name_id); - g_own_name_id = 0; - } - return 0; -#else pthread_mutex_lock(&g_w_dbus_mutex); DBusError err; dbus_error_init(&err); if (NULL != g_w_fd_handler) { - ecore_main_fd_handler_del(g_w_fd_handler); - g_w_fd_handler = NULL; + ecore_main_fd_handler_del(g_w_fd_handler); + g_w_fd_handler = NULL; } if (NULL != g_w_conn_listener) { @@ -562,24 +437,10 @@ int vc_widget_dbus_close_connection() SLOG(LOG_INFO, TAG_VCW, "[INFO] widget dbus connection is closed"); return 0; -#endif } int vc_widget_dbus_reconnect() { -#ifdef USE_GDBUS - if (!g_own_name_id || !g_daemon_proxy) { - vc_widget_dbus_close_connection(); - - if (0 != vc_widget_dbus_open_connection()) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect"); //LCOV_EXCL_LINE - return -1; - } - - SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect"); //LCOV_EXCL_LINE - } - return 0; -#else if (!g_w_conn_sender || !g_w_conn_listener) { vc_widget_dbus_close_connection(); @@ -609,45 +470,15 @@ int vc_widget_dbus_reconnect() } return 0; -#endif } static int __dbus_check() { -#ifdef USE_GDBUS - SLOG(LOG_DEBUG, TAG_VCW, "%d %p", g_own_name_id, g_daemon_proxy); //LCOV_EXCL_LINE - if (0 == g_own_name_id || NULL == g_daemon_proxy) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); //LCOV_EXCL_LINE - return vc_widget_dbus_reconnect(); - } - return 0; -#else if (NULL == g_w_conn_sender || NULL == g_w_conn_listener) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); return vc_widget_dbus_reconnect(); } return 0; -#endif -} - -static GDBusVcmanager* get_manager_proxy() { - char service_name[64] = {0,}; - char object_path[64] = {0,}; - - snprintf(service_name, 64, "%s", VC_MANAGER_SERVICE_NAME); - snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH); - - GError *error = NULL; - GDBusVcmanager *proxy = gdbus_vcmanager_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - service_name, object_path, NULL, &error); - - if (error) { - SLOG(LOG_ERROR, TAG_VCC, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", - proxy, service_name, object_path, error->message); - g_error_free(error); - } - - return proxy; } int vc_widget_dbus_request_hello() @@ -655,20 +486,7 @@ int vc_widget_dbus_request_hello() if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result = 0; - if (!gdbus_vcdaemon_call_vc_method_hello_sync(g_daemon_proxy, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCW, "Failed without explicit error"); - } - } - return result; -#else + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -706,27 +524,11 @@ int vc_widget_dbus_request_hello() } return result; -#endif } int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid) { -#ifdef USE_GDBUS - GError *error = NULL; - int result; - if (!gdbus_vcdaemon_call_vcw_daemon_method_initialize_sync(g_daemon_proxy, - pid, &result, service_state, daemon_pid, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else pthread_mutex_lock(&g_w_init_mutex); if (0 != __dbus_check()) { pthread_mutex_unlock(&g_w_init_mutex); @@ -817,26 +619,10 @@ int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_p pthread_mutex_unlock(&g_w_init_mutex); return result; -#endif } int vc_widget_dbus_request_finalize(int pid) { -#ifdef USE_GDBUS - GError *error = NULL; - int result; - if (!gdbus_vcdaemon_call_vcw_daemon_method_finalize_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else pthread_mutex_lock(&g_w_init_mutex); if (0 != __dbus_check()) { pthread_mutex_unlock(&g_w_init_mutex); @@ -914,7 +700,6 @@ int vc_widget_dbus_request_finalize(int pid) pthread_mutex_unlock(&g_w_init_mutex); return result; -#endif } int vc_widget_dbus_request_start_recording(int pid, bool command) @@ -922,21 +707,7 @@ int vc_widget_dbus_request_start_recording(int pid, bool command) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result; - if (!gdbus_vcdaemon_call_vcw_daemon_method_start_recording_sync(g_daemon_proxy, - pid, command, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -995,7 +766,6 @@ int vc_widget_dbus_request_start_recording(int pid, bool command) } return result; -#endif } int vc_widget_dbus_set_foreground(int pid, bool value) @@ -1003,14 +773,7 @@ int vc_widget_dbus_set_foreground(int pid, bool value) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - /* To Manager */ - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcw_manager_method_set_foreground(proxy, - pid, value, NULL, NULL, NULL); - if (proxy) g_object_unref(proxy); - return 0; -#else + DBusMessage* msg = NULL; int tmp_value = 0; @@ -1073,7 +836,6 @@ int vc_widget_dbus_set_foreground(int pid, bool value) dbus_message_unref(msg); return 0; -#endif } int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) @@ -1081,21 +843,7 @@ int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result; - if (!gdbus_vcdaemon_call_vcw_daemon_method_start_recording_sync(g_daemon_proxy, - pid, enable, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else + DBusMessage* msg; /* create a signal & check for errors */ @@ -1160,7 +908,6 @@ int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) } return result; -#endif } int vc_widget_dbus_request_start(int pid, int silence) @@ -1168,21 +915,7 @@ int vc_widget_dbus_request_start(int pid, int silence) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result; - if (!gdbus_vcdaemon_call_vcw_daemon_method_start_sync(g_daemon_proxy, - pid, silence, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else + DBusMessage* msg; /* create a signal & check for errors */ @@ -1244,7 +977,6 @@ int vc_widget_dbus_request_start(int pid, int silence) } return result; -#endif } int vc_widget_dbus_request_stop(int pid) @@ -1252,21 +984,7 @@ int vc_widget_dbus_request_stop(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result; - if (!gdbus_vcdaemon_call_vcw_daemon_method_stop_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else + DBusMessage* msg; /* create a signal & check for errors */ @@ -1325,7 +1043,6 @@ int vc_widget_dbus_request_stop(int pid) } return result; -#endif } int vc_widget_dbus_request_cancel(int pid) @@ -1333,21 +1050,7 @@ int vc_widget_dbus_request_cancel(int pid) if (0 != __dbus_check()) { return VC_ERROR_OPERATION_FAILED; } -#ifdef USE_GDBUS - GError *error = NULL; - int result; - if (!gdbus_vcdaemon_call_vcw_daemon_method_cancel_sync(g_daemon_proxy, - pid, &result, NULL, &error)) { - if (error) { - SLOG(LOG_ERROR, TAG_VCW, "Error : %s", error->message); - result = VC_ERROR_OPERATION_FAILED; - g_error_free(error); - } else { - SLOG(LOG_ERROR, TAG_VCC, "Failed without explicit error"); - } - } - return result; -#else + DBusMessage* msg; /* create a signal & check for errors */ @@ -1406,5 +1109,4 @@ int vc_widget_dbus_request_cancel(int pid) } return result; -#endif } diff --git a/common/vc_defs.h b/common/vc_defs.h index b3db152..4011131 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -30,7 +30,7 @@ extern "C" { *******************************************************************************************/ #define VC_CLIENT_SERVICE_NAME "org.tizen.voice.vcclient" -#define VC_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/voice/vcclient" +#define VC_CLIENT_SERVICE_OBJECT_PATH "/org/tize/voice/vcclient" #define VC_CLIENT_SERVICE_INTERFACE "org.tizen.voice.vcclient" #define VC_WIDGET_SERVICE_NAME "org.tizen.voice.vcwidget" @@ -38,15 +38,15 @@ extern "C" { #define VC_WIDGET_SERVICE_INTERFACE "org.tizen.voice.vcwidget" #define VC_MANAGER_SERVICE_NAME "org.tizen.voice.vcmanager" -#define VC_MANAGER_SERVICE_OBJECT_PATH "/org/tizen/voice/vcmanager" +#define VC_MANAGER_SERVICE_OBJECT_PATH "/org/tize/voice/vcmanager" #define VC_MANAGER_SERVICE_INTERFACE "org.tizen.voice.vcmanager" -#define VC_DAEMON_SERVICE_NAME "org.tizen.voice.vcdaemon" -#define VC_DAEMON_SERVICE_OBJECT_PATH "/org/tizen/voice/vcdaemon" -#define VC_DAEMON_SERVICE_INTERFACE "org.tizen.voice.vcdaemon" +#define VC_SERVER_SERVICE_NAME "org.tizen.voice.vcserver" +#define VC_SERVER_SERVICE_OBJECT_PATH "/org/tizen/voice/vcserver" +#define VC_SERVER_SERVICE_INTERFACE "org.tizen.voice.vcserver" #define VC_SETTING_SERVICE_NAME "org.tizen.voice.vcsetting" -#define VC_SETTING_SERVICE_OBJECT_PATH "/org/tizen/voice/vcsetting" +#define VC_SETTING_SERVICE_OBJECT_PATH "/org/tize/voice/vcsetting" #define VC_SETTING_SERVICE_INTERFACE "org.tizen.voice.vcsetting" /****************************************************************************************** diff --git a/org.tizen.voice.vcdaemon.service b/org.tizen.voice.vcserver.service similarity index 87% rename from org.tizen.voice.vcdaemon.service rename to org.tizen.voice.vcserver.service index 4c73109..aa51fd1 100644 --- a/org.tizen.voice.vcdaemon.service +++ b/org.tizen.voice.vcserver.service @@ -1,5 +1,5 @@ [D-BUS Service] -Name=org.tizen.voice.vcdaemon +Name=org.tizen.voice.vcserver #Exec=/usr/bin/vc-daemon #Exec=/bin/sh -c "launch_app org.tizen.vc-engine-default" Exec=/bin/sh -c "vc_getengine get system db/voice/vc/engine/default | awk '{print$5}' | xargs -t -i launch_app {}" diff --git a/org.tizen.voice.vcdaemon.tv.service b/org.tizen.voice.vcserver.tv.service similarity index 75% rename from org.tizen.voice.vcdaemon.tv.service rename to org.tizen.voice.vcserver.tv.service index 33ae340..22b0781 100644 --- a/org.tizen.voice.vcdaemon.tv.service +++ b/org.tizen.voice.vcserver.tv.service @@ -1,4 +1,4 @@ [D-BUS Service] -Name=org.tizen.voice.vcdaemon +Name=org.tizen.voice.vcserver #Exec=/usr/bin/vc-daemon Exec=/bin/sh -c "launch_app org.tizen.voice-client" diff --git a/org.tizen.voice.voice-control.gdbus.xml b/org.tizen.voice.voice-control.gdbus.xml deleted file mode 100644 index b424ee6..0000000 --- a/org.tizen.voice.voice-control.gdbus.xml +++ /dev/null @@ -1,360 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index 8872f45..d7ceb5a 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -33,8 +33,6 @@ BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(pkgmgr-installer) -BuildRequires: pkgconfig(gio-2.0) -BuildRequires: pkgconfig(gio-unix-2.0) %if "%{tizen_profile_name}" == "tv" BuildRequires: pkgconfig(capi-network-bluetooth) BuildRequires: pkgconfig(capi-network-bluetooth-tv) @@ -133,7 +131,7 @@ find . -name '*.gcno' -exec cp '{}' gcov-obj ';' rm -rf %{buildroot} %if "%{tizen_profile_name}" == "tv" -mv -f org.tizen.voice.vcdaemon.tv.service org.tizen.voice.vcdaemon.service +mv -f org.tizen.voice.vcserver.tv.service org.tizen.voice.vcserver.service %endif %make_install @@ -164,7 +162,7 @@ mkdir -p %{_libdir}/voice/vc %{TZ_SYS_RO_SHARE}/dbus-1/services/org.tizen.voice* %{TZ_SYS_RO_SHARE}/parser-plugins/voice-control.info %{TZ_SYS_RO_ETC}/package-manager/parserlib/metadata/libvc-engine-parser.so* -/etc/dbus-1/session.d/vc-service.conf +/etc/dbus-1/session.d/vc-server.conf %files devel %manifest %{name}-devel.manifest diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 98a5c30..778f56d 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -6,7 +6,6 @@ SET(SRCS ../common/vc_config_parser.c ../common/vc_info_parser.c ../common/vc_json_parser.c - ../common/vc_gdbus.c vcd_client_data.c vcd_server_data.cpp vcd_config.c diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 853a26e..462f1a6 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -20,84 +20,17 @@ #include "vcd_dbus_server.h" #include "vcd_main.h" -#define USE_GDBUS -#ifdef USE_GDBUS -#include "vc_gdbus.h" -static GDBusVcdaemon *g_daemon = NULL; -static int g_own_name_id = 0; -#else -static Ecore_Fd_Handler* g_dbus_fd_handler = NULL; static DBusConnection* g_conn_sender = NULL; static DBusConnection* g_conn_listener = NULL; -static int g_waiting_time = 3000; +static Ecore_Fd_Handler* g_dbus_fd_handler = NULL; -#endif +static int g_waiting_time = 3000; static int g_volume_count = 0; -#ifdef USE_GDBUS -static GDBusVcmanager* get_manager_proxy() { - char service_name[64] = {0,}; - char object_path[64] = {0,}; - - snprintf(service_name, 64, "%s", VC_MANAGER_SERVICE_NAME); - snprintf(object_path, 64, "%s", VC_MANAGER_SERVICE_OBJECT_PATH); - - GError *error = NULL; - GDBusVcmanager *proxy = gdbus_vcmanager_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - service_name, object_path, NULL, &error); - - if (error) { - SLOG(LOG_ERROR, TAG_VCD, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", - proxy, service_name, object_path, error->message); - g_error_free(error); - } - - return proxy; -} - -static GDBusVcclient* get_client_proxy(int pid) { - char service_name[64] = {0,}; - char object_path[64] = {0,}; - - snprintf(service_name, 64, "%s%d", VC_CLIENT_SERVICE_NAME, pid); - snprintf(object_path, 64, "%s", VC_CLIENT_SERVICE_OBJECT_PATH); - - GError *error = NULL; - GDBusVcclient *proxy = gdbus_vcclient_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - service_name, object_path, NULL, &error); - - if (error) { - SLOG(LOG_ERROR, TAG_VCD, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", - proxy, service_name, object_path, error->message); - g_error_free(error); - } - - return proxy; -} - -static GDBusVcwidget* get_widget_proxy(int pid) { - char service_name[64] = {0,}; - char object_path[64] = {0,}; - - snprintf(service_name, 64, "%s%d", VC_WIDGET_SERVICE_NAME, pid); - snprintf(object_path, 64, "%s", VC_WIDGET_SERVICE_OBJECT_PATH); - - GError *error = NULL; - GDBusVcwidget *proxy = gdbus_vcwidget_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, 0, - service_name, object_path, NULL, &error); - - if (error) { - SLOG(LOG_ERROR, TAG_VCD, "[DBUS] Proxy : %p, service_name(%s), object_path(%s) : %s", - proxy, service_name, object_path, error->message); - g_error_free(error); - } - return proxy; -} -#else static DBusMessage* __get_message(int pid, const char* method, vcd_client_type_e type) { char service_name[64] = {0,}; @@ -225,17 +158,9 @@ int vcdc_send_hello(int pid, vcd_client_type_e type) return result; } -#endif int vcdc_send_show_tooltip(int pid, bool show) { -#ifdef USE_GDBUS - GDBusVcwidget* proxy = get_widget_proxy(pid); - gdbus_vcwidget_call_vcd_widget_method_show_tooltip(proxy, - pid, show, NULL, NULL, NULL); - g_object_unref(proxy); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -289,25 +214,10 @@ int vcdc_send_show_tooltip(int pid, bool show) dbus_message_unref(msg); return 0; -#endif } int vcdc_send_set_volume(int manger_pid, float volume) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_set_volume(proxy, - volume, NULL, NULL, NULL); - g_object_unref(proxy); - - if (10 == g_volume_count) { - SLOG(LOG_DEBUG, TAG_VCD, "@@ Send set volume : pid(%d), volume(%f)", manger_pid, volume); - g_volume_count = 0; - } - g_volume_count++; - - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -346,49 +256,10 @@ int vcdc_send_set_volume(int manger_pid, float volume) dbus_message_unref(msg); return 0; -#endif } int vcdc_send_result(int pid, int manager_pid, int cmd_type) { -#ifdef USE_GDBUS - SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Result command type(%d)", cmd_type); - - switch (cmd_type) { - case VC_COMMAND_TYPE_FOREGROUND: - case VC_COMMAND_TYPE_BACKGROUND: - if (pid == manager_pid) { - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_result(proxy, NULL, NULL, NULL); - g_object_unref(proxy); - } else { - GDBusVcclient* proxy = get_client_proxy(pid); - gdbus_vcclient_call_vcd_client_method_result(proxy, NULL, NULL, NULL); - g_object_unref(proxy); - } - break; - case VC_COMMAND_TYPE_WIDGET: { - GDBusVcwidget* proxy = get_widget_proxy(pid); - gdbus_vcwidget_call_vcd_widget_method_result(proxy, NULL, NULL, NULL); - g_object_unref(proxy); - } - break; - case VC_COMMAND_TYPE_SYSTEM: - case VC_COMMAND_TYPE_SYSTEM_BACKGROUND: - case VC_COMMAND_TYPE_EXCLUSIVE: { - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_result(proxy, NULL, NULL, NULL); - g_object_unref(proxy); - } - break; - - default: - SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); - return -1; - } - - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -438,24 +309,10 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) dbus_message_unref(msg); return 0; -#endif } int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_type, bool* is_consumed) { -#ifdef USE_GDBUS - GError *error = NULL; - gint result = 0; - GDBusVcwidget* proxy = get_widget_proxy(pid); - gdbus_vcwidget_call_vcd_widget_method_asr_result_sync(proxy, - event, asr_result, &result, NULL, &error); - if (error) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Dbus Error (%s)", error->message); - g_error_free(error); - } - g_object_unref(proxy); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -513,18 +370,10 @@ int vcdc_send_asr_result(int pid, int event, const char* asr_result, int cmd_typ SLOG(LOG_ERROR, TAG_VCD, "@@ Result message is NULL "); return VCD_ERROR_OPERATION_FAILED; } -#endif } int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_pre_result(proxy, - event, pre_result, NULL, NULL, NULL); - g_object_unref(proxy); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -554,18 +403,10 @@ int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_ } return 0; -#endif } int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* engine_app_id, const char* event, const char* result) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_specific_engine_result(proxy, - engine_app_id, event, result, NULL, NULL, NULL); - g_object_unref(proxy); - return 0; -#else SLOG(LOG_DEBUG, TAG_VCD, "[VCDC] send specific engine result to manager, mgr pid(%d), engine app id(%s), event(%s), result(%s),", manager_pid, engine_app_id, event, result); @@ -598,19 +439,10 @@ int vcdc_send_specific_engine_result_to_manager(int manager_pid, const char* eng } return 0; -#endif } int vcdc_send_result_to_manager(int manger_pid, int result_type) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] send result : result type(%d)", result_type); - gdbus_vcmanager_call_vcd_manager_method_all_result(proxy, - result_type, NULL, NULL, NULL); - g_object_unref(proxy); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -644,18 +476,10 @@ int vcdc_send_result_to_manager(int manger_pid, int result_type) dbus_message_unref(msg); return 0; -#endif } int vcdc_send_speech_detected(int manger_pid) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_speech_detected(proxy, - NULL, NULL, NULL); - g_object_unref(proxy); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -686,15 +510,10 @@ int vcdc_send_speech_detected(int manger_pid) dbus_message_unref(msg); return 0; -#endif } int vcdc_send_service_state(vcd_state_e state) { -#ifdef USE_GDBUS - gdbus_vcdaemon_emit_vcd_signal_set_service_state(g_daemon, state); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -776,14 +595,10 @@ int vcdc_send_service_state(vcd_state_e state) dbus_message_unref(msg); return 0; -#endif } int vcdc_send_manager_pid(int manager_pid) { -#ifdef USE_GDBUS - gdbus_vcdaemon_emit_vcd_client_signal_send_manager_pid(g_daemon, manager_pid); -#else DBusError err; dbus_error_init(&err); @@ -811,19 +626,12 @@ int vcdc_send_manager_pid(int manager_pid) } dbus_message_unref(msg); -#endif + return 0; } int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* utt_text, int continuous) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_dialog(proxy, - pid, disp_text, utt_text, continuous, NULL, NULL, NULL); - g_object_unref(proxy); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -885,16 +693,10 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* } return ret; -#endif } int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg) { -#ifdef USE_GDBUS - int daemon_pid = getpid(); - gdbus_vcdaemon_emit_vcd_manager_signal_send_error(g_daemon, reason, daemon_pid, err_msg); - return 0; -#else SLOG(LOG_ERROR, TAG_VCD, "@@ Send error signal to manager"); if (0 != __dbus_check()) { @@ -947,18 +749,10 @@ int vcdc_send_error_signal_to_manager(int manager_pid, int reason, char *err_msg } return 0; -#endif } int vcdc_send_error_signal(int reason, char *err_msg) { -#ifdef USE_GDBUS - int daemon_pid = getpid(); - gdbus_vcdaemon_emit_vcd_client_signal_send_error(g_daemon, reason, daemon_pid, err_msg); - gdbus_vcdaemon_emit_vcd_manager_signal_send_error(g_daemon, reason, daemon_pid, err_msg); - gdbus_vcdaemon_emit_vcd_widget_signal_send_error(g_daemon, reason, daemon_pid, err_msg); - return 0; -#else SLOG(LOG_ERROR, TAG_VCD, "@@ Send error signal"); if (NULL == err_msg) { @@ -1046,18 +840,10 @@ int vcdc_send_error_signal(int reason, char *err_msg) dbus_message_unref(msg); return 0; -#endif } int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_set_private_data(proxy, - pid, key, data, NULL, NULL, NULL); - g_object_unref(proxy); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -1089,28 +875,10 @@ int vcdc_send_request_set_private_data(int pid, const char* key, const char* dat dbus_message_unref(msg); return VCD_ERROR_NONE; -#endif } int vcdc_send_request_get_private_data(int pid, const char* key, char** data) { -#ifdef USE_GDBUS - GError *error = NULL; - gint result = 0; - gchar* value = NULL; - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_get_private_data_sync(proxy, - pid, key, &result, &value, NULL, &error); - if (error) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Dbus Error (%s)", error->message); - g_error_free(error); - } - if (NULL != data && NULL != value) { - *data = strdup(value); - } - g_object_unref(proxy); - return 0; -#else if (0 != __dbus_check()) { return VCD_ERROR_OPERATION_FAILED; } @@ -1168,18 +936,10 @@ int vcdc_send_request_get_private_data(int pid, const char* key, char** data) } return result; -#endif } int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_audio_channel_e channel, vce_audio_type_e audio_type) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - gdbus_vcmanager_call_vcd_manager_method_feedback_audio_format(proxy, - rate, channel, audio_type, NULL, NULL, NULL); - g_object_unref(proxy); - return 0; -#else SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback audio format : manager_pid(%d), rate(%d), audio channel(%d), audio type(%d)", manager_pid, rate, channel, audio_type); if (0 != __dbus_check()) { @@ -1218,23 +978,10 @@ int vcdc_send_feedback_audio_format_to_manager(int manager_pid, int rate, vc_aud dbus_message_unref(msg); return ret; -#endif } int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) { -#ifdef USE_GDBUS - GDBusVcmanager* proxy = get_manager_proxy(); - GVariant *variant = g_variant_new_from_data(G_VARIANT_TYPE ("ay"), - buffer, len, TRUE, NULL, NULL); - - gdbus_vcmanager_call_vcd_manager_method_feedback_streaming(proxy, - pid, utt_id, event, len, variant, NULL, NULL, NULL); - - g_object_unref(proxy); - g_variant_ref(variant); - return 0; -#else SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : manager_pid(%d), pid(%d), utt_id(%d) feedback event(%d), buffer(%p), length(%d)", manager_pid, pid, utt_id, event, buffer, len); if (0 != __dbus_check()) { @@ -1275,23 +1022,10 @@ int vcdc_send_feedback_streaming_to_manager(int manager_pid, int pid, int utt_id dbus_message_unref(msg); return ret; -#endif } int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len) { -#ifdef USE_GDBUS - GDBusVcclient* proxy = get_client_proxy(pid); - GVariant *variant = g_variant_new_from_data(G_VARIANT_TYPE ("ay"), - buffer, len, TRUE, NULL, NULL); - - gdbus_vcclient_call_vcd_client_method_feedback_streaming(proxy, - utt_id, event, len, variant, NULL, NULL, NULL); - - g_object_unref(proxy); - g_variant_ref(variant); - return 0; -#else SLOG(LOG_INFO, TAG_VCD, "[Dbus] Send TTS feedback streaming : pid(%d), utt_id(%d), feedback event(%d), buffer(%p), length(%d)", pid, utt_id, event, buffer, len); if (0 != __dbus_check()) { @@ -1331,10 +1065,8 @@ int vcdc_send_feedback_streaming(int pid, int utt_id, vc_feedback_event_e event, dbus_message_unref(msg); return ret; -#endif } -#ifndef USE_GDBUS static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW; @@ -1529,129 +1261,9 @@ static void __vcd_dbus_connection_free() g_conn_sender = NULL; } } -#endif - -#ifdef USE_GDBUS -static void -on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "Name acquired : %s", name); - - GError *error = NULL; - - g_daemon = gdbus_vcdaemon_skeleton_new(); - - /* vc common methods */ - g_signal_connect(g_daemon, "handle-vc-method-hello", - G_CALLBACK(vc_method_hello), NULL); - - /* vc client methods */ - g_signal_connect(g_daemon, "handle-vcc-daemon-method-initialize", - G_CALLBACK(vcc_daemon_method_initialize), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-finalize", - G_CALLBACK(vcc_daemon_method_finalize), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-set-exclusive-cmd", - G_CALLBACK(vcc_daemon_method_set_exclusive_cmd), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-set-command", - G_CALLBACK(vcc_daemon_method_set_command), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-unset-command", - G_CALLBACK(vcc_daemon_method_unset_command), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-set-foreground", - G_CALLBACK(vcc_daemon_method_set_foreground), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-set-server-dialog", - G_CALLBACK(vcc_daemon_method_set_server_dialog), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-dialog", - G_CALLBACK(vcc_daemon_method_dialog), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-is-system-command-valid", - G_CALLBACK(vcc_daemon_method_is_system_command_valid), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-request-tts", - G_CALLBACK(vcc_daemon_method_request_tts), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-cancel-tts", - G_CALLBACK(vcc_daemon_method_cancel_tts), NULL); - g_signal_connect(g_daemon, "handle-vcc-daemon-method-get-tts-audio-format", - G_CALLBACK(vcc_daemon_method_get_tts_audio_format), NULL); - - /* vc widget methods */ - g_signal_connect(g_daemon, "handle-vcw-daemon-method-initialize", - G_CALLBACK(vcw_daemon_method_initialize), NULL); - g_signal_connect(g_daemon, "handle-vcw-daemon-method-finalize", - G_CALLBACK(vcw_daemon_method_finalize), NULL); - g_signal_connect(g_daemon, "handle-vcw-daemon-method-start-recording", - G_CALLBACK(vcw_daemon_method_start_recording), NULL); - g_signal_connect(g_daemon, "handle-vcw-daemon-method-enable-asr-result", - G_CALLBACK(vcw_daemon_method_enable_asr_result), NULL); - g_signal_connect(g_daemon, "handle-vcw-daemon-method-start", - G_CALLBACK(vcw_daemon_method_start), NULL); - g_signal_connect(g_daemon, "handle-vcw-daemon-method-stop", - G_CALLBACK(vcw_daemon_method_stop), NULL); - g_signal_connect(g_daemon, "handle-vcw-daemon-method-cancel", - G_CALLBACK(vcw_daemon_method_cancel), NULL); - - /* vc manager methods */ - g_signal_connect(g_daemon, "handle-vcm-daemon-method-initialize", - G_CALLBACK(vcm_daemon_method_initialize), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-finalize", - G_CALLBACK(vcm_daemon_method_finalize), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-command", - G_CALLBACK(vcm_daemon_method_set_command), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-unset-command", - G_CALLBACK(vcm_daemon_method_unset_command), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-demandable-client", - G_CALLBACK(vcm_daemon_method_set_demandable_client), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-audio-type", - G_CALLBACK(vcm_daemon_method_set_audio_type), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-get-audio-type", - G_CALLBACK(vcm_daemon_method_get_audio_type), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-client-info", - G_CALLBACK(vcm_daemon_method_set_client_info), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-private-data", - G_CALLBACK(vcm_daemon_method_set_private_data), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-get-private-data", - G_CALLBACK(vcm_daemon_method_get_private_data), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-enable-command-type", - G_CALLBACK(vcm_daemon_method_enable_command_type), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-disable-command-type", - G_CALLBACK(vcm_daemon_method_disable_command_type), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-request-start", - G_CALLBACK(vcm_daemon_method_request_start), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-request-stop", - G_CALLBACK(vcm_daemon_method_request_stop), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-request-cancel", - G_CALLBACK(vcm_daemon_method_request_cancel), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-result-selection", - G_CALLBACK(vcm_daemon_method_result_selection), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-set-domain", - G_CALLBACK(vcm_daemon_method_set_domain), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-do-action", - G_CALLBACK(vcm_daemon_method_do_action), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-specific-engine-request", - G_CALLBACK(vcm_daemon_method_specific_engine_request), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-send-audio-streaming", - G_CALLBACK(vcm_daemon_method_send_audio_streaming), NULL); - g_signal_connect(g_daemon, "handle-vcm-daemon-method-change-system-volume", - G_CALLBACK(vcm_daemon_method_change_system_volume), NULL); - - /* vc setting methods */ - g_signal_connect(g_daemon, "handle-vcs-daemon-method-set-language", - G_CALLBACK(vcs_daemon_method_set_language), NULL); - - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(g_daemon), - connection, VC_DAEMON_SERVICE_OBJECT_PATH, &error); - - if (error) { - SLOG(LOG_ERROR, TAG_VCD, "Exporting interface error : %s", error->message); - g_error_free(error); - } -} -#endif int vcd_dbus_open_connection() { -#ifdef USE_GDBUS - g_own_name_id = g_bus_own_name(G_BUS_TYPE_SESSION, - VC_DAEMON_SERVICE_NAME, G_BUS_NAME_OWNER_FLAGS_REPLACE, NULL, on_name_acquired, NULL, NULL, NULL); - SLOG(LOG_DEBUG, TAG_VCD, "g_bus_own_name returned %d", g_own_name_id); -#else DBusError err; dbus_error_init(&err); @@ -1744,22 +1356,12 @@ int vcd_dbus_open_connection() } SLOG(LOG_INFO, TAG_VCD, "[INFO] Success to open dbus connection"); -#endif + return 0; } int vcd_dbus_close_connection() { -#ifdef USE_GDBUS - if (g_daemon) { - g_object_unref(g_daemon); - g_daemon = NULL; - } - if (g_own_name_id) { - g_bus_unown_name(g_own_name_id); - g_own_name_id = 0; - } -#else DBusError err; dbus_error_init(&err); @@ -1776,7 +1378,6 @@ int vcd_dbus_close_connection() } __vcd_dbus_connection_free(); -#endif return 0; } diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index f880201..b1affc8 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -22,705 +22,6 @@ #include "vcd_server.h" #include "vcd_config.h" -#define USE_GDBUS - -#ifdef USE_GDBUS -gboolean vc_method_hello(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[ENTER]"); - gdbus_vcdaemon_complete_vc_method_hello(service, invocation); - return TRUE; -} - -gboolean vcc_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_initialize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize"); - } - - int service_state = vcd_server_get_service_state(); - int daemon_pid = getpid(); - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd initialize : pid(%d) daemon_pid(%d)", pid, daemon_pid); - - int mgr_pid = vcd_client_manager_get_pid(); - - if (0 == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); - } else { - SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); - } - - gdbus_vcdaemon_complete_vcc_daemon_method_initialize(service, invocation, - ret, mgr_pid, service_state, daemon_pid); - - return TRUE; -} - -gboolean vcc_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_mgr_finalize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd finalize : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcc_daemon_method_finalize(service, invocation, ret); - - return TRUE; -} - -gboolean vcc_daemon_method_set_exclusive_cmd(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean value, gpointer user_data) -{ - /* - int ret = vcd_server_set_exclusive_command(pid, value); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_exclusive_cmd"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_exclusive_cmd : pid(%d), exclusive(%d)", pid, value); - - gdbus_vcdaemon_complete_vcc_daemon_method_set_exclusive_cmd(service, invocation, ret); - */ - return TRUE; -} - -gboolean vcc_daemon_method_set_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int cmd_type, gpointer user_data) -{ - int ret = vcd_server_set_command(pid, (vc_cmd_type_e)cmd_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_command"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_command : pid(%d), cmd_type(%d)", pid, cmd_type); - - gdbus_vcdaemon_complete_vcc_daemon_method_set_command(service, invocation, ret); - - return TRUE; -} - -gboolean vcc_daemon_method_unset_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int cmd_type, gpointer user_data) -{ - int ret = vcd_server_unset_command(pid, (vc_cmd_type_e)cmd_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to unset_command"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd unset_command : pid(%d), cmd_type(%d)", pid, cmd_type); - - gdbus_vcdaemon_complete_vcc_daemon_method_unset_command(service, invocation, ret); - - return TRUE; -} - -gboolean vcc_daemon_method_set_foreground(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean value, gpointer user_data) -{ - int ret = vcd_server_set_foreground(pid, value); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_foreground"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_foreground : pid(%d), value(%d)", pid, value); - - gdbus_vcdaemon_complete_vcc_daemon_method_set_foreground(service, invocation); - - return TRUE; -} - -gboolean vcc_daemon_method_set_server_dialog(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* app_id, const gchar* credential, gpointer user_data) -{ - int ret = vcd_server_set_server_dialog(pid, app_id, credential); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_server_dialog"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_server_dialog : pid(%d), app_id(%s)", pid, app_id); - - gdbus_vcdaemon_complete_vcc_daemon_method_set_server_dialog(service, invocation, ret); - - return TRUE; -} - -gboolean vcc_daemon_method_dialog(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* disp_text, const gchar* utt_text, gboolean continuous, gpointer user_data) -{ - int ret = vcd_server_dialog(pid, disp_text, utt_text, continuous); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to dialog"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd dialog : pid(%d), disp_text(%s), utt_text(%s)", pid, disp_text, utt_text); - - gdbus_vcdaemon_complete_vcc_daemon_method_dialog(service, invocation); - - return TRUE; -} - -gboolean vcc_daemon_method_is_system_command_valid(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int is_sys_cmd_valid; - int ret = vcd_server_is_system_command_valid(pid, &is_sys_cmd_valid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to is_system_command_valid"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd is_system_command_valid : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcc_daemon_method_is_system_command_valid(service, invocation, - ret, is_sys_cmd_valid); - - return TRUE; -} - -gboolean vcc_daemon_method_request_tts(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* text, const gchar* language, gboolean to_vcm, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd request tts : pid(%d), text(%s), language(%s), to_vcm(%d)", - pid, text, language, to_vcm); - - int utt_id = -1; - int ret = vcd_server_request_tts(pid, text, language, to_vcm, &utt_id); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to request_tts"); - } - - gdbus_vcdaemon_complete_vcc_daemon_method_request_tts(service, invocation, ret, utt_id); - - return TRUE; -} - -gboolean vcc_daemon_method_cancel_tts(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int utt_id, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd cancel tts : pid(%d), utt_id(%d)", pid, utt_id); - - int ret = vcd_server_cancel_tts(pid, utt_id); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to cancel_tts"); - } - - gdbus_vcdaemon_complete_vcc_daemon_method_cancel_tts(service, invocation, ret); - - return TRUE; -} - -gboolean vcc_daemon_method_get_tts_audio_format(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd get tts audio format : pid(%d)", pid); - - int rate; - int channel; - int audio_type; - int ret = vcd_server_get_tts_audio_format(pid, &rate, &channel, &audio_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get_tts_audio_format"); - } - - gdbus_vcdaemon_complete_vcc_daemon_method_get_tts_audio_format(service, invocation, - ret, rate, channel, audio_type); - - return TRUE; -} - -gboolean vcw_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_widget_initialize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to widget_initialize"); - } - int service_state = vcd_server_get_service_state(); - int daemon_pid = getpid(); - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget initialize : pid(%d) daemon_pid(%d)", pid, daemon_pid); - - gdbus_vcdaemon_complete_vcw_daemon_method_initialize(service, invocation, - ret, service_state, daemon_pid); - - return TRUE; -} - -gboolean vcw_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget finalize : pid(%d)", pid); - - int ret = vcd_server_widget_finalize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to widget_finalize"); - } - - gdbus_vcdaemon_complete_vcw_daemon_method_finalize(service, invocation, ret); - - return TRUE; -} - -gboolean vcw_daemon_method_start_recording(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int widget_command, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget start recording : pid(%d)", pid); - - int ret = vcd_server_widget_start_recording(pid, widget_command); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start_recording"); - } - - gdbus_vcdaemon_complete_vcw_daemon_method_start_recording(service, invocation, ret); - - return TRUE; -} - -gboolean vcw_daemon_method_enable_asr_result(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean enable, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget enable asr result : pid(%d) enable(%d)", pid, enable); - - int ret = vcd_server_widget_enable_asr_result(pid, enable); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to enable_asr_result"); - } - - gdbus_vcdaemon_complete_vcw_daemon_method_enable_asr_result(service, invocation, ret); - - return TRUE; -} - -gboolean vcw_daemon_method_start(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean silence, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget start : pid(%d), silence(%d)", pid, silence); - - int ret = vcd_server_widget_start(pid, silence); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start"); - } - - gdbus_vcdaemon_complete_vcw_daemon_method_start(service, invocation, ret); - - return TRUE; -} - -gboolean vcw_daemon_method_stop(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget stop : pid(%d)", pid); - - int ret = vcd_server_widget_stop(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop"); - } - - gdbus_vcdaemon_complete_vcw_daemon_method_stop(service, invocation, ret); - - return TRUE; -} - -gboolean vcw_daemon_method_cancel(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget cancel : pid(%d)", pid); - - int ret = vcd_server_widget_cancel(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to cancel"); - } - - gdbus_vcdaemon_complete_vcw_daemon_method_cancel(service, invocation, ret); - - return TRUE; -} - -gboolean vcw_daemon_method_set_foreground(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean value, gpointer user_data) -{ - int ret = vcd_server_set_foreground(pid, value); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_foreground"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd set_foreground : pid(%d), value(%d)", pid, value); - - gdbus_vcdaemon_complete_vcw_daemon_method_set_foreground(service, invocation); - - return TRUE; -} - -gboolean vcm_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int streaming_mode, gpointer user_data) -{ - vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)streaming_mode); - int ret = vcd_server_mgr_initialize(pid); - int service_state = vcd_server_get_service_state(); - int foreground = vcd_server_get_foreground(); - int daemon_pid = getpid(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to initialize"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr initialize : pid(%d) service state(%d) foreground(%d) daemon_pid(%d)", pid, service_state, foreground, daemon_pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_initialize(service, invocation, - ret, service_state, foreground, daemon_pid); - - return TRUE; -} - -gboolean vcm_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_mgr_finalize(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to finalize"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr finalize : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_finalize(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_set_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_mgr_set_command(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_command"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set command : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_set_command(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_unset_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_mgr_unset_command(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to unset_command"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr unset command : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_unset_command(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_set_demandable_client(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_mgr_set_demandable_client(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_demandable_client"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set demandable client : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_set_demandable_client(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_set_audio_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* audio_type, gpointer user_data) -{ - int ret = vcd_server_mgr_set_audio_type(pid, audio_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_audio_type"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set audio type : pid(%d), audio type(%s)", pid, audio_type); - - gdbus_vcdaemon_complete_vcm_daemon_method_set_audio_type(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_get_audio_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - char* audio_type = NULL; - int ret = vcd_server_mgr_get_audio_type(pid, &audio_type); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_audio_type"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr get audio type : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_get_audio_type(service, invocation, ret, audio_type); - if (audio_type) { - free (audio_type); - audio_type = NULL; - } - return TRUE; -} - -gboolean vcm_daemon_method_set_client_info(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_mgr_set_client_info(pid); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_client_info"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set client info : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_set_client_info(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_set_private_data(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* key, const gchar* data, gpointer user_data) -{ - int ret = vcd_server_mgr_set_private_data(pid, key, data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_private_data"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), key(%s), data(%s)", pid, key, data); - - gdbus_vcdaemon_complete_vcm_daemon_method_set_private_data(service, invocation); - - return TRUE; -} - -gboolean vcm_daemon_method_get_private_data(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* key, gpointer user_data) -{ - char* data = NULL; - int ret = vcd_server_mgr_get_private_data(pid, key, &data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to get_private_data"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr get private data : pid(%d), key(%s)", pid, key); - - gdbus_vcdaemon_complete_vcm_daemon_method_get_private_data(service, invocation, ret, data); - - return TRUE; -} - -gboolean vcm_daemon_method_enable_command_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int cmd_type, gpointer user_data) -{ - int ret = vcd_server_mgr_enable_command_type(pid, cmd_type); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to enable_command_type"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr enable command type : pid(%d), cmd_type(%d)", pid, cmd_type); - - gdbus_vcdaemon_complete_vcm_daemon_method_enable_command_type(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_disable_command_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int cmd_type, gpointer user_data) -{ - int ret = vcd_server_mgr_disable_command_type(pid, cmd_type); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to disable_command_type"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr disable command type : pid(%d), cmd_type(%d)", pid, cmd_type); - - gdbus_vcdaemon_complete_vcm_daemon_method_disable_command_type(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_request_start(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int recognition_mode, gboolean exclusive, gboolean start_by_client, gpointer user_data) -{ - int ret = vcd_server_mgr_start((vcd_recognition_mode_e)recognition_mode, exclusive, start_by_client); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to request_start"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr start : pid(%d) recognition_mode(%d) exclusive(%d) start by client(%d)", pid, recognition_mode, exclusive, start_by_client); - - gdbus_vcdaemon_complete_vcm_daemon_method_request_start(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_request_stop(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_mgr_stop(); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to request_stop"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr stop : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_request_stop(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_request_cancel(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - int ret = vcd_server_mgr_cancel(); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to request_cancel"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr cancel : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_request_cancel(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_result_selection(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data) -{ - vcd_server_mgr_result_select(); - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr result selection : pid(%d)", pid); - - gdbus_vcdaemon_complete_vcm_daemon_method_result_selection(service, invocation); - - return TRUE; -} - -gboolean vcm_daemon_method_set_domain(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* domain, gpointer user_data) -{ - int ret = vcd_server_mgr_set_domain(pid, domain); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to disable_command_type"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr set domain : pid(%d), domain(%s)", pid, domain); - - gdbus_vcdaemon_complete_vcm_daemon_method_set_domain(service, invocation, ret); - - return TRUE; -} - -gboolean vcm_daemon_method_do_action(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int type, const gchar* send_event, gpointer user_data) -{ - int ret = vcd_server_mgr_do_action(pid, type, send_event); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to disable_command_type"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr request to do action : pid(%d), type(%d) send_event(%s)", pid, type, send_event); - - gdbus_vcdaemon_complete_vcm_daemon_method_do_action(service, invocation); - - return TRUE; -} - -gboolean vcm_daemon_method_specific_engine_request(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* engine_app_id, const gchar* event, const gchar* request, gpointer user_data) -{ - int ret = vcd_server_mgr_send_specific_engine_request(pid, engine_app_id, event, request); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to specific_engine_request"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr specific engine request : pid(%d), engine_app_id(%s), event(%s), request(%s), ret(%d)", pid, engine_app_id, event, request, ret); - - gdbus_vcdaemon_complete_vcm_daemon_method_specific_engine_request(service, invocation); - - return TRUE; -} - -gboolean vcm_daemon_method_send_audio_streaming(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int event, GVariant *buffer, gpointer user_data) -{ - int len = 0; - GVariantIter *iter; - guchar uc; - const int MAX_STREAMING_DATA_SIZE = 4096; - unsigned char data[MAX_STREAMING_DATA_SIZE]; - - gdbus_vcdaemon_complete_vcm_daemon_method_send_audio_streaming(service, invocation); - - g_variant_get(buffer, "ay", &iter); - while (g_variant_iter_loop(iter, "y", &uc)) { - if (len < MAX_STREAMING_DATA_SIZE) { - data[len++] = uc; - } else { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] max size reached : %d", len); - } - } - g_variant_iter_free(iter); - - int ret = vcd_server_mgr_send_audio_streaming(pid, event, data, len); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send_audio_streaming"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, data, len); - - return TRUE; -} - -gboolean vcm_daemon_method_change_system_volume(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int volume_event, gpointer user_data) -{ - int ret = vcd_server_mgr_change_system_volume(pid, volume_event); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to change_system_volume"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr change system volume: pid(%d), volume_event(%d)", pid, volume_event); - - gdbus_vcdaemon_complete_vcm_daemon_method_change_system_volume(service, invocation, ret); - - return TRUE; -} - -gboolean vcs_daemon_method_set_language(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* language, gpointer user_data) -{ - int ret = vcd_server_set_language(language); - - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set_language"); - } - - SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd server set language : language(%s)", language); - - gdbus_vcdaemon_complete_vcs_daemon_method_set_language(service, invocation, ret); - - return TRUE; -} -#else int __dbus_error_return(DBusConnection* conn, DBusMessage* msg, int ret) { DBusMessage* reply; @@ -3074,4 +2375,3 @@ int vcd_dbus_server_get_tts_audio_format(DBusConnection* conn, DBusMessage* msg) return 0; } -#endif diff --git a/server/vcd_dbus_server.h b/server/vcd_dbus_server.h index bebf860..6182697 100644 --- a/server/vcd_dbus_server.h +++ b/server/vcd_dbus_server.h @@ -25,159 +25,6 @@ extern "C" { #endif -#define USE_GDBUS - -#ifdef USE_GDBUS -#include "vc_gdbus.h" - -/* -* Dbus Common Server functions -*/ -gboolean vc_method_hello(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - gpointer user_data); - -/* -* Dbus Server functions for client -*/ -gboolean vcc_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcc_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcc_daemon_method_set_exclusive_cmd(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean value, gpointer user_data); - -gboolean vcc_daemon_method_set_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int cmd_type, gpointer user_data); - -gboolean vcc_daemon_method_unset_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int cmd_type, gpointer user_data); - -gboolean vcc_daemon_method_set_foreground(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean value, gpointer user_data); - -gboolean vcc_daemon_method_set_server_dialog(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* app_id, const gchar* credential, gpointer user_data); - -gboolean vcc_daemon_method_dialog(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* disp_text, const gchar* utt_text, gboolean continuous, gpointer user_data); - -gboolean vcc_daemon_method_is_system_command_valid(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcc_daemon_method_request_tts(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* text, const gchar* language, gboolean to_vcm, gpointer user_data); - -gboolean vcc_daemon_method_cancel_tts(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int utt_id, gpointer user_data); - -gboolean vcc_daemon_method_get_tts_audio_format(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -/* -* Dbus Server functions for widget -*/ - -gboolean vcw_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcw_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcw_daemon_method_start_recording(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int widget_command, gpointer user_data); - -gboolean vcw_daemon_method_enable_asr_result(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean enable, gpointer user_data); - -gboolean vcw_daemon_method_start(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean silence, gpointer user_data); - -gboolean vcw_daemon_method_stop(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcw_daemon_method_cancel(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcw_daemon_method_set_foreground(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gboolean value, gpointer user_data); - -/* -* Dbus Server functions for manager -*/ - -gboolean vcm_daemon_method_initialize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int streaming_mode, gpointer user_data); - -gboolean vcm_daemon_method_finalize(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_set_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_unset_command(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_set_demandable_client(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_set_audio_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* audio_type, gpointer user_data); - -gboolean vcm_daemon_method_get_audio_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_set_client_info(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_set_private_data(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* key, const gchar* data, gpointer user_data); - -gboolean vcm_daemon_method_get_private_data(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* key, gpointer user_data); - -gboolean vcm_daemon_method_enable_command_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int cmd_type, gpointer user_data); - -gboolean vcm_daemon_method_disable_command_type(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int cmd_type, gpointer user_data); - -gboolean vcm_daemon_method_request_start(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int recognition_mode, gboolean exclusive, gboolean start_by_client, gpointer user_data); - -gboolean vcm_daemon_method_request_stop(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_request_cancel(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_result_selection(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, gpointer user_data); - -gboolean vcm_daemon_method_set_domain(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* domain, gpointer user_data); - -gboolean vcm_daemon_method_do_action(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int type, const gchar* send_event, gpointer user_data); - -gboolean vcm_daemon_method_specific_engine_request(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* engine_app_id, const gchar* event, const gchar* request, gpointer user_data); - -gboolean vcm_daemon_method_send_audio_streaming(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int event, GVariant *buffer, gpointer user_data); - -gboolean vcm_daemon_method_change_system_volume(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, int volume_event, gpointer user_data); - -/* -* Dbus Server functions for setting -*/ - -gboolean vcs_daemon_method_set_language(GDBusVcdaemon *service, GDBusMethodInvocation *invocation, - int pid, const gchar* language, gpointer user_data); - -#else int vcd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg); /* @@ -290,7 +137,6 @@ int vcd_dbus_server_cancel_tts(DBusConnection* conn, DBusMessage* msg); int vcd_dbus_server_get_tts_audio_format(DBusConnection* conn, DBusMessage* msg); -#endif #ifdef __cplusplus } diff --git a/server/vce.c b/server/vce.c index 1cd3c2b..7a9bf97 100644 --- a/server/vce.c +++ b/server/vce.c @@ -150,10 +150,6 @@ int vce_main(int argc, char** argv, vce_request_callback_s *callback) SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_init()"); return VCE_ERROR_OPERATION_FAILED; } - if (!ecore_main_loop_glib_integrate()) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail ecore_main_loop_glib_integrate()"); - return VCE_ERROR_OPERATION_FAILED; - } // if (0 != vcd_dbus_open_connection()) { // SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open connection"); diff --git a/vc-service.conf b/vc-server.conf similarity index 85% rename from vc-service.conf rename to vc-server.conf index e7d601f..60a1d1b 100644 --- a/vc-service.conf +++ b/vc-server.conf @@ -13,7 +13,7 @@ - - + + -- 2.7.4 From 3908260b6fc3158aee6454fa4063a7b31a04dd49 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Wed, 2 Oct 2019 19:11:12 +0900 Subject: [PATCH 11/16] Remove to send RC command for BT Change-Id: I53bce76dd01afe23624d6b44c8979f6a0de37561 --- server/vcd_recorder.c | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index b42e920..27aed69 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -1025,32 +1025,9 @@ int vcd_recorder_start() if (NULL != g_current_audio_type) { if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { #ifdef TV_BT_MODE - if (BT_ERROR_NONE != bt_hid_set_audio_data_receive_cb(_bt_hid_audio_data_receive_cb, NULL)) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_set_audio_data_receive_cb()"); - } - - const unsigned char input_data[2] = {SMART_CONTROL_START_CMD, 0x00}; - int bt_retry = 0; - while (5 > bt_retry) { - ret = bt_hid_send_rc_command(NULL, input_data, sizeof(input_data)); - if (BT_ERROR_NONE == ret) { - SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Start bt audio recorder"); - started = true; - break; - } else if (BT_ERROR_NOW_IN_PROGRESS == ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_send_rc_command : %d", ret); - usleep(50000); - bt_retry++; - } else { - break; - } - } - if (false == started) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start bt audio"); - return VCD_ERROR_OPERATION_FAILED; - } - + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Start bt audio"); g_bt_extend_count = 0; + started = true; #endif } else if (0 == strncmp(VCE_AUDIO_ID_FFV, g_current_audio_type, strlen(VCE_AUDIO_ID_FFV))) { SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] call farfield_voice_register_audio_cb() function"); -- 2.7.4 From 72150c78df84572c37a28717c392146e48a869c9 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Wed, 2 Oct 2019 19:26:03 +0900 Subject: [PATCH 12/16] Change 'NULL' char to 'NNUULLLL' Change-Id: I74deaa1ce2777f6fe0b8e2d4b70b9d36fd35a192 --- client/vc_mgr_dbus.c | 4 ++-- server/vcd_dbus.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index aa20c13..caf56e9 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -263,9 +263,9 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd DBUS_TYPE_INT32, &tmp_continue, DBUS_TYPE_INVALID); - if (!strcmp(disp_text, "#NULL")) + if (!strcmp(disp_text, "NNUULLLL")) disp_text = NULL; - if (!strcmp(utt_text, "#NULL")) + if (!strcmp(utt_text, "NNUULLLL")) utt_text = NULL; __vc_mgr_cb_dialog(pid, disp_text, utt_text, (bool)tmp_continue); diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 462f1a6..758ecf8 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -654,12 +654,12 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* char* utt_null = NULL; int ret = VCD_ERROR_NONE; if (NULL == disp_text) { - disp_null = strdup("#NULL"); + disp_null = strdup("NNUULLLL"); disp_text = disp_null; } if (NULL == utt_text) { - utt_null = strdup("#NULL"); + utt_null = strdup("NNUULLLL"); utt_text = utt_null; } -- 2.7.4 From bbb8e044595d9d2f63ba6d00692d2664d67093a6 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Mon, 7 Oct 2019 13:22:09 +0900 Subject: [PATCH 13/16] Revert to remove callback Change-Id: I50478228c4b64ca1f1a3d3c2f912b6a5e9cd1794 --- server/vcd_recorder.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 27aed69..11343fb 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -1025,6 +1025,9 @@ int vcd_recorder_start() if (NULL != g_current_audio_type) { if (0 == strncmp(VCE_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCE_AUDIO_ID_BLUETOOTH))) { #ifdef TV_BT_MODE + if (BT_ERROR_NONE != bt_hid_set_audio_data_receive_cb(_bt_hid_audio_data_receive_cb, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_set_audio_data_receive_cb()"); + } SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Start bt audio"); g_bt_extend_count = 0; started = true; -- 2.7.4 From 200420c91e4b97f50aa869b945f6d9b72205a153 Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Tue, 15 Oct 2019 14:32:42 +0900 Subject: [PATCH 14/16] Fixed privlevel partner for doxygen Change-Id: I6328e620c7283f2f5f3c5a419f4947e0f1d953bb Signed-off-by: sungrae jo --- include/voice_control.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/include/voice_control.h b/include/voice_control.h index c37d991..5e28d19 100644 --- a/include/voice_control.h +++ b/include/voice_control.h @@ -608,6 +608,7 @@ int vc_unset_error_cb(void); /** + * @partner * @brief Requests to send TTS streaming data, asynchronously. * @details Using this function, the developer can request text to speech to the framework. * When the developer requests the TTS with @a language, VC engine will send PCM data which is synthesized using VC engine's own persona. @@ -616,7 +617,7 @@ int vc_unset_error_cb(void); * and then it will be spoken in VC manager. If @a to_vc_manager is false, you will receive PCM data through the vc_tts_streaming_cb() callback function if it was set using vc_tts_set_streaming_cb(). * This function is executed asynchronously, so if there is an error while synthesizing, vc_error_cb() will be called. * @since_tizen 5.5 - * @privlevel @partner + * @privlevel partner * @privilege %http://tizen.org/privilege/voicecontrol.tts * @param[in] text The text to be requested for TTS * @param[in] language The language is specified as an ISO 3166 alpha-2 two-letter country code @@ -640,9 +641,10 @@ int vc_tts_request(const char* text, const char* language, bool to_vc_manager, i /** + * @partner * @brief Requests to cancel TTS streaming data. * @since_tizen 5.5 - * @privlevel @partner + * @privlevel partner * @privilege %http://tizen.org/privilege/voicecontrol.tts * @param[in] utt_id The utterance id * @return @c 0 on success, @@ -659,10 +661,11 @@ int vc_tts_cancel(int utt_id); /** + * @partner * @brief Gets the TTS audio details. * @details Using this function, the developer can get details of synthesized audio data which is requested by vc_tts_request() function. * @since_tizen 5.5 - * @privlevel @partner + * @privlevel partner * @privilege %http://tizen.org/privilege/voicecontrol.tts * @param[out] rate The audio sampling rate * @param[out] channel The audio channel @@ -680,9 +683,10 @@ int vc_tts_get_synthesized_audio_details(int* rate, vc_audio_channel_e* channel, /** + * @partner * @brief Sets the TTS streaming callback function. * @since_tizen 5.5 - * @privlevel @partner + * @privlevel partner * @privilege %http://tizen.org/privilege/voicecontrol.tts * @param[in] callback The callback function * @param[in] user_data The user data to be passed to the callback function @@ -699,9 +703,10 @@ int vc_tts_set_streaming_cb(vc_tts_streaming_cb callback, void* user_data); /** + * @partner * @brief Unsets the TTS streaming callback function. * @since_tizen 5.5 - * @privlevel @partner + * @privlevel partner * @privilege %http://tizen.org/privilege/voicecontrol.tts * @return @c 0 on success, * otherwise a negative error value @@ -715,12 +720,13 @@ int vc_tts_unset_streaming_cb(void); /** + * @partner * @brief Sets the TTS utterance status callback function. * @details Using this function, the developer can set the utterance status callback to be called * when the VC manager client starts or stops playing TTS PCM data which was requested to be synthesized with the vc_tts_request() function. - * This function is called when @a to_vc_manager in the vc_tts_request() function call is true. + * This function is called when @a to_vc_manager in the vc_tts_request() function call is @c true. * @since_tizen 5.5 - * @privlevel @partner + * @privlevel partner * @privilege %http://tizen.org/privilege/voicecontrol.tts * @param[in] callback The callback function * @param[in] user_data The user data to be passed to the callback function @@ -738,9 +744,10 @@ int vc_tts_set_utterance_status_cb(vc_tts_utterance_status_cb callback, void* us /** + * @partner * @brief Unsets the TTS utterance status callback function. * @since_tizen 5.5 - * @privlevel @partner + * @privlevel partner * @privilege %http://tizen.org/privilege/voicecontrol.tts * @return @c 0 on success, * otherwise a negative error value -- 2.7.4 From 46a76434f6f1f5f1c7c21fb5bccd0577348613cd Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Wed, 6 Nov 2019 18:17:25 +0900 Subject: [PATCH 15/16] Added valid check about command handle code. Change-Id: Ic8259dd16160ee460bbec6f03f22e97c6085423d Signed-off-by: sungrae jo --- client/vc.c | 6 ++- client/vc_mgr.c | 18 +++++--- client/vc_widget.c | 1 + common/vc_cmd_db.c | 55 +++++++++++++++++++++++-- common/vc_command.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++---- server/vcd_server.c | 18 ++++++++ 6 files changed, 196 insertions(+), 17 deletions(-) diff --git a/client/vc.c b/client/vc.c index f63e842..ebd15ba 100644 --- a/client/vc.c +++ b/client/vc.c @@ -1763,9 +1763,12 @@ static Eina_Bool __vc_notify_result(void *data) SLOG(LOG_INFO, TAG_VCC, "Client result callback called"); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; /* Release result */ - if (NULL != temp_text) free(temp_text); + if (temp_text) + free(temp_text); + temp_text = NULL; return EINA_FALSE; } @@ -1832,6 +1835,7 @@ int vc_get_result(vc_result_cb callback, void* user_data) vc_client_not_use_callback(g_vc); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; /* Release result */ if (NULL != temp_text) { diff --git a/client/vc_mgr.c b/client/vc_mgr.c index cee3254..921f04f 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -2529,7 +2529,7 @@ static void __vc_mgr_notify_all_result(vc_result_type_e result_type) vc_cmd_print_list(vc_cmd_list); - bool cb_ret; + bool cb_ret = false; vc_mgr_client_set_all_result(g_vc_m, event, temp_text); @@ -2564,7 +2564,9 @@ static void __vc_mgr_notify_all_result(vc_result_type_e result_type) } /* Release list */ - vc_cmd_list_destroy(vc_cmd_list, true); + if (vc_cmd_list) + vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; vc_mgr_client_set_exclusive_command(g_vc_m, false); @@ -2601,7 +2603,9 @@ static void __vc_mgr_notify_all_result(vc_result_type_e result_type) } /* Release list */ - vc_cmd_list_destroy(vc_cmd_list, true); + if (vc_cmd_list) + vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; return; } @@ -2637,10 +2641,14 @@ static Eina_Bool __vc_mgr_notify_result(void *data) vc_mgr_client_not_use_callback(g_vc_m); SLOG(LOG_INFO, TAG_VCM, "Result callback called"); - vc_cmd_list_destroy(vc_cmd_list, true); + if (vc_cmd_list) + vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; /* Release result */ - if (NULL != temp_text) free(temp_text); + if (temp_text) + free(temp_text); + temp_text = NULL; return EINA_FALSE; } diff --git a/client/vc_widget.c b/client/vc_widget.c index 950f7fc..89faa97 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -1412,6 +1412,7 @@ static Eina_Bool __vc_widget_notify_result(void *data) if (NULL != temp_text) free(temp_text); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; return EINA_FALSE; } diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index f3889d5..9fdb4ec 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -1028,6 +1028,7 @@ static int __vc_db_get_result(sqlite3* db_handle, char** result_text, int* event SLOG(LOG_DEBUG, vc_db_tag(), "Fail to add command to list"); vc_cmd_destroy(temp_cmd); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; if (NULL != *result_text) { free(*result_text); *result_text = NULL; @@ -1345,6 +1346,7 @@ static int __vc_db_append_commands(sqlite3* db_handle, int pid, int type, vc_cmd SLOG(LOG_DEBUG, vc_db_tag(), "Fail to add command to list"); vc_cmd_destroy(temp_cmd); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; sqlite3_reset(stmt); sqlite3_clear_bindings(stmt); sqlite3_finalize(stmt); @@ -1416,6 +1418,51 @@ static vc_cmd_s* __vc_db_command_copy(vc_cmd_s* src_cmd) return temp_cmd; } +static int __vc_db_command_destroy(vc_cmd_h vc_command) +{ + if (NULL == vc_command) { + SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + + vc_cmd_s* command = NULL; + command = (vc_cmd_s*)vc_command; + + SLOG(LOG_DEBUG, vc_db_tag(), "[Destroy command][%p]", command); + + if (NULL != command) { + if (NULL != command->command) { + free(command->command); + command->command = NULL; + } + if (NULL != command->parameter) { + free(command->parameter); + command->parameter = NULL; + } + if (NULL != command->invocation_name) { + free(command->invocation_name); + command->invocation_name = NULL; + } + if (NULL != command->appid) { + free(command->appid); + command->appid = NULL; + } + if (NULL != command->fixed) { + free(command->fixed); + command->fixed = NULL; + } + if (NULL != command->coordinates) { + free(command->coordinates); + command->coordinates = NULL; + } + free(command); + command = NULL; + } + + return VC_ERROR_NONE; +} + + static int __vc_db_create_table(sqlite3* db_handle, const char* table) { SLOG(LOG_INFO, vc_db_tag(), "[INFO] Create DB table (%s)", table); @@ -2114,7 +2161,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to generate command, %d", ret); if (NULL != tmp_cmd) { - vc_cmd_destroy((vc_cmd_h)tmp_cmd); + __vc_db_command_destory((vc_cmd_h)tmp_cmd); } return ret; } @@ -2144,7 +2191,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ free(fixed_cmd); fixed_cmd = NULL; } - vc_cmd_destroy((vc_cmd_h)tmp_cmd); + __vc_db_command_destory((vc_cmd_h)tmp_cmd); break; } @@ -2162,7 +2209,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ free(fixed_cmd); fixed_cmd = NULL; } - vc_cmd_destroy((vc_cmd_h)tmp_cmd); + __vc_db_command_destory((vc_cmd_h)tmp_cmd); break; } } @@ -2198,7 +2245,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ free(fixed_cmd); fixed_cmd = NULL; } - vc_cmd_destroy((vc_cmd_h)tmp_cmd); + __vc_db_command_destory((vc_cmd_h)tmp_cmd); return VC_DB_ERROR_NONE; } diff --git a/common/vc_command.c b/common/vc_command.c index 08f5c9f..d1ca79b 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -37,6 +37,7 @@ static int g_feature_enabled = -1; static int g_privilege_allowed = 1; /* Always True */ static cynara *p_cynara = NULL; +static GList *g_cmd_list = NULL; static GList *g_cmdlist_list = NULL; @@ -154,6 +155,74 @@ static int __vc_cmd_check_privilege() return VC_ERROR_NONE; } +static bool __vc_cmd_is_valid(vc_cmd_h vc_command) +{ + if (NULL == g_cmd_list) { + SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] cmd_list is not valid"); + return false; + } + + if (g_list_length(g_cmd_list) == 0) { + SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] cmd_list is not valid"); + return false; + } + + bool flag = false; + vc_cmd_s *command = NULL; + command = (vc_cmd_s *)vc_command; + + GList *iter = NULL; + iter = g_list_first(g_cmd_list); + while (NULL != iter) { + vc_cmd_s *data = NULL; + data = iter->data; + if (NULL != data && command == data) { + flag = true; + break; + } + iter = g_list_next(iter); + } + + if (false == flag) + SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] command(%p) is not valid", command); + + return flag; +} + +static bool __vc_cmd_list_is_valid(vc_cmd_list_h vc_cmd_list) +{ + if (NULL == g_cmdlist_list) { + SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] cmdlist_list is not valid"); + return false; + } + + if (g_list_length(g_cmdlist_list) == 0) { + SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] cmdlist_list is not valid"); + return false; + } + + bool flag = false; + vc_cmd_list_s *list = NULL; + list = (vc_cmd_list_s *)vc_cmd_list; + + GList *iter = NULL; + iter = g_list_first(g_cmdlist_list); + while (NULL != iter) { + vc_cmd_list_s *data = NULL; + data = iter->data; + if (NULL != data && list == data) { + flag = true; + break; + } + iter = g_list_next(iter); + } + + if (false == flag) + SLOG(LOG_WARN, TAG_VCCMD, "[WARNING] list(%p) is not valid", list); + + return flag; +} + int vc_cmd_list_create(vc_cmd_list_h* vc_cmd_list) { if (0 != __vc_cmd_get_feature_enabled()) { @@ -201,6 +270,11 @@ int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command) return VC_ERROR_INVALID_PARAMETER; } + if (false == __vc_cmd_list_is_valid(vc_cmd_list)) { + SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + vc_cmd_list_remove_all(vc_cmd_list, release_command); vc_cmd_list_s* list = NULL; @@ -218,7 +292,7 @@ int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command) while (NULL != iter) { data = iter->data; - if (data && list == data) { + if (NULL != data && list == data) { g_cmdlist_list = g_list_remove_link(g_cmdlist_list, iter); free(data); @@ -226,6 +300,7 @@ int vc_cmd_list_destroy(vc_cmd_list_h vc_cmd_list, bool release_command) SLOG(LOG_DEBUG, TAG_VCCMD, "Client destroy"); g_list_free(iter); + iter = NULL; return VC_ERROR_NONE; } @@ -373,12 +448,8 @@ int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command) , list, release_command ? "true" : "false"); int count = g_slist_length(list->list); - - int i ; - vc_cmd_s *temp_cmd; - - for (i = 0; i < count ; i++) { - temp_cmd = g_slist_nth_data(list->list, 0); + for (int i = 0; i < count ; i++) { + vc_cmd_s *temp_cmd = g_slist_nth_data(list->list, 0); if (NULL != temp_cmd) { list->list = g_slist_remove(list->list, temp_cmd); @@ -733,6 +804,8 @@ int vc_cmd_create(vc_cmd_h* vc_command) *vc_command = (vc_cmd_h)command; + g_cmd_list = g_list_append(g_cmd_list, command); + SLOG(LOG_DEBUG, TAG_VCCMD, "[Create command][%p]", *vc_command); return VC_ERROR_NONE; @@ -752,11 +825,39 @@ int vc_cmd_destroy(vc_cmd_h vc_command) return VC_ERROR_INVALID_PARAMETER; } + if (false == __vc_cmd_is_valid(vc_command)) { + SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + vc_cmd_s* command = NULL; command = (vc_cmd_s*)vc_command; SLOG(LOG_DEBUG, TAG_VCCMD, "[Destroy command][%p]", command); + bool flag = false; + GList *iter = NULL; + iter = g_list_first(g_cmd_list); + while (NULL != iter) { + vc_cmd_s *data = NULL; + data = iter->data; + if (NULL != data && command == data) { + g_cmd_list = g_list_remove_link(g_cmd_list, iter); + flag = true; + break; + } + iter = g_list_next(iter); + } + + if (false == flag) { + SLOG(LOG_ERROR, TAG_VCCMD, "Fail to destroy client : handle is not valid"); + return VC_ERROR_INVALID_PARAMETER; + } + + if (iter) + g_list_free(iter); + iter = NULL; + if (NULL != command) { if (NULL != command->command) { free(command->command); diff --git a/server/vcd_server.c b/server/vcd_server.c index c4425d0..8f8c608 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -526,6 +526,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c if (!filtered_id) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to allocate memory"); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; return VCD_ERROR_OUT_OF_MEMORY; } int filtered_count = 0; @@ -593,6 +594,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c vcd_config_set_service_state(VCD_STATE_READY); vcdc_send_service_state(VCD_STATE_READY); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; if (NULL != filtered_id) { free(filtered_id); filtered_id = NULL; @@ -691,6 +693,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c if (0 != vc_cmd_list_create(&widget_cmd_list)) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle"); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; return VCD_ERROR_OUT_OF_MEMORY; } @@ -709,7 +712,9 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c if (0 != vc_cmd_list_create(&foreground_cmd_list)) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle"); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; vc_cmd_list_destroy(widget_cmd_list, true); + widget_cmd_list = NULL; return VCD_ERROR_OUT_OF_MEMORY; } @@ -726,8 +731,10 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c } } vc_cmd_list_destroy(foreground_cmd_list, true); + foreground_cmd_list = NULL; } vc_cmd_list_destroy(widget_cmd_list, true); + widget_cmd_list = NULL; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL"); } @@ -757,6 +764,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c vcd_client_manager_set_exclusive(false); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; return VCD_ERROR_NONE; } @@ -778,13 +786,16 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c if (0 != vc_cmd_list_create(&temp_list)) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle"); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; return VCD_ERROR_OUT_OF_MEMORY; } if (0 != vc_cmd_list_create(&widget_cmd_list)) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create widget command list handle"); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; vc_cmd_list_destroy(temp_list, true); + temp_list = NULL; return VCD_ERROR_OUT_OF_MEMORY; } @@ -808,7 +819,9 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c if (0 != vc_cmd_list_create(&foreground_cmd_list)) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to create foreground command list handle"); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; vc_cmd_list_destroy(widget_cmd_list, true); + widget_cmd_list = NULL; return VCD_ERROR_OUT_OF_MEMORY; } @@ -830,8 +843,10 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c } } vc_cmd_list_destroy(foreground_cmd_list, true); + foreground_cmd_list = NULL; } vc_cmd_list_destroy(widget_cmd_list, true); + widget_cmd_list = NULL; } int pid = vcd_client_widget_get_foreground_pid(); @@ -842,6 +857,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, false); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; if (-1 != vcd_client_manager_get_pid()) { /* Manager client is available */ @@ -856,6 +872,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c /* exclusive command */ vc_info_parser_set_result(all_result, event, msg, vc_cmd_list, true); vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; if (-1 != vcd_client_manager_get_pid()) { /* Manager client is available */ @@ -1047,6 +1064,7 @@ int vcd_send_result(vce_result_event_e event, int* result_id, int count, const c } vc_cmd_list_destroy(vc_cmd_list, true); + vc_cmd_list = NULL; return; #endif -- 2.7.4 From 63c3fc7a19bcea0110722efc953b34fe1084fff3 Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Fri, 8 Nov 2019 15:18:48 +0900 Subject: [PATCH 16/16] Fixed typos Change-Id: I52b57ab51959eafd2c711058389778b8716dbf4c Signed-off-by: sungrae jo --- common/vc_cmd_db.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 9fdb4ec..ad72839 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -2161,7 +2161,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to generate command, %d", ret); if (NULL != tmp_cmd) { - __vc_db_command_destory((vc_cmd_h)tmp_cmd); + __vc_db_command_destroy((vc_cmd_h)tmp_cmd); } return ret; } @@ -2191,7 +2191,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ free(fixed_cmd); fixed_cmd = NULL; } - __vc_db_command_destory((vc_cmd_h)tmp_cmd); + __vc_db_command_destroy((vc_cmd_h)tmp_cmd); break; } @@ -2209,7 +2209,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ free(fixed_cmd); fixed_cmd = NULL; } - __vc_db_command_destory((vc_cmd_h)tmp_cmd); + __vc_db_command_destroy((vc_cmd_h)tmp_cmd); break; } } @@ -2245,7 +2245,7 @@ static int __vc_db_insert_command(sqlite3* db_handle, int pid, vc_cmd_type_e typ free(fixed_cmd); fixed_cmd = NULL; } - __vc_db_command_destory((vc_cmd_h)tmp_cmd); + __vc_db_command_destroy((vc_cmd_h)tmp_cmd); return VC_DB_ERROR_NONE; } -- 2.7.4