From: Kwangyoun Kim Date: Wed, 5 Oct 2016 10:53:00 +0000 (+0900) Subject: Add internal state for prevent bug from async api call X-Git-Tag: accepted/tizen/common/20161031.122126~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91de4233b949bfa1120895e7175a7ce42ce01767;p=platform%2Fcore%2Fuifw%2Fvoice-control.git Add internal state for prevent bug from async api call Change-Id: I8a0539cc5291f5e8860a7d6cc47950628b0ea6f7 --- diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 0469551..ab5c2f4 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -179,6 +179,8 @@ static void __vc_mgr_internal_unprepare() if (0 != ret) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to request finalize : %s", __vc_mgr_get_error_code(ret)); } + + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); return; } @@ -1555,6 +1557,14 @@ int vc_mgr_start(bool exclusive_command_option) return VC_ERROR_INVALID_STATE; } + /* Check internal state for async */ + vc_internal_state_e internal_state = -1; + vc_mgr_client_get_internal_state(g_vc_m, &internal_state); + if (internal_state != VC_INTERNAL_STATE_NONE) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invaid State : Internal state is NOT none : %d", internal_state); + return VC_ERROR_IN_PROGRESS_TO_RECORDING; + } + vc_mgr_client_set_exclusive_command(g_vc_m, exclusive_command_option); bool start_by_client = false; @@ -1590,6 +1600,7 @@ int vc_mgr_start(bool exclusive_command_option) } } else { SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] start recognition"); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STARTING); } } @@ -1629,6 +1640,20 @@ int vc_mgr_stop() return VC_ERROR_INVALID_STATE; } + /* Check internal state for async */ + vc_internal_state_e internal_state = -1; + vc_mgr_client_get_internal_state(g_vc_m, &internal_state); + if (VC_INTERNAL_STATE_STARTING == internal_state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STARTING"); + return VC_ERROR_IN_PROGRESS_TO_RECORDING; + } else if (VC_INTERNAL_STATE_STOPPING == internal_state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STOPPING"); + return VC_ERROR_IN_PROGRESS_TO_PROCESSING; + } else if (VC_INTERNAL_STATE_CANCELING == internal_state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is CANCELING"); + return VC_ERROR_IN_PROGRESS_TO_READY; + } + int ret = -1; int count = 0; /* do request */ @@ -1649,6 +1674,7 @@ int vc_mgr_stop() } } else { SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Stop recognition"); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_STOPPING); } } @@ -1688,6 +1714,19 @@ int vc_mgr_cancel() return VC_ERROR_INVALID_STATE; } + vc_internal_state_e internal_state = -1; + vc_mgr_client_get_internal_state(g_vc_m, &internal_state); + if (VC_INTERNAL_STATE_STARTING == internal_state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STARTING"); + return VC_ERROR_IN_PROGRESS_TO_RECORDING; + } else if (VC_INTERNAL_STATE_STOPPING == internal_state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is STOPPING"); + return VC_ERROR_IN_PROGRESS_TO_PROCESSING; + } else if (VC_INTERNAL_STATE_CANCELING == internal_state) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Invalid State : Internal state is CANCELING"); + return VC_ERROR_IN_PROGRESS_TO_READY; + } + int ret = -1; int count = 0; while (0 != ret) { @@ -1707,6 +1746,7 @@ int vc_mgr_cancel() } } else { SLOG(LOG_DEBUG, TAG_VCM, "[SUCCESS] Cancel recognition"); + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_CANCELING); } } @@ -2243,6 +2283,8 @@ int __vc_mgr_cb_error(int reason, int daemon_pid, char* msg) return -1; } + vc_mgr_client_set_internal_state(g_vc_m, VC_INTERNAL_STATE_NONE); + if (VC_ERROR_SERVICE_RESET == reason) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] VC daemon reset"); @@ -2344,6 +2386,15 @@ int __vc_mgr_cb_service_state(int state) SLOG(LOG_DEBUG, TAG_VCM, "Service State changed : Before(%d) Current(%d)", before_state, current_state); + vc_internal_state_e internal_state = -1; + vc_mgr_client_get_internal_state(g_vc_m, &internal_state); + if ((VC_INTERNAL_STATE_STARTING == internal_state && VC_SERVICE_STATE_RECORDING == current_state) || + (VC_INTERNAL_STATE_STOPPING == internal_state && VC_SERVICE_STATE_PROCESSING == current_state) || + (VC_INTERNAL_STATE_CANCELING == internal_state && VC_SERVICE_STATE_READY == current_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); + } + /* Save service state */ vc_mgr_client_set_service_state(g_vc_m, current_state); diff --git a/client/vc_mgr_client.c b/client/vc_mgr_client.c index 4f01521..e44644e 100644 --- a/client/vc_mgr_client.c +++ b/client/vc_mgr_client.c @@ -58,6 +58,8 @@ typedef struct { /* service state */ vc_service_state_e service_state; + vc_internal_state_e internal_state; + /* state */ vc_state_e before_state; vc_state_e current_state; @@ -175,6 +177,8 @@ int vc_mgr_client_create(vc_h* vc) client->service_state = 0; + client->internal_state = VC_INTERNAL_STATE_NONE; + client->before_state = VC_STATE_INITIALIZED; client->current_state = VC_STATE_INITIALIZED; @@ -603,6 +607,32 @@ int vc_mgr_client_get_service_state(vc_h vc, vc_service_state_e* state) return 0; } +int vc_mgr_client_set_internal_state(vc_h vc, vc_internal_state_e state) +{ + vc_mgr_client_s* client = __mgr_client_get(vc); + + /* check handle */ + if (NULL == client) + return VC_ERROR_INVALID_PARAMETER; + + client->internal_state = state; + + return 0; +} + +int vc_mgr_client_get_internal_state(vc_h vc, vc_internal_state_e* state) +{ + vc_mgr_client_s* client = __mgr_client_get(vc); + + /* check handle */ + if (NULL == client) + return VC_ERROR_INVALID_PARAMETER; + + *state = client->internal_state; + + return 0; +} + int vc_mgr_client_set_client_state(vc_h vc, vc_state_e state) { vc_mgr_client_s* client = __mgr_client_get(vc); diff --git a/client/vc_mgr_client.h b/client/vc_mgr_client.h index 51088c5..afee7a4 100644 --- a/client/vc_mgr_client.h +++ b/client/vc_mgr_client.h @@ -26,6 +26,13 @@ extern "C" { #endif +typedef enum { + VC_INTERNAL_STATE_NONE = 0, + VC_INTERNAL_STATE_STARTING = 1, + VC_INTERNAL_STATE_STOPPING = 2, + VC_INTERNAL_STATE_CANCELING = 3 +} vc_internal_state_e; + /* * Common function */ @@ -87,6 +94,10 @@ int vc_mgr_client_set_service_state(vc_h vc, vc_service_state_e state); int vc_mgr_client_get_service_state(vc_h vc, vc_service_state_e* state); +int vc_mgr_client_set_internal_state(vc_h vc, vc_internal_state_e state); + +int vc_mgr_client_get_internal_state(vc_h vc, vc_internal_state_e* state); + int vc_mgr_client_set_client_state(vc_h vc, vc_state_e state); int vc_mgr_client_get_client_state(vc_h vc, vc_state_e* state); diff --git a/client/vc_widget.c b/client/vc_widget.c old mode 100644 new mode 100755 index f05a6b6..e7a9ed1 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -1106,7 +1106,7 @@ int vc_widget_set_send_current_command_list_cb(vc_widget_send_current_command_li return 0; } -int vc_widget_unsset_send_current_command_list_cb() +int vc_widget_unset_send_current_command_list_cb() { vc_state_e state; if (0 != vc_widget_client_get_state(g_vc_w, &state)) { diff --git a/include/voice_control_command_expand.h b/include/voice_control_command_expand.h index 695641f..fdb4101 100755 --- a/include/voice_control_command_expand.h +++ b/include/voice_control_command_expand.h @@ -18,6 +18,7 @@ #ifndef __VOICE_CONTROL_COMMAND_EXPAND_H__ #define __VOICE_CONTROL_COMMAND_EXPAND_H__ +#include #include #include diff --git a/include/voice_control_common.h b/include/voice_control_common.h index 86b07ac..b491719 100644 --- a/include/voice_control_common.h +++ b/include/voice_control_common.h @@ -50,7 +50,10 @@ typedef enum { VC_ERROR_OPERATION_REJECTED = TIZEN_ERROR_VOICE_CONTROL | 0x015, /**< Operation rejected */ VC_ERROR_ITERATION_END = TIZEN_ERROR_VOICE_CONTROL | 0x016, /**< List reached end */ VC_ERROR_EMPTY = TIZEN_ERROR_VOICE_CONTROL | 0x017, /**< List empty */ - VC_ERROR_SERVICE_RESET = TIZEN_ERROR_VOICE_CONTROL | 0x018 /**< Service Damon reset */ + VC_ERROR_SERVICE_RESET = TIZEN_ERROR_VOICE_CONTROL | 0x018, /**< Service Damon reset */ + VC_ERROR_IN_PROGRESS_TO_READY = TIZEN_ERROR_VOICE_CONTROL | 0x019, + VC_ERROR_IN_PROGRESS_TO_RECORDING = TIZEN_ERROR_VOICE_CONTROL | 0x020, + VC_ERROR_IN_PROGRESS_TO_PROCESSING = TIZEN_ERROR_VOICE_CONTROL | 0x021 } vc_error_e; /** diff --git a/include/voice_control_widget.h b/include/voice_control_widget.h index 91ddf74..2f8ca7a 100755 --- a/include/voice_control_widget.h +++ b/include/voice_control_widget.h @@ -63,7 +63,7 @@ typedef void (*vc_widget_show_tooltip_cb)(bool show, void* user_data); * @pre An application registers callback function using vc_widget_set_send_current_command_group_cb(). * * @see vc_widget_set_send_current_command_list_cb() -* @see vc_widget_unsset_send_current_command_list_cb() +* @see vc_widget_unset_send_current_command_list_cb() */ typedef void (*vc_widget_send_current_command_list_cb)(vc_cmd_list_h* vc_cmd_list, void* user_data); @@ -374,7 +374,7 @@ int vc_widget_set_send_current_command_list_cb(vc_widget_send_current_command_li * * @see vc_widget_set_send_current_command_list_cb() */ -int vc_widget_unsset_send_current_command_list_cb(); +int vc_widget_unset_send_current_command_list_cb(); /** * @brief Registers a callback function to be called when service state is changed. diff --git a/server/vcd_engine_agent.c b/server/vcd_engine_agent.c index 0863583..12f5754 100644 --- a/server/vcd_engine_agent.c +++ b/server/vcd_engine_agent.c @@ -428,6 +428,9 @@ int __internal_update_engine_list() } if (NULL != dirp) { + if (!strcmp(".", dirp->d_name) || !strcmp("..", dirp->d_name)) + continue; + vcengine_info_s* info = NULL; char* filepath = NULL; int filesize = 0; diff --git a/server/vcd_recorder.c b/server/vcd_recorder.c index bcda93e..f7e7313 100644 --- a/server/vcd_recorder.c +++ b/server/vcd_recorder.c @@ -194,6 +194,7 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void #endif +#if 0 static const char* __get_focus_changed_reason_code(sound_stream_focus_change_reason_e reason) { switch (reason) { @@ -238,6 +239,7 @@ static void __recorder_focus_state_cb(sound_stream_info_h stream_info, sound_str } } } +#endif int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb interrupt_cb) { @@ -287,9 +289,11 @@ int vcd_recorder_create(vcd_recoder_audio_cb audio_cb, vcd_recorder_interrupt_cb g_is_valid_audio_in = false; } +#if 0 if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_RECOGNITION, __recorder_focus_state_cb, NULL, &g_stream_info_h)) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to create stream info"); } +#endif g_audio_cb = audio_cb; g_interrupt_cb = interrupt_cb; @@ -349,9 +353,11 @@ int vcd_recorder_destroy() g_recorder_state = VCD_RECORDER_STATE_READY; } +#if 0 if (0 != sound_manager_destroy_stream_information(g_stream_info_h)) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to destroy stream info"); } +#endif audio_in_destroy(g_audio_h); @@ -623,6 +629,7 @@ int vcd_recorder_start() SLOG(LOG_ERROR, TAG_VCD, "[Recorder] started = %d", started); if (false == started) { +#if 0 ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL); if (SOUND_MANAGER_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to acquire focus : %d", ret); @@ -632,6 +639,7 @@ int vcd_recorder_start() SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to set stream info : %d", ret); } } +#endif ret = audio_in_prepare(g_audio_h); if (AUDIO_IO_ERROR_NONE != ret) { @@ -720,10 +728,12 @@ int vcd_recorder_stop() return VCD_ERROR_OPERATION_FAILED; } +#if 0 ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_RECORDING, NULL); if (SOUND_MANAGER_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Recorder ERROR] Fail to release focus : %d", ret); } +#endif } return 0; }