From f18071058a259bc26a475a6e8648ab44f0e64310 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Thu, 20 Sep 2018 15:40:39 +0900 Subject: [PATCH 01/16] Fix coverity issue (pointer deference) Change-Id: I545ff21f6efa01fc1a905f57f6ea0009068062da Signed-off-by: sooyeon.kim --- client/vc_mgr.c | 79 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 17bbbb8..8493fb9 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -4068,50 +4068,53 @@ static void __tts_feedback_thread(void* data, Ecore_Thread* thread) continue; } - if (getpid() == feedback_data->pid) { - vc_mgr_feedback_streaming_cb callback = NULL; - void* user_data = NULL; - - vc_mgr_client_get_feedback_streaming_cb(g_vc_m, &callback, &user_data); - if (NULL == callback) { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] TTS feedback streaming callback is null"); - return; - } + if (NULL != feedback_data) { + if (getpid() == feedback_data->pid) { + vc_mgr_feedback_streaming_cb callback = NULL; + void* user_data = NULL; + + vc_mgr_client_get_feedback_streaming_cb(g_vc_m, &callback, &user_data); + if (NULL == callback) { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] TTS feedback streaming callback is null"); + vc_mgr_data_clear_feedback_data(&feedback_data); + return; + } - SLOG(LOG_DEBUG, TAG_VCM, "TTS feedback streaming callback is called"); - vc_mgr_client_use_callback(g_vc_m); - callback(feedback_data->event, feedback_data->data, feedback_data->data_size, user_data); - vc_mgr_client_not_use_callback(g_vc_m); + SLOG(LOG_DEBUG, TAG_VCM, "TTS feedback streaming callback is called"); + vc_mgr_client_use_callback(g_vc_m); + callback(feedback_data->event, feedback_data->data, feedback_data->data_size, user_data); + vc_mgr_client_not_use_callback(g_vc_m); - /* If no feedback data and EVENT_FINISH */ - if (0 >= vc_mgr_data_get_feedback_data_size() && VC_FEEDBACK_EVENT_FINISH == feedback_data->event) { - SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish feedback"); - break; - } - } else { - vc_mgr_vc_tts_streaming_cb callback = NULL; - void* user_data = NULL; - - vc_mgr_client_get_vc_tts_streaming_cb(g_vc_m, &callback, &user_data); - if (NULL == callback) { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] vc tts streaming callback is null"); - vc_mgr_data_clear_feedback_data(&feedback_data); - return; - } + /* If no feedback data and EVENT_FINISH */ + if (0 >= vc_mgr_data_get_feedback_data_size() && VC_FEEDBACK_EVENT_FINISH == feedback_data->event) { + SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish feedback"); + break; + } + } else { + vc_mgr_vc_tts_streaming_cb callback = NULL; + void* user_data = NULL; - SLOG(LOG_DEBUG, TAG_VCM, "vc tts feedback streaming callback is called"); - vc_mgr_client_use_callback(g_vc_m); - callback(feedback_data->pid, feedback_data->utt_id, feedback_data->event, feedback_data->data, feedback_data->data_size, user_data); - vc_mgr_client_not_use_callback(g_vc_m); + vc_mgr_client_get_vc_tts_streaming_cb(g_vc_m, &callback, &user_data); + if (NULL == callback) { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] vc tts streaming callback is null"); + vc_mgr_data_clear_feedback_data(&feedback_data); + return; + } - /* If no feedback data and EVENT_FINISH */ - if (0 >= vc_mgr_data_get_feedback_data_size() && VC_FEEDBACK_EVENT_FINISH == feedback_data->event) { - SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish vc tts feedback"); - break; + SLOG(LOG_DEBUG, TAG_VCM, "vc tts feedback streaming callback is called"); + vc_mgr_client_use_callback(g_vc_m); + callback(feedback_data->pid, feedback_data->utt_id, feedback_data->event, feedback_data->data, feedback_data->data_size, user_data); + vc_mgr_client_not_use_callback(g_vc_m); + + /* If no feedback data and EVENT_FINISH */ + if (0 >= vc_mgr_data_get_feedback_data_size() && VC_FEEDBACK_EVENT_FINISH == feedback_data->event) { + SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish vc tts feedback"); + break; + } } - } - if (feedback_data) free(feedback_data); + feedback_data = NULL; + } } } -- 2.7.4 From d260b04b09f192c34570644311ba1efb26e1a734 Mon Sep 17 00:00:00 2001 From: yhji Date: Thu, 27 Sep 2018 16:47:07 +0900 Subject: [PATCH 02/16] Fix Wformat build warning Change-Id: Ib936e1857b9d1bda728d30c4e49fb8a5bc235b25 Signed-off-by: yhji --- client/vc_mgr_data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/vc_mgr_data.cpp b/client/vc_mgr_data.cpp index 7053c46..866d3da 100644 --- a/client/vc_mgr_data.cpp +++ b/client/vc_mgr_data.cpp @@ -35,7 +35,7 @@ int vc_mgr_data_add_feedback_data(vc_feedback_data_s* data) SLOG(LOG_ERROR, TAG_VCM, "[DATA ERROR] feedback data is NULL"); return VC_ERROR_INVALID_PARAMETER; } - SLOG(LOG_DEBUG, TAG_VCM, "[DATA] feedback_data : %p", *data); + SLOG(LOG_DEBUG, TAG_VCM, "[DATA] feedback_data : %p", data); pthread_mutex_lock(&g_feedback_data_mutex); -- 2.7.4 From ffd0494e481ecfc89e0d71260db9e22a7bb0fc79 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Wed, 19 Sep 2018 16:06:51 +0900 Subject: [PATCH 03/16] Support Multi-Assistant Change-Id: I062eadc3b60af5051a3460a5d6d9388796da3e48 Signed-off-by: sooyeon.kim --- client/vc_mgr.c | 104 +++++++++++++++++++++++++- client/vc_mgr_client.c | 31 ++++++++ client/vc_mgr_client.h | 13 +++- client/vc_mgr_dbus.c | 44 ++++++++++- client/vc_mgr_dbus.h | 5 +- common/vc_defs.h | 2 + include/voice_control_manager_internal.h | 21 ++++++ server/vcd_config.c | 14 ++++ server/vcd_config.h | 5 ++ server/vcd_dbus.c | 3 + server/vcd_dbus_server.c | 39 +++++++++- server/vcd_dbus_server.h | 3 + server/vcd_main.h | 13 ++++ server/vcd_recorder.c | 121 ++++++++++++++++++++++++++++++- server/vcd_recorder.h | 6 ++ server/vcd_server.c | 30 ++++++++ server/vcd_server.h | 3 + 17 files changed, 447 insertions(+), 10 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 17bbbb8..fee9d82 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -213,7 +213,6 @@ static int __vc_mgr_check_privilege() __check_privilege_deinitialize(); } - g_privilege_allowed = 1; return VC_ERROR_NONE; } @@ -270,6 +269,14 @@ int vc_mgr_initialize(void) return ret; } + ret = vc_mgr_client_set_audio_streaming_mode(g_vc_m, VC_AUDIO_STREAMING_MODE_VC_SERVICE); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set audio streaming mode : %d", ret); + vc_config_mgr_finalize(g_vc_m->handle + VC_MANAGER_CONFIG_HANDLE); + vc_mgr_client_destroy(g_vc_m); + return ret; + } + /* for TTS feedback */ /* ret = vc_mgr_player_init(); if (0 != ret) { @@ -377,7 +384,10 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data) g_m_connect_timer = NULL; - ret = vc_mgr_dbus_request_initialize(g_vc_m->handle, &service_state, &foreground, &g_daemon_pid); + vc_audio_streaming_mode_e streaming_mode; + vc_mgr_client_get_audio_streaming_mode(g_vc_m, &streaming_mode); + + ret = vc_mgr_dbus_request_initialize(g_vc_m->handle, (int)streaming_mode, &service_state, &foreground, &g_daemon_pid); if (VC_ERROR_ENGINE_NOT_FOUND == ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret)); @@ -4255,3 +4265,93 @@ int vc_mgr_send_utterance_status(int pid, int utt_id, int utt_status) return 0; } +int vc_mgr_send_audio_streaming(vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Send audio streaming to the engine service"); + + if (NULL == buffer) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid parameter"); + return VC_ERROR_INVALID_PARAMETER; + } + + if (0 != __vc_mgr_get_feature_enabled()) { + SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported"); + return VC_ERROR_NOT_SUPPORTED; + } + + if (0 != __vc_mgr_check_privilege()) { + return VC_ERROR_PERMISSION_DENIED; + } + + 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, "@@@"); + 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, "@@@"); + 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 (VC_SERVICE_STATE_READY != service_state && VC_SERVICE_STATE_RECORDING != service_state) { + + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: service state is not 'READY' and 'RECORDING', state(%d)", service_state); + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + return VC_ERROR_INVALID_STATE; + } + + /* send audio streaming */ + int ret = vc_mgr_dbus_send_audio_streaming(g_vc_m->handle, event, buffer, len); + if (0 != ret) { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to send audio streaming data"); + } else { + SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] Success to send"); + } + + return ret; +} + +int vc_mgr_set_audio_streaming_mode(vc_audio_streaming_mode_e streaming_mode) +{ + SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Set multi assistant mode"); + + if (0 != __vc_mgr_get_feature_enabled()) { + SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported"); + return VC_ERROR_NOT_SUPPORTED; + } + + if (0 != __vc_mgr_check_privilege()) { + return VC_ERROR_PERMISSION_DENIED; + } + + 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, "@@@"); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != VC_STATE_INITIALIZED) { + + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State: Current state is not 'INITIALIZED', state(%d)", state); + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + return VC_ERROR_INVALID_STATE; + } + + int ret = vc_mgr_client_set_audio_streaming_mode(g_vc_m, streaming_mode); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to set multi assistant mode, ret(%d)", ret); + return VC_ERROR_INVALID_STATE; + } + + return ret; +} diff --git a/client/vc_mgr_client.c b/client/vc_mgr_client.c index 9f5124d..2317c43 100644 --- a/client/vc_mgr_client.c +++ b/client/vc_mgr_client.c @@ -102,6 +102,9 @@ typedef struct { /* foreground pid */ int foreground_pid; + + /* multi-assistant */ + vc_audio_streaming_mode_e streaming_mode; } vc_mgr_client_s; typedef struct { @@ -227,6 +230,8 @@ int vc_mgr_client_create(vc_h* vc) client->foreground_pid = VC_RUNTIME_INFO_NO_FOREGROUND; + client->streaming_mode = VC_AUDIO_STREAMING_MODE_VC_SERVICE; + g_mgr_client_list = g_slist_append(g_mgr_client_list, client); *vc = temp; @@ -1322,3 +1327,29 @@ int vc_mgr_client_get_specific_engine_result_cb(vc_h vc, vc_mgr_specific_engine_ return 0; } + +int vc_mgr_client_set_audio_streaming_mode(vc_h vc, vc_audio_streaming_mode_e streaming_mode) +{ + vc_mgr_client_s* client = __mgr_client_get(vc); + + /* check handle */ + if (NULL == client) + return VC_ERROR_INVALID_PARAMETER; + + client->streaming_mode = streaming_mode; + + return 0; +} + +int vc_mgr_client_get_audio_streaming_mode(vc_h vc, vc_audio_streaming_mode_e* streaming_mode) +{ + vc_mgr_client_s* client = __mgr_client_get(vc); + + /* check handle */ + if (NULL == client) + return VC_ERROR_INVALID_PARAMETER; + + *streaming_mode = client->streaming_mode; + + return 0; +} diff --git a/client/vc_mgr_client.h b/client/vc_mgr_client.h index 9128f95..3ee6512 100644 --- a/client/vc_mgr_client.h +++ b/client/vc_mgr_client.h @@ -21,6 +21,7 @@ #include "vc_info_parser.h" #include "voice_control_manager.h" +#include "voice_control_manager_internal.h" #ifdef __cplusplus extern "C" { @@ -111,7 +112,6 @@ int vc_mgr_client_set_vc_tts_streaming_cb(vc_h vc, vc_mgr_vc_tts_streaming_cb ca int vc_mgr_client_get_vc_tts_streaming_cb(vc_h vc, vc_mgr_vc_tts_streaming_cb* callback, void** user_data); - /* * set/get option */ @@ -161,6 +161,11 @@ int vc_mgr_client_set_foreground(vc_h vc, int pid, bool value); int vc_mgr_client_get_foreground(vc_h vc, int* pid); +int vc_mgr_client_set_multi_assistant(vc_h vc, bool use_multi_assistant); + +int vc_mgr_client_get_multi_assistant(vc_h vc, bool* use_multi_assistant); + + /* utils */ int vc_mgr_client_get_count(); @@ -185,6 +190,12 @@ int vc_mgr_client_set_start_by_client(vc_h vc, bool option); int vc_mgr_client_get_start_by_client(vc_h vc, bool* option); +/* multi assistant */ +int vc_mgr_client_set_audio_streaming_mode(vc_h vc, vc_audio_streaming_mode_e streaming_mode); + +int vc_mgr_client_get_audio_streaming_mode(vc_h vc, vc_audio_streaming_mode_e* streaming_mode); + + #ifdef __cplusplus } #endif diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index 8f8adf6..f889e43 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -891,7 +891,7 @@ static int __dbus_restore_daemon() return ret; } -int vc_mgr_dbus_request_initialize(int pid, int* service_state, int* foreground, int* daemon_pid) +int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid) { DBusError err; dbus_error_init(&err); @@ -929,6 +929,7 @@ int vc_mgr_dbus_request_initialize(int pid, int* service_state, int* foreground, dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &audio_streaming_mode, DBUS_TYPE_INVALID); DBusMessage* result_msg; @@ -2301,8 +2302,6 @@ int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status) { DBusMessage* msg; - - /* create a signal & check for errors */ msg = __get_message(pid, VC_MANAGER_METHOD_UTTERANCE_STATUS, VC_COMMAND_TYPE_FOREGROUND); if (NULL == msg) { @@ -2329,3 +2328,42 @@ int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status) return 0; } + +int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) +{ + DBusMessage* msg; + msg = dbus_message_new_method_call( + VC_SERVER_SERVICE_NAME, + VC_SERVER_SERVICE_OBJECT_PATH, + VC_SERVER_SERVICE_INTERFACE, + VC_MANAGER_METHOD_SEND_AUDIO_STREAMING); + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc send audio streaming : Fail to make message"); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, + &buffer, len, + DBUS_TYPE_INVALID); + + dbus_message_set_no_reply(msg, TRUE); + + /* send dbus message and flush the connection */ + if (!dbus_connection_send(g_m_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_VCM, "[Dbus ERROR] Fail to send audio streaming"); + } else { + SLOG(LOG_DEBUG, TAG_VCM, "[Dbus DEBUG] Success to send audio streaming"); + dbus_connection_flush(g_m_conn_sender); + } + + dbus_message_unref(msg); + + return 0; +} + diff --git a/client/vc_mgr_dbus.h b/client/vc_mgr_dbus.h index b0b5c2f..9ce1239 100644 --- a/client/vc_mgr_dbus.h +++ b/client/vc_mgr_dbus.h @@ -18,6 +18,8 @@ #ifndef __VC_DBUS_H_ #define __VC_DBUS_H_ +#include "voice_control_manager_internal.h" + #ifdef __cplusplus extern "C" { @@ -30,7 +32,7 @@ int vc_mgr_dbus_close_connection(); int vc_mgr_dbus_request_hello(); -int vc_mgr_dbus_request_initialize(int pid, int* service_state, int* foreground, int* daemon_pid); +int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid); int vc_mgr_dbus_request_finalize(int pid); @@ -76,6 +78,7 @@ int vc_mgr_dbus_request_stop_feedback(int pid); int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status); +int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len); #ifdef __cplusplus } diff --git a/common/vc_defs.h b/common/vc_defs.h index 0458c37..55fc210 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -151,6 +151,8 @@ extern "C" { #define VC_MANAGER_METHOD_STOP_FEEDBACK "vc_manager_method_request_stop_feedback" #define VC_MANAGER_METHOD_UTTERANCE_STATUS "vc_manager_method_utterance_status" +#define VC_MANAGER_METHOD_SEND_AUDIO_STREAMING "vc_manager_method_send_audio_streaming" + #define VCD_MANAGER_METHOD_HELLO "vcd_manager_method_hello" #define VCD_MANAGER_METHOD_SPEECH_DETECTED "vcd_manager_method_speech_detected" #define VCD_MANAGER_METHOD_ALL_RESULT "vcd_manager_method_all_result" diff --git a/include/voice_control_manager_internal.h b/include/voice_control_manager_internal.h index c06d38b..4b58230 100644 --- a/include/voice_control_manager_internal.h +++ b/include/voice_control_manager_internal.h @@ -27,6 +27,18 @@ extern "C" { #endif +typedef enum { + VC_AUDIO_STREAMING_EVENT_FAIL = -1, /**< Failed */ + VC_AUDIO_STREAMING_EVENT_START = 1, /**< Start event */ + VC_AUDIO_STREAMING_EVENT_CONTINUE = 2, /**< Continue event */ + VC_AUDIO_STREAMING_EVENT_FINISH = 3 /**< Finish event */ +} vc_audio_streaming_event_e; + +typedef enum { + VC_AUDIO_STREAMING_MODE_VC_SERVICE = 0, /**< Use audio recording from vc service */ + VC_AUDIO_STREAMING_MODE_MULTI_ASSISTANT = 1, /**< Use audio streaming from multi-assistant */ + VC_AUDIO_STREAMING_MODE_OUTSIDE = 2, /**< Use audio streaming from outside */ +} vc_audio_streaming_mode_e; /** * @brief Sets demandable client list. @@ -79,6 +91,15 @@ int vc_mgr_unset_demandable_client_rule(void); */ int vc_mgr_set_domain(const char* domain); +/** + * @brief Sends audio streaming to the engine service. + * @since_tizen 5.0 + * + */ +int vc_mgr_send_audio_streaming(vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len); + +int vc_mgr_set_audio_streaming_mode(vc_audio_streaming_mode_e streaming_mode); + #ifdef __cplusplus } diff --git a/server/vcd_config.c b/server/vcd_config.c index 8d707b7..629487e 100755 --- a/server/vcd_config.c +++ b/server/vcd_config.c @@ -28,6 +28,8 @@ static vcd_state_e g_state; static int g_foreground_pid; +static int g_audio_streaming_mode; + #define COMMAND_TYPE_MAX 7 static int g_enabled_command_type[COMMAND_TYPE_MAX] = { 0, /* NONE */ @@ -185,3 +187,15 @@ int vcd_config_get_command_type_enabled(int cmd_type) return g_enabled_command_type[cmd_type]; } + +int vcd_config_get_audio_streaming_mode(vcd_audio_streaming_mode_e* streaming_mode) +{ + *streaming_mode = g_audio_streaming_mode; + return 0; +} + +int vcd_config_set_audio_streaming_mode(vcd_audio_streaming_mode_e streaming_mode) +{ + g_audio_streaming_mode = streaming_mode; + return 0; +} diff --git a/server/vcd_config.h b/server/vcd_config.h index de6589d..68db934 100755 --- a/server/vcd_config.h +++ b/server/vcd_config.h @@ -51,6 +51,11 @@ int vcd_config_disable_command_type(int cmd_type); int vcd_config_get_command_type_enabled(int cmd_type); +int vcd_config_get_audio_streaming_mode(vcd_audio_streaming_mode_e* streaming_mode); + +int vcd_config_set_audio_streaming_mode(vcd_audio_streaming_mode_e streaming_mode); + + #ifdef __cplusplus } #endif diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 69e1f52..1718191 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -1150,6 +1150,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_MANAGER_METHOD_STOP_FEEDBACK)) vcd_dbus_server_mgr_stop_feedback(g_conn_listener, msg); + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_SEND_AUDIO_STREAMING)) + vcd_dbus_server_mgr_send_audio_streaming(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 68b0ae1..9740609 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -20,7 +20,7 @@ #include "vcd_dbus_server.h" #include "vcd_main.h" #include "vcd_server.h" - +#include "vcd_config.h" int __dbus_error_return(DBusConnection* conn, DBusMessage* msg, int ret) { @@ -86,6 +86,7 @@ int vcd_dbus_server_mgr_initialize(DBusConnection* conn, DBusMessage* msg) dbus_error_init(&err); int pid; + int streaming_mode; int service_state; int foreground; int daemon_pid; @@ -93,6 +94,7 @@ int vcd_dbus_server_mgr_initialize(DBusConnection* conn, DBusMessage* msg) dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &streaming_mode, DBUS_TYPE_INVALID); SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager Initialize"); @@ -102,6 +104,7 @@ int vcd_dbus_server_mgr_initialize(DBusConnection* conn, DBusMessage* msg) dbus_error_free(&err); ret = VCD_ERROR_OPERATION_FAILED; } else { + vcd_config_set_audio_streaming_mode((vcd_audio_streaming_mode_e)streaming_mode); ret = vcd_server_mgr_initialize(pid); service_state = vcd_server_get_service_state(); foreground = vcd_server_get_foreground(); @@ -1188,6 +1191,39 @@ int vcd_dbus_server_mgr_stop_feedback(DBusConnection* conn, DBusMessage* msg) return 0; } +int vcd_dbus_server_mgr_send_audio_streaming(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + int event = 0; + unsigned char* buffer = NULL; + unsigned int len = 0; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager send audio streaming"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &event, + DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, + &buffer, &len, + DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_VCD, "[IN ERROR] vcd mgr send audio streaming : get arguments error (%s)", err.message); + dbus_error_free(&err); + ret = VCD_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCD, "[IN] vcd mgr send audio streaming : pid(%d), event(%d), buffer(%p), len(%d)", pid, event, buffer, len); + ret = vcd_server_mgr_send_audio_streaming(pid, event, buffer, len); + } + + return ret; +} + /* * Dbus Server functions for client @@ -2206,6 +2242,7 @@ int vcd_dbus_server_set_language(DBusConnection* conn, DBusMessage* msg) return 0; } + int vcd_dbus_server_request_tts(DBusConnection* conn, DBusMessage* msg) { DBusError err; diff --git a/server/vcd_dbus_server.h b/server/vcd_dbus_server.h index bef7205..ac02296 100644 --- a/server/vcd_dbus_server.h +++ b/server/vcd_dbus_server.h @@ -74,6 +74,9 @@ int vcd_dbus_server_mgr_start_feedback(DBusConnection* conn, DBusMessage* msg); int vcd_dbus_server_mgr_stop_feedback(DBusConnection* conn, DBusMessage* msg); +/* for Multi-assistant */ +int vcd_dbus_server_mgr_send_audio_streaming(DBusConnection* conn, DBusMessage* msg); + /* * Dbus Server functions for client diff --git a/server/vcd_main.h b/server/vcd_main.h index 3d8525b..46b9fd8 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -74,6 +74,19 @@ typedef enum { VCD_STATE_PROCESSING = 3 } vcd_state_e; +typedef enum { + VCD_AUDIO_STREAMING_EVENT_FAIL = -1, /**< Failed */ + VCD_AUDIO_STREAMING_EVENT_START = 1, /**< Start event */ + VCD_AUDIO_STREAMING_EVENT_CONTINUE = 2, /**< Continue event */ + VCD_AUDIO_STREAMING_EVENT_FINISH = 3 /**< Finish event */ +} vcd_audio_streaming_event_e; + +typedef enum { + VCD_AUDIO_STREAMING_MODE_VC_SERVICE = 0, /**< Use audio recording from vc service */ + VCD_AUDIO_STREAMING_MODE_MULTI_ASSISTANT = 1, /**< Use audio streaming from multi-assistant */ + VCD_AUDIO_STREAMING_MODE_OUTSIDE = 2, /**< Use audio streaming from outside */ +} vcd_audio_streaming_mode_e; + struct vce_cmd_s { int index; }; diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index ca49fb9..6ffb708 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -75,9 +75,9 @@ static int g_buffer_count; static int g_device_id = -1; /* Sound buf save */ -/* +#if 0 #define BUF_SAVE_MODE - */ +#endif #ifdef BUF_SAVE_MODE static FILE* g_normal_file; @@ -507,6 +507,13 @@ int vcd_recorder_destroy() int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, int channel) { + vcd_audio_streaming_mode_e streaming_mode; + vcd_config_get_audio_streaming_mode(&streaming_mode); + if (VCD_AUDIO_STREAMING_MODE_MULTI_ASSISTANT == streaming_mode || VCD_AUDIO_STREAMING_MODE_OUTSIDE == streaming_mode) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Current audio streaming mode(%d)", streaming_mode); + return VCD_ERROR_NONE; + } + if (NULL == audio_type) { return VCD_ERROR_INVALID_PARAMETER; } @@ -627,6 +634,13 @@ int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, in int vcd_recorder_get(char** audio_type) { + vcd_audio_streaming_mode_e streaming_mode; + vcd_config_get_audio_streaming_mode(&streaming_mode); + if (VCD_AUDIO_STREAMING_MODE_MULTI_ASSISTANT == streaming_mode || VCD_AUDIO_STREAMING_MODE_OUTSIDE == streaming_mode) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Current audio streaming mode(%d)", streaming_mode); + return VCD_ERROR_NONE; + } + if (NULL == audio_type) { return VCD_ERROR_INVALID_PARAMETER; } @@ -793,11 +807,107 @@ static void __check_audio_format() } } +int vcd_recorder_start_streaming() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] start streaming"); + + vcd_audio_streaming_mode_e streaming_mode; + vcd_config_get_audio_streaming_mode(&streaming_mode); + if (VCD_AUDIO_STREAMING_MODE_VC_SERVICE == streaming_mode) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Current audio streaming mode(%d)", streaming_mode); + return VCD_ERROR_NONE; + } + +#ifdef BUF_SAVE_MODE + char normal_file_name[128] = {'\0',}; + g_count++; + + while (1) { + snprintf(normal_file_name, sizeof(normal_file_name), "/tmp/vc_streaming_%d_%d", getpid(), g_count); + int ret = access(normal_file_name, 0); + + if (0 == ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] File is already exist"); + if (0 == remove(normal_file_name)) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Remove file"); + break; + } else { + g_count++; + } + } else { + break; + } + } + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] File normal name : %s", normal_file_name); + + /* open test file */ + g_normal_file = fopen(normal_file_name, "wb+x"); + if (!g_normal_file) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] File not found!"); + } +#endif + + return 0; +} + +int vcd_recorder_send_streaming(const void* buffer, const unsigned int length) +{ + vcd_audio_streaming_mode_e streaming_mode; + vcd_config_get_audio_streaming_mode(&streaming_mode); + if (VCD_AUDIO_STREAMING_MODE_VC_SERVICE == streaming_mode) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Current audio streaming mode(%d)", streaming_mode); + return VCD_ERROR_NONE; + } + + if (NULL != g_audio_cb) { + int ret = g_audio_cb(buffer, length); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start streaming : %d", ret); + vcd_recorder_stop(); + return ret; + } + } + +#ifdef BUF_SAVE_MODE + /* write pcm buffer */ + if (g_normal_file) + fwrite(buffer, 1, length, g_normal_file); +#endif + + return 0; +} + +int vcd_recorder_stop_streaming() +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] stop streaming"); + + vcd_audio_streaming_mode_e streaming_mode; + vcd_config_get_audio_streaming_mode(&streaming_mode); + if (VCD_AUDIO_STREAMING_MODE_VC_SERVICE == streaming_mode) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Current audio streaming mode(%d)", streaming_mode); + return VCD_ERROR_NONE; + } + +#ifdef BUF_SAVE_MODE + if (g_normal_file) + fclose(g_normal_file); +#endif + + return 0; +} int vcd_recorder_start() { int ret = -1; + + vcd_audio_streaming_mode_e streaming_mode; + vcd_config_get_audio_streaming_mode(&streaming_mode); + if (VCD_AUDIO_STREAMING_MODE_MULTI_ASSISTANT == streaming_mode || VCD_AUDIO_STREAMING_MODE_OUTSIDE == streaming_mode) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Current audio streaming mode(%d)", streaming_mode); + return VCD_ERROR_NONE; + } + g_buffer_count = 0; SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Enter, recorder state(%d)", g_recorder_state); @@ -919,6 +1029,13 @@ int vcd_recorder_stop() { int ret = -1; + vcd_audio_streaming_mode_e streaming_mode; + vcd_config_get_audio_streaming_mode(&streaming_mode); + if (VCD_AUDIO_STREAMING_MODE_MULTI_ASSISTANT == streaming_mode || VCD_AUDIO_STREAMING_MODE_OUTSIDE == streaming_mode) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Current audio streaming mode(%d)", streaming_mode); + return VCD_ERROR_NONE; + } + if (VCD_RECORDER_STATE_READY == g_recorder_state) return 0; diff --git a/server/vcd_recorder.h b/server/vcd_recorder.h index a061d2a..7a612b8 100644 --- a/server/vcd_recorder.h +++ b/server/vcd_recorder.h @@ -43,6 +43,12 @@ int vcd_recorder_set(const char* audio_type, vce_audio_type_e type, int rate, in int vcd_recorder_get(char** audio_type); +int vcd_recorder_start_streaming(); + +int vcd_recorder_send_streaming(const void* buffer, const unsigned int length); + +int vcd_recorder_stop_streaming(); + int vcd_recorder_start(); int vcd_recorder_read(); diff --git a/server/vcd_server.c b/server/vcd_server.c index d79b946..8de4a88 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -2226,6 +2226,36 @@ int vcd_server_mgr_stop_feedback(void) return VCD_ERROR_NONE; } +int vcd_server_mgr_send_audio_streaming(int pid, int event, unsigned char* buffer, unsigned int len) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] Send Audio Streaming from Multi-assistant. event(%d), buffer(%p), len(%d)", event, &buffer, len); + + int ret = 0; + if (VCD_AUDIO_STREAMING_EVENT_START == event) { + ret = vcd_recorder_start_streaming(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret); + return ret; + } + } + + ret = vcd_recorder_send_streaming((const void*)buffer, (const unsigned int)len); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to start streaming, ret(%d)", ret); + return ret; + } + + if (VCD_AUDIO_STREAMING_EVENT_FINISH == event) { + ret = vcd_recorder_stop_streaming(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to stop streaming, ret(%d)", ret); + return ret; + } + } + + return VCD_ERROR_NONE; +} + /* * VC Server Functions for Client diff --git a/server/vcd_server.h b/server/vcd_server.h index 87b735c..d6270f1 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -85,6 +85,9 @@ int vcd_server_mgr_start_feedback(void); int vcd_server_mgr_stop_feedback(void); +/* for Multi-assistant */ +int vcd_server_mgr_send_audio_streaming(int pid, int event, unsigned char* buffer, unsigned int len); + /* * For client -- 2.7.4 From a7a674f08246f9f367e06a166168f9d79b659945 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Fri, 28 Sep 2018 16:02:12 +0900 Subject: [PATCH 04/16] Check if connection is NULL or not Change-Id: Ib6758c097f17969a12721915e459c2168717b24e Signed-off-by: Wonnam Jang --- client/vc_dbus.c | 2 +- client/vc_mgr_dbus.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ client/vc_widget_dbus.c | 2 +- 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/client/vc_dbus.c b/client/vc_dbus.c index 2da8f6b..ebdce04 100644 --- a/client/vc_dbus.c +++ b/client/vc_dbus.c @@ -409,7 +409,7 @@ int vc_dbus_reconnect() static int __dbus_check() { - if (NULL == g_conn_sender) { + if (NULL == g_conn_sender || NULL == g_conn_listener) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] NULL connection"); //LCOV_EXCL_LINE return vc_dbus_reconnect(); } diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index f889e43..7545a7f 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -825,8 +825,21 @@ int vc_mgr_dbus_reconnect() return 0; } +static int __dbus_check() +{ + if (NULL == g_m_conn_sender || NULL == g_m_conn_listener) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] NULL connection"); //LCOV_EXCL_LINE + return vc_mgr_dbus_reconnect(); + } + return 0; +} + int vc_mgr_dbus_request_hello() { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = dbus_message_new_method_call( @@ -893,6 +906,10 @@ static int __dbus_restore_daemon() int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* service_state, int* foreground, int* daemon_pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -993,6 +1010,10 @@ int vc_mgr_dbus_request_initialize(int pid, int audio_streaming_mode, int* servi int vc_mgr_dbus_request_finalize(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1081,6 +1102,10 @@ int vc_mgr_dbus_request_finalize(int pid) int vc_mgr_dbus_request_set_command(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1158,6 +1183,10 @@ int vc_mgr_dbus_request_set_command(int pid) int vc_mgr_dbus_request_unset_command(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1235,6 +1264,10 @@ int vc_mgr_dbus_request_unset_command(int pid) int vc_mgr_dbus_request_demandable_client(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1312,6 +1345,10 @@ int vc_mgr_dbus_request_demandable_client(int pid) int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1391,6 +1428,10 @@ int vc_mgr_dbus_request_set_audio_type(int pid, const char* audio_type) int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1475,6 +1516,10 @@ int vc_mgr_dbus_request_get_audio_type(int pid, char** audio_type) int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* data) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -1516,6 +1561,10 @@ int vc_mgr_dbus_request_set_private_data(int pid, const char* key, const char* d int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -1586,6 +1635,10 @@ int vc_mgr_dbus_request_get_private_data(int pid, const char* key, char** data) int vc_mgr_dbus_request_set_client_info(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1664,6 +1717,10 @@ int vc_mgr_dbus_request_set_client_info(int pid) int vc_mgr_dbus_request_set_domain(int pid, const char* domain) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -1727,6 +1784,10 @@ int vc_mgr_dbus_request_set_domain(int pid, const char* domain) int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send_event) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -1764,6 +1825,10 @@ int vc_mgr_dbus_request_do_action(int pid, vc_send_event_type_e type, char* send int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_command_option, bool start_by_client) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1849,6 +1914,10 @@ int vc_mgr_dbus_request_start(int pid, int recognition_mode, bool exclusive_comm int vc_mgr_dbus_request_stop(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -1927,6 +1996,10 @@ int vc_mgr_dbus_request_stop(int pid) int vc_mgr_dbus_request_cancel(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -2005,6 +2078,10 @@ int vc_mgr_dbus_request_cancel(int pid) int vc_mgr_dbus_request_enable_command_type(int pid, int cmd_type) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -2084,6 +2161,10 @@ 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) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusError err; dbus_error_init(&err); @@ -2190,6 +2271,10 @@ static DBusMessage* __get_message(int pid, const char* method, int type) int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg = NULL; switch (cmd_type) { @@ -2228,6 +2313,10 @@ int vc_mgr_dbus_send_result(int pid, int cmd_type, int result_id) int vc_mgr_dbus_send_result_selection(int pid) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -2263,6 +2352,10 @@ int vc_mgr_dbus_send_result_selection(int pid) int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, const char* event, const char* request) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; /* create a signal & check for errors */ @@ -2301,6 +2394,10 @@ int vc_mgr_dbus_send_specific_engine_request(int pid, const char* engine_app_id, int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = __get_message(pid, VC_MANAGER_METHOD_UTTERANCE_STATUS, VC_COMMAND_TYPE_FOREGROUND); @@ -2331,6 +2428,10 @@ int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status) int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len) { + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + DBusMessage* msg; msg = dbus_message_new_method_call( VC_SERVER_SERVICE_NAME, diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index 2289060..d71d479 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -453,7 +453,7 @@ int vc_widget_dbus_reconnect() static int __dbus_check() { - if (NULL == g_w_conn_sender) { + if (NULL == g_w_conn_sender || NULL == g_w_conn_listener) { SLOG(LOG_ERROR, TAG_VCW, "[ERROR] NULL connection"); return vc_widget_dbus_reconnect(); } -- 2.7.4 From 49344121d2107f17dab64d78cbb33b60a5945e02 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Fri, 28 Sep 2018 21:01:21 +0900 Subject: [PATCH 05/16] Add updating logic Change-Id: Ic01f22d43e21c4f1f534492a5d24ae051f7331e3 Signed-off-by: Wonnam Jang --- client/vc_mgr.c | 11 +++++++++++ include/vce.h | 1 - include/vce_internal.h | 12 ++++++++++++ include/voice_control_common.h | 2 +- include/voice_control_internal.h | 1 + include/voice_control_manager_internal.h | 2 ++ server/vcd_main.h | 3 ++- server/vcd_server.c | 28 ++++++++++++++++++++++++++++ server/vcd_server.h | 3 +++ server/vce.c | 28 ++++++++++++++++++++++++++++ 10 files changed, 88 insertions(+), 3 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index a1e4ea0..d97a038 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -2917,6 +2917,13 @@ int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg) if (VC_ERROR_SERVICE_RESET == reason) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] VC daemon reset"); + vc_service_state_e service_state = -1; + vc_mgr_client_get_service_state(g_vc_m, &service_state); + if (service_state != VC_SERVICE_STATE_UPDATING) { + SLOG(LOG_INFO, TAG_VCM, "[INFO] VC daemon is terminated by update manager"); + return 0; + } + vc_mgr_client_set_client_state(g_vc_m, VC_STATE_INITIALIZED); __vc_mgr_notify_state_changed(g_vc_m); @@ -3035,6 +3042,10 @@ int __vc_mgr_cb_service_state(int state) SLOG(LOG_DEBUG, TAG_VCM, "Internal state is changed to NONE"); vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); } + if (VC_SERVICE_STATE_UPDATING == current_state) { + SLOG(LOG_DEBUG, TAG_VCM, "Internal state is changed to NONE by updating"); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); + } if (current_state == before_state) { SLOG(LOG_WARN, TAG_VCM, "Service State NOT changed : Before(%d) Current(%d)", diff --git a/include/vce.h b/include/vce.h index af6f5ce..b73fabd 100644 --- a/include/vce.h +++ b/include/vce.h @@ -121,7 +121,6 @@ typedef enum { VCE_FEEDBACK_EVENT_FINISH = 3 /**< Finish event */ } vce_feedback_event_e; - /** * @brief A structure of handle for VC command. * @since_tizen @if MOBILE 4.0 @elseif WEARABLE 5.0 @endif diff --git a/include/vce_internal.h b/include/vce_internal.h index c7439bb..19c51f6 100644 --- a/include/vce_internal.h +++ b/include/vce_internal.h @@ -41,6 +41,18 @@ typedef struct { void* get_tts_audio_format_user_data; } vce_internal_request_callback_s; +/** + * @brief Enumeration for TTS feedback events. + * @since_tizen 5.0 + */ +typedef enum { + VCE_UPDATE_EVENT_FAIL = -1, /**< Failed */ + VCE_UPDATE_EVENT_START = 1, /**< Start event */ + VCE_UPDATE_EVENT_FINISH = 2 /**< Finish event */ +} vce_update_event_e; + +int vce_send_update_status(vce_update_event_e update_event, const char* msg); + #ifdef __cplusplus } diff --git a/include/voice_control_common.h b/include/voice_control_common.h index 5ae1ffa..4bf4ba1 100644 --- a/include/voice_control_common.h +++ b/include/voice_control_common.h @@ -79,7 +79,7 @@ typedef enum { VC_SERVICE_STATE_NONE = 0, /**< 'None' state */ VC_SERVICE_STATE_READY = 1, /**< 'Ready' state */ VC_SERVICE_STATE_RECORDING = 2, /**< 'Recording' state */ - VC_SERVICE_STATE_PROCESSING = 3 /**< 'Processing' state */ + VC_SERVICE_STATE_PROCESSING = 3 /**< 'Processing' state */ } vc_service_state_e; diff --git a/include/voice_control_internal.h b/include/voice_control_internal.h index dc26186..8bc1961 100644 --- a/include/voice_control_internal.h +++ b/include/voice_control_internal.h @@ -40,6 +40,7 @@ typedef enum { VC_TTS_UTTERANCE_CANCELED = 3 } vc_tts_utterance_status_e; + /** * @brief Called when client gets the asr recognition result from vc-daemon. * diff --git a/include/voice_control_manager_internal.h b/include/voice_control_manager_internal.h index 4b58230..91778b2 100644 --- a/include/voice_control_manager_internal.h +++ b/include/voice_control_manager_internal.h @@ -40,6 +40,8 @@ typedef enum { VC_AUDIO_STREAMING_MODE_OUTSIDE = 2, /**< Use audio streaming from outside */ } vc_audio_streaming_mode_e; +#define VC_SERVICE_STATE_UPDATING 4 /**< 'Updating' state */ + /** * @brief Sets demandable client list. * diff --git a/server/vcd_main.h b/server/vcd_main.h index 46b9fd8..782f501 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -71,7 +71,8 @@ typedef enum { VCD_STATE_NONE = 0, VCD_STATE_READY = 1, VCD_STATE_RECORDING = 2, - VCD_STATE_PROCESSING = 3 + VCD_STATE_PROCESSING = 3, + VCD_STATE_UPDATING = 4 } vcd_state_e; typedef enum { diff --git a/server/vcd_server.c b/server/vcd_server.c index 8de4a88..3839763 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -30,6 +30,7 @@ #include "vcd_config.h" #include "vcd_recorder.h" #include "vcd_dbus.h" +#include "vce_internal.h" #include "voice_control_command_expand.h" #include "voice_control_common.h" @@ -3074,6 +3075,33 @@ int vcd_stop_recording() return ret; } +int vcd_send_update_status(vce_update_event_e update_event, const char* msg) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[Server] update status, update event(%d), msg(%s)", update_event, msg); + + int ret = 0; + if (VCE_UPDATE_EVENT_START == update_event) { + if (VCD_STATE_RECORDING == vcd_config_get_service_state() || VCD_STATE_PROCESSING == vcd_config_get_service_state()) { + ret = vcd_server_mgr_cancel(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server Error] Fail to cancel, ret(%d)", ret); + return ret; + } + } + vcd_config_set_service_state(VCD_STATE_UPDATING); + vcdc_send_service_state(VCD_STATE_UPDATING); + + } else if (VCE_UPDATE_EVENT_FINISH == update_event) { + vcd_config_set_service_state(VCD_STATE_READY); + vcdc_send_service_state(VCD_STATE_READY); + + } else if (VCE_UPDATE_EVENT_FAIL == update_event) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Update event : Fail - msg(%s)", msg); + } + + return 0; +} + int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func) { SLOG(LOG_DEBUG, TAG_VCD, "[Server] Set private data set cb"); diff --git a/server/vcd_server.h b/server/vcd_server.h index d6270f1..739e6ec 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -22,6 +22,7 @@ #include "vcd_client_data.h" #include "vce.h" +#include "vce_internal.h" #ifdef __cplusplus extern "C" { @@ -172,6 +173,8 @@ int vcd_start_recording(); int vcd_stop_recording(); +int vcd_send_update_status(vce_update_event_e update_event, const char* msg); + int vcd_set_private_data_set_cb(vce_private_data_set_cb callback_func); int vcd_set_private_data_requested_cb(vce_private_data_requested_cb callback_func); diff --git a/server/vce.c b/server/vce.c index cfc93a8..cc9f73f 100644 --- a/server/vce.c +++ b/server/vce.c @@ -372,6 +372,17 @@ int vce_set_private_data(const char* key, const char* data) return VCE_ERROR_INVALID_PARAMETER; } + if (!strncmp(key, "UpdateEventStart", strlen(key))) + ret = vce_send_update_status(VCE_UPDATE_EVENT_START, NULL); + else if (!strncmp(data, "UpdateEventComplete", strlen(key))) + ret = vce_send_update_status(VCE_UPDATE_EVENT_FINISH, NULL); + else if (!strncmp(data, "UpdateEventFail", strlen(key))) + ret = vce_send_update_status(VCE_UPDATE_EVENT_FAIL, data); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send update status, event(%s), msg(%s): ret(%d)", key, data, ret); + return ret; + } + ret = vcd_set_private_data(key, data); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to set private data to vc manager"); @@ -442,6 +453,23 @@ int vce_stop_recording() return ret; } +int vce_send_update_status(vce_update_event_e update_event, const char* msg) +{ + if (0 != __vce_get_feature_enabled()) { + return VCE_ERROR_NOT_SUPPORTED; + } + if (0 != __vce_check_privilege()) { + return VCE_ERROR_PERMISSION_DENIED; + } + + int ret = vcd_send_update_status(update_event, msg); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to send update status"); + } + + return ret; +} + int vce_set_private_data_set_cb(vce_private_data_set_cb callback_func) { if (0 != __vce_get_feature_enabled()) { -- 2.7.4 From 14eb3b4d4d85cb8d9b7502eeddd38ff9323fcdb5 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 1 Oct 2018 19:23:52 +0900 Subject: [PATCH 06/16] Add apis to change system volume Change-Id: Ic04618b85abd6e5c3a162bd3d204dd91bc4aeac9 Signed-off-by: Wonnam Jang --- client/vc_mgr.c | 75 ++++++++++++++++++++++++++++ client/vc_mgr_dbus.c | 84 ++++++++++++++++++++++++++++++++ client/vc_mgr_dbus.h | 2 + common/vc_defs.h | 1 + include/voice_control_manager_internal.h | 5 ++ server/vcd_dbus.c | 3 ++ server/vcd_dbus_server.c | 53 ++++++++++++++++++++ server/vcd_dbus_server.h | 2 + server/vcd_main.h | 5 ++ server/vcd_recorder.c | 56 +++++++++++++++++++++ server/vcd_recorder.h | 4 ++ server/vcd_server.c | 22 +++++++++ server/vcd_server.h | 2 + 13 files changed, 314 insertions(+) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index d97a038..553ef4c 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -4369,3 +4369,78 @@ int vc_mgr_set_audio_streaming_mode(vc_audio_streaming_mode_e streaming_mode) return ret; } + +int vc_mgr_change_system_volume() +{ + SLOG(LOG_DEBUG, TAG_VCM, "[Manager] Change system volume"); + + if (0 != __vc_mgr_get_feature_enabled()) { + SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported"); + return VC_ERROR_NOT_SUPPORTED; + } + + if (0 != __vc_mgr_check_privilege()) { + return VC_ERROR_PERMISSION_DENIED; + } + + 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, "@@@"); + 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', state(%d)", state); + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + return VC_ERROR_INVALID_STATE; + } + + /* send audio streaming */ + int ret = vc_mgr_dbus_change_system_volume(g_vc_m->handle, VC_SYSTEM_VOLUME_EVENT_CHANGE); + if (0 != ret) { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to change volume"); + } else { + SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] Success to send"); + } + return ret; +} + +int vc_mgr_recover_system_volume() +{ + SLOG(LOG_DEBUG, TAG_VCM, "[Manager] recover system volume"); + + if (0 != __vc_mgr_get_feature_enabled()) { + SLOG(LOG_DEBUG, TAG_VCM, "@@@ [Manager] not supported"); + return VC_ERROR_NOT_SUPPORTED; + } + + if (0 != __vc_mgr_check_privilege()) { + return VC_ERROR_PERMISSION_DENIED; + } + + 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, "@@@"); + 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', state(%d)", state); + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + return VC_ERROR_INVALID_STATE; + } + + /* send audio streaming */ + int ret = vc_mgr_dbus_change_system_volume(g_vc_m->handle, VC_SYSTEM_VOLUME_EVENT_RECOVER); + if (0 != ret) { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] retry to recover volume"); + } else { + SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] Success to send"); + } + return ret; + +} diff --git a/client/vc_mgr_dbus.c b/client/vc_mgr_dbus.c index 7545a7f..7b7c432 100644 --- a/client/vc_mgr_dbus.c +++ b/client/vc_mgr_dbus.c @@ -2468,3 +2468,87 @@ int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, return 0; } +int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_event) +{ + if (0 != __dbus_check()) { + return VC_ERROR_OPERATION_FAILED; + } + + 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; + int temp_event = (int)volume_event; + 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_CHANGE_SYSTEM_VOLUME); /* name of the signal */ + + if (NULL == msg) { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc change system volume : Fail to make message "); + return VC_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_VCM, "@@ vc change system volume : pid(%d) volume_event(%d)", pid, temp_event); + } + + dbus_message_append_args(msg, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &temp_event, + 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 change system volume : result = %d", result); + } else { + SLOG(LOG_ERROR, TAG_VCM, "@@ vc change system volume : result = %d", result); + } + } else { + SLOG(LOG_DEBUG, TAG_VCM, "@@ Result Message is NULL"); + vc_mgr_dbus_reconnect(); + result = VC_ERROR_TIMED_OUT; + } + + return result; +} + diff --git a/client/vc_mgr_dbus.h b/client/vc_mgr_dbus.h index 9ce1239..a6202ea 100644 --- a/client/vc_mgr_dbus.h +++ b/client/vc_mgr_dbus.h @@ -80,6 +80,8 @@ int vc_mgr_dbus_send_utterance_status(int pid, int utt_id, int utt_status); int vc_mgr_dbus_send_audio_streaming(int pid, vc_audio_streaming_event_e event, unsigned char* buffer, unsigned int len); +int vc_mgr_dbus_change_system_volume(int pid, vc_system_volume_event_e volume_event); + #ifdef __cplusplus } #endif diff --git a/common/vc_defs.h b/common/vc_defs.h index 55fc210..79b6d7a 100644 --- a/common/vc_defs.h +++ b/common/vc_defs.h @@ -152,6 +152,7 @@ extern "C" { #define VC_MANAGER_METHOD_UTTERANCE_STATUS "vc_manager_method_utterance_status" #define VC_MANAGER_METHOD_SEND_AUDIO_STREAMING "vc_manager_method_send_audio_streaming" +#define VC_MANAGER_METHOD_CHANGE_SYSTEM_VOLUME "vc_manager_method_change_system_volume" #define VCD_MANAGER_METHOD_HELLO "vcd_manager_method_hello" #define VCD_MANAGER_METHOD_SPEECH_DETECTED "vcd_manager_method_speech_detected" diff --git a/include/voice_control_manager_internal.h b/include/voice_control_manager_internal.h index 91778b2..4e3953c 100644 --- a/include/voice_control_manager_internal.h +++ b/include/voice_control_manager_internal.h @@ -40,6 +40,11 @@ typedef enum { VC_AUDIO_STREAMING_MODE_OUTSIDE = 2, /**< Use audio streaming from outside */ } vc_audio_streaming_mode_e; +typedef enum { + VC_SYSTEM_VOLUME_EVENT_CHANGE, + VC_SYSTEM_VOLUME_EVENT_RECOVER +} vc_system_volume_event_e; + #define VC_SERVICE_STATE_UPDATING 4 /**< 'Updating' state */ /** diff --git a/server/vcd_dbus.c b/server/vcd_dbus.c index 1718191..4c9fde0 100644 --- a/server/vcd_dbus.c +++ b/server/vcd_dbus.c @@ -1153,6 +1153,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_MANAGER_METHOD_SEND_AUDIO_STREAMING)) vcd_dbus_server_mgr_send_audio_streaming(g_conn_listener, msg); + else if (dbus_message_is_method_call(msg, VC_SERVER_SERVICE_INTERFACE, VC_MANAGER_METHOD_CHANGE_SYSTEM_VOLUME)) + vcd_dbus_server_mgr_change_system_volume(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 9740609..2739c5b 100644 --- a/server/vcd_dbus_server.c +++ b/server/vcd_dbus_server.c @@ -1224,6 +1224,59 @@ int vcd_dbus_server_mgr_send_audio_streaming(DBusConnection* conn, DBusMessage* return ret; } +int vcd_dbus_server_mgr_change_system_volume(DBusConnection* conn, DBusMessage* msg) +{ + DBusError err; + dbus_error_init(&err); + + int pid = 0; + int volume_event = 0; + + int ret = VCD_ERROR_OPERATION_FAILED; + + SLOG(LOG_DEBUG, TAG_VCD, "@@@ VCD Manager change system volume"); + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &pid, + DBUS_TYPE_INT32, &volume_event, + 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 change system volume: pid(%d), volume_event(%d)", pid, volume_event); + ret = vcd_server_mgr_change_system_volume(pid, volume_event); + } + + 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, "@@@"); + + return 0; + +} /* * Dbus Server functions for client diff --git a/server/vcd_dbus_server.h b/server/vcd_dbus_server.h index ac02296..6182697 100644 --- a/server/vcd_dbus_server.h +++ b/server/vcd_dbus_server.h @@ -69,6 +69,8 @@ int vcd_dbus_server_mgr_disable_command_type(DBusConnection* conn, DBusMessage* int vcd_dbus_server_mgr_send_specific_engine_request(DBusConnection* conn, DBusMessage* msg); +int vcd_dbus_server_mgr_change_system_volume(DBusConnection* conn, DBusMessage* msg); + /* for TTS feedback */ int vcd_dbus_server_mgr_start_feedback(DBusConnection* conn, DBusMessage* msg); diff --git a/server/vcd_main.h b/server/vcd_main.h index 782f501..04ecdbf 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -88,6 +88,11 @@ typedef enum { VCD_AUDIO_STREAMING_MODE_OUTSIDE = 2, /**< Use audio streaming from outside */ } vcd_audio_streaming_mode_e; +typedef enum { + VCD_SYSTEM_VOLUME_EVENT_CHANGE, + VCD_SYSTEM_VOLUME_EVENT_RECOVER +} vcd_system_volume_event_e; + struct vce_cmd_s { int index; }; diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index 6ffb708..a024942 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -74,6 +74,9 @@ static int g_buffer_count; static int g_device_id = -1; +static sound_stream_info_h g_stream_for_volume_h = NULL; +static virtual_sound_stream_h g_virtual_sound_stream_h = NULL; + /* Sound buf save */ #if 0 #define BUF_SAVE_MODE @@ -897,6 +900,59 @@ int vcd_recorder_stop_streaming() return 0; } +int vcd_recorder_change_system_volume() +{ + if (!g_stream_for_volume_h) { + int ret = sound_manager_create_stream_information_internal(SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE, NULL, NULL, &g_stream_for_volume_h); + if (0 != ret) { + SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Fail to create stream information, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + if (!g_virtual_sound_stream_h) { + ret = sound_manager_create_virtual_stream(g_stream_for_volume_h, &g_virtual_sound_stream_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to create virtual stream, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + ret = sound_manager_start_virtual_stream(g_virtual_sound_stream_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start virtual stream, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + } + } + + return 0; +} + +int vcd_recorder_recover_system_volume() +{ + if (g_virtual_sound_stream_h) { + int ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to stop virtual stream, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy virtual stream, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + g_virtual_sound_stream_h = NULL; + + if (g_stream_for_volume_h) { + ret = sound_manager_destroy_stream_information(g_stream_for_volume_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream information, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + g_stream_for_volume_h = NULL; + } + } + + return 0; +} + int vcd_recorder_start() { int ret = -1; diff --git a/server/vcd_recorder.h b/server/vcd_recorder.h index 7a612b8..9ac8b1e 100644 --- a/server/vcd_recorder.h +++ b/server/vcd_recorder.h @@ -49,6 +49,10 @@ int vcd_recorder_send_streaming(const void* buffer, const unsigned int length); int vcd_recorder_stop_streaming(); +int vcd_recorder_change_system_volume(); + +int vcd_recorder_recover_system_volume(); + int vcd_recorder_start(); int vcd_recorder_read(); diff --git a/server/vcd_server.c b/server/vcd_server.c index 3839763..4f369e0 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -2257,6 +2257,28 @@ int vcd_server_mgr_send_audio_streaming(int pid, int event, unsigned char* buffe return VCD_ERROR_NONE; } +int vcd_server_mgr_change_system_volume(int pid, vcd_system_volume_event_e system_volume_event) +{ + SLOG(LOG_DEBUG, TAG_VCD, "[DEBUG] change system volume, system volume event(%d)", system_volume_event); + + int ret = 0; + if (VCD_SYSTEM_VOLUME_EVENT_CHANGE == system_volume_event) { + ret = vcd_recorder_change_system_volume(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to change system volume, ret(%d)", ret); + return ret; + } + } else if (VCD_SYSTEM_VOLUME_EVENT_RECOVER == system_volume_event) { + ret = vcd_recorder_recover_system_volume(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Fail to recover system volume, ret(%d)", ret); + return ret; + } + } + + return ret; +} + /* * VC Server Functions for Client diff --git a/server/vcd_server.h b/server/vcd_server.h index 739e6ec..7979e4a 100644 --- a/server/vcd_server.h +++ b/server/vcd_server.h @@ -81,6 +81,8 @@ int vcd_server_mgr_enable_command_type(int pid, int cmd_type); int vcd_server_mgr_disable_command_type(int pid, int cmd_type); +int vcd_server_mgr_change_system_volume(int pid, vcd_system_volume_event_e system_volume_event); + /* for TTS feedback */ int vcd_server_mgr_start_feedback(void); -- 2.7.4 From ce46d2756a744b8b2320d84c0d6764651f84b1dc Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 1 Oct 2018 20:55:45 +0900 Subject: [PATCH 07/16] Add system volume api on internal header Change-Id: I5ade6a51bf9c30ebc75d06ccdb9c3ed528df5087 Signed-off-by: Wonnam Jang --- include/voice_control_manager_internal.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/voice_control_manager_internal.h b/include/voice_control_manager_internal.h index 4e3953c..9d22ede 100644 --- a/include/voice_control_manager_internal.h +++ b/include/voice_control_manager_internal.h @@ -108,6 +108,20 @@ int vc_mgr_send_audio_streaming(vc_audio_streaming_event_e event, unsigned char* int vc_mgr_set_audio_streaming_mode(vc_audio_streaming_mode_e streaming_mode); +/** + * @brief Changes system volume. + * @since_tizen 5.0 + * + */ +int vc_mgr_change_system_volume(); + +/** + * @brief Recover system volume. + * @since_tizen 5.0 + * + */ +int vc_mgr_recover_system_volume(); + #ifdef __cplusplus } #endif -- 2.7.4 From b6e06afc544143e6b05f3fb0cc59a9386784a430 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 8 Oct 2018 17:51:01 +0900 Subject: [PATCH 08/16] Sync with tizen 4.0 branch Change-Id: I22ddb9911deeafa4b12dc3d89fea3b0059fec383 Signed-off-by: Wonnam Jang --- client/vc_mgr.c | 4 +- client/vc_mgr_data.cpp | 18 +++--- include/voice_control_internal.h | 56 +++++++++---------- include/voice_control_manager.h | 118 ++++++++++++++++++++------------------- server/vcd_main.h | 3 +- server/vcd_server.c | 72 ++++++++++++++++-------- 6 files changed, 152 insertions(+), 119 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 553ef4c..39e46e9 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -3443,7 +3443,7 @@ int __vc_mgr_cb_feedback_streaming(int pid, int utt_id, vc_feedback_event_e even } } - return ret; + return ret; } @@ -4079,6 +4079,7 @@ static void __tts_feedback_thread(void* data, Ecore_Thread* thread) } if (200 < cnt) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Wrong request, there's no pcm data"); + vc_mgr_data_clear_feedback_data(&feedback_data); return; } cnt++; @@ -4086,6 +4087,7 @@ static void __tts_feedback_thread(void* data, Ecore_Thread* thread) SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish to wait for new feedback data come"); /* resume feedback thread */ + vc_mgr_data_clear_feedback_data(&feedback_data); continue; } diff --git a/client/vc_mgr_data.cpp b/client/vc_mgr_data.cpp index 866d3da..26482c1 100644 --- a/client/vc_mgr_data.cpp +++ b/client/vc_mgr_data.cpp @@ -96,20 +96,22 @@ int vc_mgr_data_get_feedback_data_size() int vc_mgr_data_clear_feedback_data(vc_feedback_data_s** data) { - SLOG(LOG_DEBUG, TAG_VCM, "[DATA] clear feedback data"); + SLOG(LOG_DEBUG, TAG_VCM, "[DATA] clear feedback data, empty(%d)", g_feedback_data.empty()); pthread_mutex_lock(&g_feedback_data_mutex); if (!g_feedback_data.empty()) { - SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] pid(%d), utt_id(%d), data(%p) size(%d) rate(%d)", (*data)->pid, (*data)->utt_id, (*data)->data, (*data)->data_size, (*data)->rate); + if (NULL != *data) { + SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] pid(%d), utt_id(%d), data(%p) size(%d) rate(%d)", (*data)->pid, (*data)->utt_id, (*data)->data, (*data)->data_size, (*data)->rate); - if (NULL != (*data)->data) { - free((*data)->data); - (*data)->data = NULL; - } + if (NULL != (*data)->data) { + free((*data)->data); + (*data)->data = NULL; + } - free(*data); - *data = NULL; + free(*data); + *data = NULL; + } } pthread_mutex_unlock(&g_feedback_data_mutex); diff --git a/include/voice_control_internal.h b/include/voice_control_internal.h index 8bc1961..cfbb9ea 100644 --- a/include/voice_control_internal.h +++ b/include/voice_control_internal.h @@ -1,18 +1,18 @@ -/* - * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/** + * Copyright (c) 2011-2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __VOICE_CONTROL_INTERNAL_H__ @@ -42,19 +42,19 @@ typedef enum { /** -* @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() -*/ + * @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); /** diff --git a/include/voice_control_manager.h b/include/voice_control_manager.h index 430daa5..3d4ece3 100644 --- a/include/voice_control_manager.h +++ b/include/voice_control_manager.h @@ -1,18 +1,18 @@ -/* -* Copyright (c) 2011-2018 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ +/** + * Copyright (c) 2011-2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef __VOICE_CONTROL_MANAGER_H__ @@ -247,55 +247,57 @@ typedef int (*vc_mgr_private_data_requested_cb)(const char *key, char **data, vo /* for TTS feedback */ /** -* @brief Called when engine sends audio formats necessary for playing TTS feedback -* @since_tizen 5.0 -* -* @param[in] rate Audio sampling rate -* @param[in] channel Audio channel (e.g. #VC_AUDIO_CHANNEL_MONO, #VC_AUDIO_CHANNEL_STEREO) -* @param[in] audio_type Audio type (e.g. #VC_AUDIO_TYPE_PCM_S16_LE, #VC_AUDIO_TYPE_PCM_U8) -* @param[in] user_data The user data passed from the callback registration function -* -* @pre An application registers callback function using vc_mgr_set_feedback_audio_format_cb(). -* -* @see vc_mgr_set_feedback_audio_format_cb() -* @see vc_mgr_unset_feedback_audio_format_cb() -*/ + * @brief Called when engine sends audio formats necessary for playing TTS feedback + * @since_tizen 5.0 + * + * @param[in] rate Audio sampling rate + * @param[in] channel Audio channel (e.g. #VC_AUDIO_CHANNEL_MONO, #VC_AUDIO_CHANNEL_STEREO) + * @param[in] audio_type Audio type (e.g. #VC_AUDIO_TYPE_PCM_S16_LE, #VC_AUDIO_TYPE_PCM_U8) + * @param[in] user_data The user data passed from the callback registration function + * + * @pre An application registers callback function using vc_mgr_set_feedback_audio_format_cb(). + * + * @see vc_mgr_set_feedback_audio_format_cb() + * @see vc_mgr_unset_feedback_audio_format_cb() + */ typedef void (*vc_mgr_feedback_audio_format_cb)(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type, void *user_data); /** -* @brief Called when engine sends audio streaming for TTS feedback -* @since_tizen 5.0 -* -* @param[in] event TTS feedback event (e.g. #VC_FEEDBACK_EVENT_START, #VC_FEEDBACK_EVENT_CONTINUE) -* @param[in] buffer Audio streaming data -* @param[in] len Length of the audio streaming data -* @param[in] user_data The user data passed from the callback registration function -* -* @pre An application registers callback function using vc_mgr_set_feedback_streaming_cb(). -* -* @see vc_mgr_set_feedback_streaming_cb() -* @see vc_mgr_unset_feedback_streaming_cb() -*/ + * @brief Called when engine sends audio streaming for TTS feedback + * @since_tizen 5.0 + * + * @remarks The @a buffer must be released with free() by you when you no longer need it. + * + * @param[in] event TTS feedback event (e.g. #VC_FEEDBACK_EVENT_START, #VC_FEEDBACK_EVENT_CONTINUE) + * @param[in] buffer Audio streaming data + * @param[in] len Length of the audio streaming data + * @param[in] user_data The user data passed from the callback registration function + * + * @pre An application registers callback function using vc_mgr_set_feedback_streaming_cb(). + * + * @see vc_mgr_set_feedback_streaming_cb() + * @see vc_mgr_unset_feedback_streaming_cb() + */ typedef void (*vc_mgr_feedback_streaming_cb)(vc_feedback_event_e event, char* buffer, int len, void *user_data); /** -* @brief Called when the vc client sends audio streaming for TTS feedback -* @since_tizen 5.0 -* -* @remarks The @a buffer must be released with free() by you when you no longer need it. -* -* @param[in] pid The process id of the vc client -* @param[in] utt_id The utterance id -* @param[in] event TTS feedback event (e.g. #VC_FEEDBACK_EVENT_START, #VC_FEEDBACK_EVENT_CONTINUE) -* @param[in] buffer Audio streaming data -* @param[in] len Length of the audio streaming data -* @param[in] user_data The user data passed from the callback registration function -* -* @pre An application registers callback function using vc_mgr_set_vc_tts_streaming_cb(). -* -* @see vc_mgr_set_vc_tts_streaming_cb() -* @see vc_mgr_unset_vc_tts_streaming_cb() -*/ + * @brief Called when the vc client sends audio streaming for TTS feedback + * @since_tizen 5.0 + * + * @remarks The @a buffer must be released with free() by you when you no longer need it. + * + * @param[in] pid The process id of the vc client + * @param[in] utt_id The utterance id + * @param[in] event TTS feedback event (e.g. #VC_FEEDBACK_EVENT_START, #VC_FEEDBACK_EVENT_CONTINUE) + * @param[in] buffer Audio streaming data + * @param[in] len Length of the audio streaming data + * @param[in] user_data The user data passed from the callback registration function + * + * @pre An application registers callback function using vc_mgr_set_vc_tts_streaming_cb(). + * + * @see vc_mgr_set_vc_tts_streaming_cb() + * @see vc_mgr_unset_vc_tts_streaming_cb() + */ typedef void (*vc_mgr_vc_tts_streaming_cb)(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len, void *user_data); /** diff --git a/server/vcd_main.h b/server/vcd_main.h index 04ecdbf..70bcd18 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -72,7 +72,8 @@ typedef enum { VCD_STATE_READY = 1, VCD_STATE_RECORDING = 2, VCD_STATE_PROCESSING = 3, - VCD_STATE_UPDATING = 4 + VCD_STATE_SYNTHESIZING = 4, + VCD_STATE_UPDATING = 5 } vcd_state_e; typedef enum { diff --git a/server/vcd_server.c b/server/vcd_server.c index 4f369e0..f2e34f1 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1098,16 +1098,16 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data) /* for TTS feedback */ int vcd_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type) { - SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format"); + SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format, g_current_uid(%d)", g_current_uid); /* send TTS feedback audio format to VC manager */ int ret = VCD_ERROR_NONE; int pid = g_current_uid / 1000; if (-1 == g_current_uid || vcd_client_manager_get_pid() == pid) { - ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type); - if (VCD_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager"); - } + ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type); + if (VCD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager"); + } } else { SLOG(LOG_INFO, TAG_VCD, "[Server INFO] Do not send TTS feedback audio format to VC manager"); } @@ -1120,14 +1120,14 @@ int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int le if (-1 == g_current_uid && VCE_FEEDBACK_EVENT_START == event) { g_current_utt_id = (g_current_utt_id + 1) % 1000; g_current_uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id; - SLOG(LOG_INFO, TAG_VCD, "[Server info] set current uid and utt_id as manager pid"); + SLOG(LOG_INFO, TAG_VCD, "[Server info] set current uid and utt_id as manager pid(%d)", vcd_client_manager_get_pid()); } int ret = VCD_ERROR_NONE; int pid = g_current_uid / 1000; int utt_id = g_current_uid % 1000; - SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback streaming to pid(%d), is_mgr_client(%d)", pid, (pid == vcd_client_manager_get_pid() ? true : false)); + SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback streaming event(%d), uid(%d), is_mgr_client(%d)", event, g_current_uid, (pid == vcd_client_manager_get_pid() ? true : false)); if (pid == vcd_client_manager_get_pid()) { /* send TTS feedback streaming to manager client */ @@ -1138,14 +1138,21 @@ int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int le } else { /* send TTS feedback streaming to client */ ret = vcdc_send_feedback_streaming(pid, utt_id, event, buffer, len); - if (VCD_ERROR_NONE != ret) { + if (VCD_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to client"); - } + } } if (VCE_FEEDBACK_EVENT_FINISH == event) { /* reset current uid */ g_current_uid = -1; + + /* Set service state to ready if state is synthesizing */ + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_SYNTHESIZING == state) { + vcd_config_set_service_state(VCD_STATE_READY); + } + SLOG(LOG_INFO, TAG_VCD, "[Server info] feedback streaming finish event, reset current uid & service state(%d)", vcd_config_get_service_state()); } return ret; } @@ -1845,8 +1852,8 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive /* 1. check current state */ 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"); + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizine, state(%d)", state); return VCD_ERROR_INVALID_STATE; } if (-1 == vcd_client_manager_get_pid()) { @@ -2091,8 +2098,8 @@ int vcd_server_mgr_send_specific_engine_request(int pid, const char* engine_app_ 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"); + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state); return VCD_ERROR_INVALID_STATE; } @@ -2118,8 +2125,8 @@ int vcd_server_mgr_do_action(int pid, int type, const char* action) } 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"); + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state); return VCD_ERROR_INVALID_STATE; } @@ -2514,6 +2521,7 @@ static void __start_tts_request_thread(void* data, Ecore_Thread* thread) while (1) { int ret = -1; + int cnt = 0; /* Get tts text data */ ret = vcd_data_get_first_tts_text_data(&tts_text_data); @@ -2527,6 +2535,23 @@ static void __start_tts_request_thread(void* data, Ecore_Thread* thread) continue; } + while (1) { + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_READY != state) { + if (0 == cnt++ % 10) + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Waiting to request TTS, state(%d)", state); + usleep(100000); + continue; + } + break; + } + + /* Set service state to synthesizing */ + vcd_config_set_service_state(VCD_STATE_SYNTHESIZING); + + /* Set current uid */ + g_current_uid = tts_text_data->uid; + /* Request tts to engine */ ret = vcd_engine_request_tts(tts_text_data->pid, tts_text_data->utt_id, tts_text_data->text, tts_text_data->language); if (0 != ret) { @@ -2556,20 +2581,21 @@ int vcd_server_request_tts(int pid, const char* text, const char* language, int } vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_READY != state) { + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state); return VCD_ERROR_INVALID_STATE; } + int uid = -1; g_current_utt_id = (g_current_utt_id + 1) % 1000; *utt_id = g_current_utt_id; if (0 == to_vcm) { - g_current_uid = pid * 1000 + g_current_utt_id; + uid = pid * 1000 + g_current_utt_id; } else { - g_current_uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id; + uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id; } SLOG(LOG_INFO, TAG_VCD, "[Server INFO] pid(%d), text(%s), language(%s), to_vcm(%d), ", pid, text, language, to_vcm); - SLOG(LOG_INFO, TAG_VCD, "[Server INFO] current_uid(%d), current_utt_id(%d)", g_current_uid, g_current_utt_id); + SLOG(LOG_INFO, TAG_VCD, "[Server INFO] current_uid(%d), current_utt_id(%d)", uid, g_current_utt_id); vc_tts_text_data_s* tts_text_data; tts_text_data = (vc_tts_text_data_s*)calloc(1, sizeof(vc_tts_text_data_s)); @@ -2577,7 +2603,7 @@ int vcd_server_request_tts(int pid, const char* text, const char* language, int SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to callocate memory "); return VCD_ERROR_OUT_OF_MEMORY; } - tts_text_data->uid = g_current_uid; + tts_text_data->uid = uid; tts_text_data->pid = pid; tts_text_data->utt_id = g_current_utt_id; tts_text_data->text = strdup(text); @@ -2606,7 +2632,7 @@ int vcd_server_cancel_tts(int pid, int utt_id) } vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_READY != state) { + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state); return VCD_ERROR_INVALID_STATE; } @@ -2642,8 +2668,8 @@ int vcd_server_get_tts_audio_format(int pid, int* rate, int* channel, int* audio } 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"); + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state); return VCD_ERROR_INVALID_STATE; } -- 2.7.4 From ea44357fdcbd58eb9ebc7aacaed248c8f9b0fad0 Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Mon, 8 Oct 2018 20:48:50 +0900 Subject: [PATCH 09/16] Fixed update service code Change-Id: I3b1809b0bdd16c6607af4567f2a4530125d7eecd Signed-off-by: sungrae jo --- include/voice_control_manager_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/voice_control_manager_internal.h b/include/voice_control_manager_internal.h index 9d22ede..e50011f 100644 --- a/include/voice_control_manager_internal.h +++ b/include/voice_control_manager_internal.h @@ -45,7 +45,7 @@ typedef enum { VC_SYSTEM_VOLUME_EVENT_RECOVER } vc_system_volume_event_e; -#define VC_SERVICE_STATE_UPDATING 4 /**< 'Updating' state */ +#define VC_SERVICE_STATE_UPDATING 5 /**< 'Updating' state */ /** * @brief Sets demandable client list. -- 2.7.4 From 07eb236de91fa87bd005eb9fd5332a5be4bcae2c Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Mon, 8 Oct 2018 21:02:41 +0900 Subject: [PATCH 10/16] Fixed service state compare code. Change-Id: Ibf2650c502b121a7dd2d581dbf823d4a3a405c50 Signed-off-by: sungrae jo --- client/vc_mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 39e46e9..516db90 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -2919,7 +2919,7 @@ int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg) vc_service_state_e service_state = -1; vc_mgr_client_get_service_state(g_vc_m, &service_state); - if (service_state != VC_SERVICE_STATE_UPDATING) { + if (VC_SERVICE_STATE_UPDATING == service_state) { SLOG(LOG_INFO, TAG_VCM, "[INFO] VC daemon is terminated by update manager"); return 0; } -- 2.7.4 From 075cc94926c53a9f9c3db378cb38a3c3b8c589ab Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Thu, 11 Oct 2018 10:37:12 +0900 Subject: [PATCH 11/16] Fix dbus crash issue in vc widget Change-Id: I15087eaa8dfc7e042f7c6fbb385b78f478087503 Signed-off-by: sooyeon.kim --- client/vc_widget_dbus.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/vc_widget_dbus.c b/client/vc_widget_dbus.c index d71d479..4cd4b9d 100644 --- a/client/vc_widget_dbus.c +++ b/client/vc_widget_dbus.c @@ -15,11 +15,15 @@ */ +#include + #include "vc_main.h" #include "vc_widget_client.h" #include "vc_widget_dbus.h" +static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER; + static int g_w_waiting_time = 3000; static Ecore_Fd_Handler* g_w_fd_handler = NULL; @@ -286,8 +290,11 @@ static void __vc_widget_dbus_connection_free() int vc_widget_dbus_open_connection() { + pthread_mutex_lock(&g_w_dbus_mutex); + if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) { SLOG(LOG_WARN, TAG_VCW, "Already existed connection "); + pthread_mutex_unlock(&g_w_dbus_mutex); return 0; } @@ -307,6 +314,7 @@ int vc_widget_dbus_open_connection() if (NULL == g_w_conn_sender) { SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection "); + pthread_mutex_unlock(&g_w_dbus_mutex); return VC_ERROR_OPERATION_FAILED; } @@ -322,6 +330,7 @@ int vc_widget_dbus_open_connection() if (NULL == g_w_conn_listener) { SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection "); __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); return VC_ERROR_OPERATION_FAILED; } @@ -346,12 +355,14 @@ int vc_widget_dbus_open_connection() if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { SLOG(LOG_ERROR, TAG_VCW, "fail dbus_bus_request_name()"); __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); return -2; } if (NULL != g_w_fd_handler) { SLOG(LOG_WARN, TAG_VCW, "The handler already exists."); __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); return 0; } @@ -365,6 +376,7 @@ int vc_widget_dbus_open_connection() SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message); dbus_error_free(&err); __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); return VC_ERROR_OPERATION_FAILED; } @@ -372,6 +384,7 @@ int vc_widget_dbus_open_connection() if (1 != dbus_connection_get_unix_fd(g_w_conn_listener, &fd)) { SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus "); __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); return VC_ERROR_OPERATION_FAILED; } else { SLOG(LOG_DEBUG, TAG_VCW, "Get fd from dbus : %d", fd); @@ -382,14 +395,18 @@ int vc_widget_dbus_open_connection() if (NULL == g_w_fd_handler) { SLOG(LOG_ERROR, TAG_VCW, "fail to get fd handler from ecore "); __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); return VC_ERROR_OPERATION_FAILED; } + pthread_mutex_unlock(&g_w_dbus_mutex); return 0; } int vc_widget_dbus_close_connection() { + pthread_mutex_lock(&g_w_dbus_mutex); + DBusError err; dbus_error_init(&err); @@ -415,6 +432,8 @@ int vc_widget_dbus_close_connection() __vc_widget_dbus_connection_free(); + pthread_mutex_unlock(&g_w_dbus_mutex); + return 0; } -- 2.7.4 From 74a2b9c52036bb66d43233c13b058fc09890d7f9 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Thu, 11 Oct 2018 19:46:06 +0900 Subject: [PATCH 12/16] check vc_m handle before use Change-Id: I49c9f14e30c30208597fb8f41470e55d65cd9e20 Signed-off-by: Wonnam Jang --- client/vc_mgr.c | 101 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 516db90..70c7190 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -384,69 +384,77 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data) g_m_connect_timer = NULL; - vc_audio_streaming_mode_e streaming_mode; - vc_mgr_client_get_audio_streaming_mode(g_vc_m, &streaming_mode); + /* check handle */ + if (true == vc_mgr_client_is_valid(g_vc_m)) { + SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] g_vc_m is valid"); - ret = vc_mgr_dbus_request_initialize(g_vc_m->handle, (int)streaming_mode, &service_state, &foreground, &g_daemon_pid); + vc_audio_streaming_mode_e streaming_mode; + vc_mgr_client_get_audio_streaming_mode(g_vc_m, &streaming_mode); - if (VC_ERROR_ENGINE_NOT_FOUND == ret) { - SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret)); + ret = vc_mgr_dbus_request_initialize(g_vc_m->handle, (int)streaming_mode, &service_state, &foreground, &g_daemon_pid); - vc_mgr_client_set_error(g_vc_m, VC_ERROR_ENGINE_NOT_FOUND); - ecore_main_loop_thread_safe_call_async(__vc_mgr_notify_error, (void*)g_vc_m); + if (VC_ERROR_ENGINE_NOT_FOUND == ret) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to initialize : %s", __vc_mgr_get_error_code(ret)); - SLOG(LOG_DEBUG, TAG_VCM, "@@@"); - return EINA_FALSE; + vc_mgr_client_set_error(g_vc_m, VC_ERROR_ENGINE_NOT_FOUND); + ecore_main_loop_thread_safe_call_async(__vc_mgr_notify_error, (void*)g_vc_m); - } else if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Fail to connection. Retry to connect : %s", __vc_mgr_get_error_code(ret)); - return EINA_TRUE; - } else { - /* Success to connect */ - } + SLOG(LOG_DEBUG, TAG_VCM, "@@@"); + return EINA_FALSE; - /* Set service state */ - vc_service_state_e previous_service_state; - vc_mgr_client_get_service_state(g_vc_m, &previous_service_state); + } else if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCM, "[WARNING] Fail to connection. Retry to connect : %s", __vc_mgr_get_error_code(ret)); + return EINA_TRUE; + } else { + /* Success to connect */ + } - vc_mgr_client_set_service_state(g_vc_m, (vc_service_state_e)service_state); + /* Set service state */ + vc_service_state_e previous_service_state; + vc_mgr_client_get_service_state(g_vc_m, &previous_service_state); - vc_service_state_changed_cb service_changed_callback = NULL; - void* user_data = NULL; - vc_mgr_client_get_service_state_changed_cb(g_vc_m, &service_changed_callback, &user_data); + vc_mgr_client_set_service_state(g_vc_m, (vc_service_state_e)service_state); - if (NULL != service_changed_callback) { - vc_mgr_client_use_callback(g_vc_m); - service_changed_callback(previous_service_state, service_state, user_data); - vc_mgr_client_not_use_callback(g_vc_m); - SLOG(LOG_DEBUG, TAG_VCM, "Service state changed callback is called"); - } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null"); - } + vc_service_state_changed_cb service_changed_callback = NULL; + void* user_data = NULL; + vc_mgr_client_get_service_state_changed_cb(g_vc_m, &service_changed_callback, &user_data); - /* Set foreground */ - vc_mgr_client_set_foreground(g_vc_m, foreground, true); + if (NULL != service_changed_callback) { + vc_mgr_client_use_callback(g_vc_m); + service_changed_callback(previous_service_state, service_state, user_data); + vc_mgr_client_not_use_callback(g_vc_m); + SLOG(LOG_DEBUG, TAG_VCM, "Service state changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] Service state changed callback is null"); + } - SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Connected daemon"); + /* Set foreground */ + vc_mgr_client_set_foreground(g_vc_m, foreground, true); - /* Set client state */ - vc_mgr_client_set_client_state(g_vc_m, VC_STATE_READY); + SLOG(LOG_ERROR, TAG_VCM, "[SUCCESS] Connected daemon"); - vc_state_changed_cb changed_callback = NULL; - vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data); + /* Set client state */ + vc_mgr_client_set_client_state(g_vc_m, VC_STATE_READY); - vc_state_e current_state; - vc_state_e before_state; + vc_state_changed_cb changed_callback = NULL; + vc_mgr_client_get_state_changed_cb(g_vc_m, &changed_callback, &user_data); - vc_mgr_client_get_before_state(g_vc_m, ¤t_state, &before_state); + vc_state_e current_state; + vc_state_e before_state; - if (NULL != changed_callback) { - vc_mgr_client_use_callback(g_vc_m); - changed_callback(before_state, current_state, user_data); - vc_mgr_client_not_use_callback(g_vc_m); - SLOG(LOG_DEBUG, TAG_VCM, "State changed callback is called"); + vc_mgr_client_get_before_state(g_vc_m, ¤t_state, &before_state); + + if (NULL != changed_callback) { + vc_mgr_client_use_callback(g_vc_m); + changed_callback(before_state, current_state, user_data); + vc_mgr_client_not_use_callback(g_vc_m); + SLOG(LOG_DEBUG, TAG_VCM, "State changed callback is called"); + } else { + SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null"); + } } else { - SLOG(LOG_WARN, TAG_VCM, "[WARNING] State changed callback is null"); + SLOG(LOG_ERROR, TAG_VCM, "[Not ERROR] g_vc_m is not valid. It is destroyed."); //LCOV_EXCL_LINE + return EINA_FALSE; } SLOG(LOG_DEBUG, TAG_VCM, "@@@"); @@ -454,6 +462,7 @@ static Eina_Bool __vc_mgr_connect_daemon(void *data) return EINA_FALSE; } + static void __start_prepare_thread(void *data, Ecore_Thread *thread) { SLOG(LOG_ERROR, TAG_VCM, "@@@ Start prepare thread"); -- 2.7.4 From 33e3ca166a54031f2081eb1b75ff87c856a22b33 Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Wed, 24 Oct 2018 18:56:44 +0900 Subject: [PATCH 13/16] Add init code for STT user_data Change-Id: I7d9285046c6b46cd7443cc420112c59fa4e7e466 Signed-off-by: sungrae jo --- server/vcd_engine_agent.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 68b8f83..7b1dde8 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -236,8 +236,11 @@ int __internal_get_engine_info(vce_request_callback_s* callback) g_dynamic_engine.callbacks->nlu_base_info_request = NULL; g_dynamic_engine.callbacks->specific_engine_request = NULL; g_dynamic_engine.internal_callbacks->request_tts = NULL; + g_dynamic_engine.internal_callbacks->request_tts_user_data = NULL; g_dynamic_engine.internal_callbacks->cancel_tts = NULL; + g_dynamic_engine.internal_callbacks->cancel_tts_user_data = NULL; g_dynamic_engine.internal_callbacks->get_tts_audio_format = NULL; + g_dynamic_engine.internal_callbacks->get_tts_audio_format_user_data = NULL; SLOG(LOG_DEBUG, TAG_VCD, "@@@ Valid Engine"); SLOG(LOG_DEBUG, TAG_VCD, "Engine uuid : %s", g_dynamic_engine.engine_uuid); -- 2.7.4 From 743e25a7735d0bc67aae2dc66dcae86c944b4c3a Mon Sep 17 00:00:00 2001 From: sungrae jo Date: Mon, 5 Nov 2018 19:31:59 +0900 Subject: [PATCH 14/16] Fixed system volume code Change-Id: I45f881d10ae13fd6c0e19a6772d66f5376c7a1fb Signed-off-by: sungrae jo --- server/vcd_recorder.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index a024942..8151e00 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -902,33 +902,39 @@ int vcd_recorder_stop_streaming() int vcd_recorder_change_system_volume() { + int ret = VCD_ERROR_NONE; + if (!g_stream_for_volume_h) { - int ret = sound_manager_create_stream_information_internal(SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE, NULL, NULL, &g_stream_for_volume_h); + ret = sound_manager_create_stream_information_internal(SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE, NULL, NULL, &g_stream_for_volume_h); if (0 != ret) { SLOG(LOG_DEBUG, TAG_VCD, "[Recorder] Fail to create stream information, ret(%d)", ret); return VCD_ERROR_OPERATION_FAILED; } - if (!g_virtual_sound_stream_h) { - ret = sound_manager_create_virtual_stream(g_stream_for_volume_h, &g_virtual_sound_stream_h); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to create virtual stream, ret(%d)", ret); - return VCD_ERROR_OPERATION_FAILED; - } - ret = sound_manager_start_virtual_stream(g_virtual_sound_stream_h); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start virtual stream, ret(%d)", ret); - return VCD_ERROR_OPERATION_FAILED; - } + } + + if (!g_virtual_sound_stream_h) { + ret = sound_manager_create_virtual_stream(g_stream_for_volume_h, &g_virtual_sound_stream_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to create virtual stream, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; } } + ret = sound_manager_start_virtual_stream(g_virtual_sound_stream_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to start virtual stream, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; + } + return 0; } int vcd_recorder_recover_system_volume() { + int ret = VCD_ERROR_NONE; + if (g_virtual_sound_stream_h) { - int ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h); + ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to stop virtual stream, ret(%d)", ret); return VCD_ERROR_OPERATION_FAILED; @@ -939,15 +945,15 @@ int vcd_recorder_recover_system_volume() return VCD_ERROR_OPERATION_FAILED; } g_virtual_sound_stream_h = NULL; + } - if (g_stream_for_volume_h) { - ret = sound_manager_destroy_stream_information(g_stream_for_volume_h); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream information, ret(%d)", ret); - return VCD_ERROR_OPERATION_FAILED; - } - g_stream_for_volume_h = NULL; + if (g_stream_for_volume_h) { + ret = sound_manager_destroy_stream_information(g_stream_for_volume_h); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream information, ret(%d)", ret); + return VCD_ERROR_OPERATION_FAILED; } + g_stream_for_volume_h = NULL; } return 0; -- 2.7.4 From 21dbcba34abd3e5c96a59ee5dfbf818a2950a315 Mon Sep 17 00:00:00 2001 From: "sooyeon.kim" Date: Wed, 7 Nov 2018 14:52:28 +0900 Subject: [PATCH 15/16] Fix setting vc mgr pid Change-Id: I520abf1debc3d20c66752b8ce94251c3705cfbb1 Signed-off-by: sooyeon.kim --- server/vcd_client_data.c | 20 +++++++++++--------- server/vcd_server.c | 3 ++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server/vcd_client_data.c b/server/vcd_client_data.c index 8639155..2944216 100644 --- a/server/vcd_client_data.c +++ b/server/vcd_client_data.c @@ -52,15 +52,6 @@ vc_client_info_s* __client_get_element(int pid); int vcd_client_manager_set(int pid) { - if (-1 != g_manager.pid && NULL != g_manager.appid) { - SLOG(LOG_DEBUG, TAG_VCD, "Manager has already registered"); - return -1; - } - g_manager.pid = pid; - g_manager.manager_cmd = false; - g_manager.exclusive_cmd_option = false; - g_manager.appid = NULL; - // Get appid by pid using app control char* appid = NULL; int ret = app_manager_get_app_id(pid, &appid); @@ -68,6 +59,17 @@ int vcd_client_manager_set(int pid) SLOG(LOG_ERROR, TAG_VCD, "[ERROR] fail to get app id, ret(%d), pid(%d)", ret, pid); return -1; } + + if (-1 != g_manager.pid && NULL != g_manager.appid && 0 == strncmp(g_manager.appid, appid, strlen(g_manager.appid))) { + SLOG(LOG_WARN, TAG_VCD, "Same manager has already registered. It doesn't need to set manager again."); + return 0; + } + + g_manager.pid = pid; + g_manager.manager_cmd = false; + g_manager.exclusive_cmd_option = false; + g_manager.appid = NULL; + g_manager.appid = strdup(appid); free(appid); diff --git a/server/vcd_server.c b/server/vcd_server.c index f2e34f1..0a109ca 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1568,7 +1568,8 @@ int vcd_server_mgr_initialize(int pid) } /* Add client information to client manager */ - if (0 != vcd_client_manager_set(pid)) { + int ret = vcd_client_manager_set(pid); + if (0 != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to add manager"); return VCD_ERROR_OPERATION_FAILED; } -- 2.7.4 From 68e7335ae5aced5b0622f2cc7a5f756cef6941bb Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 7 Dec 2018 17:01:57 +0900 Subject: [PATCH 16/16] Fix mismatch between log format and actual parameter Change-Id: I7df022dc33db89c28acc3d5b97b8074b07cfa7ca Signed-off-by: Jihoon Kim --- common/vc_info_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/vc_info_parser.c b/common/vc_info_parser.c index 864f470..d4b48ac 100644 --- a/common/vc_info_parser.c +++ b/common/vc_info_parser.c @@ -401,7 +401,7 @@ int vc_info_parser_set_nlu_result(const char* nlu_result) SLOG(LOG_ERROR, vc_info_tag(), "[ERROR] Fail to set file mode - %s", VC_RUNTIME_INFO_NLU_RESULT); } - SLOG(LOG_DEBUG, vc_info_tag(), "[SUCCESS] Write file (%s) size (%d)", VC_RUNTIME_INFO_NLU_RESULT, strlen(nlu_result)); + SLOG(LOG_DEBUG, vc_info_tag(), "[SUCCESS] Write file (%s) size (%zu)", VC_RUNTIME_INFO_NLU_RESULT, strlen(nlu_result)); return 0; } -- 2.7.4