From 5614bbd09b7fc3fc9ca7d2e635b58d09df6d87cc Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Fri, 17 Mar 2017 17:17:21 +0900 Subject: [PATCH 01/16] Get focused pid to set foreground Change-Id: I73848b36bb8472b1bcd4ec364607a27c22e84c63 Signed-off-by: Wonnam Jang --- server/vcd_client_data.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 9b2a00f..b033950 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -16,6 +16,7 @@ #include #include +#include #include "vcd_client_data.h" #include "vcd_config.h" @@ -1396,9 +1397,14 @@ 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',}; + int pid = VC_RUNTIME_INFO_NO_FOREGROUND; + int ret = aul_window_get_focused_pid(&pid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to get focused pid, ret(%d)", ret); + } + SLOG(LOG_INFO, TAG_VCD, "[INFO] Foreground pid (%d), Focused pid (%d)", tmp_pid, pid); + GSList *iter = NULL; vc_client_info_s *data = NULL; @@ -1417,10 +1423,7 @@ void vcd_client_update_foreground_pid() 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) { + if (pid == data->pid) { SLOG(LOG_INFO, TAG_VCD, "[INFO] foreground pid (%d)", data->pid); vcd_config_set_foreground(data->pid, true); if (tmp_pid != data->pid) { @@ -1448,10 +1451,7 @@ void vcd_client_update_foreground_pid() 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) { + if (pid == widget_data->pid) { 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) { -- 2.7.4 From e0e37ff8cf6b14dcc68581e7f0294eb88eb8cc75 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Mon, 13 Mar 2017 16:00:56 +0900 Subject: [PATCH 02/16] Fix direct leak Change-Id: I51d8fbbaa46a3a318b3e1a3102c0e21269b9690c Signed-off-by: sooyeon.kim (cherry picked from commit b8f1f78a4f93753984e63e7ead6f246da7faf1fe) --- server/vcd_engine_agent.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 8166f36..0c9faa7 100755 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -173,15 +173,15 @@ int vcd_engine_agent_release() if (NULL != data) { if (NULL != data->engine_uuid) { - free(data->engine_uuid); + g_free(data->engine_uuid); data->engine_uuid = NULL; } if (NULL != data->engine_name) { - free(data->engine_name); + g_free(data->engine_name); data->engine_name = NULL; } if (NULL != data->engine_path) { - free(data->engine_path); + g_free(data->engine_path); data->engine_path = NULL; } @@ -266,9 +266,9 @@ int vcd_engine_agent_initialize_current_engine() } else { if (NULL != g_dynamic_engine.engine_uuid) { /* set data from g_engine_list */ - if (g_dynamic_engine.engine_uuid != NULL) free(g_dynamic_engine.engine_uuid); - if (g_dynamic_engine.engine_name != NULL) free(g_dynamic_engine.engine_name); - if (g_dynamic_engine.engine_path != NULL) free(g_dynamic_engine.engine_path); + if (g_dynamic_engine.engine_uuid != NULL) g_free(g_dynamic_engine.engine_uuid); + if (g_dynamic_engine.engine_name != NULL) g_free(g_dynamic_engine.engine_name); + if (g_dynamic_engine.engine_path != NULL) g_free(g_dynamic_engine.engine_path); } g_dynamic_engine.engine_uuid = g_strdup(dynamic_engine->engine_uuid); @@ -419,9 +419,13 @@ int __internal_update_engine_list() data = iter->data; if (NULL != data) { - if (NULL != data->engine_uuid) free(data->engine_uuid); - if (NULL != data->engine_path) free(data->engine_path); - if (NULL != data->engine_name) free(data->engine_name); + if (NULL != data->engine_uuid) g_free(data->engine_uuid); + if (NULL != data->engine_path) g_free(data->engine_path); + if (NULL != data->engine_name) g_free(data->engine_name); + + data->engine_uuid = NULL; + data->engine_path = NULL; + data->engine_name = NULL; free(data); } -- 2.7.4 From 372ae871173b5ffed66cedd519d140b7c7b32e40 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Fri, 17 Mar 2017 21:56:40 +0900 Subject: [PATCH 03/16] Add private interface between engine and manager client Change-Id: I50f34a58199bf0daaa033cf017c5f8c01fbe57fd Signed-off-by: Kwangyoun Kim --- client/vc_mgr.c | 122 ++++++++++++++++++++++++++++++++++ client/vc_mgr_client.c | 65 ++++++++++++++++++ client/vc_mgr_client.h | 8 +++ client/vc_mgr_dbus.c | 97 +++++++++++++++++++++++++++ common/vc_defs.h | 2 + include/voice_control_manager.h | 90 +++++++++++++++++++++++++ include/voice_control_plugin_engine.h | 25 +++++++ server/vcd_dbus.c | 118 ++++++++++++++++++++++++++++++++ server/vcd_dbus.h | 3 + server/vcd_engine_agent.c | 20 ++++++ 10 files changed, 550 insertions(+) mode change 100755 => 100644 server/vcd_engine_agent.c diff --git a/client/vc_mgr.c b/client/vc_mgr.c index cfea1e3..868d187 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -2748,6 +2748,46 @@ int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, boo return 0; } +int __vc_mgr_cb_private_data_set(const char* key, const char* data) +{ + vc_mgr_private_data_set_cb callback = NULL; + void* user_data = NULL; + int ret = -1; + + vc_mgr_client_get_private_data_set_cb(g_vc_m, &callback, &user_data); + + if (NULL != callback) { + vc_mgr_client_use_callback(g_vc_m); + ret = callback(key, data, user_data); + vc_mgr_client_not_use_callback(g_vc_m); + SLOG(LOG_DEBUG, TAG_VCM, "Private data set callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] Private data set callback is null"); + } + + return ret; +} + +int __vc_mgr_cb_private_data_requested(const char* key, char** data) +{ + vc_mgr_private_data_requested_cb callback = NULL; + void* user_data = NULL; + int ret = -1; + + vc_mgr_client_get_private_data_requested_cb(g_vc_m, &callback, &user_data); + + if (NULL != callback) { + vc_mgr_client_use_callback(g_vc_m); + ret = callback(key, data, user_data); + vc_mgr_client_not_use_callback(g_vc_m); + SLOG(LOG_DEBUG, TAG_VCM, "Private data requested callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] Private data requested callback is null"); + } + + return ret; +} + int vc_mgr_set_dialog_request_cb(vc_mgr_dialog_request_cb callback, void* user_data) { if (NULL == callback) @@ -2789,6 +2829,88 @@ int vc_mgr_unset_dialog_request_cb() return 0; } +int vc_mgr_set_private_data_set_cb(vc_mgr_private_data_set_cb callback, void* user_data) +{ + if (NULL == callback) + return VC_ERROR_INVALID_PARAMETER; + + vc_state_e state; + if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data set callback : A handle is not available"); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (VC_STATE_INITIALIZED != state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data set callback : Current state is not 'Initialized'"); + return VC_ERROR_INVALID_STATE; + } + + vc_mgr_client_set_private_data_set_cb(g_vc_m, callback, user_data); + + return 0; +} + +int vc_mgr_unset_private_data_set_cb() +{ + vc_state_e state; + if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data set callback : A handle is not available"); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (VC_STATE_INITIALIZED != state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data set callback : Current state is not 'Initialized'"); + return VC_ERROR_INVALID_STATE; + } + + vc_mgr_client_set_private_data_set_cb(g_vc_m, NULL, NULL); + + return 0; +} + +int vc_mgr_set_private_data_requested_cb(vc_mgr_private_data_requested_cb callback, void* user_data) +{ + if (NULL == callback) + return VC_ERROR_INVALID_PARAMETER; + + vc_state_e state; + if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data requested callback : A handle is not available"); + return VC_ERROR_INVALID_STATE; + } + + /* check state*/ + if (VC_STATE_INITIALIZED != state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Set private data requested callback : Current state is not 'Initialized'"); + return VC_ERROR_INVALID_STATE; + } + + vc_mgr_client_set_private_data_requested_cb(g_vc_m, callback, user_data); + + return 0; +} + +int vc_mgr_unset_private_data_requested_cb() +{ + vc_state_e state; + if (0 != vc_mgr_client_get_client_state(g_vc_m, &state)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data requested callback : A handle is not available"); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (VC_STATE_INITIALIZED != state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Unset private data requested callback : Current state is not 'Initialized'"); + return VC_ERROR_INVALID_STATE; + } + + vc_mgr_client_set_private_data_requested_cb(g_vc_m, NULL, NULL); + + return 0; +} + static bool __vc_mgr_check_demandable_client(int pid) { if (0 == g_slist_length(g_demandable_client_list)) { diff --git a/client/vc_mgr_client.c b/client/vc_mgr_client.c index b3cf80d..94be682 100644 --- a/client/vc_mgr_client.c +++ b/client/vc_mgr_client.c @@ -43,6 +43,10 @@ typedef struct { void* current_lang_changed_user_data; vc_mgr_dialog_request_cb diaglog_requst_cb; void* dialog_request_user_data; + vc_mgr_private_data_set_cb private_data_set_cb; + void* private_data_set_user_data; + vc_mgr_private_data_requested_cb private_data_requested_cb; + void* private_data_requested_user_data; /* All result */ vc_result_event_e all_result_event; @@ -166,6 +170,10 @@ int vc_mgr_client_create(vc_h* vc) client->current_lang_changed_user_data = NULL; client->diaglog_requst_cb = NULL; client->dialog_request_user_data = NULL; + client->private_data_set_cb = NULL; + client->private_data_set_user_data = NULL; + client->private_data_requested_cb = NULL; + client->private_data_requested_user_data = NULL; client->exclusive_cmd_option = false; @@ -580,6 +588,63 @@ int vc_mgr_client_get_dialog_request_cb(vc_h vc, vc_mgr_dialog_request_cb* callb return 0; } + +int vc_mgr_client_set_private_data_set_cb(vc_h vc, vc_mgr_private_data_set_cb callback, void* user_data) +{ + vc_mgr_client_s* client = __mgr_client_get(vc); + + /* check handle */ + if (NULL == client) + return VC_ERROR_INVALID_PARAMETER; + + client->private_data_set_cb = callback; + client->private_data_set_user_data = user_data; + + return 0; +} + +int vc_mgr_client_get_private_data_set_cb(vc_h vc, vc_mgr_private_data_set_cb* callback, void** user_data) +{ + vc_mgr_client_s* client = __mgr_client_get(vc); + + /* check handle */ + if (NULL == client) + return VC_ERROR_INVALID_PARAMETER; + + *callback = client->private_data_set_cb; + *user_data = client->private_data_set_user_data; + + return 0; +} + +int vc_mgr_client_set_private_data_requested_cb(vc_h vc, vc_mgr_private_data_requested_cb callback, void* user_data) +{ + vc_mgr_client_s* client = __mgr_client_get(vc); + + /* check handle */ + if (NULL == client) + return VC_ERROR_INVALID_PARAMETER; + + client->private_data_requested_cb = callback; + client->private_data_requested_user_data = user_data; + + return 0; +} + +int vc_mgr_client_get_private_data_requested_cb(vc_h vc, vc_mgr_private_data_requested_cb* callback, void** user_data) +{ + vc_mgr_client_s* client = __mgr_client_get(vc); + + /* check handle */ + if (NULL == client) + return VC_ERROR_INVALID_PARAMETER; + + *callback = client->private_data_requested_cb; + *user_data = client->private_data_requested_user_data; + + return 0; +} + /* set/get option */ int vc_mgr_client_set_service_state(vc_h vc, vc_service_state_e state) { diff --git a/client/vc_mgr_client.h b/client/vc_mgr_client.h index afee7a4..4c91392 100644 --- a/client/vc_mgr_client.h +++ b/client/vc_mgr_client.h @@ -87,6 +87,14 @@ int vc_mgr_client_set_dialog_request_cb(vc_h vc, vc_mgr_dialog_request_cb callba int vc_mgr_client_get_dialog_request_cb(vc_h vc, vc_mgr_dialog_request_cb* callback, void** user_data); +int vc_mgr_client_set_private_data_set_cb(vc_h vc, vc_mgr_private_data_set_cb callback, void* user_data); + +int vc_mgr_client_get_private_data_set_cb(vc_h vc, vc_mgr_private_data_set_cb* callback, void** user_data); + +int vc_mgr_client_set_private_data_requested_cb(vc_h vc, vc_mgr_private_data_requested_cb callback, void* user_data); + +int vc_mgr_client_get_private_data_requested_cb(vc_h vc, vc_mgr_private_data_requested_cb* callback, void** user_data); + /* * set/get option */ diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index fe4ad31..3087a04 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -47,6 +47,10 @@ extern int __vc_mgr_cb_service_state(int state); extern int __vc_mgr_cb_set_foreground(int pid, bool value); +extern int __vc_mgr_cb_private_data_set(const char* key, const char* data); + +extern int __vc_mgr_cb_private_data_requested(const char* key, char** data); + /* Authority */ extern int __vc_mgr_request_auth_enable(int pid); @@ -272,6 +276,99 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd SLOG(LOG_DEBUG, TAG_VCM, " "); } /* VCD_MANAGER_METHOD_ERROR */ + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_SET_PRIVATE_DATA)) { + SLOG(LOG_DEBUG, TAG_VCM, "===== Get request set private data"); + int pid = 0; + int ret = -1; + char* key = NULL; + char* data = NULL; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &data, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCM, "<<<< vc mgr get request set private data : pid(%d) ", pid); + ret = __vc_mgr_cb_private_data_set(key, data); + } else { + SLOG(LOG_ERROR, TAG_VCM, "<<<< vc mgr get requset set private data : invalid pid "); + } + + DBusMessage *reply = NULL; + 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_m_conn_listener, reply, NULL)) + SLOG(LOG_ERROR, TAG_VCM, ">>>> vc get request set private data : fail to send reply"); + else + SLOG(LOG_DEBUG, TAG_VCM, ">>>> vc get request set private data : result(%d)", ret); + + dbus_connection_flush(g_m_conn_listener); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCM, ">>>> vc mgr get request set private data : fail to create reply message"); + } + + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + } /* VCD_MANAGER_METHOD_SET_PRIVATE_DATA */ + + else if (dbus_message_is_method_call(msg, if_name, VCD_MANAGER_METHOD_GET_PRIVATE_DATA)) { + SLOG(LOG_DEBUG, TAG_VCM, "===== Get request get private data"); + int pid = 0; + int ret = -1; + char* key = NULL; + char* temp = NULL; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Dbus Error (%s)", err.message); + dbus_error_free(&err); + } + + if (pid > 0) { + SLOG(LOG_DEBUG, TAG_VCM, "<<<< vc mgr get request get private data : pid(%d) ", pid); + ret = __vc_mgr_cb_private_data_requested(key, &temp); + } else { + SLOG(LOG_ERROR, TAG_VCM, "<<<< vc mgr get request get private data : invalid pid "); + } + + DBusMessage *reply = NULL; + reply = dbus_message_new_method_return(msg); + + if (NULL != reply) { + dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID); + + if (!dbus_connection_send(g_m_conn_listener, reply, NULL)) + SLOG(LOG_ERROR, TAG_VCM, ">>>> vc get request get private data : fail to send reply"); + else + SLOG(LOG_DEBUG, TAG_VCM, ">>>> vc get request get private data : result(%d)", ret); + + dbus_connection_flush(g_m_conn_listener); + dbus_message_unref(reply); + } else { + SLOG(LOG_ERROR, TAG_VCM, ">>>> vc mgr get request get private data : fail to create reply message"); + } + + if (NULL != temp) free(temp); + + SLOG(LOG_DEBUG, TAG_VCM, "====="); + SLOG(LOG_DEBUG, TAG_VCM, " "); + } /* VCD_MANAGER_METHOD_GET_PRIVATE_DATA */ + /* Authority */ else if (dbus_message_is_method_call(msg, if_name, VC_METHOD_AUTH_ENABLE)) { SLOG(LOG_DEBUG, TAG_VCM, "===== Get request auth enable"); diff --git a/common/vc_defs.h b/common/vc_defs.h index f647506..60e0aa4 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -145,6 +145,8 @@ extern "C" { #define VCD_MANAGER_METHOD_SET_VOLUME "vcd_manager_method_set_volume" #define VCD_MANAGER_METHOD_SET_SERVICE_STATE "vcd_manager_method_set_service_state" #define VCD_MANAGER_METHOD_DIALOG "vcd_manager_method_dialog" +#define VCD_MANAGER_METHOD_SET_PRIVATE_DATA "vcd_manager_set_private_data" +#define VCD_MANAGER_METHOD_GET_PRIVATE_DATA "vcd_manager_get_private_data" #define VCD_MANAGER_METHOD_ERROR "vcd_manager_method_error" diff --git a/include/voice_control_manager.h b/include/voice_control_manager.h index 9d738dc..3f31922 100644 --- a/include/voice_control_manager.h +++ b/include/voice_control_manager.h @@ -180,6 +180,34 @@ typedef void (*vc_mgr_begin_speech_detected_cb)(void *user_data); */ typedef void (*vc_mgr_dialog_request_cb)(int pid, const char* disp_text, const char* utt_text, bool continuous, void *user_data); +/** +* @brief Called when engine set private data to manager client +* +* @param[in] key Private key +* @param[in] data Private data +* @param[in] user_data The user data passed from the callback registration function +* +* @pre An application registers callback function using vc_mgr_set_private_data_set_cb(). +* +* @see vc_mgr_set_private_data_set_cb() +* @see vc_mgr_unset_private_data_set_cb() +*/ +typedef int (*vc_mgr_private_data_set_cb)(const char* key, const char* data, void *user_data); + +/** +* @brief Called when engine request private data from manager client +* +* @param[in] key Private key +* @param[out] data Private data +* @param[in] user_data The user data passed from the callback registration function +* +* @pre An application registers callback function using vc_mgr_set_private_data_requested_cb(). +* +* @see vc_mgr_set_private_data_requested_cb() +* @see vc_mgr_unset_private_data_requested_cb() +*/ +typedef int (*vc_mgr_private_data_requested_cb)(const char* key, char** data, void *user_data); + /** * @brief Initialize voice control manager. @@ -1008,6 +1036,68 @@ int vc_mgr_enable_command_type(int cmd_type); */ int vc_mgr_disable_command_type(int cmd_type); +/** +* @brief Registers a callback function to be called when engine set private data. +* +* @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_private_data_set_cb() +* @see vc_mgr_unset_private_data_set_cb() +*/ +int vc_mgr_set_private_data_set_cb(vc_mgr_private_data_set_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_mgr_set_private_data_set_cb() +*/ +int vc_mgr_unset_private_data_set_cb(); + +/** +* @brief Registers a callback function to be called when engine request private data. +* +* @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_private_data_requested_cb() +* @see vc_mgr_unset_private_data_requested_cb() +*/ +int vc_mgr_set_private_data_requested_cb(vc_mgr_private_data_requested_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_mgr_set_private_data_requested_cb() +*/ +int vc_mgr_unset_private_data_requested_cb(); + #ifdef __cplusplus } #endif diff --git a/include/voice_control_plugin_engine.h b/include/voice_control_plugin_engine.h index c6c3ab5..04a1cf0 100644 --- a/include/voice_control_plugin_engine.h +++ b/include/voice_control_plugin_engine.h @@ -598,6 +598,28 @@ typedef int (*vcpd_get_command_count)(vcp_cmd_h vcp_command); typedef int (*vcpd_get_audio_type)(char** audio_type); /** +* @brief Sets private data to Manager client. +* +* @param[in] key Private key +* @param[in] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpd_set_private_data)(const char* key, const char* data); + +/** +* @brief Gets private data from Manager client. +* +* @param[in] key Private key +* @param[out] data Private data +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpd_get_private_data)(const char* key, char** data); + +/** * @brief A structure of the engine functions. */ typedef struct { @@ -648,6 +670,9 @@ typedef struct { vcpd_get_command_count get_command_count; /**< Get command count */ vcpd_get_audio_type get_audio_type; /**< Get audio type */ + + vcpd_set_private_data set_private_data; /**< Set private data to Manager */ + vcpd_get_private_data get_private_data; /**< Get private data from Manager */ } vcpd_funcs_s; /** diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 5012b21..05a66a1 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -771,6 +771,124 @@ int vcdc_send_error_signal(int reason, char *err_msg) return 0; } +int vcdc_send_request_set_private_data(int pid, const char* key, const char* data) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + msg = __get_message(pid, VCD_MANAGER_METHOD_SET_PRIVATE_DATA, VCD_CLIENT_TYPE_MANAGER); + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to create message"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &data, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = -1; + + 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, "[Dbus ERROR] %s", err.message); + if (NULL != err.name) { + if (!strcmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN)) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Unknown service. Client is not available"); + dbus_error_free(&err); + return 0; + } + } + 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, "[Dbus] Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VCD_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Result message is NULL. Client is not available"); + } + + return result; +} + +int vcdc_send_request_get_private_data(int pid, const char* key, char** data) +{ + if (0 != __dbus_check()) { + return VCD_ERROR_OPERATION_FAILED; + } + + DBusMessage* msg = NULL; + msg = __get_message(pid, VCD_MANAGER_METHOD_GET_PRIVATE_DATA, VCD_CLIENT_TYPE_MANAGER); + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus ERROR] Fail to create message"); + return VCD_ERROR_OUT_OF_MEMORY; + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_INVALID); + + DBusError err; + dbus_error_init(&err); + + DBusMessage* result_msg; + int result = -1; + char* temp = NULL; + + 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, "[Dbus ERROR] %s", err.message); + if (NULL != err.name) { + if (!strcmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN)) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Unknown service. Client is not available"); + dbus_error_free(&err); + return 0; + } + } + dbus_error_free(&err); + } + + if (NULL != result_msg) { + dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[Dbus] Get arguments error (%s)", err.message); + dbus_error_free(&err); + result = VCD_ERROR_OPERATION_FAILED; + } + + dbus_message_unref(result_msg); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] Result message is NULL. Client is not available"); + } + + if (NULL != data && NULL != temp) { + *data = strdup(temp); + } + + return result; +} + static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW; diff --git a/server/vcd_dbus.h b/server/vcd_dbus.h index 5c4e357..ad6ebb8 100644 --- a/server/vcd_dbus.h +++ b/server/vcd_dbus.h @@ -62,6 +62,9 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* int vcdc_send_manager_pid(int manager_pid); +int vcdc_send_request_set_private_data(int pid, const char* key, const char* data); + +int vcdc_send_request_get_private_data(int pid, const char* key, char** data); #ifdef __cplusplus } diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c old mode 100755 new mode 100644 index 0c9faa7..1e52a70 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -23,6 +23,7 @@ #include "vcd_engine_agent.h" #include "vcd_main.h" #include "vcd_recorder.h" +#include "vcd_dbus.h" /* * Internal data structure @@ -510,6 +511,22 @@ int __get_audio_type(char** audio_type) return vcd_recorder_get(audio_type); } +int __set_private_data(const char* key, const char* data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request set private data"); + vcdc_send_request_set_private_data(vcd_client_manager_get_pid(), key, data); + + return 0; +} + +int __get_private_data(const char* key, char** data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request get private data"); + vcdc_send_request_get_private_data(vcd_client_manager_get_pid(), key, data); + + return 0; +} + void __result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed, const char* nlu_result, const char* msg, void *user_data) { SLOG(LOG_DEBUG, TAG_VCD, "[Engine agent] Event(%d), Count(%d) Text(%s) Nonfixed(%s) NLU result(%s) Msg(%s)", event, count, all_result, non_fixed, nlu_result, msg); @@ -590,6 +607,9 @@ int __load_engine(vcengine_s* engine) engine->pdfuncs->get_command_count = __command_get_length; engine->pdfuncs->get_audio_type = __get_audio_type; + engine->pdfuncs->set_private_data = __set_private_data; + engine->pdfuncs->get_private_data = __get_private_data; + if (0 != engine->vcp_load_engine(engine->pdfuncs, engine->pefuncs)) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail vcp_load_engine()"); dlclose(engine->handle); -- 2.7.4 From 88b4ebf37ce81917f6167985dbb780c488a19153 Mon Sep 17 00:00:00 2001 From: "Park, Sehwan" Date: Wed, 29 Mar 2017 20:50:01 +0900 Subject: [PATCH 04/16] The description related with X window system is changed Change-Id: Id1d12638b54e83af6c118d239aba4bb9425ee50c --- client/vc_widget_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/vc_widget_client.h b/client/vc_widget_client.h index b5c9633..55a44e3 100644 --- a/client/vc_widget_client.h +++ b/client/vc_widget_client.h @@ -31,7 +31,7 @@ typedef struct { vc_h vc; int pid; int uid; /*<< unique id = pid + handle */ - int xid; /*<< main X window id */ + int xid; /*<< main Wayland window id */ vc_result_cb result_cb; void* result_user_data; -- 2.7.4 From c15bb24cec65ecc5987adc862e70edc42ebde2be Mon Sep 17 00:00:00 2001 From: "Park, Sehwan" Date: Wed, 29 Mar 2017 21:48:20 +0900 Subject: [PATCH 05/16] Unused codes and unnecessary variable initializing are removed Change-Id: Ifb50e234008e7c0935c6fd8eb06ef11c50967661 --- client/vc_mgr.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index cfea1e3..5b45991 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -559,33 +559,6 @@ int vc_mgr_set_demandable_client_rule(const char* rule) SLOG(LOG_DEBUG, TAG_VCM, " "); return 0; - - /* - int count = 0; - ret = -1; - while (0 != ret) { - ret = vc_mgr_dbus_request_demandable_client(g_vc_m->handle); - if (0 != ret) { - if (VC_ERROR_TIMED_OUT != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request set client rule to daemon : %s", __vc_mgr_get_error_code(ret)); - break; - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry request set client rule : %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; - } - } - } - } - - SLOG(LOG_DEBUG, TAG_VCM, "====="); - SLOG(LOG_DEBUG, TAG_VCM, " "); - - return 0; - */ } int vc_mgr_unset_demandable_client_rule() @@ -1033,12 +1006,10 @@ int vc_mgr_set_audio_type(const char* audio_id) return VC_ERROR_INVALID_STATE; } - int ret; + int ret = -1; int count = 0; /* Request */ - ret = -1; - count = 0; while (0 != ret) { ret = vc_mgr_dbus_request_set_audio_type(g_vc_m->handle, audio_id); if (0 != ret) { -- 2.7.4 From 51bd4ceb583eb41218bbc62fcdc9fe0445314060 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Mon, 6 Mar 2017 15:19:17 +0900 Subject: [PATCH 06/16] Add command list handle check logic Change-Id: I5a258cbdd2761cb6c99e14b38f72f33e02e8a375 --- client/vc.c | 5 +++++ client/vc_mgr.c | 15 +++++++++++++++ common/vc_command.c | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) mode change 100755 => 100644 common/vc_command.c diff --git a/client/vc.c b/client/vc.c index 345dfaf..75b930e 100644 --- a/client/vc.c +++ b/client/vc.c @@ -1056,6 +1056,11 @@ int vc_set_command_list(vc_cmd_list_h vc_cmd_list, int type) vc_cmd_list_s* list = NULL; list = (vc_cmd_list_s*)vc_cmd_list; + if (NULL == list->list) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid command list"); + return VC_ERROR_INVALID_PARAMETER; + } + int ret = 0; char* invocation_name = NULL; if (VC_COMMAND_TYPE_BACKGROUND == type) { diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 2001006..4609a1a 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -792,8 +792,19 @@ int vc_mgr_set_command_list(vc_cmd_list_h vc_cmd_list) return VC_ERROR_INVALID_STATE; } + if (NULL == vc_cmd_list) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Input parameter is NULL"); + return VC_ERROR_INVALID_PARAMETER; + } + vc_cmd_list_s* list = NULL; list = (vc_cmd_list_s*)vc_cmd_list; + SLOG(LOG_INFO, TAG_VCM, "[List] (%p) (%p)", list, list->list); + + if (NULL == list->list) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid command list"); + return VC_ERROR_INVALID_PARAMETER; + } int i; int ret; @@ -1723,6 +1734,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/common/vc_command.c b/common/vc_command.c old mode 100755 new mode 100644 index b085344..49f0edc --- a/common/vc_command.c +++ b/common/vc_command.c @@ -366,7 +366,7 @@ int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool release_command) } } } - + list->list = NULL; list->index = -1; SLOG(LOG_DEBUG, TAG_VCCMD, "====="); -- 2.7.4 From 87a0c3e05f31dc546f8cdafe8c6a185f68285c3c Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 5 Apr 2017 18:26:06 +0900 Subject: [PATCH 07/16] Update url link Change-Id: Id60a547ac2a04d21749ce686b27032e6a5bac315 Signed-off-by: Wonnam Jang (cherry picked from commit 7e1ac460467e1f0e073762b4d8c9a403762270b7) --- doc/uix_vc_doc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/uix_vc_doc.h b/doc/uix_vc_doc.h index 040b006..771f326 100644 --- a/doc/uix_vc_doc.h +++ b/doc/uix_vc_doc.h @@ -197,7 +197,7 @@ * It is recommended to design feature related codes in your application for reliability.
* You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.
* To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
- * More details on featuring your application can be found from Feature Element. + * More details on featuring your application can be found from Feature Element. */ -- 2.7.4 From 3e48f6c59b224e35fc206e201a721de2ba16caf3 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Tue, 11 Apr 2017 15:38:58 +0900 Subject: [PATCH 08/16] Use license macro in .spec file Change-Id: I3c3e50f372350c7a8c36b6cb7e96838409448ec2 Signed-off-by: Suyeon Hwang --- packaging/voice-control.spec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packaging/voice-control.spec b/packaging/voice-control.spec index be8e8a0..25c0471 100644 --- a/packaging/voice-control.spec +++ b/packaging/voice-control.spec @@ -102,8 +102,6 @@ make %{?jobs:-j%jobs} %install rm -rf %{buildroot} -mkdir -p %{buildroot}%{TZ_SYS_RO_SHARE}/license -install LICENSE %{buildroot}%{TZ_SYS_RO_SHARE}/license/%{name} %make_install @@ -115,6 +113,7 @@ mkdir -p %{_libdir}/voice/vc %postun -p /sbin/ldconfig %files +%license LICENSE %manifest %{name}.manifest %defattr(-,root,root,-) %{_libdir}/libvc.so @@ -125,7 +124,6 @@ mkdir -p %{_libdir}/voice/vc %{TZ_SYS_RO_SHARE}/upgrade/scripts/502.vc_upgrade_24to30.sh %{TZ_SYS_RO_SHARE}/voice/vc/1.0/vc-config.xml %{TZ_SYS_RO_SHARE}/dbus-1/services/org.tizen.voice* -%{TZ_SYS_RO_SHARE}/license/%{name} /etc/dbus-1/session.d/vc-server.conf %files devel -- 2.7.4 From 6304a412ac3bd88bb362dab4bfecee0e8f9ed84a Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Wed, 12 Apr 2017 10:51:23 +0900 Subject: [PATCH 09/16] Fix calling duplicated result callback Change-Id: I3c1b2a49bb2aa1d0e795c1811a4d1ccee83cc12b Signed-off-by: Suyeon Hwang --- common/vc_cmd_db.c | 8 +++----- server/vcd_server.c | 6 +++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 4218894..30e0266 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -989,7 +989,8 @@ int __vc_db_get_result_pid_list(const char* result, GSList** pid_list) int ret = 0; sqlite3_stmt* stmt = NULL; - const char* sql = "SELECT * FROM vc_result WHERE result = ? COLLATE NOCASE;"; + const char* sql = "SELECT DISTINCT pid, type FROM vc_result WHERE result = ? COLLATE NOCASE ORDER BY pid ASC;"; + ret = sqlite3_prepare_v2(db_handle, sql, -1, &stmt, NULL); if (ret != SQLITE_OK) { @@ -1031,12 +1032,9 @@ int __vc_db_get_result_pid_list(const char* result, GSList** pid_list) } temp = sqlite3_column_int(stmt, 0); - temp_cmd->id = temp; - - temp = sqlite3_column_int(stmt, 5); temp_cmd->pid = temp; - temp = sqlite3_column_int(stmt, 6); + temp = sqlite3_column_int(stmt, 1); temp_cmd->type = temp; temp_pid_list = g_slist_append(temp_pid_list, temp_cmd); diff --git a/server/vcd_server.c b/server/vcd_server.c index de53304..26f4b7c 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -387,12 +387,14 @@ static Eina_Bool __vcd_send_selected_result(void *data) GSList* iter = NULL; vc_cmd_s* temp_cmd = NULL; int ret = 0; + int pre_pid = -1; + int pre_type = -1; iter = g_slist_nth(pid_list, 0); while (NULL != iter) { temp_cmd = iter->data; - if (NULL != temp_cmd) { + if (NULL != temp_cmd && (pre_pid != temp_cmd->pid || pre_type == VC_COMMAND_TYPE_WIDGET || temp_cmd->type == VC_COMMAND_TYPE_WIDGET)) { /* Launch deactivated several apps that is matched with result */ ret = __vcd_launch_app(result); if (0 != ret) { @@ -405,6 +407,8 @@ static Eina_Bool __vcd_send_selected_result(void *data) break; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Send result : pid(%d) type(%d)", temp_cmd->pid, temp_cmd->type); + pre_pid = temp_cmd->pid; + pre_type = temp_cmd->type; } } free(temp_cmd); -- 2.7.4 From 411065bfa9a7296a5030f1d78aa08466b2551b05 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Thu, 20 Apr 2017 14:58:16 +0900 Subject: [PATCH 10/16] Fix invalid volume value when recording value is zero Change-Id: I05c815b192380c575da1b4217bd26e8f2f5c81bf --- server/vcd_recorder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 4d3cb7e..5ba69d6 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -514,8 +514,8 @@ static float get_volume_decibel(char* data, int size) count++; } - if (0 == count) { - SLOG(LOG_ERROR, TAG_VCD, "[ERROR] NULL data"); + if (0 == count || 0 == square_sum) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] No data"); rms = 1.0; } else { rms = sqrt((float)square_sum/count); -- 2.7.4 From c9f8884299559c7b73b5c047607f92a185be584b Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Wed, 29 Mar 2017 10:52:19 +0900 Subject: [PATCH 11/16] Fix event of consumed ASR result to become success Change-Id: I153ea61d8b7245c729459ac72f74f18032cd5008 Signed-off-by: Suyeon Hwang --- server/vcd_server.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/vcd_server.c b/server/vcd_server.c index 26f4b7c..aff998d 100755 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -31,6 +31,7 @@ #include "vcd_dbus.h" #include "voice_control_command_expand.h" +#include "voice_control_common.h" /* * VC Server static variable @@ -510,12 +511,17 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int vcdc_send_show_tooltip(pid, false); if (-1 != vcd_client_manager_get_pid()) { /* Manager client is available */ + vc_info_parser_unset_result(false); + vc_info_parser_set_result(all_result, VC_RESULT_EVENT_RESULT_SUCCESS, msg, NULL, false); 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); + + vcd_config_set_service_state(VCD_STATE_READY); + vcdc_send_service_state(VCD_STATE_READY); return; } } -- 2.7.4 From cb53d6b1113a0b975131c3628dac5d3fdf353314 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Thu, 27 Apr 2017 14:19:46 +0900 Subject: [PATCH 12/16] Fix bug Change-Id: Id7e51b54f188abf87734575a162817a434b8df98 Signed-off-by: Wonnam Jang --- server/vcd_recorder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 5ba69d6..3b33e95 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -143,7 +143,7 @@ static void _bt_cb_hid_state_changed(int result, bool connected, const char *rem static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void *user_data) { - if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH))) { + if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, strlen(VCP_AUDIO_ID_BLUETOOTH))) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); return; } -- 2.7.4 From d5ee7634d3d134323526d03da0deae1101c0ffb2 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Thu, 27 Apr 2017 14:46:31 +0900 Subject: [PATCH 13/16] Fix internal state error when api is called in thread Change-Id: I1aaab56682def70092c9241503e7ab844f87e580 Signed-off-by: Wonnam Jang --- client/vc_mgr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index ee31520..cad7905 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -1684,10 +1684,12 @@ int vc_mgr_start(bool exclusive_command_option) ret = -1; count = 0; while (0 != ret) { + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STARTING); ret = vc_mgr_dbus_request_start(g_vc_m->handle, (int)recognition_mode, exclusive_command_option, start_by_client); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to start request start : %s", __vc_mgr_get_error_code(ret)); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); break; } else { SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry start request start : %s", __vc_mgr_get_error_code(ret)); @@ -1696,12 +1698,12 @@ int vc_mgr_start(bool exclusive_command_option) if (VC_RETRY_COUNT == count) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); vc_mgr_client_set_exclusive_command(g_vc_m, false); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); break; } } } else { SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] start recognition"); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STARTING); } } @@ -1763,10 +1765,12 @@ int vc_mgr_stop() int count = 0; /* do request */ while (0 != ret) { + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING); ret = vc_mgr_dbus_request_stop(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to stop request : %s", __vc_mgr_get_error_code(ret)); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); break; } else { SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry stop request : %s", __vc_mgr_get_error_code(ret)); @@ -1774,12 +1778,12 @@ int vc_mgr_stop() count++; if (VC_RETRY_COUNT == count) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); break; } } } else { SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Stop recognition"); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING); } } @@ -1835,10 +1839,12 @@ int vc_mgr_cancel() int ret = -1; int count = 0; while (0 != ret) { + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING); ret = vc_mgr_dbus_request_cancel(g_vc_m->handle); if (0 != ret) { if (VC_ERROR_TIMED_OUT != ret) { SLOG(LOG_DEBUG, TAG_VCM, "[ERROR] Fail to cancel request : %s", __vc_mgr_get_error_code(ret)); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); break; } else { SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry cancel request : %s", __vc_mgr_get_error_code(ret)); @@ -1846,12 +1852,12 @@ int vc_mgr_cancel() count++; if (VC_RETRY_COUNT == count) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request"); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); break; } } } else { SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Cancel recognition"); - vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING); } } -- 2.7.4 From d78ad0b02b5661469f2bb87007c6db6db8ad1087 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 10 May 2017 16:29:44 +0900 Subject: [PATCH 14/16] add NLG result callback Change-Id: I3248d4bb092007f78c9916bf2e7b33763f9b202a --- client/vc_mgr.c | 2 +- client/vc_mgr_dbus.c | 5 +++++ include/voice_control_plugin_engine.h | 20 ++++++++++++++++++++ server/vcd_dbus.c | 5 +++++ server/vcd_engine_agent.c | 26 ++++++++++++++++++++++++-- server/vcd_engine_agent.h | 4 +++- server/vcd_server.c | 18 +++++++++++++++++- 7 files changed, 75 insertions(+), 5 deletions(-) mode change 100755 => 100644 server/vcd_server.c diff --git a/client/vc_mgr.c b/client/vc_mgr.c index cad7905..c626f34 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -2728,7 +2728,7 @@ int __vc_mgr_cb_dialog(int pid, const char* disp_text, const char* utt_text, boo vc_mgr_client_use_callback(g_vc_m); callback(pid, disp_text, utt_text, continuous, user_data); vc_mgr_client_not_use_callback(g_vc_m); - SLOG(LOG_DEBUG, TAG_VCM, "Dialog callback is called"); + SLOG(LOG_DEBUG, TAG_VCM, "Dialog callback is called, disp_text(%s), utt)text(%s), continous(%d)", disp_text, utt_text, continuous); } else { SLOG(LOG_WARN, TAG_VCM, "[WARNING] Error callback is null"); } diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index 3087a04..06175e3 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -245,6 +245,11 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd DBUS_TYPE_INT32, &tmp_continue, DBUS_TYPE_INVALID); + if (!strcmp(disp_text, "#NULL")) + disp_text = NULL; + if (!strcmp(utt_text, "#NULL")) + utt_text = NULL; + __vc_mgr_cb_dialog(pid, disp_text, utt_text, (bool)tmp_continue); SLOG(LOG_DEBUG, TAG_VCM, "====="); diff --git a/include/voice_control_plugin_engine.h b/include/voice_control_plugin_engine.h index 04a1cf0..82ce330 100644 --- a/include/voice_control_plugin_engine.h +++ b/include/voice_control_plugin_engine.h @@ -182,6 +182,14 @@ typedef void (*vcpe_result_cb)(vcp_result_event_e event, int* result_id, int cou typedef void (*vcpe_asr_result_cb)(vcp_asr_result_event_e event, const char* asr_result, void *user_data); /** +* @brief Called when the daemon gets nlg result. +* +* @param[in] nlg_result Nlg result +* @param[in] user_data The user data passed from the start +*/ +typedef void (*vcpe_nlg_result_cb)(const char* nlg_result, void *user_data); + +/** * @brief Called when the daemon gets error. * * @param[in] error Error type @@ -260,6 +268,17 @@ typedef int (*vcpe_set_result_cb)(vcpe_result_cb callback, void* user_data); */ typedef int (*vcpe_set_asr_result_cb)(vcpe_asr_result_cb callback, void* user_data); +/** +* @brief Registers a callback function for getting nlg 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 +* +*/ +typedef int (*vcpe_set_nlg_result_cb)(vcpe_nlg_result_cb, void* user_data); + #if 0 /** * @brief Registers a callback function for getting partial recognition result. @@ -648,6 +667,7 @@ typedef struct { //vcpe_set_pre_result_cb set_pre_result_cb; /**< Set pre result callback */ vcpe_set_asr_result_cb set_asr_result_cb; /**< Set asr result callback */ + vcpe_set_nlg_result_cb set_nlg_result_cb; /**< Set nlg result callback */ vcpe_set_error_cb set_error_cb; /**< Set error callback */ vcpe_set_domain set_domain; /**< Set domain */ vcpe_get_nlu_base_info get_nlu_base_info; /**< Get essential info */ diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 05a66a1..75a8c63 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -613,6 +613,11 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] send dialog : pid(%d), disp_text(%s), utt_text(%s), continue(%d)", pid, disp_text, utt_text, continuous); + if (NULL == disp_text) + disp_text = strdup("#NULL"); + if (NULL == utt_text) + utt_text = strdup("#NULL"); + dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_STRING, &disp_text, diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 1e52a70..1e457b5 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -73,6 +73,7 @@ static char* g_default_lang; static result_callback g_result_cb = NULL; static asr_result_callback g_asr_result_cb = NULL; +static nlg_result_callback g_nlg_result_cb = NULL; #if 0 static pre_result_callback g_pre_result_cb = NULL; @@ -111,7 +112,7 @@ int __log_enginelist(); * VCS Engine Agent Interfaces */ //int vcd_engine_agent_init(pre_result_callback pre_result_cb, result_callback result_cb, nlu_result_callback nlu_result_cb, error_callback error_cb) -int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, error_callback error_cb) +int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, nlg_result_callback nlg_result_cb, error_callback error_cb) { if (/*NULL == pre_result_cb*/ NULL == asr_result_cb || NULL == result_cb /*|| NULL == nlu_result_cb*/ || NULL == error_cb) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Input parameter is NULL"); @@ -134,6 +135,7 @@ int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback res //g_pre_result_cb = pre_result_cb; g_asr_result_cb = asr_result_cb; + g_nlg_result_cb = nlg_result_cb; g_result_cb = result_cb; //g_nlu_result_cb = nlu_result_cb; g_error_cb = error_cb; @@ -209,6 +211,7 @@ int vcd_engine_agent_release() //g_pre_result_cb = NULL; g_asr_result_cb = NULL; + g_nlg_result_cb = NULL; g_result_cb = NULL; //g_nlu_result_cb = NULL; g_error_cb = NULL; @@ -553,6 +556,19 @@ void __asr_result_cb(vcp_asr_result_event_e event, const char* asr_result, void return; } +void __nlg_result_cb(const char* nlg_result, void *user_data) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] NLG result - Result(%s)", nlg_result); + + if (NULL != g_nlg_result_cb) { + g_nlg_result_cb(nlg_result, user_data); + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent ERROR] NLG result callback function is NOT valid"); + } + + return; +} + void __error_cb(vcp_error_e error, const char* msg, void *user_data) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent] ERROR(%d)", error); @@ -616,7 +632,7 @@ int __load_engine(vcengine_s* engine) return VCD_ERROR_OPERATION_FAILED; } - SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] engine info : version(%d), size(%d)", engine->pefuncs->version, engine->pefuncs->size); + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] engine info : version(%d), size(%d)(%d)", engine->pefuncs->version, engine->pefuncs->size, sizeof(vcpe_funcs_s)); /* engine error check */ if (engine->pefuncs->size != sizeof(vcpe_funcs_s)) { @@ -639,6 +655,7 @@ int __load_engine(vcengine_s* engine) NULL == engine->pefuncs->stop || NULL == engine->pefuncs->cancel || NULL == engine->pefuncs->set_asr_result_cb || + NULL == engine->pefuncs->set_nlg_result_cb || //NULL == engine->pefuncs->set_pre_result_cb || NULL == engine->pefuncs->set_error_cb || NULL == engine->pefuncs->set_domain || @@ -669,6 +686,11 @@ int __load_engine(vcengine_s* engine) return VCD_ERROR_OPERATION_FAILED; } + if (0 != engine->pefuncs->set_nlg_result_cb(__nlg_result_cb, NULL)) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set nlg result callback of vc-engine"); + return VCD_ERROR_OPERATION_FAILED; + } + if (0 != engine->pefuncs->set_error_cb(__error_cb, NULL)) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set error callback of vc-engine"); return VCD_ERROR_OPERATION_FAILED; diff --git a/server/vcd_engine_agent.h b/server/vcd_engine_agent.h index 8e50ff9..4b4a21e 100644 --- a/server/vcd_engine_agent.h +++ b/server/vcd_engine_agent.h @@ -36,6 +36,8 @@ typedef void (*result_callback)(vcp_result_event_e event, int* result_id, int co typedef void (*asr_result_callback)(vcp_asr_result_event_e event, const char* asr_result, void *user_data); +typedef void (*nlg_result_callback)(const char* nlg_result, void *user_data); + #if 0 typedef void (*pre_result_callback)(vcp_pre_result_event_e event, const char* pre_result, void *user_data); @@ -50,7 +52,7 @@ typedef void (*silence_dectection_callback)(void *user_data); /** Init engine agent */ //int vcd_engine_agent_init(pre_result_callback pre_result_cb, result_callback result_cb, nlu_result_callback nlu_result_cb, error_callback error_cb); -int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, error_callback error_cb); +int vcd_engine_agent_init(asr_result_callback asr_result_cb, result_callback result_cb, nlg_result_callback nlg_result_cb, error_callback error_cb); /** Release engine agent */ int vcd_engine_agent_release(); diff --git a/server/vcd_server.c b/server/vcd_server.c old mode 100755 new mode 100644 index aff998d..79bb719 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -51,6 +51,8 @@ typedef enum { VCD_SEND_EVENT_TYPE_HAPTIC_EVENT /**< send haptic event to vc engine */ } vcd_send_event_type_e; +static int __vcd_server_launch_manager_app(); + /* * VC Server Internal Functions */ @@ -440,6 +442,20 @@ static void __vcd_server_asr_result_cb(vcp_asr_result_event_e event, const char* return; } +static void __vcd_server_nlg_result_cb(const char* nlg_result, void *user_data) +{ + int ret = __vcd_server_launch_manager_app(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result); + return; + } + + ret = vcdc_send_dialog(vcd_client_manager_get_pid(), -1, nlg_result, NULL, 0); //0: VC_DIALOG_END + if (0 != ret) + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send dialog : mgr_pid(%d), nlg_result(%s)", vcd_client_manager_get_pid(), nlg_result); + return; +} + static void* __recorder_stop(void *data) { vcd_recorder_stop(); @@ -972,7 +988,7 @@ int vcd_initialize() vcd_config_set_service_state(VCD_STATE_NONE); //ret = vcd_engine_agent_init(__vcd_server_pre_result_cb, __vcd_server_result_cb, __vcd_server_nlu_result_cb, __vcd_server_error_cb); - ret = vcd_engine_agent_init(__vcd_server_asr_result_cb, __vcd_server_result_cb, __vcd_server_error_cb); + ret = vcd_engine_agent_init(__vcd_server_asr_result_cb, __vcd_server_result_cb, __vcd_server_nlg_result_cb, __vcd_server_error_cb); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to engine agent initialize : result(%d)", ret); return ret; -- 2.7.4 From dd1a46f2e0f5e887af7bc8058e720ffd26bb46d8 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Thu, 11 May 2017 14:25:59 +0900 Subject: [PATCH 15/16] Change audio recording procedure Change-Id: Ic23c55aece9b34b3af587451e2eee35a4b4fa2b2 --- client/vc_mgr.c | 4 +-- include/voice_control_plugin_engine.h | 30 +++++++++++++++++++++++ server/vcd_engine_agent.c | 46 +++++++++++++++++++++++++++++++++++ server/vcd_engine_agent.h | 2 ++ server/vcd_recorder.c | 30 +++++++++++++++++++---- server/vcd_server.c | 21 +++++++++++----- 6 files changed, 120 insertions(+), 13 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index c626f34..26b1630 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -1816,8 +1816,8 @@ int vc_mgr_cancel() /* 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_RECORDING && service_state != VC_SERVICE_STATE_PROCESSING) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'RECORDING' or 'PROCESSING'"); + if (service_state == VC_SERVICE_STATE_NONE) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State"); SLOG(LOG_DEBUG, TAG_VCM, "====="); SLOG(LOG_DEBUG, TAG_VCM, " "); return VC_ERROR_INVALID_STATE; diff --git a/include/voice_control_plugin_engine.h b/include/voice_control_plugin_engine.h index 82ce330..b6926da 100644 --- a/include/voice_control_plugin_engine.h +++ b/include/voice_control_plugin_engine.h @@ -479,6 +479,15 @@ typedef int (*vcpe_stop)(void); typedef int (*vcpe_cancel)(void); /** +* @brief Set audio recording type. +* +* @return 0 on success, otherwise a negative error value. +* @retval #VCP_ERROR_NONE Successful. +* +*/ +typedef int (*vcpe_set_audio_type)(const char* audio); + +/** * @brief Sets domain (Agent or device type) * * @param[in] domain available Agent or device type @@ -639,6 +648,22 @@ typedef int (*vcpd_set_private_data)(const char* key, const char* data); typedef int (*vcpd_get_private_data)(const char* key, char** data); /** +* @brief Request start recording. +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpd_start_recording)(); + +/** +* @brief Request stop recording. +* +* @return 0 on success, otherwise a negative error value. +* +*/ +typedef int (*vcpd_stop_recording)(); + +/** * @brief A structure of the engine functions. */ typedef struct { @@ -665,6 +690,8 @@ typedef struct { vcpe_stop stop; /**< Stop recording for getting result */ vcpe_cancel cancel; /**< Cancel recording and processing */ + vcpe_set_audio_type set_audio_type; /**< Set audio type */ + //vcpe_set_pre_result_cb set_pre_result_cb; /**< Set pre result callback */ vcpe_set_asr_result_cb set_asr_result_cb; /**< Set asr result callback */ vcpe_set_nlg_result_cb set_nlg_result_cb; /**< Set nlg result callback */ @@ -693,6 +720,9 @@ typedef struct { vcpd_set_private_data set_private_data; /**< Set private data to Manager */ vcpd_get_private_data get_private_data; /**< Get private data from Manager */ + + vcpd_start_recording start_recording; /**< Request start recording */ + vcpd_stop_recording stop_recording; /**< Request stop recording */ } vcpd_funcs_s; /** diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 1e457b5..1718842 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -530,6 +530,29 @@ int __get_private_data(const char* key, char** data) return 0; } +int __start_recording() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request start recording"); + + int ret = vcd_recorder_start(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to start recorder : result(%d)", ret); + vcd_engine_recognize_cancel(); + /* Send error cb to manager */ + vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); + return ret; + } + + return 0; +} + +int __stop_recording() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Engine Agent] Request stop recording"); + + return vcd_recorder_stop(); +} + void __result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed, const char* nlu_result, const char* msg, void *user_data) { SLOG(LOG_DEBUG, TAG_VCD, "[Engine agent] Event(%d), Count(%d) Text(%s) Nonfixed(%s) NLU result(%s) Msg(%s)", event, count, all_result, non_fixed, nlu_result, msg); @@ -626,6 +649,9 @@ int __load_engine(vcengine_s* engine) engine->pdfuncs->set_private_data = __set_private_data; engine->pdfuncs->get_private_data = __get_private_data; + engine->pdfuncs->start_recording = __start_recording; + engine->pdfuncs->stop_recording = __stop_recording; + if (0 != engine->vcp_load_engine(engine->pdfuncs, engine->pefuncs)) { SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail vcp_load_engine()"); dlclose(engine->handle); @@ -654,6 +680,7 @@ int __load_engine(vcengine_s* engine) NULL == engine->pefuncs->set_recording || NULL == engine->pefuncs->stop || NULL == engine->pefuncs->cancel || + NULL == engine->pefuncs->set_audio_type || NULL == engine->pefuncs->set_asr_result_cb || NULL == engine->pefuncs->set_nlg_result_cb || //NULL == engine->pefuncs->set_pre_result_cb || @@ -880,6 +907,25 @@ int vcd_engine_recognize_cancel() return 0; } +int vcd_engine_set_audio_type(const char* audio) +{ + if (false == g_agent_init) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Not Initialized"); + return VCD_ERROR_OPERATION_FAILED; + } + + int ret = -1; + if (true == g_dynamic_engine.is_loaded) { + ret = g_dynamic_engine.pefuncs->set_audio_type(audio); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Engine Agent ERROR] Fail to set audio type(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + } + + return 0; +} + int vcd_engine_set_domain(int pid, const char* domain) { if (false == g_agent_init) { diff --git a/server/vcd_engine_agent.h b/server/vcd_engine_agent.h index 4b4a21e..7166cc8 100644 --- a/server/vcd_engine_agent.h +++ b/server/vcd_engine_agent.h @@ -91,6 +91,8 @@ int vcd_engine_recognize_stop(); int vcd_engine_recognize_cancel(); +int vcd_engine_set_audio_type(const char* audio); + int vcd_engine_set_domain(int pid, const char* domain); int vcd_engine_get_nlu_base_info(int pid, const char* key, char** value); diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 3b33e95..6202720 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -32,7 +32,9 @@ #endif #include "vcd_client_data.h" +#include "vcd_config.h" #include "vcd_dbus.h" +#include "vcd_engine_agent.h" #include "vcd_recorder.h" #include "vcd_main.h" #include "voice_control_plugin_engine.h" @@ -87,8 +89,14 @@ static float get_volume_decibel(char* data, int size); static void __msf_wifi_audio_data_receive_cb(msf_wifi_voice_data_s *voice_data, void* user_data) { if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_MSF, sizeof(VCP_AUDIO_ID_MSF))) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); - return; + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_READY == state) { + vcd_engine_set_audio_type(VCP_AUDIO_ID_MSF); + vcd_recorder_set(VCP_AUDIO_ID_MSF, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); + return; + } } if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) { @@ -143,9 +151,15 @@ static void _bt_cb_hid_state_changed(int result, bool connected, const char *rem static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void *user_data) { - if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, strlen(VCP_AUDIO_ID_BLUETOOTH))) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); - return; + if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_BLUETOOTH, sizeof(VCP_AUDIO_ID_BLUETOOTH))) { + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_READY == state) { + vcd_engine_set_audio_type(VCP_AUDIO_ID_BLUETOOTH); + vcd_recorder_set(VCP_AUDIO_ID_BLUETOOTH, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); + } else { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] current audio type is (%s)", g_current_audio_type); + return; + } } if (VCD_RECORDER_STATE_RECORDING != g_recorder_state) { @@ -739,6 +753,12 @@ int vcd_recorder_stop() } #endif } + + if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, sizeof(VCP_AUDIO_ID_NONE))) { + vcd_recorder_set(VCP_AUDIO_ID_NONE, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); + vcd_engine_set_audio_type(VCP_AUDIO_ID_NONE); + } + return 0; } diff --git a/server/vcd_server.c b/server/vcd_server.c index 79bb719..bed1370 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1521,6 +1521,7 @@ static int __start_internal_recognition() SLOG(LOG_DEBUG, TAG_VCD, "[Server Success] Start engine"); +#if 0 /* 5. recorder start */ ret = vcd_recorder_start(); if (0 != ret) { @@ -1532,6 +1533,7 @@ static int __start_internal_recognition() vcdc_send_error_signal_to_manager(vcd_client_manager_get_pid(), VCD_ERROR_OPERATION_FAILED, "voice_engine.error.proc_fail"); return ret; } +#endif vcd_config_set_service_state(VCD_STATE_RECORDING); vcdc_send_service_state(VCD_STATE_RECORDING); @@ -1622,8 +1624,10 @@ int vcd_server_mgr_stop() return VCD_ERROR_OPERATION_FAILED; } +#if 0 /* 2. Stop recorder */ vcd_recorder_stop(); +#endif /* 3. Stop engine recognition */ int ret = vcd_engine_recognize_stop(); @@ -1640,12 +1644,6 @@ int vcd_server_mgr_stop() int vcd_server_mgr_cancel() { - /* 1. Check current state */ - vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_RECORDING != state && VCD_STATE_PROCESSING != state) { - SLOG(LOG_WARN, TAG_VCD, "[Server ERROR] Current state is not recording or processing"); - return VCD_ERROR_INVALID_STATE; - } if (-1 == vcd_client_manager_get_pid()) { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Manager is NOT available."); return VCD_ERROR_OPERATION_FAILED; @@ -1657,8 +1655,19 @@ int vcd_server_mgr_cancel() g_restart_timer = NULL; } + /* 1. Check current state */ + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_READY == state) { + SLOG(LOG_DEBUG, TAG_VCD, "[Server] Current state is READY"); + vcd_recorder_stop(); + return VCD_ERROR_NONE; + } + +#if 0 /* 2. Stop recorder */ vcd_recorder_stop(); +#endif + /* 3. Cancel engine */ int ret = vcd_engine_recognize_cancel(); if (0 != ret) { -- 2.7.4 From ff65c8eed642e1b8d4b8c32183c234df8b91221c Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 11 May 2017 18:15:33 +0900 Subject: [PATCH 16/16] Fix memory leak Change-Id: I6d8d02a895d84e9a9469930aef3dd2e198a30983 Signed-off-by: Suyeon Hwang --- common/vc_cmd_db.c | 50 +++++++++++++++++++++++++++++++----------------- common/vc_command.c | 1 - server/vcd_client_data.c | 8 ++++++++ server/vcd_dbus.c | 25 ++++++++++++++++++++---- server/vcd_recorder.c | 2 +- 5 files changed, 62 insertions(+), 24 deletions(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 30e0266..2e35e84 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -22,7 +22,7 @@ #include "vc_cmd_db.h" #include "vc_main.h" -#include "voice_control_command.h" +#include "vc_command.h" #include "voice_control_command_expand.h" @@ -361,10 +361,12 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) while (SQLITE_ROW == ret) { int temp = 0; + int ret = -1; char* temp_text = NULL; - vc_cmd_s* temp_cmd = NULL; - temp_cmd = (vc_cmd_s*)calloc(1, sizeof(vc_cmd_s)); - if (NULL == temp_cmd) { + vc_cmd_h temp_cmd; + ret = vc_cmd_create(&temp_cmd); + + if (0 != ret) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory"); if (NULL != appid) { free(appid); @@ -380,12 +382,16 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) temp_text = (char*)sqlite3_column_text(stmt, 7); if (NULL != temp_text) - temp_cmd->appid = strdup(temp_text); + vc_cmd_set_appid(temp_cmd, temp_text); - if (NULL != appid && NULL != temp_cmd->appid) { - if (VC_COMMAND_TYPE_BACKGROUND == type && 0 == strncmp(appid, temp_cmd->appid, strlen(appid))) { + ret = vc_cmd_get_appid(temp_cmd, &temp_text); + if (NULL != appid && 0 == ret) { + if (VC_COMMAND_TYPE_BACKGROUND == type && 0 == strncmp(appid, temp_text, strlen(appid))) { SLOG(LOG_DEBUG, vc_db_tag(), "Skip get background commands when app is foreground, appid(%s)", appid); + free(temp_text); + temp_text = NULL; + ret = sqlite3_step(stmt); if (SQLITE_DONE == ret) break; @@ -394,41 +400,49 @@ static int __vc_db_get_commands(int pid, vc_cmd_type_e type, GSList** cmd_list) } } + if (NULL != temp_text) { + free(temp_text); + temp_text = NULL; + } + temp = sqlite3_column_int(stmt, 0); - temp_cmd->id = temp; + vc_cmd_set_id(temp_cmd, temp); temp = sqlite3_column_int(stmt, 1); - temp_cmd->pid = temp; + vc_cmd_set_pid(temp_cmd, temp); temp = sqlite3_column_int(stmt, 2); - temp_cmd->type = temp; + vc_cmd_set_type(temp_cmd, temp); temp = sqlite3_column_int(stmt, 3); - temp_cmd->format = temp; + vc_cmd_set_format(temp_cmd, temp); temp = sqlite3_column_int(stmt, 4); - temp_cmd->domain = temp; + vc_cmd_set_domain(temp_cmd, temp); temp_text = (char*)sqlite3_column_text(stmt, 5); if (NULL != temp_text) - temp_cmd->command = strdup(temp_text); + vc_cmd_set_command(temp_cmd, temp_text); temp_text = (char*)sqlite3_column_text(stmt, 6); if (NULL != temp_text) - temp_cmd->parameter = strdup(temp_text); + vc_cmd_set_unfixed_command(temp_cmd, temp_text); temp_text = (char*)sqlite3_column_text(stmt, 8); if (NULL != temp_text) - temp_cmd->invocation_name = strdup(temp_text); + vc_cmd_set_invocation_name(temp_cmd, temp_text); temp_text = (char*)sqlite3_column_text(stmt, 9); if (NULL != temp_text) - temp_cmd->fixed = strdup(temp_text); + vc_cmd_set_fixed_command(temp_cmd, temp_text); - if (type == temp_cmd->type) { + ret = vc_cmd_get_type(temp_cmd, &temp); + if (0 == ret && type == temp) { *cmd_list = g_slist_append(*cmd_list, temp_cmd); } else { - SLOG(LOG_WARN, vc_db_tag(), "[WARNING] 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, type); + + vc_cmd_destroy((vc_cmd_h)temp_cmd); } ret = sqlite3_step(stmt); if (SQLITE_DONE == ret) diff --git a/common/vc_command.c b/common/vc_command.c index 38f0299..1478fcd 100644 --- a/common/vc_command.c +++ b/common/vc_command.c @@ -702,7 +702,6 @@ int vc_cmd_create(vc_cmd_h* vc_command) command->key = VC_KEY_NONE; command->modifier = VC_MODIFIER_NONE; command->invocation_name = NULL; - command->parameter = NULL; command->appid = NULL; command->fixed = NULL; diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index b033950..e7a9a00 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -942,6 +942,10 @@ int vcd_client_add(int pid) if (NULL == g_client_list) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new client"); + + free(info); + info = NULL; + return -1; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Client Data SUCCESS] Add new client"); @@ -1263,6 +1267,10 @@ int vcd_client_widget_add(int pid) if (NULL == g_widget_list) { SLOG(LOG_ERROR, TAG_VCD, "[Client Data ERROR] Fail to add new widget"); + + free(info); + info = NULL; + return -1; } else { SLOG(LOG_DEBUG, TAG_VCD, "[Client Data SUCCESS] Add new widget"); diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 75a8c63..eed98a8 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -613,10 +613,17 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* SLOG(LOG_DEBUG, TAG_VCD, "[Dbus] send dialog : pid(%d), disp_text(%s), utt_text(%s), continue(%d)", pid, disp_text, utt_text, continuous); - if (NULL == disp_text) - disp_text = strdup("#NULL"); - if (NULL == utt_text) - utt_text = strdup("#NULL"); + char* disp_null = NULL; + char* utt_null = NULL; + if (NULL == disp_text) { + disp_null = strdup("#NULL"); + disp_text = disp_null; + } + + if (NULL == utt_text) { + utt_null = strdup("#NULL"); + utt_text = utt_null; + } dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, @@ -637,6 +644,16 @@ int vcdc_send_dialog(int manger_pid, int pid, const char* disp_text, const char* dbus_message_unref(msg); + if (NULL != disp_null) { + free(disp_null); + disp_null = NULL; + } + + if (NULL != utt_null) { + free(utt_null); + utt_null = NULL; + } + return 0; } diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 6202720..25df611 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -754,7 +754,7 @@ int vcd_recorder_stop() #endif } - if (0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, sizeof(VCP_AUDIO_ID_NONE))) { + if (NULL != g_current_audio_type && 0 != strncmp(g_current_audio_type, VCP_AUDIO_ID_NONE, sizeof(VCP_AUDIO_ID_NONE))) { vcd_recorder_set(VCP_AUDIO_ID_NONE, VCP_AUDIO_TYPE_PCM_S16_LE, 16000, 1); vcd_engine_set_audio_type(VCP_AUDIO_ID_NONE); } -- 2.7.4