From 7717f835c9b0f4bc4d30cd65ebe7fa1e388c65b7 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 18 Sep 2017 20:02:29 +0900 Subject: [PATCH] Add synchronous prepare function for web API Change-Id: Ie70180121c1569d602d439cd9a295d2ec617be36 Signed-off-by: Suyeon Hwang --- client/vc.c | 38 +++++++++++++++++++++++++++++++++++--- include/voice_control_internal.h | 2 ++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/client/vc.c b/client/vc.c index e5bb5c6..7fe220e 100644 --- a/client/vc.c +++ b/client/vc.c @@ -310,13 +310,13 @@ int vc_initialize(void) /* check handle */ if (true == vc_client_is_valid(g_vc)) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Already initialized"); - return VC_ERROR_INVALID_STATE; + SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] Already initialized"); + return VC_ERROR_NONE; } if (0 < vc_client_get_count()) { SLOG(LOG_DEBUG, TAG_VCC, "[DEBUG] Already initialized"); - return VC_ERROR_INVALID_STATE; + return VC_ERROR_NONE; } if (0 != vc_dbus_open_connection()) { @@ -572,6 +572,38 @@ int vc_prepare(void) return VC_ERROR_NONE; } +int vc_prepare_sync(void) +{ + if (0 != __vc_get_feature_enabled()) { + return VC_ERROR_NOT_SUPPORTED; + } + if (0 != __vc_check_privilege()) { + return VC_ERROR_PERMISSION_DENIED; + } + + SLOG(LOG_DEBUG, TAG_VCC, "@@@ [Client] Prepare"); + + vc_state_e state; + if (0 != vc_client_get_client_state(g_vc, &state)) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] A handle is not available"); + SLOG(LOG_DEBUG, TAG_VCC, "@@@"); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + if (state != VC_STATE_INITIALIZED) { + SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Invalid State: Current state is not 'CREATED'"); + SLOG(LOG_DEBUG, TAG_VCC, "@@@"); + return VC_ERROR_INVALID_STATE; + } + + while (EINA_TRUE == __vc_connect_daemon(NULL)); + + SLOG(LOG_DEBUG, TAG_VCC, "@@@"); + + return VC_ERROR_NONE; +} + int vc_unprepare(void) { if (0 != __vc_get_feature_enabled()) { diff --git a/include/voice_control_internal.h b/include/voice_control_internal.h index 8465e9e..d73dcfb 100644 --- a/include/voice_control_internal.h +++ b/include/voice_control_internal.h @@ -68,6 +68,8 @@ typedef bool (*vc_asr_result_cb)(vc_result_event_e event, const char* result, vo */ int vc_set_command_list_from_file(const char* file_path, int type); +int vc_prepare_sync(void); + #ifdef __cplusplus } -- 2.7.4