From 874b9d08c169fcc47d0c13f401fa6c63f360a9d0 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Fri, 23 Dec 2016 17:26:33 +0900 Subject: [PATCH 01/16] Change deprecated api(readdir_r -> readdir) Change-Id: I2ddffe4758041c8af9dbac2c5f1119cb1a14782e Signed-off-by: Suyeon Hwang --- common/vc_config_mgr.c | 10 ++-------- server/vcd_engine_agent.c | 8 +------- server/vcd_server.c | 16 ++-------------- 3 files changed, 5 insertions(+), 29 deletions(-) mode change 100644 => 100755 common/vc_config_mgr.c mode change 100644 => 100755 server/vcd_engine_agent.c mode change 100644 => 100755 server/vcd_server.c diff --git a/common/vc_config_mgr.c b/common/vc_config_mgr.c old mode 100644 new mode 100755 index 822f81d..961a3b6 --- a/common/vc_config_mgr.c +++ b/common/vc_config_mgr.c @@ -535,9 +535,7 @@ int vc_config_mgr_initialize(int uid) /* Get file name from default engine directory */ DIR *dp = NULL; - int ret = -1; - struct dirent entry; - struct dirent *dirp = NULL; + struct dirent *dirp; g_engine_list = NULL; @@ -561,11 +559,7 @@ int vc_config_mgr_initialize(int uid) dp = opendir(VC_DEFAULT_ENGINE_INFO); if (NULL != dp) { do { - ret = readdir_r(dp, &entry, &dirp); - if (0 != ret) { - SLOG(LOG_ERROR, vc_config_tag(), "[File ERROR] Fail to read directory"); - break; - } + dirp = readdir(dp); if (NULL != dirp) { if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name)) diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c old mode 100644 new mode 100755 index 12f5754..3d9ec29 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -414,18 +414,12 @@ int __internal_update_engine_list() /* Get file name from default engine directory */ DIR *dp = NULL; - int ret = -1; - struct dirent entry; struct dirent *dirp = NULL; dp = opendir(VC_DEFAULT_ENGINE); if (NULL != dp) { do { - ret = readdir_r(dp, &entry, &dirp); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[File ERROR] Fail to read directory"); - break; - } + dirp = readdir(dp); if (NULL != dirp) { if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name)) diff --git a/server/vcd_server.c b/server/vcd_server.c old mode 100644 new mode 100755 index 7787e21..bdef2f0 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -865,8 +865,6 @@ static void __vcd_file_clean_up() SLOG(LOG_DEBUG, TAG_VCD, "== Old file clean up == "); DIR *dp = NULL; - int ret = -1; - struct dirent entry; struct dirent *dirp = NULL; dp = opendir(VC_RUNTIME_INFO_ROOT); @@ -877,11 +875,7 @@ static void __vcd_file_clean_up() char remove_path[256] = {0, }; do { - ret = readdir_r(dp, &entry, &dirp); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[File ERROR] Fail to read directory"); - break; - } + dirp = readdir(dp); if (NULL != dirp) { if (!strncmp("vc_", dirp->d_name, strlen("vc_"))) { @@ -1033,9 +1027,7 @@ static Eina_Bool __finalize_quit_ecore_loop(void *data) static void __read_proc() { DIR *dp = NULL; - struct dirent entry; struct dirent *dirp = NULL; - int ret = -1; int tmp; GList *iter = NULL; @@ -1052,11 +1044,7 @@ static void __read_proc() SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to open proc"); } else { do { - ret = readdir_r(dp, &entry, &dirp); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to readdir"); - break; - } + dirp = readdir(dp); if (NULL != dirp) { tmp = atoi(dirp->d_name); -- 2.7.4 From 6558d63c58523b4d16c3b2c3e72481301c1774a5 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Thu, 22 Dec 2016 00:10:12 -0800 Subject: [PATCH 02/16] Add internal method for asr result This reverts commit a54acbf16b441a041280630fc32295d8a4355fae. Change-Id: Ia836be7836a0f228577fea2dd66ed3ea16d342df (cherry picked from commit f1a57c169d24867fced57deeef6f33f885db658f) --- client/vc_widget.c | 127 +++++++++++++++++++++++++++++++++++++++ client/vc_widget_client.c | 32 ++++++++++ client/vc_widget_client.h | 5 ++ client/vc_widget_dbus.c | 96 +++++++++++++++++++++++++++++ client/vc_widget_dbus.h | 1 + common/vc_defs.h | 3 + include/voice_control_internal.h | 17 +++++- include/voice_control_widget.h | 52 ++++++++++++++++ packaging/voice-control.spec | 1 + server/vcd_client_data.c | 28 +++++++++ server/vcd_client_data.h | 4 ++ server/vcd_dbus.c | 62 +++++++++++++++++++ server/vcd_dbus.h | 2 + server/vcd_dbus_server.c | 48 +++++++++++++++ server/vcd_dbus_server.h | 1 + server/vcd_server.c | 46 ++++++++++++-- server/vcd_server.h | 1 + 17 files changed, 520 insertions(+), 6 deletions(-) mode change 100755 => 100644 include/voice_control_widget.h diff --git a/client/vc_widget.c b/client/vc_widget.c index ff34a07..6212288 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -25,6 +25,7 @@ #include "vc_widget_dbus.h" #include "voice_control_command.h" #include "voice_control_command_expand.h" +#include "voice_control_internal.h" #include "voice_control_widget.h" @@ -384,6 +385,53 @@ int vc_widget_unprepare() return VC_ERROR_NONE; } +int vc_widget_enable_asr_result(bool enable) +{ + SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Enable asr result"); + + vc_state_e state; + if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_VCW, "====="); + SLOG(LOG_DEBUG, TAG_VCW, " "); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != VC_STATE_READY) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'READY'"); + SLOG(LOG_DEBUG, TAG_VCW, "====="); + SLOG(LOG_DEBUG, TAG_VCW, " "); + return VC_ERROR_INVALID_STATE; + } + + int count = 0; + int ret = -1; + + do { + ret = vc_widget_dbus_request_enable_asr_result(g_vc_w->handle, enable); + if (0 != ret) { + if (VC_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to enable asr result : %s", __vc_widget_get_error_code(ret)); + break; + } else { + SLOG(LOG_WARN, TAG_VCW, "[WARNING] retry to enable asr result : %s", __vc_widget_get_error_code(ret)); + usleep(10000); + count++; + if (VC_RETRY_COUNT == count) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request"); + break; + } + } + } + } while (0 != ret); + + SLOG(LOG_DEBUG, TAG_VCW, "====="); + SLOG(LOG_DEBUG, TAG_VCW, " "); + + return ret; +} + int vc_widget_foreach_supported_languages(vc_supported_language_cb callback, void* user_data) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Foreach Supported Language"); @@ -1042,6 +1090,44 @@ void __vc_widget_cb_result() return; } +bool __vc_widget_cb_asr_result() +{ + char* temp_text; + int event; + vc_cmd_list_h vc_cmd_list = NULL; + + vc_asr_result_cb callback = NULL; + void* user_data = NULL; + + vc_widget_client_get_asr_result_cb(g_vc_w, &callback, &user_data); + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Client result callback is NULL"); + return EINA_FALSE; + } + + if (0 != vc_cmd_list_create(&vc_cmd_list)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create command list"); + return EINA_FALSE; + } + + vc_info_parser_get_result(&temp_text, &event, NULL, -1, vc_cmd_list, false); + + SLOG(LOG_DEBUG, TAG_VCW, "Result info : result text(%s) event(%d)", temp_text, event); + + vc_widget_client_use_callback(g_vc_w); + bool ret = callback(event, temp_text, user_data); + vc_widget_client_not_use_callback(g_vc_w); + + SLOG(LOG_DEBUG, TAG_VCW, "Widget asr result callback called"); + + /* Release result */ + if (NULL != temp_text) free(temp_text); + + vc_cmd_list_destroy(vc_cmd_list, true); + + return ret; +} + static Eina_Bool __vc_widget_notify_state_changed(void *data) { vc_state_changed_cb changed_callback = NULL; @@ -1296,6 +1382,47 @@ int vc_widget_unset_state_changed_cb() return 0; } +int vc_widget_set_asr_result_cb(vc_asr_result_cb callback, void* user_data) +{ + if (NULL == callback) + return VC_ERROR_INVALID_PARAMETER; + + vc_state_e state; + if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != VC_STATE_INITIALIZED) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'"); + return VC_ERROR_INVALID_STATE; + } + + vc_widget_client_set_asr_result_cb(g_vc_w, callback, user_data); + + return 0; +} + +int vc_widget_unset_asr_result_cb() +{ + vc_state_e state; + if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != VC_STATE_INITIALIZED) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: Current state is not 'Initialized'"); + return VC_ERROR_INVALID_STATE; + } + + vc_widget_client_set_asr_result_cb(g_vc_w, NULL, NULL); + + return 0; +} + int vc_widget_set_current_language_changed_cb(vc_current_language_changed_cb callback, void* user_data) { if (NULL == callback) diff --git a/client/vc_widget_client.c b/client/vc_widget_client.c index 2bea424..d32c23d 100644 --- a/client/vc_widget_client.c +++ b/client/vc_widget_client.c @@ -30,6 +30,8 @@ typedef struct { vc_result_cb result_cb; void* result_user_data; + vc_asr_result_cb asr_result_cb; + void* asr_result_user_data; vc_error_cb error_cb; void* error_user_data; vc_service_state_changed_cb service_state_changed_cb; @@ -119,6 +121,8 @@ int vc_widget_client_create(vc_h* vc) widget->result_cb = NULL; widget->result_user_data = NULL; + widget->asr_result_cb = NULL; + widget->asr_result_user_data = NULL; widget->service_state_changed_cb = NULL; widget->service_state_changed_user_data = NULL; widget->state_changed_cb = NULL; @@ -262,6 +266,34 @@ int vc_widget_client_get_result_cb(vc_h vc, vc_result_cb* callback, void** user_ return 0; } +int vc_widget_client_set_asr_result_cb(vc_h vc, vc_asr_result_cb callback, void* user_data) +{ + vc_widget_s* widget = __widget_get(vc); + + /* check handle */ + if (NULL == widget) + return VC_ERROR_INVALID_PARAMETER; + + widget->asr_result_cb = callback; + widget->asr_result_user_data = user_data; + + return 0; +} + +int vc_widget_client_get_asr_result_cb(vc_h vc, vc_asr_result_cb* callback, void** user_data) +{ + vc_widget_s* widget = __widget_get(vc); + + /* check handle */ + if (NULL == widget) + return VC_ERROR_INVALID_PARAMETER; + + *callback = widget->asr_result_cb; + *user_data = widget->asr_result_user_data; + + return 0; +} + int vc_widget_client_set_service_state_changed_cb(vc_h vc, vc_service_state_changed_cb callback, void* user_data) { vc_widget_s* widget = __widget_get(vc); diff --git a/client/vc_widget_client.h b/client/vc_widget_client.h index 12a2a85..ca2dc90 100644 --- a/client/vc_widget_client.h +++ b/client/vc_widget_client.h @@ -19,6 +19,7 @@ #define __VC_WIDGET_CLIENT_H_ #include "voice_control_common.h" +#include "voice_control_internal.h" #include "voice_control_widget.h" #ifdef __cplusplus @@ -45,6 +46,10 @@ int vc_widget_client_set_result_cb(vc_h vc, vc_result_cb callback, void* user_da int vc_widget_client_get_result_cb(vc_h vc, vc_result_cb* callback, void** user_data); +int vc_widget_client_set_asr_result_cb(vc_h vc, vc_asr_result_cb callback, void* user_data); + +int vc_widget_client_get_asr_result_cb(vc_h vc, vc_asr_result_cb* callback, void** user_data); + int vc_widget_client_set_service_state_changed_cb(vc_h vc, vc_service_state_changed_cb callback, void* user_data); int vc_widget_client_get_service_state_changed_cb(vc_h vc, vc_service_state_changed_cb* callback, void** user_data); diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index d491393..8ed3ff4 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -33,6 +33,8 @@ extern void __vc_widget_cb_show_tooltip(int pid, bool show); extern void __vc_widget_cb_result(); +extern bool __vc_widget_cb_asr_result(); + extern int __vc_widget_cb_service_state(int state); @@ -166,6 +168,33 @@ static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd } /* VCD_WIDGET_METHOD_RESULT */ + else if (dbus_message_is_method_call(msg, if_name, VCD_WIDGET_METHOD_ASR_RESULT)) { + SLOG(LOG_DEBUG, TAG_VCW, "===== Get widget asr result"); + int ret = 0; + if (false == __vc_widget_cb_asr_result()) + ret = 0; + else + ret = 1; + + DBusMessage* reply = dbus_message_new_method_return(msg); + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + if (!dbus_connection_send(g_w_conn_listener, reply, NULL)) + SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget get asr result : fail to send reply"); + else + SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget get asr result"); + + dbus_connection_flush(g_w_conn_listener); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget asr get result : fail to create reply message"); + } + + SLOG(LOG_DEBUG, TAG_VCW, "====="); + SLOG(LOG_DEBUG, TAG_VCW, " "); + + } /* VCD_WIDGET_METHOD_ASR_RESULT */ + else if (dbus_message_is_signal(msg, if_name, VCD_WIDGET_METHOD_ERROR)) { SLOG(LOG_DEBUG, TAG_VCW, "===== Get widget error"); int reason; @@ -696,6 +725,73 @@ int vc_widget_dbus_set_foreground(int pid, bool value) return 0; } +int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) +{ + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_WIDGET_METHOD_ENABLE_ASR_RESULT); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCW, ">>>> vc widget enable asr result : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCW, ">>>> vc widget enable asr result : pid(%d), enable(%d)", pid, enable); + } + + DBusMessageIter args; + dbus_message_iter_init_append(msg, &args); + + /* Append result*/ + int temp; + if (false == enable) temp = 0; + else temp = 1; + dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(pid)); + dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(temp)); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_w_conn_sender, msg, g_w_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCW, "<<<< vc widget enable asr result : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCW, "<<<< vc widget enable asr result : result = %d", result); + } + } else { + SLOG(LOG_DEBUG, TAG_VCW, "<<<< Result Message is NULL"); + vc_widget_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} int vc_widget_dbus_request_start(int pid, int silence) { diff --git a/client/vc_widget_dbus.h b/client/vc_widget_dbus.h index fe995c5..01fba7a 100644 --- a/client/vc_widget_dbus.h +++ b/client/vc_widget_dbus.h @@ -38,6 +38,7 @@ int vc_widget_dbus_request_start_recording(int pid, bool command); int vc_widget_dbus_set_foreground(int pid, bool value); +int vc_widget_dbus_request_enable_asr_result(int pid, bool enable); int vc_widget_dbus_request_start(int pid, int silence); diff --git a/common/vc_defs.h b/common/vc_defs.h index 5859338..095ba66 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -98,11 +98,14 @@ extern "C" { #define VC_WIDGET_METHOD_START_RECORDING "vc_widget_method_start_recording" +#define VC_WIDGET_METHOD_ENABLE_ASR_RESULT "vc_widget_method_enable_asr_result" + #define VC_WIDGET_METHOD_START "vc_widget_method_start" #define VC_WIDGET_METHOD_STOP "vc_widget_method_stop" #define VC_WIDGET_METHOD_CANCEL "vc_widget_method_cancel" #define VCD_WIDGET_METHOD_RESULT "vcd_widget_method_result" +#define VCD_WIDGET_METHOD_ASR_RESULT "vcd_widget_method_asr_result" #define VCD_WIDGET_METHOD_ERROR "vcd_widget_method_error" #define VCD_WIDGET_METHOD_HELLO "vcd_widget_method_hello" #define VCD_WIDGET_METHOD_SHOW_TOOLTIP "vcd_widget_method_show_tooltip" diff --git a/include/voice_control_internal.h b/include/voice_control_internal.h index 4935a91..8465e9e 100644 --- a/include/voice_control_internal.h +++ b/include/voice_control_internal.h @@ -19,7 +19,6 @@ #define __VOICE_CONTROL_INTERNAL_H__ #include -#include #ifdef __cplusplus @@ -28,6 +27,22 @@ extern "C" #endif /** +* @brief Called when client gets the asr recognition result from vc-daemon. +* +* @param[in] event The result event +* @param[in] result ASR text +* @param[in] user_data The user data passed from the callback registration function +* +* @return @c true when asr result is consumed \n @c false to propagate. +* +* @pre An application registers callback function using vc_mgr_set_pre_result_cb(). +* +* @see vc_widget_set_asr_result_cb() +* @see vc_widget_unset_asr_result_cb() +*/ +typedef bool (*vc_asr_result_cb)(vc_result_event_e event, const char* result, void *user_data); + +/** * @brief Sets command list from file. * @since_tizen 3.0 * @privlevel public diff --git a/include/voice_control_widget.h b/include/voice_control_widget.h old mode 100755 new mode 100644 index 2f8ca7a..03b6c89 --- a/include/voice_control_widget.h +++ b/include/voice_control_widget.h @@ -21,6 +21,7 @@ #include #include #include +#include /** @@ -515,6 +516,57 @@ int vc_widget_set_error_cb(vc_error_cb callback, void* user_data); */ int vc_widget_unset_error_cb(); +/** + * @brief Sets option for obtain ASR result as dictation via result callback. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/recorder + * + * @param[in] enable enable to get asr result + * + * @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_widget_enable_asr_result(bool enable); + +/** +* @brief Registers a callback function for an asr result. +* +* @param[in] callback Callback function to register +* @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 +* +* @pre The state should be #VC_STATE_INITIALIZED. +* +* @see vc_asr_result_cb() +* @see vc_widget_enable_asr_result() +* @see vc_widget_unset_asr_result_cb() +*/ +int vc_widget_set_asr_result_cb(vc_asr_result_cb callback, void* user_data); + +/** +* @brief Unregisters the callback function. +* +* @return 0 on success, otherwise a negative error value +* @retval #VC_ERROR_NONE Successful +* @retval #VC_ERROR_INVALID_STATE Invalid state +* +* @pre The state should be #VC_STATE_INITIALIZED. +* +* @see vc_widget_set_asr_result_cb() +*/ +int vc_widget_unset_asr_result_cb(); #ifdef __cplusplus } diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index a1e54b0..be8e8a0 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -148,6 +148,7 @@ mkdir -p %{_libdir}/voice/vc %{_includedir}/voice_control_common.h %{_includedir}/voice_control_key_defines.h %{_includedir}/voice_control_command_expand.h +%{_includedir}/voice_control_internal.h %files manager-devel %defattr(-,root,root,-) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 70f3749..5e0253d 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -1349,3 +1349,31 @@ int vcd_client_widget_unset_command(int pid) return 0; } + +int vcd_client_widget_set_asr_result_enabled(int pid, bool enable) +{ + widget_info_s *info = NULL; + info = __widget_get_element(pid); + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + info->asr_result_enabled = enable; + + return 0; +} + +int vcd_client_widget_get_asr_result_enabled(int pid, bool* enable) +{ + widget_info_s *info = NULL; + info = __widget_get_element(pid); + if (NULL == info) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] pid(%d) is NOT valid", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + *enable = info->asr_result_enabled; + + return 0; +} \ No newline at end of file diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index 62f3120..d84ba3b 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -62,6 +62,7 @@ typedef struct { typedef struct { int pid; bool widget_cmd; + bool asr_result_enabled; } widget_info_s; typedef enum { @@ -168,6 +169,9 @@ int vcd_client_widget_set_command(int pid); int vcd_client_widget_unset_command(int pid); +int vcd_client_widget_set_asr_result_enabled(int pid, bool enable); + +int vcd_client_widget_get_asr_result_enabled(int pid, bool* enable); #ifdef __cplusplus } diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 0d33cb3..7d0f348 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -311,6 +311,65 @@ int vcdc_send_result(int pid, int manager_pid, int cmd_type) return 0; } +int vcdc_send_asr_result(int pid, int cmd_type, bool* is_consumed) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + + SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Result command type(%d)", cmd_type); + + switch (cmd_type) { + case VC_COMMAND_TYPE_WIDGET: + msg = __get_message(pid, VCD_WIDGET_METHOD_ASR_RESULT, VCD_CLIENT_TYPE_WIDGET); + break; + default: + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Command type is NOT valid(%d)", cmd_type); + return VCD_ERROR_INVALID_PARAMETER; + } + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Message is NULL"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + + int result = 0; + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VCD_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + SLOG(LOG_DEBUG, TAG_VCD, "<<<< vc send asr result : result = %d", result); + *is_consumed = result; + return VCD_ERROR_NONE; + } else { + SLOG(LOG_ERROR, TAG_VCD, "<<<< Result message is NULL "); + return VCD_ERROR_OPERATION_FAILED; + } +} + int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result) { if (0 != __dbus_check()) { @@ -834,6 +893,9 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_CANCEL)) vcd_dbus_server_widget_cancel(g_conn_listener, msg); + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_WIDGET_METHOD_ENABLE_ASR_RESULT)) + vcd_dbus_server_widget_enable_asr_result(g_conn_listener, msg); + else { SLOG(LOG_DEBUG, TAG_VCD, "Message is NOT valid"); dbus_message_unref(msg); diff --git a/server/vcd_dbus.h b/server/vcd_dbus.h index a075a25..5c4e357 100644 --- a/server/vcd_dbus.h +++ b/server/vcd_dbus.h @@ -44,6 +44,8 @@ int vcdc_send_set_volume(int manger_pid, float volume); int vcdc_send_result(int pid, int manager_pid, int cmd_type); +int vcdc_send_asr_result(int pid, int cmd_type, bool* is_consumed); + int vcdc_send_pre_result_to_manager(int manager_pid, int event, const char* pre_result); int vcdc_send_result_to_manager(int manger_pid, int result_type); diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index e263cdd..4a19a0b 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -1826,3 +1826,51 @@ int vcd_dbus_server_widget_cancel(DBusConnection* conn, DBusMessage* msg) return 0; } +int vcd_dbus_server_widget_enable_asr_result(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid; + int enable; + int ret = VCD_ERROR_OPERATION_FAILED; + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INT32, &enable, DBUS_TYPE_INVALID); + + SLOG(LOG_DEBUG, TAG_VCD, ">>>>> VCD widget enable asr result"); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd widget enable asr result : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd widget enable asr result : pid(%d) enable(%d)", pid, enable); + ret = vcd_server_widget_enable_asr_result(pid, enable); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "<<<<<"); + SLOG(LOG_DEBUG, TAG_VCD, " "); + + return 0; +} \ No newline at end of file diff --git a/server/vcd_dbus_server.h b/server/vcd_dbus_server.h index b29fc5d..4a7fc7b 100644 --- a/server/vcd_dbus_server.h +++ b/server/vcd_dbus_server.h @@ -108,6 +108,7 @@ int vcd_dbus_server_widget_stop(DBusConnection* conn, DBusMessage* msg); int vcd_dbus_server_widget_cancel(DBusConnection* conn, DBusMessage* msg); +int vcd_dbus_server_widget_enable_asr_result(DBusConnection* conn, DBusMessage* msg); #ifdef __cplusplus } diff --git a/server/vcd_server.c b/server/vcd_server.c index 112e13b..eeed30e 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -488,6 +488,37 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int } } #if 1 + + int pid = vcd_client_widget_get_foreground_pid(); + if (-1 != pid) { + if (NULL != all_result) { + vc_info_parser_set_result(all_result, event, msg, NULL, false); + bool enable = false; + vcd_client_widget_get_asr_result_enabled(pid, &enable); + if (true == enable) { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send ASR result to Widget client"); + bool is_consumed = false; + if (0 != vcdc_send_asr_result(pid, VC_COMMAND_TYPE_WIDGET, &is_consumed)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send asr result"); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] ASR result is consumed(%d)", is_consumed); + if (true == is_consumed) { + vcdc_send_show_tooltip(pid, false); + if (-1 != vcd_client_manager_get_pid()) { + /* Manager client is available */ + if (0 != vcdc_send_result_to_manager(vcd_client_manager_get_pid(), VC_RESULT_TYPE_NOTIFICATION)) { + SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] Fail to send result"); + } + } + + vcd_client_manager_set_exclusive(false); + return; + } + } + } + } + } + /* if nlu_result is exist, Add command handle(is_action) into result list */ /* Normal result */ SLOG(LOG_DEBUG, TAG_VCD, "[Server] === Get engine result ==="); @@ -616,11 +647,6 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) { - if (NULL != all_result) { - /* Send result text to widget */ - vcdc_send_result(pid, vcd_client_manager_get_pid(), VC_COMMAND_TYPE_WIDGET); - } - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide"); /* Send to hide tooltip */ vcdc_send_show_tooltip(pid, false); @@ -2228,3 +2254,13 @@ int vcd_server_widget_cancel(int pid) return VCD_ERROR_NONE; } +int vcd_server_widget_enable_asr_result(int pid, bool enable) +{ + int ret; + ret = vcd_client_widget_set_asr_result_enabled(pid, enable); + if (0 != ret) { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to enable asr result : %d", ret); + } + + return ret; +} diff --git a/server/vcd_server.h b/server/vcd_server.h index 5166ccb..c8b0284 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -116,6 +116,7 @@ int vcd_server_widget_stop(int pid); int vcd_server_widget_cancel(int pid); +int vcd_server_widget_enable_asr_result(int pid, bool enable); #ifdef __cplusplus } -- 2.7.4 From c0af39d5e482d9cf06f2993426b4e37a5fb0533c Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 26 Dec 2016 16:01:46 +0900 Subject: [PATCH 03/16] Fix log level of 'vcdb' and 'vcd' logs Change-Id: I4cdee201d254a3bb3f38c704c6a54c68b13ecf5f Signed-off-by: Suyeon Hwang --- common/vc_cmd_db.c | 4 ++-- server/vcd_recorder.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 7696982..16ca81d 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -377,7 +377,7 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) if (type == temp_cmd->type) { *cmd_list = g_slist_append(*cmd_list, temp_cmd); } else { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Command type(%d) is NOT valid : request type(%d)", temp_cmd->type, type); + SLOG(LOG_WARN, vc_db_tag(), "[WARNING] Command type(%d) is NOT valid : request type(%d)", temp_cmd->type, type); } ret = sqlite3_step(stmt); if (SQLITE_DONE == ret) @@ -1487,7 +1487,7 @@ int vc_db_insert_commands_list(int pid, vc_cmd_type_e type, GSList* cmd_list, ch return ret; } } else { - SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Command type(%d) is NOT valid : request type(%d)", temp_cmd->type, type); + SLOG(LOG_WARN, vc_db_tag(), "[WARNING] Command type(%d) is NOT valid : request type(%d)", temp_cmd->type, type); } iter = g_slist_next(iter); } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 5ad08b5..160ecec 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -580,12 +580,12 @@ int vcd_recorder_start() int ret = -1; g_buffer_count = 0; - SLOG(LOG_ERROR, TAG_VCD, "[Recorder] Enter, recorder state(%d)", g_recorder_state); + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Enter, recorder state(%d)", g_recorder_state); if (VCD_RECORDER_STATE_RECORDING == g_recorder_state) return 0; bool started = false; - SLOG(LOG_ERROR, TAG_VCD, "[Recorder] audio type : %s", g_current_audio_type); + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] audio type : %s", g_current_audio_type); if (NULL != g_current_audio_type) { if (0 == strncmp(VCP_AUDIO_ID_BLUETOOTH, g_current_audio_type, strlen(VCP_AUDIO_ID_BLUETOOTH))) { @@ -614,7 +614,7 @@ int vcd_recorder_start() g_bt_extend_count = 0; #endif } else if (0 == strncmp(VCP_AUDIO_ID_MSF, g_current_audio_type, strlen(VCP_AUDIO_ID_MSF))) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder] call RegisterMSFAudioCallback() function"); + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] call RegisterMSFAudioCallback() function"); #ifdef TV_MSF_WIFI_MODE ret = RegisterMSFAudioCallback(__msf_wifi_audio_data_receive_cb, NULL); @@ -629,7 +629,7 @@ int vcd_recorder_start() } } - SLOG(LOG_ERROR, TAG_VCD, "[Recorder] started = %d", started); + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] started = %d", started); if (false == started) { #if 0 ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL); -- 2.7.4 From 99db1687554d3b0bd7d5671e9f19d397378bed44 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 28 Dec 2016 21:09:18 +0900 Subject: [PATCH 04/16] Add ref count for db init/deinit Change-Id: I4234b263278ef94db192d1142b8e12a9451b9416 Signed-off-by: Wonnam Jang (cherry picked from commit 45e9a90b27cbb347f2839bd645513687520186c3) --- common/vc_cmd_db.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 16ca81d..3a040a6 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -59,6 +59,7 @@ const char* vc_db_tag() static sqlite3* db_handle = NULL; char* path = NULL; int g_fpid = -1; +int g_ref_cnt = 0; static int __vc_db_transaction(const char* transaction) { @@ -1063,6 +1064,11 @@ int vc_db_initialize(void) { SLOG(LOG_INFO, vc_db_tag(), "DB initialization"); + if (0 < g_ref_cnt) { + g_ref_cnt++; + return VC_DB_ERROR_NONE; + } + path = (char*)calloc(256, sizeof(char)); if (NULL == path) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory"); @@ -1112,12 +1118,16 @@ int vc_db_initialize(void) SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_exec returned %d: %s", ret, err_msg); } } - + g_ref_cnt++; return VC_DB_ERROR_NONE; } int vc_db_finalize(void) { + if (0 >= g_ref_cnt) return VC_DB_ERROR_INVALID_STATE; + if (0 != --g_ref_cnt) + return VC_DB_ERROR_NONE; + if (NULL != path) { free(path); path = NULL; -- 2.7.4 From a114d972263d15d37313543d224592f5bde19052 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Wed, 28 Dec 2016 21:50:54 +0900 Subject: [PATCH 05/16] Add internal method for enable/disable command type Change-Id: I95241d6fcab013766bb3febb5a2445c639143a28 Signed-off-by: Kwangyoun Kim (cherry picked from commit 4f7cc1642addef112004b8223eeb3372f3db7012) --- client/vc_mgr.c | 112 ++++++++++++++++++++++++++++ client/vc_mgr_dbus.c | 158 ++++++++++++++++++++++++++++++++++++++++ client/vc_mgr_dbus.h | 3 + common/vc_defs.h | 3 + include/voice_control_manager.h | 25 +++++++ server/vcd_client_data.c | 36 +++++---- server/vcd_config.c | 42 +++++++++++ server/vcd_config.h | 5 ++ server/vcd_dbus.c | 6 ++ server/vcd_dbus_server.c | 108 +++++++++++++++++++++++++++ server/vcd_dbus_server.h | 4 + server/vcd_server.c | 74 ++++++++++++++++--- server/vcd_server.h | 4 + 13 files changed, 555 insertions(+), 25 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 878f3a7..2001006 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -650,6 +650,118 @@ int vc_mgr_is_command_format_supported(vc_cmd_format_e format, bool* support) return VC_ERROR_NONE; } +int vc_mgr_enable_command_type(int cmd_type) +{ + SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Enable Command Type"); + + vc_state_e state; + if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != VC_STATE_READY) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'"); + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + return VC_ERROR_INVALID_STATE; + } + + /* Check service state */ + vc_service_state_e service_state = -1; + vc_mgr_client_get_service_state(g_vc_m, &service_state); + if (service_state != VC_SERVICE_STATE_READY) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'"); + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + return VC_ERROR_INVALID_STATE; + } + + int ret; + int count = 0; + do { + ret = vc_mgr_dbus_request_enable_command_type(g_vc_m->handle, cmd_type); + if (0 != ret) { + if (VC_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request enable command type : %s", __vc_mgr_get_error_code(ret)); + break; + } else { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request enable command type : %s", __vc_mgr_get_error_code(ret)); + usleep(10000); + count++; + if (VC_RETRY_COUNT == count) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); + break; + } + } + } + } while (0 != ret); + + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + + return ret; +} + +int vc_mgr_disable_command_type(int cmd_type) +{ + SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Disable Command Type"); + + vc_state_e state; + if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != VC_STATE_READY) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'READY'"); + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + return VC_ERROR_INVALID_STATE; + } + + /* Check service state */ + vc_service_state_e service_state = -1; + vc_mgr_client_get_service_state(g_vc_m, &service_state); + if (service_state != VC_SERVICE_STATE_READY) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY'"); + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + return VC_ERROR_INVALID_STATE; + } + + int ret; + int count = 0; + do { + ret = vc_mgr_dbus_request_disable_command_type(g_vc_m->handle, cmd_type); + if (0 != ret) { + if (VC_ERROR_TIMED_OUT != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request disable command type : %s", __vc_mgr_get_error_code(ret)); + break; + } else { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request disable command type : %s", __vc_mgr_get_error_code(ret)); + usleep(10000); + count++; + if (VC_RETRY_COUNT == count) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); + break; + } + } + } + } while (0 != ret); + + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + + return ret; +} + int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list) { SLOG(LOG_DEBUG, TAG_VCM, "===== [Manager] Set Command list"); diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index 93cbb17..2349eea 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -1829,6 +1829,164 @@ int vc_mgr_dbus_request_cancel(int pid) return result; } +int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type) +{ + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + 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; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_ENABLE_COMMAND_TYPE); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, ">>>> vc enable command type : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCM, ">>>> vc enable command type : pid(%d) type(%d)", pid, cmd_type); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &cmd_type, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCM, "<<<< vc enable command type : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "<<<< vc enable command type : result = %d", result); + } + } else { + SLOG(LOG_DEBUG, TAG_VCM, "<<<< Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + +int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type) +{ + DBusError err; + dbus_error_init(&err); + + bool exist = dbus_bus_name_has_owner(g_m_conn_sender, VC_SERVER_SERVICE_NAME, &err); + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + int ret; + if (false == exist) { + 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; + } + + DBusMessage* msg; + + /* create a signal & check for errors */ + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, /* object name of the signal */ + VC_SERVER_SERVICE_INTERFACE, /* interface name of the signal */ + VC_MANAGER_METHOD_DISABLE_COMMAND_TYPE); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, ">>>> vc disable command type : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCM, ">>>> vc disable command type : pid(%d) type(%d)", pid, cmd_type); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &cmd_type, + DBUS_TYPE_INVALID); + + DBusMessage* result_msg; + int result = VC_ERROR_OPERATION_FAILED; + + result_msg = dbus_connection_send_with_reply_and_block(g_m_conn_sender, msg, g_m_waiting_time, &err); + dbus_message_unref(msg); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, + DBUS_TYPE_INT32, &result, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "<<<< Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VC_ERROR_OPERATION_FAILED; + } + dbus_message_unref(result_msg); + + if (0 == result) { + SLOG(LOG_DEBUG, TAG_VCM, "<<<< vc disable command type : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "<<<< vc disable command type : result = %d", result); + } + } else { + SLOG(LOG_DEBUG, TAG_VCM, "<<<< Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + static DBusMessage* __get_message(int pid, const char* method, int type) { char service_name[64]; diff --git a/client/vc_mgr_dbus.h b/client/vc_mgr_dbus.h index c12baa6..267aa05 100644 --- a/client/vc_mgr_dbus.h +++ b/client/vc_mgr_dbus.h @@ -64,6 +64,9 @@ int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id); int vc_mgr_dbus_send_result_selection(int pid); +int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type); + +int vc_mgr_dbus_request_disable_command_type(int pid, int cmd_type); #ifdef __cplusplus } diff --git a/common/vc_defs.h b/common/vc_defs.h index 095ba66..f647506 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -127,6 +127,8 @@ extern "C" { #define VC_MANAGER_METHOD_SET_CLIENT_INFO "vc_manager_method_set_client_info" #define VC_MANAGER_METHOD_SET_PRIVATE_DATA "vc_manager_method_set_private_data" #define VC_MANAGER_METHOD_GET_PRIVATE_DATA "vc_manager_method_get_private_data" +#define VC_MANAGER_METHOD_ENABLE_COMMAND_TYPE "vc_manager_method_enable_command_type" +#define VC_MANAGER_METHOD_DISABLE_COMMAND_TYPE "vc_manager_method_disable_command_type" #define VC_MANAGER_METHOD_START "vc_manager_method_request_start" #define VC_MANAGER_METHOD_STOP "vc_manager_method_request_stop" @@ -149,6 +151,7 @@ extern "C" { #define VCC_MANAGER_METHOD_SET_FOREGROUND "vcd_manager_method_set_foreground" + /****************************************************************************************** * Definitions for configuration *******************************************************************************************/ diff --git a/include/voice_control_manager.h b/include/voice_control_manager.h index 32f4cd7..9d738dc 100644 --- a/include/voice_control_manager.h +++ b/include/voice_control_manager.h @@ -982,6 +982,31 @@ int vc_mgr_set_dialog_request_cb(vc_mgr_dialog_request_cb callback, void* user_d */ int vc_mgr_unset_dialog_request_cb(); +/** +* @brief Enable command type as candidate command. +* +* @return 0 on success, otherwise a negative error value +* @retval #VC_ERROR_NONE Successful +* @retval #VC_ERROR_INVALID_STATE Invalid state +* +* @pre The state should be #VC_STATE_READY. +* +* @see vc_mgr_disable_command_type() +*/ +int vc_mgr_enable_command_type(int cmd_type); + +/** +* @brief Disable command type as candidate command. +* +* @return 0 on success, otherwise a negative error value +* @retval #VC_ERROR_NONE Successful +* @retval #VC_ERROR_INVALID_STATE Invalid state +* +* @pre The state should be #VC_STATE_READY. +* +* @see vc_mgr_enable_command_type() +*/ +int vc_mgr_disable_command_type(int cmd_type); #ifdef __cplusplus } diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 5e0253d..562b77a 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -319,7 +319,7 @@ int vcd_client_command_collect_command() __vcd_client_release_commands(); /* Check exclusive system command */ - if (true == g_manager.exclusive_cmd_option) { + if (true == g_manager.exclusive_cmd_option && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_EXCLUSIVE)) { SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] Exclusive option of manager is ON"); GSList* ex_sys_cmd_list = NULL; @@ -339,7 +339,7 @@ int vcd_client_command_collect_command() /* 3. Set system command */ GSList* sys_cmd_list = NULL; - if (true == g_manager.manager_cmd) { + if (true == g_manager.manager_cmd && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_SYSTEM)) { ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_SYSTEM, &sys_cmd_list); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list"); @@ -351,7 +351,7 @@ int vcd_client_command_collect_command() } GSList* sys_back_cmd_list = NULL; - if (true == g_manager.manager_cmd) { + if (true == g_manager.manager_cmd && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_SYSTEM_BACKGROUND)) { ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_SYSTEM_BACKGROUND, &sys_back_cmd_list); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the system command list"); @@ -372,7 +372,7 @@ int vcd_client_command_collect_command() /* 4-1. Set widget command */ widget_info_s* widget_info = NULL; widget_info = __widget_get_element(fg_pid); - if (NULL != widget_info) { + if (NULL != widget_info && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) { if (true == widget_info->widget_cmd) { ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_WIDGET, &widget_cmd_list); if (0 != ret) { @@ -386,16 +386,18 @@ int vcd_client_command_collect_command() } /* 4-2. Set foreground command of foreground app */ - ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_FOREGROUND, &fg_cmd_list); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the fg command list"); - } else { - g_cur_cmd_list.foreground_cmds = fg_cmd_list; + if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_FOREGROUND)) { + ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_FOREGROUND, &fg_cmd_list); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the fg command list"); + } else { + g_cur_cmd_list.foreground_cmds = fg_cmd_list; + } } } else { SLOG(LOG_DEBUG, TAG_VCD, "[Client Data] No foreground app"); } - if (true == g_manager.manager_cmd) { + if (true == g_manager.manager_cmd && 1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_FOREGROUND)) { /* 4-3. Set foreground command by manager */ ret = vc_cmd_parser_get_commands(g_manager.pid, VC_COMMAND_TYPE_FOREGROUND, &fg_cmd_list); if (0 != ret) { @@ -407,12 +409,14 @@ int vcd_client_command_collect_command() /* 5. Set background commands */ GSList* bg_cmd_list = NULL; - ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_BACKGROUND, &bg_cmd_list); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the bg command list"); - } else { - /* Add item to global command list */ - g_cur_cmd_list.background_cmds = bg_cmd_list; + if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_BACKGROUND)) { + ret = vc_cmd_parser_get_commands(fg_pid, VC_COMMAND_TYPE_BACKGROUND, &bg_cmd_list); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get the bg command list"); + } else { + /* Add item to global command list */ + g_cur_cmd_list.background_cmds = bg_cmd_list; + } } return 0; } diff --git a/server/vcd_config.c b/server/vcd_config.c index 7c46573..287ba23 100644 --- a/server/vcd_config.c +++ b/server/vcd_config.c @@ -28,6 +28,16 @@ static vcd_state_e g_state; static int g_foreground_pid; +#define COMMAND_TYPE_MAX 7 +static int g_enabled_command_type[COMMAND_TYPE_MAX] = { + 0, /* NONE */ + 1, /* FOREGROUND */ + 1, /* BACKGROUND */ + 1, /* WIDGET */ + 1, /* SYSTEM */ + 1, /* SYSTEM_BACKGROUND */ + 1 /* EXCLUSIVE */ +}; void __vcd_config_lang_changed_cb(const char* before_lang, const char* current_lang) { @@ -128,3 +138,35 @@ int vcd_config_set_foreground(int pid, bool value) } return 0; } + +int vcd_config_enable_command_type(int cmd_type) +{ + if (cmd_type <= 0 || cmd_type >= COMMAND_TYPE_MAX) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid command type"); + return -1; + } + + g_enabled_command_type[cmd_type] = 1; + return 0; +} + +int vcd_config_disable_command_type(int cmd_type) +{ + if (cmd_type <= 0 || cmd_type >= COMMAND_TYPE_MAX) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid command type"); + return -1; + } + + g_enabled_command_type[cmd_type] = 0; + return 0; +} + +int vcd_config_get_command_type_enabled(int cmd_type) +{ + if (cmd_type <= 0 || cmd_type >= COMMAND_TYPE_MAX) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Invalid command type"); + return 0; + } + + return g_enabled_command_type[cmd_type]; +} diff --git a/server/vcd_config.h b/server/vcd_config.h index 2cf332f..047d6d6 100644 --- a/server/vcd_config.h +++ b/server/vcd_config.h @@ -43,6 +43,11 @@ int vcd_config_get_foreground(int* pid); int vcd_config_set_foreground(int pid, bool value); +int vcd_config_enable_command_type(int cmd_type); + +int vcd_config_disable_command_type(int cmd_type); + +int vcd_config_get_command_type_enabled(int cmd_type); #ifdef __cplusplus } diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 7d0f348..586e65b 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -839,6 +839,12 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_DO_ACTION)) vcd_dbus_server_mgr_do_action(g_conn_listener, msg); + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_ENABLE_COMMAND_TYPE)) + vcd_dbus_server_mgr_enable_command_type(g_conn_listener, msg); + + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_DISABLE_COMMAND_TYPE)) + vcd_dbus_server_mgr_disable_command_type(g_conn_listener, msg); + /* client event */ else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_METHOD_INITIALIZE)) vcd_dbus_server_initialize(g_conn_listener, msg); diff --git a/server/vcd_dbus_server.c b/server/vcd_dbus_server.c index 4a19a0b..169e3f4 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -742,6 +742,114 @@ int vcd_dbus_server_mgr_do_action(DBusConnection* conn, DBusMessage* msg) return 0; } +int vcd_dbus_server_mgr_enable_command_type(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + int cmd_type = 0; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, ">>>>> VCD Manager enable command type"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &cmd_type, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr enable command type : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr enable command type : pid(%d), cmd_type(%d)", pid, cmd_type); + ret = vcd_server_mgr_enable_command_type(pid, cmd_type); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "<<<<<"); + SLOG(LOG_DEBUG, TAG_VCD, " "); + + return 0; +} + +int vcd_dbus_server_mgr_disable_command_type(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + int cmd_type = 0; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, ">>>>> VCD Manager disable command type"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &cmd_type, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr disable command type : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr disable command type : pid(%d), cmd_type(%d)", pid, cmd_type); + ret = vcd_server_mgr_disable_command_type(pid, cmd_type); + } + + DBusMessage* reply; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID); + + if (0 == ret) { + SLOG(LOG_DEBUG, TAG_VCD, "[OUT SUCCESS] Result(%d)", ret); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Result(%d)", ret); + } + + if (!dbus_connection_send(conn, reply, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Out Of Memory!"); + } + + dbus_connection_flush(conn); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[OUT ERROR] Fail to create reply message!!"); + } + + SLOG(LOG_DEBUG, TAG_VCD, "<<<<<"); + SLOG(LOG_DEBUG, TAG_VCD, " "); + + return 0; +} + int vcd_dbus_server_mgr_start(DBusConnection* conn, DBusMessage* msg) { DBusError err; diff --git a/server/vcd_dbus_server.h b/server/vcd_dbus_server.h index 4a7fc7b..626d415 100644 --- a/server/vcd_dbus_server.h +++ b/server/vcd_dbus_server.h @@ -63,6 +63,10 @@ int vcd_dbus_server_mgr_cancel(DBusConnection* conn, DBusMessage* msg); int vcd_dbus_server_mgr_result_selection(DBusConnection* conn, DBusMessage* msg); +int vcd_dbus_server_mgr_enable_command_type(DBusConnection* conn, DBusMessage* msg); + +int vcd_dbus_server_mgr_disable_command_type(DBusConnection* conn, DBusMessage* msg); + /* * Dbus Server functions for client */ diff --git a/server/vcd_server.c b/server/vcd_server.c index a452b68..07f9fbe 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1535,11 +1535,13 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive if (false == exclusive_cmd) { /* Notify show tooltip */ - int pid = vcd_client_widget_get_foreground_pid(); - if (-1 != pid) { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command"); - ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true); - return 0; + if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) { + int pid = vcd_client_widget_get_foreground_pid(); + if (-1 != pid) { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command"); + ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true); + return 0; + } } } else { vcd_client_manager_set_exclusive(exclusive_cmd); @@ -1627,10 +1629,12 @@ int vcd_server_mgr_cancel() } if (false == vcd_client_manager_get_exclusive()) { - int pid = vcd_client_widget_get_foreground_pid(); - if (-1 != pid) { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide"); - ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false); + if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) { + int pid = vcd_client_widget_get_foreground_pid(); + if (-1 != pid) { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip hide"); + ecore_timer_add(0, __vcd_request_show_tooltip, (void*)false); + } } } else { vcd_client_manager_set_exclusive(false); @@ -1758,6 +1762,58 @@ int vcd_server_mgr_do_action(int pid, int type, const char* action) return ret; } +int vcd_server_mgr_enable_command_type(int pid, int cmd_type) +{ + int ret = -1; + + /* check if pid is valid */ + if (false == vcd_client_manager_is_valid(pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_READY != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready"); + return VCD_ERROR_INVALID_STATE; + } + + ret = vcd_config_enable_command_type(cmd_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to enable command type"); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Enable command type(%d)", cmd_type); + } + + return ret; +} + +int vcd_server_mgr_disable_command_type(int pid, int cmd_type) +{ + int ret = -1; + + /* check if pid is valid */ + if (false == vcd_client_manager_is_valid(pid)) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The manager pid(%d) is NOT valid", pid); + return VCD_ERROR_INVALID_PARAMETER; + } + + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_READY != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready"); + return VCD_ERROR_INVALID_STATE; + } + + ret = vcd_config_disable_command_type(cmd_type); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to disable command type"); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Disable command type(%d)", cmd_type); + } + + return ret; +} + /* * VC Server Functions for Client */ diff --git a/server/vcd_server.h b/server/vcd_server.h index c8b0284..b97589d 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -74,6 +74,10 @@ int vcd_server_mgr_get_private_data(int pid, const char* key, char** data); int vcd_server_mgr_do_action(int pid, int type, const char* action); +int vcd_server_mgr_enable_command_type(int pid, int cmd_type); + +int vcd_server_mgr_disable_command_type(int pid, int cmd_type); + /* * For client */ -- 2.7.4 From 30747512b113e3f9b5788779d517ed9cb74646c0 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Mon, 26 Dec 2016 13:51:43 +0900 Subject: [PATCH 06/16] Enhancement for widget client internal multi handle Change-Id: I5aaf4cee1d8a4d2cd48bbe8a9966a6c965cba620 Signed-off-by: Kwangyoun Kim (cherry picked from commit d99e9cfd7db9ccc0dcef3e0232999d4fa7786192) --- client/vc_widget.c | 676 ++++++++++++++++++++++++----------------- client/vc_widget_client.c | 158 +++++----- client/vc_widget_client.h | 53 ++++ include/voice_control_widget.h | 57 ++-- server/vcd_dbus.c | 2 +- server/vcd_server.c | 4 +- 6 files changed, 563 insertions(+), 387 deletions(-) diff --git a/client/vc_widget.c b/client/vc_widget.c index 6212288..3989c99 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -31,15 +31,10 @@ #define VC_WIDGET_CONFIG_HANDLE 200000 -static Ecore_Timer* g_w_connect_timer = NULL; - static Ecore_Event_Handler* g_focus_in_handler = NULL; static Ecore_Event_Handler* g_focus_out_handler = NULL; static Ecore_Timer* g_w_start_timer = NULL; -static Ecore_Timer* g_w_tooltip_timer = NULL; - -static vc_h g_vc_w = NULL; static int g_daemon_pid = 0; @@ -88,28 +83,41 @@ static void __vc_widget_lang_changed_cb(const char* before_lang, const char* cur vc_current_language_changed_cb callback; void* lang_user_data; - vc_widget_client_get_current_lang_changed_cb(g_vc_w, &callback, &lang_user_data); - if (NULL != callback) { - vc_widget_client_use_callback(g_vc_w); - callback(before_lang, current_lang, lang_user_data); - vc_widget_client_not_use_callback(g_vc_w); - SLOG(LOG_DEBUG, TAG_VCW, "Language changed callback is called"); - } else { - SLOG(LOG_WARN, TAG_VCW, "[WARNING] Language changed callback is null"); - } + GSList* client_list = vc_widget_client_get_client_list(); + vc_widget_s *widget_data = NULL; + vc_h vc_w = NULL; + + int count = g_slist_length(client_list); + int i; + for (i = 0; i < count; i++) { + widget_data = g_slist_nth_data(client_list, i); + if (NULL != widget_data) { + vc_w = widget_data->vc; + + vc_widget_client_get_current_lang_changed_cb(vc_w, &callback, &lang_user_data); + + if (NULL != callback) { + vc_widget_client_use_callback(vc_w); + callback(before_lang, current_lang, lang_user_data); + vc_widget_client_not_use_callback(vc_w); + SLOG(LOG_DEBUG, TAG_VCW, "Language changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCW, "[WARNING] Language changed callback is null"); + } + } + } return; } -int vc_widget_initialize() +int vc_widget_initialize(vc_h* vc_w) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Initialize"); - /* check handle */ - if (true == vc_widget_client_is_valid(g_vc_w)) { - SLOG(LOG_ERROR, TAG_VCW, "[WARNING] Already initialized"); - return VC_ERROR_NONE; + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; } if (0 == vc_widget_client_get_count()) { @@ -117,41 +125,41 @@ int vc_widget_initialize() SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to open connection"); return VC_ERROR_OPERATION_FAILED; } - } else { - SLOG(LOG_WARN, TAG_VCW, "[WARN] Already initialized"); - return VC_ERROR_NONE; } - if (0 != vc_widget_client_create(&g_vc_w)) { + if (0 != vc_widget_client_create(vc_w)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create client!!!!!"); return VC_ERROR_OUT_OF_MEMORY; } - int ret = vc_config_mgr_initialize(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE); + /* TODO - each handle? */ + int ret = vc_config_mgr_initialize((*vc_w)->handle); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to init config manager : %s", __vc_widget_get_error_code(__vc_widget_convert_config_error_code(ret))); - vc_widget_client_destroy(g_vc_w); + vc_widget_client_destroy((*vc_w)); return __vc_widget_convert_config_error_code(ret); } - ret = vc_config_mgr_set_lang_cb(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE, __vc_widget_lang_changed_cb); + ret = vc_config_mgr_set_lang_cb((*vc_w)->handle, __vc_widget_lang_changed_cb); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to set config changed : %d", ret); - vc_config_mgr_finalize(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE); - vc_widget_client_destroy(g_vc_w); + vc_config_mgr_finalize((*vc_w)->handle); + vc_widget_client_destroy((*vc_w)); return __vc_widget_convert_config_error_code(ret); } - ret = vc_db_initialize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize DB : %d", ret); - vc_config_mgr_finalize(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE); - vc_widget_client_destroy(g_vc_w); - return ret; + if (1 == vc_widget_client_get_count()) { + ret = vc_db_initialize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize DB : %d", ret); + vc_config_mgr_finalize((*vc_w)->handle); + vc_widget_client_destroy((*vc_w)); + return ret; + } } - SLOG(LOG_DEBUG, TAG_VCW, "[Success] pid(%d)", g_vc_w->handle); + SLOG(LOG_DEBUG, TAG_VCW, "[Success] uid(%d)", (*vc_w)->handle); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -159,9 +167,9 @@ int vc_widget_initialize() return VC_ERROR_NONE; } -static void __vc_widget_internal_unprepare() +static void __vc_widget_internal_unprepare(vc_h vc_w) { - int ret = vc_widget_dbus_request_finalize(g_vc_w->handle); + int ret = vc_widget_dbus_request_finalize(getpid()); if (0 != ret) { SLOG(LOG_WARN, TAG_VCW, "[ERROR] Fail to request finalize : %s", __vc_widget_get_error_code(ret)); } @@ -182,11 +190,11 @@ static void __vc_widget_internal_unprepare() return; } -int vc_widget_deinitialize() +int vc_widget_deinitialize(vc_h vc_w) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Deinitialize"); - if (false == vc_widget_client_is_valid(g_vc_w)) { + if (false == vc_widget_client_is_valid(vc_w)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NOT initialized"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -194,26 +202,29 @@ int vc_widget_deinitialize() } vc_state_e state; - vc_widget_client_get_state(g_vc_w, &state); + vc_widget_client_get_state(vc_w, &state); + vc_widget_s* widget = widget_get(vc_w); /* check state */ switch (state) { case VC_STATE_READY: - __vc_widget_internal_unprepare(); + if (1 == vc_widget_client_get_count()) { + __vc_widget_internal_unprepare(vc_w); + } /* no break. need to next step*/ case VC_STATE_INITIALIZED: - if (NULL != g_w_connect_timer) { + if (NULL != widget->conn_timer) { SLOG(LOG_DEBUG, TAG_VCW, "Connect Timer is deleted"); - ecore_timer_del(g_w_connect_timer); - g_w_connect_timer = NULL; + ecore_timer_del(widget->conn_timer); + widget->conn_timer = NULL; } - vc_config_mgr_unset_lang_cb(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE); - vc_config_mgr_finalize(g_vc_w->handle + VC_WIDGET_CONFIG_HANDLE); + vc_config_mgr_unset_lang_cb(vc_w->handle); + vc_config_mgr_finalize(vc_w->handle); /* Free resources */ - vc_widget_client_destroy(g_vc_w); - g_vc_w = NULL; + vc_widget_client_destroy(vc_w); + vc_w = NULL; break; case VC_STATE_NONE: break; @@ -221,13 +232,15 @@ int vc_widget_deinitialize() SLOG(LOG_DEBUG, TAG_VCW, "Success: destroy"); - int ret = vc_db_finalize(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to finalize DB, ret(%d)", ret); - } + if (0 == vc_widget_client_get_count()) { + int ret = vc_db_finalize(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to finalize DB, ret(%d)", ret); + } - if (0 != vc_widget_dbus_close_connection()) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to close connection"); + if (0 != vc_widget_dbus_close_connection()) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to close connection"); + } } SLOG(LOG_DEBUG, TAG_VCW, "====="); @@ -265,6 +278,8 @@ static Eina_Bool __focus_changed_cb(void *data, int type, void *event) static Eina_Bool __vc_widget_connect_daemon(void *data) { + vc_h vc_w = (vc_h)data; + /* Send hello */ if (0 != vc_widget_dbus_request_hello()) { return EINA_TRUE; @@ -272,38 +287,43 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Connect daemon"); - g_w_connect_timer = NULL; + vc_widget_s* widget = widget_get(vc_w); + widget->conn_timer = NULL; /* request initialization */ int ret = -1; int service_state = 0; - ret = vc_widget_dbus_request_initialize(g_vc_w->handle, &service_state, &g_daemon_pid); + ret = vc_widget_dbus_request_initialize(getpid(), &service_state, &g_daemon_pid); if (VC_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret)); - vc_widget_client_set_error(g_vc_w, VC_ERROR_ENGINE_NOT_FOUND); - ecore_timer_add(0, __vc_widget_notify_error, g_vc_w); + vc_widget_client_set_error(vc_w, VC_ERROR_ENGINE_NOT_FOUND); + ecore_timer_add(0, __vc_widget_notify_error, vc_w); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); return EINA_FALSE; + } else if (VC_ERROR_INVALID_PARAMETER == ret) { + SLOG(LOG_WARN, TAG_VCW, "[WARNING] Invalid Parameter"); } else if (VC_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to initialize : %s", __vc_widget_get_error_code(ret)); - vc_widget_client_set_error(g_vc_w, VC_ERROR_TIMED_OUT); - ecore_timer_add(0, __vc_widget_notify_error, g_vc_w); + vc_widget_client_set_error(vc_w, VC_ERROR_TIMED_OUT); + ecore_timer_add(0, __vc_widget_notify_error, vc_w); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); return EINA_FALSE; } - vc_widget_client_set_service_state(g_vc_w, (vc_service_state_e)service_state); + vc_widget_client_set_service_state(vc_w, (vc_service_state_e)service_state); - g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL); - g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL); + if (NULL == g_focus_in_handler) + g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL); + if (NULL == g_focus_out_handler) + g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL); char appid[255] = {'\0',}; aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)); @@ -317,8 +337,8 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) } } - vc_widget_client_set_state(g_vc_w, VC_STATE_READY); - ecore_timer_add(0, __vc_widget_notify_state_changed, g_vc_w); + vc_widget_client_set_state(vc_w, VC_STATE_READY); + ecore_timer_add(0, __vc_widget_notify_state_changed, vc_w); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -326,12 +346,12 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) return EINA_FALSE; } -int vc_widget_prepare() +int vc_widget_prepare(vc_h vc_w) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Prepare"); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -346,7 +366,8 @@ int vc_widget_prepare() return VC_ERROR_INVALID_STATE; } - g_w_connect_timer = ecore_timer_add(0, __vc_widget_connect_daemon, NULL); + vc_widget_s* widget = widget_get(vc_w); + widget->conn_timer = ecore_timer_add(0, __vc_widget_connect_daemon, (void*)vc_w); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -354,12 +375,12 @@ int vc_widget_prepare() return VC_ERROR_NONE; } -int vc_widget_unprepare() +int vc_widget_unprepare(vc_h vc_w) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Unprepare"); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -374,10 +395,10 @@ int vc_widget_unprepare() return VC_ERROR_INVALID_STATE; } - __vc_widget_internal_unprepare(); + __vc_widget_internal_unprepare(vc_w); - vc_widget_client_set_state(g_vc_w, VC_STATE_INITIALIZED); - ecore_timer_add(0, __vc_widget_notify_state_changed, g_vc_w); + vc_widget_client_set_state(vc_w, VC_STATE_INITIALIZED); + ecore_timer_add(0, __vc_widget_notify_state_changed, vc_w); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -385,12 +406,12 @@ int vc_widget_unprepare() return VC_ERROR_NONE; } -int vc_widget_enable_asr_result(bool enable) +int vc_widget_enable_asr_result(vc_h vc_w, bool enable) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Enable asr result"); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -409,7 +430,7 @@ int vc_widget_enable_asr_result(bool enable) int ret = -1; do { - ret = vc_widget_dbus_request_enable_asr_result(g_vc_w->handle, enable); + ret = vc_widget_dbus_request_enable_asr_result(getpid(), enable); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to enable asr result : %s", __vc_widget_get_error_code(ret)); @@ -426,13 +447,15 @@ int vc_widget_enable_asr_result(bool enable) } } while (0 != ret); + vc_widget_client_set_asr_result_enabled(vc_w, enable); + SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); return ret; } -int vc_widget_foreach_supported_languages(vc_supported_language_cb callback, void* user_data) +int vc_widget_foreach_supported_languages(vc_h vc_w, vc_supported_language_cb callback, void* user_data) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Foreach Supported Language"); @@ -444,7 +467,7 @@ int vc_widget_foreach_supported_languages(vc_supported_language_cb callback, voi } vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -464,7 +487,7 @@ int vc_widget_foreach_supported_languages(vc_supported_language_cb callback, voi return VC_ERROR_NONE; } -int vc_widget_get_current_language(char** language) +int vc_widget_get_current_language(vc_h vc_w, char** language) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Get Current Language"); @@ -476,7 +499,7 @@ int vc_widget_get_current_language(char** language) } vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -496,7 +519,7 @@ int vc_widget_get_current_language(char** language) return ret; } -int vc_widget_get_state(vc_state_e* state) +int vc_widget_get_state(vc_h vc_w, vc_state_e* state) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Get State"); @@ -506,7 +529,7 @@ int vc_widget_get_state(vc_state_e* state) } vc_state_e temp; - if (0 != vc_widget_client_get_state(g_vc_w, &temp)) { + if (0 != vc_widget_client_get_state(vc_w, &temp)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -528,7 +551,7 @@ int vc_widget_get_state(vc_state_e* state) return VC_ERROR_NONE; } -int vc_widget_get_service_state(vc_service_state_e* state) +int vc_widget_get_service_state(vc_h vc_w, vc_service_state_e* state) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Get Service State"); @@ -538,7 +561,7 @@ int vc_widget_get_service_state(vc_service_state_e* state) } vc_state_e temp; - if (0 != vc_widget_client_get_state(g_vc_w, &temp)) { + if (0 != vc_widget_client_get_state(vc_w, &temp)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -554,7 +577,7 @@ int vc_widget_get_service_state(vc_service_state_e* state) /* get service state */ vc_service_state_e service_state; - if (0 != vc_widget_client_get_service_state(g_vc_w, &service_state)) { + if (0 != vc_widget_client_get_service_state(vc_w, &service_state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to get service state"); return VC_ERROR_OPERATION_FAILED; } @@ -575,12 +598,12 @@ int vc_widget_get_service_state(vc_service_state_e* state) return VC_ERROR_NONE; } -int vc_widget_set_foreground(bool value) +int vc_widget_set_foreground(vc_h vc_w, bool value) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Set foreground state"); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not valid"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -608,12 +631,12 @@ int vc_widget_set_foreground(bool value) return VC_ERROR_NONE; } -int vc_widget_is_format_supported(vc_cmd_format_e format, bool* support) +int vc_widget_is_format_supported(vc_h vc_w, vc_cmd_format_e format, bool* support) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Is command type supported"); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not valid"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -712,7 +735,7 @@ int vc_widget_start(bool stop_by_silence, vc_cmd_group_h vc_group) } else { int count = 0; do { - ret = vc_widget_dbus_request_start(g_vc_w->handle, stop_by_silence); + ret = vc_widget_dbus_request_start(getpid(), stop_by_silence); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start : %s", __vc_widget_get_error_code(ret)); @@ -798,7 +821,7 @@ int vc_widget_stop() int count = 0; do { - ret = vc_widget_dbus_request_stop(g_vc_w->handle); + ret = vc_widget_dbus_request_stop(getpid()); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request stop : %s", __vc_widget_get_error_code(ret)); @@ -819,12 +842,12 @@ int vc_widget_stop() } #endif -int vc_widget_cancel() +int vc_widget_cancel(vc_h vc_w) { SLOG(LOG_DEBUG, TAG_VCW, "===== [Widget] Cancel Recognition"); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); @@ -841,7 +864,7 @@ int vc_widget_cancel() /* Check service state */ vc_service_state_e service_state = -1; - vc_widget_client_get_service_state(g_vc_w, &service_state); + vc_widget_client_get_service_state(vc_w, &service_state); if (service_state != VC_SERVICE_STATE_RECORDING && service_state != VC_SERVICE_STATE_PROCESSING) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Invalid State: service state is not 'RECORDING' or 'PROCESSING'"); SLOG(LOG_DEBUG, TAG_VCW, "====="); @@ -853,7 +876,7 @@ int vc_widget_cancel() int ret = -1; do { - ret = vc_widget_dbus_request_cancel(g_vc_w->handle); + ret = vc_widget_dbus_request_cancel(getpid()); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request cancel : %s", __vc_widget_get_error_code(ret)); @@ -877,17 +900,18 @@ int vc_widget_cancel() static Eina_Bool __vc_widget_notify_error(void *data) { + vc_h vc_w = (vc_h)data; vc_error_cb callback = NULL; void* user_data; int reason; - vc_widget_client_get_error_cb(g_vc_w, &callback, &user_data); - vc_widget_client_get_error(g_vc_w, &reason); + vc_widget_client_get_error_cb(vc_w, &callback, &user_data); + vc_widget_client_get_error(vc_w, &reason); if (NULL != callback) { - vc_widget_client_use_callback(g_vc_w); + vc_widget_client_use_callback(vc_w); callback(reason, user_data); - vc_widget_client_not_use_callback(g_vc_w); + vc_widget_client_not_use_callback(vc_w); SLOG(LOG_DEBUG, TAG_VCW, "[Error] callback is called"); } else { SLOG(LOG_WARN, TAG_VCW, "[WARNING] Error callback is null"); @@ -899,32 +923,47 @@ static Eina_Bool __vc_widget_notify_error(void *data) int __vc_widget_cb_error(int reason, int daemon_pid, char* msg) { vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { - SLOG(LOG_ERROR, TAG_VCW, "[WARNING] Invalid client"); - return -1; - } - /* check state */ - if (state != VC_STATE_READY) { - SLOG(LOG_ERROR, TAG_VCW, "[WARNING] not connected client yet"); - return -1; - } + GSList* client_list = vc_widget_client_get_client_list(); - if (VC_ERROR_SERVICE_RESET == reason) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] VC daemon reset"); + vc_widget_s *data = NULL; + vc_h vc_w = NULL; - vc_widget_client_set_state(g_vc_w, VC_STATE_INITIALIZED); - __vc_widget_notify_state_changed(g_vc_w); + int count = g_slist_length(client_list); + int i; + for (i = 0; i < count; i++) { + data = g_slist_nth_data(client_list, i); + if (NULL != data) { + vc_w = data->vc; - if (0 != vc_widget_prepare()) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to prepare"); - } - } + if (0 != vc_widget_client_get_state(vc_w, &state)) { + SLOG(LOG_ERROR, TAG_VCW, "[WARNING] Invalid client"); + return -1; + } - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Error reason(%d), msg(%s)", reason, msg); + /* check state */ + if (state != VC_STATE_READY) { + SLOG(LOG_ERROR, TAG_VCW, "[WARNING] not connected client yet"); + return -1; + } - vc_widget_client_set_error(g_vc_w, reason); - ecore_timer_add(0, __vc_widget_notify_error, g_vc_w); + if (VC_ERROR_SERVICE_RESET == reason) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] VC daemon reset"); + + vc_widget_client_set_state(vc_w, VC_STATE_INITIALIZED); + __vc_widget_notify_state_changed(vc_w); + + if (0 != vc_widget_prepare(vc_w)) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to prepare"); + } + } + + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Error reason(%d), msg(%s)", reason, msg); + + vc_widget_client_set_error(vc_w, reason); + ecore_timer_add(0, __vc_widget_notify_error, vc_w); + } + } return 0; } @@ -936,51 +975,60 @@ static Eina_Bool __vc_widget_start_recording(void *data) g_w_start_timer = NULL; } + int ret; + ret = vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_WIDGET); + if (0 != ret) + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to delete file, type(%d), ret(%d)", VC_COMMAND_TYPE_WIDGET, ret); + vc_widget_send_current_command_list_cb send_command_list_cb = NULL; void* send_command_user_data = NULL; vc_cmd_list_h vc_cmd_list = NULL; - int ret = vc_widget_client_get_send_command_list_cb(g_vc_w, &send_command_list_cb, &send_command_user_data); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCW, "[WARNING] Invalid client"); - return -1; - } - - if (NULL != send_command_list_cb) { - vc_widget_client_use_callback(g_vc_w); - send_command_list_cb(&vc_cmd_list, send_command_user_data); - vc_widget_client_not_use_callback(g_vc_w); - SLOG(LOG_DEBUG, TAG_VCW, "client result callback called"); - - } else { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] User show tooltip callback is NULL"); - } + GSList* client_list = vc_widget_client_get_client_list(); + vc_widget_s *widget_data = NULL; + vc_h vc_w = NULL; bool widget_command = false; - if (NULL != vc_cmd_list) { - vc_cmd_list_s* list = NULL; - list = (vc_cmd_list_s*)vc_cmd_list; - - ret = vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_WIDGET); - if (0 != ret) - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to delete file, type(%d), ret(%d)", VC_COMMAND_TYPE_WIDGET, ret); - - ret = vc_cmd_parser_save_file(getpid(), VC_COMMAND_TYPE_WIDGET, list->list, NULL); - if (0 == ret) { - /* widget command is valid */ - widget_command = true; - SLOG(LOG_DEBUG, TAG_VCW, "Widget command is valid"); - } else { - ret = VC_ERROR_OPERATION_FAILED; - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to save command group : %s", __vc_widget_get_error_code(ret)); + int count = g_slist_length(client_list); + int i; + for (i = 0; i < count; i++) { + widget_data = g_slist_nth_data(client_list, i); + if (NULL != widget_data) { + vc_w = widget_data->vc; + + vc_widget_client_get_send_command_list_cb(vc_w, &send_command_list_cb, &send_command_user_data); + + if (NULL != send_command_list_cb) { + vc_widget_client_use_callback(vc_w); + send_command_list_cb(&vc_cmd_list, send_command_user_data); + vc_widget_client_not_use_callback(vc_w); + SLOG(LOG_DEBUG, TAG_VCW, "client command list callback called"); + if (NULL != vc_cmd_list) { + vc_cmd_list_s* list = NULL; + list = (vc_cmd_list_s*)vc_cmd_list; + ret = vc_cmd_parser_save_file(getpid(), VC_COMMAND_TYPE_WIDGET, list->list, NULL); + if (0 == ret) { + /* widget command is valid */ + widget_command = true; + SLOG(LOG_DEBUG, TAG_VCW, "Widget command is valid"); + } else { + ret = VC_ERROR_OPERATION_FAILED; + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to save command group : %s", __vc_widget_get_error_code(ret)); + } + } + } else { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] User show tooltip callback is NULL"); + } } } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] command list (%d)", g_slist_length(((vc_cmd_list_s*)vc_cmd_list)->list)); + ret = -1; - int count = 0; + count = 0; while (0 != ret) { - ret = vc_widget_dbus_request_start_recording(g_vc_w->handle, widget_command); + ret = vc_widget_dbus_request_start_recording(getpid(), widget_command); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to request start recording to daemon : %s", __vc_widget_get_error_code(ret)); @@ -1002,25 +1050,36 @@ static Eina_Bool __vc_widget_start_recording(void *data) static Eina_Bool __vc_widget_notify_tooltip(void *data) { - if (NULL != g_w_tooltip_timer) { - ecore_timer_del(g_w_tooltip_timer); - g_w_tooltip_timer = NULL; - } + bool show = (bool)data; vc_widget_show_tooltip_cb callback; void* user_data; - bool show; - vc_widget_client_get_show_tooltip_cb(g_vc_w, &callback, &user_data); - vc_widget_client_get_show_tooltip(g_vc_w, &show); + GSList* client_list = vc_widget_client_get_client_list(); - if (NULL != callback) { - vc_widget_client_use_callback(g_vc_w); - callback(show, user_data); - vc_widget_client_not_use_callback(g_vc_w); - SLOG(LOG_DEBUG, TAG_VCW, "client result callback called"); - } else { - SLOG(LOG_WARN, TAG_VCW, "[WARNING] Show tooltip callback is NULL"); + vc_widget_s *widget_data = NULL; + vc_h vc_w = NULL; + + int count = g_slist_length(client_list); + int i; + for (i = 0; i < count; i++) { + widget_data = g_slist_nth_data(client_list, i); + if (NULL != widget_data) { + vc_w = widget_data->vc; + + vc_widget_client_set_show_tooltip(vc_w, show); + vc_widget_client_get_show_tooltip_cb(vc_w, &callback, &user_data); + vc_widget_client_get_show_tooltip(vc_w, &show); + + if (NULL != callback) { + vc_widget_client_use_callback(vc_w); + callback(show, user_data); + vc_widget_client_not_use_callback(vc_w); + SLOG(LOG_DEBUG, TAG_VCW, "client show tooltip callback called"); + } else { + SLOG(LOG_WARN, TAG_VCW, "[WARNING] Show tooltip callback is NULL"); + } + } } if (true == show) { @@ -1032,15 +1091,7 @@ static Eina_Bool __vc_widget_notify_tooltip(void *data) void __vc_widget_cb_show_tooltip(int pid, bool show) { - if (0 != vc_widget_client_get_handle(pid, &g_vc_w)) { - SLOG(LOG_ERROR, TAG_VCW, "Handle is not valid : pid(%d)", pid); - return; - } - - vc_widget_client_set_show_tooltip(g_vc_w, show); - g_w_tooltip_timer = ecore_timer_add(0, __vc_widget_notify_tooltip, NULL); - - return; + ecore_timer_add(0, __vc_widget_notify_tooltip, (void*)show); } static Eina_Bool __vc_widget_notify_result(void *data) @@ -1048,16 +1099,6 @@ static Eina_Bool __vc_widget_notify_result(void *data) char* temp_text; int event; vc_cmd_list_h vc_cmd_list = NULL; - - vc_result_cb callback = NULL; - void* user_data = NULL; - - vc_widget_client_get_result_cb(g_vc_w, &callback, &user_data); - if (NULL == callback) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Client result callback is NULL"); - return EINA_FALSE; - } - if (0 != vc_cmd_list_create(&vc_cmd_list)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create command list"); return EINA_FALSE; @@ -1065,15 +1106,37 @@ static Eina_Bool __vc_widget_notify_result(void *data) vc_info_parser_get_result(&temp_text, &event, NULL, getpid(), vc_cmd_list, false); - SLOG(LOG_INFO, TAG_VCW, "Result info : result text(%s) event(%d)", temp_text, event); + SLOG(LOG_DEBUG, TAG_VCW, "Result info : result text(%s) event(%d)", temp_text, event); + + vc_result_cb callback = NULL; + void* user_data = NULL; + + GSList* client_list = vc_widget_client_get_client_list(); + + vc_widget_s *widget_data = NULL; + vc_h vc_w = NULL; + + int count = g_slist_length(client_list); + int i; + for (i = 0; i < count; i++) { + widget_data = g_slist_nth_data(client_list, i); + if (NULL != widget_data) { + vc_w = widget_data->vc; + vc_widget_client_get_result_cb(vc_w, &callback, &user_data); + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Client result callback is NULL"); + return EINA_FALSE; + } - vc_cmd_print_list(vc_cmd_list); + vc_cmd_print_list(vc_cmd_list); - vc_widget_client_use_callback(g_vc_w); - callback(event, vc_cmd_list, temp_text, user_data); - vc_widget_client_not_use_callback(g_vc_w); + vc_widget_client_use_callback(vc_w); + callback(event, vc_cmd_list, temp_text, user_data); + vc_widget_client_not_use_callback(vc_w); - SLOG(LOG_INFO, TAG_VCW, "Widget result callback called"); + SLOG(LOG_DEBUG, TAG_VCW, "Widget result callback called"); + } + } /* Release result */ if (NULL != temp_text) free(temp_text); @@ -1095,55 +1158,78 @@ bool __vc_widget_cb_asr_result() char* temp_text; int event; vc_cmd_list_h vc_cmd_list = NULL; - - vc_asr_result_cb callback = NULL; - void* user_data = NULL; - - vc_widget_client_get_asr_result_cb(g_vc_w, &callback, &user_data); - if (NULL == callback) { - SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Client result callback is NULL"); - return EINA_FALSE; - } - if (0 != vc_cmd_list_create(&vc_cmd_list)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to create command list"); - return EINA_FALSE; + return false; } vc_info_parser_get_result(&temp_text, &event, NULL, -1, vc_cmd_list, false); - SLOG(LOG_DEBUG, TAG_VCW, "Result info : result text(%s) event(%d)", temp_text, event); - vc_widget_client_use_callback(g_vc_w); - bool ret = callback(event, temp_text, user_data); - vc_widget_client_not_use_callback(g_vc_w); + vc_asr_result_cb callback = NULL; + void* user_data = NULL; + + GSList* client_list = vc_widget_client_get_client_list(); + + vc_widget_s *data = NULL; + vc_h vc_w = NULL; + + bool consumed = false; + int count = g_slist_length(client_list); + int i; + for (i = 0; i < count; i++) { + data = g_slist_nth_data(client_list, i); + if (NULL != data) { + vc_w = data->vc; + bool enabled = false; + vc_widget_client_get_asr_result_enabled(vc_w, &enabled); + if (false == enabled) + continue; + + vc_widget_client_get_asr_result_cb(vc_w, &callback, &user_data); + if (NULL == callback) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Client result callback is NULL"); + continue; + } + + vc_widget_client_use_callback(vc_w); + consumed = callback(event, temp_text, user_data); + vc_widget_client_not_use_callback(vc_w); + if (true == consumed) + break; - SLOG(LOG_DEBUG, TAG_VCW, "Widget asr result callback called"); + SLOG(LOG_DEBUG, TAG_VCW, "Widget asr result callback called"); + } + } /* Release result */ if (NULL != temp_text) free(temp_text); vc_cmd_list_destroy(vc_cmd_list, true); - return ret; + return consumed; } static Eina_Bool __vc_widget_notify_state_changed(void *data) { + vc_h vc_w = (vc_h)data; + + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); + vc_state_changed_cb changed_callback = NULL; void* user_data; - vc_widget_client_get_state_changed_cb(g_vc_w, &changed_callback, &user_data); + vc_widget_client_get_state_changed_cb(vc_w, &changed_callback, &user_data); vc_state_e current_state; vc_state_e before_state; - vc_widget_client_get_before_state(g_vc_w, ¤t_state, &before_state); + vc_widget_client_get_before_state(vc_w, ¤t_state, &before_state); if (NULL != changed_callback) { - vc_widget_client_use_callback(g_vc_w); + vc_widget_client_use_callback(vc_w); changed_callback(before_state, current_state, user_data); - vc_widget_client_not_use_callback(g_vc_w); + vc_widget_client_not_use_callback(vc_w); SLOG(LOG_DEBUG, TAG_VCW, "State changed callback is called"); } else { SLOG(LOG_WARN, TAG_VCW, "[WARNING] State changed callback is null"); @@ -1152,13 +1238,14 @@ static Eina_Bool __vc_widget_notify_state_changed(void *data) return EINA_FALSE; } -int vc_widget_set_result_cb(vc_result_cb callback, void* user_data) +int vc_widget_set_result_cb(vc_h vc_w, vc_result_cb callback, void* user_data) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { return VC_ERROR_INVALID_STATE; } @@ -1168,15 +1255,16 @@ int vc_widget_set_result_cb(vc_result_cb callback, void* user_data) return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_result_cb(g_vc_w, callback, user_data); + vc_widget_client_set_result_cb(vc_w, callback, user_data); return 0; } -int vc_widget_unset_result_cb() +int vc_widget_unset_result_cb(vc_h vc_w) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1187,18 +1275,19 @@ int vc_widget_unset_result_cb() return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_result_cb(g_vc_w, NULL, NULL); + vc_widget_client_set_result_cb(vc_w, NULL, NULL); return 0; } -int vc_widget_set_show_tooltip_cb(vc_widget_show_tooltip_cb callback, void* user_data) +int vc_widget_set_show_tooltip_cb(vc_h vc_w, vc_widget_show_tooltip_cb callback, void* user_data) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1209,15 +1298,16 @@ int vc_widget_set_show_tooltip_cb(vc_widget_show_tooltip_cb callback, void* user return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_show_tooltip_cb(g_vc_w, callback, user_data); + vc_widget_client_set_show_tooltip_cb(vc_w, callback, user_data); return 0; } -int vc_widget_unset_show_tooltip_cb() +int vc_widget_unset_show_tooltip_cb(vc_h vc_w) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1228,15 +1318,16 @@ int vc_widget_unset_show_tooltip_cb() return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_show_tooltip_cb(g_vc_w, NULL, NULL); + vc_widget_client_set_show_tooltip_cb(vc_w, NULL, NULL); return 0; } -int vc_widget_set_send_current_command_list_cb(vc_widget_send_current_command_list_cb callback, void* user_data) +int vc_widget_set_send_current_command_list_cb(vc_h vc_w, vc_widget_send_current_command_list_cb callback, void* user_data) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1247,15 +1338,16 @@ int vc_widget_set_send_current_command_list_cb(vc_widget_send_current_command_li return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_send_command_list_cb(g_vc_w, callback, user_data); + vc_widget_client_set_send_command_list_cb(vc_w, callback, user_data); return 0; } -int vc_widget_unset_send_current_command_list_cb() +int vc_widget_unset_send_current_command_list_cb(vc_h vc_w) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1266,47 +1358,62 @@ int vc_widget_unset_send_current_command_list_cb() return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_send_command_list_cb(g_vc_w, NULL, NULL); + vc_widget_client_set_send_command_list_cb(vc_w, NULL, NULL); return 0; } int __vc_widget_cb_service_state(int state) { - vc_service_state_e current_state = (vc_service_state_e)state; - vc_service_state_e before_state; - vc_widget_client_get_service_state(g_vc_w, &before_state); + GSList* client_list = vc_widget_client_get_client_list(); - if (current_state == before_state) { - return 0; - } + vc_widget_s *data = NULL; + vc_h vc_w = NULL; - SLOG(LOG_DEBUG, TAG_VCW, "Service State changed : Before(%d) Current(%d)", - before_state, current_state); + int count = g_slist_length(client_list); + int i; + for (i = 0; i < count; i++) { + data = g_slist_nth_data(client_list, i); + if (NULL != data) { + vc_w = data->vc; - /* Save service state */ - vc_widget_client_set_service_state(g_vc_w, current_state); + vc_service_state_e current_state = (vc_service_state_e)state; + vc_service_state_e before_state; + vc_widget_client_get_service_state(vc_w, &before_state); - vc_service_state_changed_cb callback = NULL; - void* service_user_data = NULL; - vc_widget_client_get_service_state_changed_cb(g_vc_w, &callback, &service_user_data); + if (current_state == before_state) { + continue; + } - if (NULL != callback) { - vc_widget_client_use_callback(g_vc_w); - callback((vc_service_state_e)before_state, (vc_service_state_e)current_state, service_user_data); - vc_widget_client_not_use_callback(g_vc_w); - SLOG(LOG_DEBUG, TAG_VCW, "Service state changed callback is called"); - } else { - SLOG(LOG_WARN, TAG_VCW, "[WARNING] Service state changed callback is null"); + SLOG(LOG_DEBUG, TAG_VCW, "Service State changed : Before(%d) Current(%d)", + before_state, current_state); + + /* Save service state */ + vc_widget_client_set_service_state(vc_w, current_state); + + vc_service_state_changed_cb callback = NULL; + void* service_user_data = NULL; + vc_widget_client_get_service_state_changed_cb(vc_w, &callback, &service_user_data); + + if (NULL != callback) { + vc_widget_client_use_callback(vc_w); + callback((vc_service_state_e)before_state, (vc_service_state_e)current_state, service_user_data); + vc_widget_client_not_use_callback(vc_w); + SLOG(LOG_DEBUG, TAG_VCW, "Service state changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCW, "[WARNING] Service state changed callback is null"); + } + } } return 0; } -int vc_widget_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* user_data) +int vc_widget_set_service_state_changed_cb(vc_h vc_w, vc_service_state_changed_cb callback, void* user_data) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1317,15 +1424,16 @@ int vc_widget_set_service_state_changed_cb(vc_service_state_changed_cb callback, return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_service_state_changed_cb(g_vc_w, callback, user_data); + vc_widget_client_set_service_state_changed_cb(vc_w, callback, user_data); return 0; } -int vc_widget_unset_service_state_changed_cb() +int vc_widget_unset_service_state_changed_cb(vc_h vc_w) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1336,18 +1444,19 @@ int vc_widget_unset_service_state_changed_cb() return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_service_state_changed_cb(g_vc_w, NULL, NULL); + vc_widget_client_set_service_state_changed_cb(vc_w, NULL, NULL); return 0; } -int vc_widget_set_state_changed_cb(vc_state_changed_cb callback, void* user_data) +int vc_widget_set_state_changed_cb(vc_h vc_w, vc_state_changed_cb callback, void* user_data) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1358,15 +1467,16 @@ int vc_widget_set_state_changed_cb(vc_state_changed_cb callback, void* user_data return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_state_changed_cb(g_vc_w, callback, user_data); + vc_widget_client_set_state_changed_cb(vc_w, callback, user_data); return 0; } -int vc_widget_unset_state_changed_cb() +int vc_widget_unset_state_changed_cb(vc_h vc_w) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1377,18 +1487,19 @@ int vc_widget_unset_state_changed_cb() return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_state_changed_cb(g_vc_w, NULL, NULL); + vc_widget_client_set_state_changed_cb(vc_w, NULL, NULL); return 0; } -int vc_widget_set_asr_result_cb(vc_asr_result_cb callback, void* user_data) +int vc_widget_set_asr_result_cb(vc_h vc_w, vc_asr_result_cb callback, void* user_data) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1399,15 +1510,16 @@ int vc_widget_set_asr_result_cb(vc_asr_result_cb callback, void* user_data) return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_asr_result_cb(g_vc_w, callback, user_data); + vc_widget_client_set_asr_result_cb(vc_w, callback, user_data); return 0; } -int vc_widget_unset_asr_result_cb() +int vc_widget_unset_asr_result_cb(vc_h vc_w) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1418,18 +1530,19 @@ int vc_widget_unset_asr_result_cb() return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_asr_result_cb(g_vc_w, NULL, NULL); + vc_widget_client_set_asr_result_cb(vc_w, NULL, NULL); return 0; } -int vc_widget_set_current_language_changed_cb(vc_current_language_changed_cb callback, void* user_data) +int vc_widget_set_current_language_changed_cb(vc_h vc_w, vc_current_language_changed_cb callback, void* user_data) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1440,15 +1553,16 @@ int vc_widget_set_current_language_changed_cb(vc_current_language_changed_cb cal return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_current_lang_changed_cb(g_vc_w, callback, user_data); + vc_widget_client_set_current_lang_changed_cb(vc_w, callback, user_data); return 0; } -int vc_widget_unset_current_language_changed_cb() +int vc_widget_unset_current_language_changed_cb(vc_h vc_w) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1459,18 +1573,19 @@ int vc_widget_unset_current_language_changed_cb() return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_current_lang_changed_cb(g_vc_w, NULL, NULL); + vc_widget_client_set_current_lang_changed_cb(vc_w, NULL, NULL); return 0; } -int vc_widget_set_error_cb(vc_error_cb callback, void* user_data) +int vc_widget_set_error_cb(vc_h vc_w, vc_error_cb callback, void* user_data) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1481,15 +1596,16 @@ int vc_widget_set_error_cb(vc_error_cb callback, void* user_data) return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_error_cb(g_vc_w, callback, user_data); + vc_widget_client_set_error_cb(vc_w, callback, user_data); return 0; } -int vc_widget_unset_error_cb() +int vc_widget_unset_error_cb(vc_h vc_w) { + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; - if (0 != vc_widget_client_get_state(g_vc_w, &state)) { + if (0 != vc_widget_client_get_state(vc_w, &state)) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] A handle is not available"); return VC_ERROR_INVALID_STATE; } @@ -1500,7 +1616,7 @@ int vc_widget_unset_error_cb() return VC_ERROR_INVALID_STATE; } - vc_widget_client_set_error_cb(g_vc_w, NULL, NULL); + vc_widget_client_set_error_cb(vc_w, NULL, NULL); return 0; } diff --git a/client/vc_widget_client.c b/client/vc_widget_client.c index d32c23d..e2415a6 100644 --- a/client/vc_widget_client.c +++ b/client/vc_widget_client.c @@ -20,54 +20,14 @@ #include "voice_control_command.h" #include "voice_control_common.h" - -typedef struct { - /* base info */ - vc_h vc; - int pid; - int uid; /*<< unique id = pid + handle */ - int xid; /*<< main X window id */ - - vc_result_cb result_cb; - void* result_user_data; - vc_asr_result_cb asr_result_cb; - void* asr_result_user_data; - vc_error_cb error_cb; - void* error_user_data; - vc_service_state_changed_cb service_state_changed_cb; - void* service_state_changed_user_data; - vc_state_changed_cb state_changed_cb; - void* state_changed_user_data; - vc_widget_show_tooltip_cb show_tooltip_cb; - void* show_tooltip_user_data; - vc_current_language_changed_cb current_lang_changed_cb; - void* current_lang_changed_user_data; - - vc_widget_send_current_command_list_cb send_command_list_cb; - void* send_command_list_user_data; - - /* tooltip */ - bool show_tooltip; - - /* service state */ - vc_service_state_e service_state; - - /* state */ - vc_state_e before_state; - vc_state_e current_state; - - /* mutex */ - int cb_ref_count; - - /* error data */ - int reason; -} vc_widget_s; - - +/* Max number of handle */ +static const int g_max_handle = 999; +/* allocated handle */ +static int g_allocated_handle = 0; /* widget list */ static GSList *g_widget_list = NULL; -static vc_widget_s* __widget_get(vc_h vc) +vc_widget_s* widget_get(vc_h vc) { if (vc == NULL) { SLOG(LOG_WARN, TAG_VCW, "[WARNING] Input parameter is NULL"); @@ -94,6 +54,18 @@ static vc_widget_s* __widget_get(vc_h vc) return NULL; } +static int __client_generate_uid(int pid) +{ + g_allocated_handle++; + + if (g_allocated_handle > g_max_handle) { + g_allocated_handle = 1; + } + + /* generate uid, handle number should be smaller than 1000 */ + return pid * 1000 + g_allocated_handle; +} + int vc_widget_client_create(vc_h* vc) { vc_widget_s *widget = NULL; @@ -111,7 +83,7 @@ int vc_widget_client_create(vc_h* vc) return VC_ERROR_OUT_OF_MEMORY; } - temp->handle = getpid(); + temp->handle = __client_generate_uid(getpid()); /* initialize widget data */ widget->vc = temp; @@ -123,6 +95,7 @@ int vc_widget_client_create(vc_h* vc) widget->result_user_data = NULL; widget->asr_result_cb = NULL; widget->asr_result_user_data = NULL; + widget->asr_result_enabled = false; widget->service_state_changed_cb = NULL; widget->service_state_changed_user_data = NULL; widget->state_changed_cb = NULL; @@ -135,6 +108,8 @@ int vc_widget_client_create(vc_h* vc) widget->before_state = VC_STATE_INITIALIZED; widget->current_state = VC_STATE_INITIALIZED; + widget->conn_timer = NULL; + widget->cb_ref_count = 0; g_widget_list = g_slist_append(g_widget_list, widget); @@ -182,9 +157,14 @@ int vc_widget_client_destroy(vc_h vc) return -1; } +GSList* vc_widget_client_get_client_list() +{ + return g_widget_list; +} + bool vc_widget_client_is_valid(vc_h vc) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) { @@ -240,7 +220,7 @@ int vc_widget_client_get_handle(int uid, vc_h* vc) /* set/get callback function */ int vc_widget_client_set_result_cb(vc_h vc, vc_result_cb callback, void* user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -254,7 +234,7 @@ int vc_widget_client_set_result_cb(vc_h vc, vc_result_cb callback, void* user_da int vc_widget_client_get_result_cb(vc_h vc, vc_result_cb* callback, void** user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -266,9 +246,35 @@ int vc_widget_client_get_result_cb(vc_h vc, vc_result_cb* callback, void** user_ return 0; } +int vc_widget_client_set_asr_result_enabled(vc_h vc, bool enabled) +{ + vc_widget_s* widget = widget_get(vc); + + /* check handle */ + if (NULL == widget) + return VC_ERROR_INVALID_PARAMETER; + + widget->asr_result_enabled = enabled; + + return 0; +} + +int vc_widget_client_get_asr_result_enabled(vc_h vc, bool* enabled) +{ + vc_widget_s* widget = widget_get(vc); + + /* check handle */ + if (NULL == widget) + return VC_ERROR_INVALID_PARAMETER; + + *enabled = widget->asr_result_enabled; + + return 0; +} + int vc_widget_client_set_asr_result_cb(vc_h vc, vc_asr_result_cb callback, void* user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -282,7 +288,7 @@ int vc_widget_client_set_asr_result_cb(vc_h vc, vc_asr_result_cb callback, void* int vc_widget_client_get_asr_result_cb(vc_h vc, vc_asr_result_cb* callback, void** user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -296,7 +302,7 @@ int vc_widget_client_get_asr_result_cb(vc_h vc, vc_asr_result_cb* callback, void int vc_widget_client_set_service_state_changed_cb(vc_h vc, vc_service_state_changed_cb callback, void* user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -310,7 +316,7 @@ int vc_widget_client_set_service_state_changed_cb(vc_h vc, vc_service_state_chan int vc_widget_client_get_service_state_changed_cb(vc_h vc, vc_service_state_changed_cb* callback, void** user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -324,7 +330,7 @@ int vc_widget_client_get_service_state_changed_cb(vc_h vc, vc_service_state_chan int vc_widget_client_set_state_changed_cb(vc_h vc, vc_state_changed_cb callback, void* user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -338,7 +344,7 @@ int vc_widget_client_set_state_changed_cb(vc_h vc, vc_state_changed_cb callback, int vc_widget_client_get_state_changed_cb(vc_h vc, vc_state_changed_cb* callback, void** user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -352,7 +358,7 @@ int vc_widget_client_get_state_changed_cb(vc_h vc, vc_state_changed_cb* callback int vc_widget_client_set_show_tooltip_cb(vc_h vc, vc_widget_show_tooltip_cb callback, void* user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -366,7 +372,7 @@ int vc_widget_client_set_show_tooltip_cb(vc_h vc, vc_widget_show_tooltip_cb call int vc_widget_client_get_show_tooltip_cb(vc_h vc, vc_widget_show_tooltip_cb* callback, void** user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -380,7 +386,7 @@ int vc_widget_client_get_show_tooltip_cb(vc_h vc, vc_widget_show_tooltip_cb* cal int vc_widget_client_set_current_lang_changed_cb(vc_h vc, vc_current_language_changed_cb callback, void* user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -394,7 +400,7 @@ int vc_widget_client_set_current_lang_changed_cb(vc_h vc, vc_current_language_ch int vc_widget_client_get_current_lang_changed_cb(vc_h vc, vc_current_language_changed_cb* callback, void** user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -408,7 +414,7 @@ int vc_widget_client_get_current_lang_changed_cb(vc_h vc, vc_current_language_ch int vc_widget_client_set_error_cb(vc_h vc, vc_error_cb callback, void* user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -422,7 +428,7 @@ int vc_widget_client_set_error_cb(vc_h vc, vc_error_cb callback, void* user_data int vc_widget_client_get_error_cb(vc_h vc, vc_error_cb* callback, void** user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -436,7 +442,7 @@ int vc_widget_client_get_error_cb(vc_h vc, vc_error_cb* callback, void** user_da int vc_widget_client_set_send_command_list_cb(vc_h vc, vc_widget_send_current_command_list_cb callback, void* user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -450,7 +456,7 @@ int vc_widget_client_set_send_command_list_cb(vc_h vc, vc_widget_send_current_co int vc_widget_client_get_send_command_list_cb(vc_h vc, vc_widget_send_current_command_list_cb* callback, void** user_data) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -466,7 +472,7 @@ int vc_widget_client_get_send_command_list_cb(vc_h vc, vc_widget_send_current_co /* set/get option */ int vc_widget_client_set_service_state(vc_h vc, vc_service_state_e state) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -479,7 +485,7 @@ int vc_widget_client_set_service_state(vc_h vc, vc_service_state_e state) int vc_widget_client_get_service_state(vc_h vc, vc_service_state_e* state) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -493,7 +499,7 @@ int vc_widget_client_get_service_state(vc_h vc, vc_service_state_e* state) int vc_widget_client_set_state(vc_h vc, vc_state_e state) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -507,7 +513,7 @@ int vc_widget_client_set_state(vc_h vc, vc_state_e state) int vc_widget_client_get_state(vc_h vc, vc_state_e* state) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -541,7 +547,7 @@ int vc_widget_client_get_state_by_uid(int uid, vc_state_e* state) int vc_widget_client_get_before_state(vc_h vc, vc_state_e* state, vc_state_e* before_state) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -555,7 +561,7 @@ int vc_widget_client_get_before_state(vc_h vc, vc_state_e* state, vc_state_e* be int vc_widget_client_set_xid(vc_h vc, int xid) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -568,7 +574,7 @@ int vc_widget_client_set_xid(vc_h vc, int xid) int vc_widget_cilent_get_xid(vc_h vc, int* xid) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -581,7 +587,7 @@ int vc_widget_cilent_get_xid(vc_h vc, int* xid) int vc_widget_client_set_error(vc_h vc, int reason) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -594,7 +600,7 @@ int vc_widget_client_set_error(vc_h vc, int reason) int vc_widget_client_get_error(vc_h vc, int* reason) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -607,7 +613,7 @@ int vc_widget_client_get_error(vc_h vc, int* reason) int vc_widget_client_set_show_tooltip(vc_h vc, bool show) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -620,7 +626,7 @@ int vc_widget_client_set_show_tooltip(vc_h vc, bool show) int vc_widget_client_get_show_tooltip(vc_h vc, bool* show) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -638,7 +644,7 @@ int vc_widget_client_get_count() int vc_widget_client_use_callback(vc_h vc) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) @@ -650,7 +656,7 @@ int vc_widget_client_use_callback(vc_h vc) int vc_widget_client_not_use_callback(vc_h vc) { - vc_widget_s* widget = __widget_get(vc); + vc_widget_s* widget = widget_get(vc); /* check handle */ if (NULL == widget) diff --git a/client/vc_widget_client.h b/client/vc_widget_client.h index ca2dc90..b5c9633 100644 --- a/client/vc_widget_client.h +++ b/client/vc_widget_client.h @@ -26,6 +26,51 @@ extern "C" { #endif +typedef struct { + /* base info */ + vc_h vc; + int pid; + int uid; /*<< unique id = pid + handle */ + int xid; /*<< main X window id */ + + vc_result_cb result_cb; + void* result_user_data; + vc_asr_result_cb asr_result_cb; + void* asr_result_user_data; + bool asr_result_enabled; + vc_error_cb error_cb; + void* error_user_data; + vc_service_state_changed_cb service_state_changed_cb; + void* service_state_changed_user_data; + vc_state_changed_cb state_changed_cb; + void* state_changed_user_data; + vc_widget_show_tooltip_cb show_tooltip_cb; + void* show_tooltip_user_data; + vc_current_language_changed_cb current_lang_changed_cb; + void* current_lang_changed_user_data; + + vc_widget_send_current_command_list_cb send_command_list_cb; + void* send_command_list_user_data; + + /* tooltip */ + bool show_tooltip; + + /* service state */ + vc_service_state_e service_state; + + /* state */ + vc_state_e before_state; + vc_state_e current_state; + + Ecore_Timer* conn_timer; + + /* mutex */ + int cb_ref_count; + + /* error data */ + int reason; +} vc_widget_s; + /* * Common function */ @@ -39,6 +84,10 @@ bool vc_widget_client_is_valid_by_uid(int uid); int vc_widget_client_get_handle(int uid, vc_h* vc); +vc_widget_s* widget_get(vc_h vc); + +GSList* vc_widget_client_get_client_list(); + /* * set/get callback function */ @@ -103,6 +152,10 @@ int vc_widget_client_set_show_tooltip(vc_h vc, bool show); int vc_widget_client_get_show_tooltip(vc_h vc, bool* show); +int vc_widget_client_set_asr_result_enabled(vc_h vc, bool enabled); + +int vc_widget_client_get_asr_result_enabled(vc_h vc, bool* enabled); + /* utils */ int vc_widget_client_get_count(); diff --git a/include/voice_control_widget.h b/include/voice_control_widget.h index 03b6c89..510eb20 100644 --- a/include/voice_control_widget.h +++ b/include/voice_control_widget.h @@ -23,6 +23,7 @@ #include #include +typedef struct vc_s *vc_h; /** * @addtogroup VOICE_CONTROL_WIDGET @@ -88,7 +89,7 @@ typedef void (*vc_widget_send_current_command_list_cb)(vc_cmd_list_h* vc_cmd_lis * * @see vc_widget_deinitialize() */ -int vc_widget_initialize(); +int vc_widget_initialize(vc_h* vc); /** * @brief Deinitialize voice control for widget. @@ -102,7 +103,7 @@ int vc_widget_initialize(); * * @see vc_widget_initialize() */ -int vc_widget_deinitialize(); +int vc_widget_deinitialize(vc_h vc); /** * @brief Connects the voice control service asynchronously. @@ -119,7 +120,7 @@ int vc_widget_deinitialize(); * * @see vc_widget_unprepare() */ -int vc_widget_prepare(); +int vc_widget_prepare(vc_h vc); /** * @brief Disconnects the voice control service. @@ -136,7 +137,7 @@ int vc_widget_prepare(); * * @see vc_widget_prepare() */ -int vc_widget_unprepare(); +int vc_widget_unprepare(vc_h vc); /** * @brief Retrieves all supported languages using callback function. @@ -157,7 +158,7 @@ int vc_widget_unprepare(); * @see vc_supported_language_cb() * @see vc_widget_get_current_language() */ -int vc_widget_foreach_supported_languages(vc_supported_language_cb callback, void* user_data); +int vc_widget_foreach_supported_languages(vc_h vc, vc_supported_language_cb callback, void* user_data); /** * @brief Gets current language set by user. @@ -180,7 +181,7 @@ int vc_widget_foreach_supported_languages(vc_supported_language_cb callback, voi * * @see vc_widget_foreach_supported_languages() */ -int vc_widget_get_current_language(char** language); +int vc_widget_get_current_language(vc_h vc, char** language); /** * @brief Gets current state of voice control widget. @@ -199,7 +200,7 @@ int vc_widget_get_current_language(char** language); * @see vc_widget_set_state_changed_cb() * @see vc_widget_unset_state_changed_cb() */ -int vc_widget_get_state(vc_state_e* state); +int vc_widget_get_state(vc_h vc, vc_state_e* state); /** * @brief Gets current state of voice control service. @@ -217,7 +218,7 @@ int vc_widget_get_state(vc_state_e* state); * @see vc_set_service_state_changed_cb() * @see vc_unset_service_state_changed_cb() */ -int vc_widget_get_service_state(vc_service_state_e* state); +int vc_widget_get_service_state(vc_h vc, vc_service_state_e* state); /** * @brief Checks whether the command format is supported. @@ -234,7 +235,7 @@ int vc_widget_get_service_state(vc_service_state_e* state); * * @pre The state should be #VC_STATE_READY. */ -int vc_widget_is_command_format_supported(vc_cmd_format_e format, bool* support); +int vc_widget_is_command_format_supported(vc_h vc, vc_cmd_format_e format, bool* support); /** @@ -251,7 +252,7 @@ int vc_widget_is_command_format_supported(vc_cmd_format_e format, bool* support) * * @pre The state should be #VC_STATE_READY. */ -int vc_widget_set_foreground(bool value); +int vc_widget_set_foreground(vc_h vc, bool value); /** * @brief Cancels recognition. @@ -272,7 +273,7 @@ int vc_widget_set_foreground(bool value); * @see vc_widget_stop() * @see vc_state_changed_cb() */ -int vc_widget_cancel(); +int vc_widget_cancel(vc_h vc); /** * @brief Registers a callback function for getting recognition result. @@ -291,7 +292,7 @@ int vc_widget_cancel(); * @see vc_widget_result_cb() * @see vc_widget_unset_result_cb() */ -int vc_widget_set_result_cb(vc_result_cb callback, void* user_data); +int vc_widget_set_result_cb(vc_h vc, vc_result_cb callback, void* user_data); /** @@ -307,7 +308,7 @@ int vc_widget_set_result_cb(vc_result_cb callback, void* user_data); * * @see vc_widget_set_result_cb() */ -int vc_widget_unset_result_cb(); +int vc_widget_unset_result_cb(vc_h vc); /** * @brief Registers a callback function for showing or hiding tooltip. @@ -326,7 +327,7 @@ int vc_widget_unset_result_cb(); * @see vc_widget_show_tooltip_cb() * @see vc_widget_unset_show_tooltip_cb() */ -int vc_widget_set_show_tooltip_cb(vc_widget_show_tooltip_cb callback, void* user_data); +int vc_widget_set_show_tooltip_cb(vc_h vc, vc_widget_show_tooltip_cb callback, void* user_data); /** * @brief Unregisters the callback function. @@ -341,7 +342,7 @@ int vc_widget_set_show_tooltip_cb(vc_widget_show_tooltip_cb callback, void* user * * @see vc_widget_set_show_tooltip_cb() */ -int vc_widget_unset_show_tooltip_cb(); +int vc_widget_unset_show_tooltip_cb(vc_h vc); /** * @brief Registers a callback function for setting current command. @@ -360,7 +361,7 @@ int vc_widget_unset_show_tooltip_cb(); * @see vc_widget_send_current_command_list_cb() * @see vc_widget_unset_send_current_command_list_cb() */ -int vc_widget_set_send_current_command_list_cb(vc_widget_send_current_command_list_cb callback, void* user_data); +int vc_widget_set_send_current_command_list_cb(vc_h vc, vc_widget_send_current_command_list_cb callback, void* user_data); /** * @brief Unregisters the callback function. @@ -375,7 +376,7 @@ int vc_widget_set_send_current_command_list_cb(vc_widget_send_current_command_li * * @see vc_widget_set_send_current_command_list_cb() */ -int vc_widget_unset_send_current_command_list_cb(); +int vc_widget_unset_send_current_command_list_cb(vc_h vc); /** * @brief Registers a callback function to be called when service state is changed. @@ -394,7 +395,7 @@ int vc_widget_unset_send_current_command_list_cb(); * @see vc_service_state_changed_cb() * @see vc_widget_unset_service_state_changed_cb() */ -int vc_widget_set_service_state_changed_cb(vc_service_state_changed_cb callback, void* user_data); +int vc_widget_set_service_state_changed_cb(vc_h vc, vc_service_state_changed_cb callback, void* user_data); /** * @brief Unregisters the callback function. @@ -409,7 +410,7 @@ int vc_widget_set_service_state_changed_cb(vc_service_state_changed_cb callback, * * @see vc_widget_set_service_state_changed_cb() */ -int vc_widget_unset_service_state_changed_cb(); +int vc_widget_unset_service_state_changed_cb(vc_h vc); /** * @brief Registers a callback function for getting state changed. @@ -429,7 +430,7 @@ int vc_widget_unset_service_state_changed_cb(); * @see vc_state_changed_cb() * @see vc_widget_unset_state_changed_cb() */ -int vc_widget_set_state_changed_cb(vc_state_changed_cb callback, void* user_data); +int vc_widget_set_state_changed_cb(vc_h vc, vc_state_changed_cb callback, void* user_data); /** * @brief Unregisters the callback function. @@ -444,7 +445,7 @@ int vc_widget_set_state_changed_cb(vc_state_changed_cb callback, void* user_data * * @see vc_widget_set_state_changed_cb() */ -int vc_widget_unset_state_changed_cb(); +int vc_widget_unset_state_changed_cb(vc_h vc); /** * @brief Registers a callback function to be called when current language is changed. @@ -464,7 +465,7 @@ int vc_widget_unset_state_changed_cb(); * @see vc_current_language_changed_cb() * @see vc_widget_unset_current_language_changed_cb() */ -int vc_widget_set_current_language_changed_cb(vc_current_language_changed_cb callback, void* user_data); +int vc_widget_set_current_language_changed_cb(vc_h vc, vc_current_language_changed_cb callback, void* user_data); /** * @brief Unregisters the callback function. @@ -479,7 +480,7 @@ int vc_widget_set_current_language_changed_cb(vc_current_language_changed_cb cal * * @see vc_widget_set_current_language_changed_cb() */ -int vc_widget_unset_current_language_changed_cb(); +int vc_widget_unset_current_language_changed_cb(vc_h vc); /** * @brief Registers a callback function for an error occurred. @@ -499,7 +500,7 @@ int vc_widget_unset_current_language_changed_cb(); * @see vc_error_cb() * @see vc_widget_unset_error_cb() */ -int vc_widget_set_error_cb(vc_error_cb callback, void* user_data); +int vc_widget_set_error_cb(vc_h vc, vc_error_cb callback, void* user_data); /** * @brief Unregisters the callback function. @@ -514,7 +515,7 @@ int vc_widget_set_error_cb(vc_error_cb callback, void* user_data); * * @see vc_widget_set_error_cb() */ -int vc_widget_unset_error_cb(); +int vc_widget_unset_error_cb(vc_h vc); /** * @brief Sets option for obtain ASR result as dictation via result callback. @@ -534,7 +535,7 @@ int vc_widget_unset_error_cb(); * @pre The state should be #VC_STATE_READY. * */ -int vc_widget_enable_asr_result(bool enable); +int vc_widget_enable_asr_result(vc_h vc, bool enable); /** * @brief Registers a callback function for an asr result. @@ -553,7 +554,7 @@ int vc_widget_enable_asr_result(bool enable); * @see vc_widget_enable_asr_result() * @see vc_widget_unset_asr_result_cb() */ -int vc_widget_set_asr_result_cb(vc_asr_result_cb callback, void* user_data); +int vc_widget_set_asr_result_cb(vc_h vc, vc_asr_result_cb callback, void* user_data); /** * @brief Unregisters the callback function. @@ -566,7 +567,7 @@ int vc_widget_set_asr_result_cb(vc_asr_result_cb callback, void* user_data); * * @see vc_widget_set_asr_result_cb() */ -int vc_widget_unset_asr_result_cb(); +int vc_widget_unset_asr_result_cb(vc_h vc); #ifdef __cplusplus } diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 7d0f348..55b75f8 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -341,7 +341,7 @@ int vcdc_send_asr_result(int pid, int cmd_type, bool* is_consumed) DBusMessage* result_msg; int result = 0; - result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); + result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 5000, &err); dbus_message_unref(msg); if (dbus_error_is_set(&err)) { diff --git a/server/vcd_server.c b/server/vcd_server.c index a452b68..4308f1e 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -2099,8 +2099,8 @@ int vcd_server_widget_initialize(int pid) /* check if pid is valid */ if (true == vcd_client_widget_is_available(pid)) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] The pid is already exist"); - return VCD_ERROR_INVALID_PARAMETER; + SLOG(LOG_WARN, TAG_VCD, "[Server WARNING] The pid is already exist"); + return VCD_ERROR_NONE; } /* Add client information to client manager */ -- 2.7.4 From c03e6c1e5c835f3a211efaa4cde12be2dbee4f69 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 2 Jan 2017 18:49:02 +0900 Subject: [PATCH 07/16] Add defence code when widget command is not registered Change-Id: Iebb921fc11044f46b0075d90c9da200c106ff539 Signed-off-by: Wonnam Jang (cherry picked from commit 69e68b702425f2d1f74151d107c1d43623bd4606) --- client/vc_widget.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/vc_widget.c b/client/vc_widget.c index 3989c99..9d3f835 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -1007,6 +1007,11 @@ static Eina_Bool __vc_widget_start_recording(void *data) if (NULL != vc_cmd_list) { vc_cmd_list_s* list = NULL; list = (vc_cmd_list_s*)vc_cmd_list; + if (NULL == list || NULL == list->list) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] No registered commands from send_command_list_cb"); + break; + } + ret = vc_cmd_parser_save_file(getpid(), VC_COMMAND_TYPE_WIDGET, list->list, NULL); if (0 == ret) { /* widget command is valid */ @@ -1023,7 +1028,10 @@ static Eina_Bool __vc_widget_start_recording(void *data) } } - SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] command list (%d)", g_slist_length(((vc_cmd_list_s*)vc_cmd_list)->list)); + if (NULL != vc_cmd_list) + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] command list (%d)", g_slist_length(((vc_cmd_list_s*)vc_cmd_list)->list)); + else + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] command list (NULL)"); ret = -1; count = 0; @@ -1048,6 +1056,7 @@ static Eina_Bool __vc_widget_start_recording(void *data) return EINA_FALSE; } + static Eina_Bool __vc_widget_notify_tooltip(void *data) { bool show = (bool)data; -- 2.7.4 From 9d64cddb8e8e894cdc68ceb16b980d1294b39142 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Tue, 3 Jan 2017 11:39:25 +0900 Subject: [PATCH 08/16] Add null checker for vc handle Change-Id: I35c95b0f1dbcdc9a77943d495fa8d7c434ef9d34 Signed-off-by: sooyeon.kim (cherry picked from commit 56d901b6741cf34b6dec4cba51d9b8020106f829) --- client/vc_widget.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/client/vc_widget.c b/client/vc_widget.c index 3989c99..3143799 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -1240,6 +1240,11 @@ static Eina_Bool __vc_widget_notify_state_changed(void *data) int vc_widget_set_result_cb(vc_h vc_w, vc_result_cb callback, void* user_data) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; @@ -1262,6 +1267,11 @@ int vc_widget_set_result_cb(vc_h vc_w, vc_result_cb callback, void* user_data) int vc_widget_unset_result_cb(vc_h vc_w) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1282,6 +1292,11 @@ int vc_widget_unset_result_cb(vc_h vc_w) int vc_widget_set_show_tooltip_cb(vc_h vc_w, vc_widget_show_tooltip_cb callback, void* user_data) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; @@ -1305,6 +1320,11 @@ int vc_widget_set_show_tooltip_cb(vc_h vc_w, vc_widget_show_tooltip_cb callback, int vc_widget_unset_show_tooltip_cb(vc_h vc_w) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1325,6 +1345,11 @@ int vc_widget_unset_show_tooltip_cb(vc_h vc_w) int vc_widget_set_send_current_command_list_cb(vc_h vc_w, vc_widget_send_current_command_list_cb callback, void* user_data) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1345,6 +1370,11 @@ int vc_widget_set_send_current_command_list_cb(vc_h vc_w, vc_widget_send_current int vc_widget_unset_send_current_command_list_cb(vc_h vc_w) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1411,6 +1441,11 @@ int __vc_widget_cb_service_state(int state) int vc_widget_set_service_state_changed_cb(vc_h vc_w, vc_service_state_changed_cb callback, void* user_data) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1431,6 +1466,11 @@ int vc_widget_set_service_state_changed_cb(vc_h vc_w, vc_service_state_changed_c int vc_widget_unset_service_state_changed_cb(vc_h vc_w) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1451,6 +1491,11 @@ int vc_widget_unset_service_state_changed_cb(vc_h vc_w) int vc_widget_set_state_changed_cb(vc_h vc_w, vc_state_changed_cb callback, void* user_data) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; @@ -1474,6 +1519,11 @@ int vc_widget_set_state_changed_cb(vc_h vc_w, vc_state_changed_cb callback, void int vc_widget_unset_state_changed_cb(vc_h vc_w) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1494,6 +1544,11 @@ int vc_widget_unset_state_changed_cb(vc_h vc_w) int vc_widget_set_asr_result_cb(vc_h vc_w, vc_asr_result_cb callback, void* user_data) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; @@ -1517,6 +1572,11 @@ int vc_widget_set_asr_result_cb(vc_h vc_w, vc_asr_result_cb callback, void* user int vc_widget_unset_asr_result_cb(vc_h vc_w) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1537,6 +1597,11 @@ int vc_widget_unset_asr_result_cb(vc_h vc_w) int vc_widget_set_current_language_changed_cb(vc_h vc_w, vc_current_language_changed_cb callback, void* user_data) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; @@ -1560,6 +1625,11 @@ int vc_widget_set_current_language_changed_cb(vc_h vc_w, vc_current_language_cha int vc_widget_unset_current_language_changed_cb(vc_h vc_w) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { @@ -1580,6 +1650,11 @@ int vc_widget_unset_current_language_changed_cb(vc_h vc_w) int vc_widget_set_error_cb(vc_h vc_w, vc_error_cb callback, void* user_data) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); if (NULL == callback) return VC_ERROR_INVALID_PARAMETER; @@ -1603,6 +1678,11 @@ int vc_widget_set_error_cb(vc_h vc_w, vc_error_cb callback, void* user_data) int vc_widget_unset_error_cb(vc_h vc_w) { + if (NULL == vc_w) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] uid (%d)", vc_w->handle); vc_state_e state; if (0 != vc_widget_client_get_state(vc_w, &state)) { -- 2.7.4 From c15f5dbfbd7112c6f3b56ce566921d0892b90b0e Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Tue, 3 Jan 2017 15:14:06 +0900 Subject: [PATCH 09/16] Fix invalid memory access Change-Id: Ic4620f58cbc31c157771a4bc21696d7489fb8dae (cherry picked from commit c5bbe2e34202f7242ab614616060ccb408d707cc) --- client/vc_widget.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/client/vc_widget.c b/client/vc_widget.c index 0f746be..98843fc 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -1028,11 +1028,6 @@ static Eina_Bool __vc_widget_start_recording(void *data) } } - if (NULL != vc_cmd_list) - SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] command list (%d)", g_slist_length(((vc_cmd_list_s*)vc_cmd_list)->list)); - else - SLOG(LOG_DEBUG, TAG_VCW, "[CHECK] command list (NULL)"); - ret = -1; count = 0; while (0 != ret) { -- 2.7.4 From 7ad17f06545f11d99c867fa7c3bccf632b51a9b2 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Wed, 4 Jan 2017 17:13:48 +0900 Subject: [PATCH 10/16] Change command collect timing Change-Id: I974664edf6c44dd7148b46c249bef55549e875bb (cherry picked from commit 705d95e146a43803ff7184b5ee087a607ef8a6f9) --- server/vcd_client_data.c | 12 +++++++++++- server/vcd_server.c | 13 ------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 562b77a..010bde0 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -444,6 +444,16 @@ int vcd_client_foreach_command(client_foreach_command_cb callback, void* user_da return VCD_ERROR_INVALID_PARAMETER; } + if (0 != vcd_client_command_collect_command()) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command"); + return VCD_ERROR_OPERATION_FAILED; + } + + if (0 >= vcd_client_get_length()) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] No current command"); + return VCD_ERROR_OPERATION_FAILED; + } + // int id_count = 1; GSList *iter = NULL; vc_cmd_s* temp_cmd; @@ -1380,4 +1390,4 @@ int vcd_client_widget_get_asr_result_enabled(int pid, bool* enable) *enable = info->asr_result_enabled; return 0; -} \ No newline at end of file +} diff --git a/server/vcd_server.c b/server/vcd_server.c index cd4088d..dcefbac 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1451,19 +1451,6 @@ static int __start_internal_recognition() { int ret; - /* 2. Get commands */ - ret = vcd_client_command_collect_command(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to collect command : %d", ret); - return VCD_ERROR_OPERATION_FAILED; - } - - ret = vcd_client_get_length(); - if (0 == ret) { - SLOG(LOG_WARN, TAG_VCD, "[Server WARNIING] No current command : %d", ret); - return VCD_ERROR_OPERATION_FAILED; - } - /* 3. Set command to engine */ ret = vcd_engine_set_commands(); if (0 != ret) { -- 2.7.4 From 6ecf371b926ff2c34ff24dec815ea6b366be4cb8 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Thu, 12 Jan 2017 14:46:35 +0900 Subject: [PATCH 11/16] Fix invalid command collect logic Change-Id: Icad239763cd78701585fa546dd215a4b2cb194da --- server/vcd_server.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/vcd_server.c b/server/vcd_server.c index dcefbac..9feed7e 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1451,6 +1451,11 @@ static int __start_internal_recognition() { int ret; + if (0 != vcd_client_command_collect_command()) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to collect command"); + return VCD_ERROR_OPERATION_FAILED; + } + /* 3. Set command to engine */ ret = vcd_engine_set_commands(); if (0 != ret) { -- 2.7.4 From 72267b8ae0a6b0871a42de2b41866b2a6c3532cd Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Wed, 18 Jan 2017 16:52:22 +0900 Subject: [PATCH 12/16] Fix restore logic Change-Id: Icbad13bd24587457356be75b42c3e70091235744 (cherry picked from commit 447469dd23fdec619c71acf8a1885e1b17e2a44b) --- client/vc_dbus.c | 12 ++++++++++++ client/vc_mgr_dbus.c | 13 +++++++++++++ client/vc_widget_dbus.c | 13 +++++++++++++ server/vcd_recorder.c | 4 ++-- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/client/vc_dbus.c b/client/vc_dbus.c index f7af5f9..27f4d54 100644 --- a/client/vc_dbus.c +++ b/client/vc_dbus.c @@ -162,6 +162,18 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) { SLOG(LOG_DEBUG, TAG_VCC, "===== Owner Changed"); + DBusError err; + dbus_error_init(&err); + /* remove a rule for daemon error */ + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + dbus_bus_remove_match(g_conn_listener, rule_err, &err); + dbus_connection_flush(g_conn_listener); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message); + dbus_error_free(&err); + } __vc_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); SLOG(LOG_DEBUG, TAG_VCC, "====="); SLOG(LOG_DEBUG, TAG_VCC, " "); diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index 2349eea..7133c92 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -465,6 +465,19 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) { SLOG(LOG_DEBUG, TAG_VCM, "===== Owner Changed"); + /* remove a rule for daemon error */ + DBusError err; + /* initialise the error value */ + dbus_error_init(&err); + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + dbus_bus_remove_match(g_m_conn_listener, rule_err, &err); + dbus_connection_flush(g_m_conn_listener); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message); + dbus_error_free(&err); + } __vc_mgr_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); SLOG(LOG_DEBUG, TAG_VCM, "====="); SLOG(LOG_DEBUG, TAG_VCM, " "); diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index 8ed3ff4..6e60acc 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -237,6 +237,19 @@ static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) { SLOG(LOG_DEBUG, TAG_VCW, "===== Owner Changed"); + DBusError err; + dbus_error_init(&err); + + /* remove a rule for daemon error */ + char rule_err[256] = {0, }; + snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", VC_SERVER_SERVICE_INTERFACE); + dbus_bus_remove_match(g_w_conn_listener, rule_err, &err); + dbus_connection_flush(g_w_conn_listener); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); + dbus_error_free(&err); + } __vc_widget_cb_error(VC_ERROR_SERVICE_RESET, -1, "Daemon Reset"); SLOG(LOG_DEBUG, TAG_VCW, "====="); SLOG(LOG_DEBUG, TAG_VCW, " "); diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 160ecec..307f75b 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -173,7 +173,7 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void if (0 == g_bt_extend_count % 5 && 0 != g_buffer_count) { const unsigned char input_data[2] = {SMART_CONTROL_EXTEND_CMD, 0x10 }; if (BT_ERROR_NONE != bt_hid_send_rc_command(NULL, input_data, sizeof(input_data))) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_send_rc_command(NULL, %s, %d)", input_data, sizeof(input_data)); + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_send_rc_command"); } else { SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Extend bt audio recorder"); } @@ -599,7 +599,7 @@ int vcd_recorder_start() started = true; break; } else if (BT_ERROR_NOW_IN_PROGRESS == ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_send_rc_command(NULL, %s, %d) : %d", input_data, sizeof(input_data), ret); + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail bt_hid_send_rc_command : %d", ret); usleep(50000); bt_retry++; } else { -- 2.7.4 From fdb034c336bc86ad0f237009a6ea5b4d6d26faf7 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Thu, 19 Jan 2017 17:29:18 +0900 Subject: [PATCH 13/16] Fix invalid volume when recorded data is NULL Change-Id: I64fddfbc492617daf1f9f512f66c1a91db00a87a (cherry picked from commit 304379bd6ce022e7bca0ed2ca71e9d01e6e2cd51) --- client/vc_mgr.c | 4 ++++ server/vcd_recorder.c | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 2001006..4560dff 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -1723,6 +1723,10 @@ int vc_mgr_start(bool exclusive_command_option) } } + g_volume_db = 0; + g_prev_volume_db = 0; + g_cur_volume_db = 0; + SLOG(LOG_DEBUG, TAG_VCM, "====="); SLOG(LOG_DEBUG, TAG_VCM, " "); diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 307f75b..4d3cb7e 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -514,10 +514,12 @@ static float get_volume_decibel(char* data, int size) count++; } - if (0 == count) - rms = 0.0; - else + if (0 == count) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] NULL data"); + rms = 1.0; + } else { rms = sqrt((float)square_sum/count); + } db = 20 * log10(rms/MAX_AMPLITUDE_MEAN_16); return db; -- 2.7.4 From 7714a8c2c1515ea0ae15e829b12099f5df6c8ad9 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Fri, 20 Jan 2017 14:32:04 +0900 Subject: [PATCH 14/16] Add a checker for dbus connection Change-Id: Ib525c09d3e780bfa7f31315b5db37ab408611a91 Signed-off-by: sooyeon.kim (cherry picked from commit 8dbf7eb488f86147a28dc18f97a42d4bf1234516) --- client/vc_widget_dbus.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index 6e60acc..56937b4 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -391,7 +391,7 @@ int vc_widget_dbus_close_connection() dbus_connection_unref(g_w_conn_sender); dbus_connection_unref(g_w_conn_listener); - + g_w_conn_sender = NULL; g_w_conn_listener = NULL; @@ -419,8 +419,21 @@ int vc_widget_dbus_reconnect() return 0; } +static int __dbus_check() +{ + if (NULL == g_w_conn_sender) { + SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); + return vc_widget_dbus_reconnect(); + } + return 0; +} + int vc_widget_dbus_request_hello() { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -461,6 +474,10 @@ int vc_widget_dbus_request_hello() int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -542,6 +559,10 @@ int vc_widget_dbus_request_initialize(int pid, int* service_state, int* daemon_p int vc_widget_dbus_request_finalize(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -614,6 +635,10 @@ int vc_widget_dbus_request_finalize(int pid) int vc_widget_dbus_request_start_recording(int pid, bool command) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -676,6 +701,10 @@ int vc_widget_dbus_request_start_recording(int pid, bool command) int vc_widget_dbus_set_foreground(int pid, bool value) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg = NULL; int tmp_value = 0; @@ -740,6 +769,10 @@ int vc_widget_dbus_set_foreground(int pid, bool value) int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -808,6 +841,10 @@ int vc_widget_dbus_request_enable_asr_result(int pid, bool enable) int vc_widget_dbus_request_start(int pid, int silence) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -873,6 +910,10 @@ int vc_widget_dbus_request_start(int pid, int silence) int vc_widget_dbus_request_stop(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -935,6 +976,10 @@ int vc_widget_dbus_request_stop(int pid) int vc_widget_dbus_request_cancel(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -993,4 +1038,4 @@ int vc_widget_dbus_request_cancel(int pid) } return result; -} \ No newline at end of file +} -- 2.7.4 From 7d3acf7119796b3e5fe2730336804d247ad33dfd Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Mon, 23 Jan 2017 15:58:03 +0900 Subject: [PATCH 15/16] Add foreground pid check logic Change-Id: I62f4d43f5adaf87377d998db4b4dbcc8e6534018 Signed-off-by: Kwangyoun Kim (cherry picked from commit 344f5d21211fca273d25226b0843de51a1d502d5) --- server/vcd_client_data.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ server/vcd_client_data.h | 1 + server/vcd_server.c | 3 +- 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 010bde0..9b2a00f 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -1391,3 +1391,80 @@ int vcd_client_widget_get_asr_result_enabled(int pid, bool* enable) return 0; } + +void vcd_client_update_foreground_pid() +{ + int tmp_pid = VC_RUNTIME_INFO_NO_FOREGROUND; + vcd_config_get_foreground(&tmp_pid); + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", tmp_pid); + + char appid[255] = {'\0',}; + GSList *iter = NULL; + vc_client_info_s *data = NULL; + + int count = g_slist_length(g_client_list); + int i; + + if (0 == count) { + SLOG(LOG_DEBUG, TAG_VCD, "No Client"); + } else { + iter = g_slist_nth(g_client_list, 0); + for (i = 0; i < count; i++) { + if (NULL == iter) + break; + + data = iter->data; + + if (NULL != data) { + SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, data->pid); + memset(appid, 0, 255); + aul_app_get_appid_bypid(data->pid, appid, sizeof(appid)); + int status = aul_app_get_status(appid); + if (status == STATUS_FOCUS) { + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", data->pid); + vcd_config_set_foreground(data->pid, true); + if (tmp_pid != data->pid) { + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid is different"); + } + return; + } + } + iter = g_slist_next(iter); + } + } + + widget_info_s *widget_data = NULL; + count = g_slist_length(g_widget_list); + + if (0 == count) { + SLOG(LOG_DEBUG, TAG_VCD, "No widget"); + } else { + iter = g_slist_nth(g_widget_list, 0); + for (i = 0; i < count; i++) { + if (NULL == iter) + break; + + widget_data = iter->data; + + if (NULL != widget_data) { + SLOG(LOG_DEBUG, TAG_VCD, "[%dth] pid(%d)", i, widget_data->pid); + memset(appid, 0, 255); + aul_app_get_appid_bypid(widget_data->pid, appid, sizeof(appid)); + int status = aul_app_get_status(appid); + if (status == STATUS_FOCUS) { + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", widget_data->pid); + vcd_config_set_foreground(widget_data->pid, true); + if (tmp_pid != widget_data->pid) { + SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid is changed"); + } + return; + } + } + iter = g_slist_next(iter); + } + } + + SLOG(LOG_INFO, TAG_VCD, "[INFO] No foreground"); + vcd_config_set_foreground(VC_RUNTIME_INFO_NO_FOREGROUND, true); + return; +} diff --git a/server/vcd_client_data.h b/server/vcd_client_data.h index d84ba3b..d38a8ba 100644 --- a/server/vcd_client_data.h +++ b/server/vcd_client_data.h @@ -152,6 +152,7 @@ int vcd_client_unset_exclusive_command(int pid); int vcd_client_save_client_info(); +void vcd_client_update_foreground_pid(); /* * widget API */ diff --git a/server/vcd_server.c b/server/vcd_server.c index 9feed7e..00f5792 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1526,11 +1526,12 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive vcd_client_set_recognition_mode(recognition_mode); if (false == exclusive_cmd) { + vcd_client_update_foreground_pid(); /* Notify show tooltip */ if (1 == vcd_config_get_command_type_enabled(VC_COMMAND_TYPE_WIDGET)) { int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) { - SLOG(LOG_DEBUG, TAG_VCD, "[Server] Request tooltip show and widget command"); + SLOG(LOG_INFO, TAG_VCD, "[Server] Request tooltip show and widget command"); ecore_timer_add(0, __vcd_request_show_tooltip, (void*)true); return 0; } -- 2.7.4 From 3403ee97db2fe169614e598cb8ac1f327774e768 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Tue, 24 Jan 2017 22:49:56 +0900 Subject: [PATCH 16/16] Fix invalid result Change-Id: I51cac04fe9e87c8b3e5fd9db73da3ada52660ef8 (cherry picked from commit 12fef272e3d75441860b0fd41c0607a747919506) --- client/vc_mgr_client.c | 5 ++++- common/vc_info_parser.c | 32 +++++++++++++++++++++++++++++--- server/vcd_server.c | 6 ++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/client/vc_mgr_client.c b/client/vc_mgr_client.c index 234d0d9..b3cf80d 100644 --- a/client/vc_mgr_client.c +++ b/client/vc_mgr_client.c @@ -798,8 +798,11 @@ int vc_mgr_client_set_all_result(vc_h vc, int event, const char* result_text) if (NULL != client->all_result_text) { free(client->all_result_text); + client->all_result_text = NULL; + } + if (NULL != result_text) { + client->all_result_text = strdup(result_text); } - client->all_result_text = strdup(result_text); return 0; } diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index f46f80a..da0ab55 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -286,11 +286,24 @@ int vc_info_parser_set_demandable_client(const char* filepath) int vc_info_parser_set_result(const char* result_text, int event, const char* msg, vc_cmd_list_h vc_cmd_list, bool exclusive) { - int ret = vc_db_insert_result(result_text, event, msg, vc_cmd_list, exclusive); + char* temp_text = NULL; + if (NULL == result_text) { + temp_text = strdup("#NULL"); + } else { + temp_text = strdup(result_text); + } + + int ret = vc_db_insert_result(temp_text, event, msg, vc_cmd_list, exclusive); if (0 != ret) { SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Insert db is failed, ret = %d", ret); } SLOG(LOG_DEBUG, vc_info_tag(), "[Success] Save result command file"); + + if (NULL != temp_text) { + free(temp_text); + temp_text = NULL; + } + return ret; } @@ -301,10 +314,23 @@ int vc_info_parser_get_result(char** result_text, int* event, char** result_mess return -1; } - int ret = vc_db_get_result(result_text, event, result_message, pid, vc_cmd_list, exclusive); + char* temp_text = NULL; + int ret = vc_db_get_result(&temp_text, event, result_message, pid, vc_cmd_list, exclusive); if (0 != ret) { SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Insert db is failed, ret = %d", ret); } + + if (!strcmp(temp_text, "#NULL")) { + *result_text = NULL; + } else { + *result_text = strdup(temp_text); + } + + if (NULL != temp_text) { + free(temp_text); + temp_text = NULL; + } + return ret; } @@ -670,4 +696,4 @@ int __vc_cmd_parser_print_commands(GSList* cmd_list) } return 0; -} \ No newline at end of file +} diff --git a/server/vcd_server.c b/server/vcd_server.c index 00f5792..c8b4169 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -641,9 +641,11 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int /* No result */ if (NULL != all_result) { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is no command : %s", all_result); - bool temp = vcd_client_manager_get_exclusive(); - vc_info_parser_set_result(all_result, event, msg, NULL, temp); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Engine result is NULL"); } + bool temp = vcd_client_manager_get_exclusive(); + vc_info_parser_set_result(all_result, event, msg, NULL, temp); int pid = vcd_client_widget_get_foreground_pid(); if (-1 != pid) { -- 2.7.4