From e9ccf77dea85b191b1ea74d6cf230d1c372d4e34 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 10 Nov 2022 18:40:31 +0900 Subject: [PATCH] Add state and parameter check logic - Issue: Some APIs are not follow its documentation. - Solution: This patch adds state and parameter check logic to make each APIs follows its documentation. Some APIs did not make error even if the API is invoked in error situation. Through this patch, each APIs will make error in some condition specified by documentation. Change-Id: Ie9c92d012e8891a168a990d5e47559add0d03e49 Signed-off-by: Suyeon Hwang --- client/vc_mgr.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/vc_mgr.c b/client/vc_mgr.c index cdb0a25..1b02441 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -68,6 +68,7 @@ static cynara *p_cynara = NULL; static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER; static bool g_err_callback_status = false; +static bool g_all_result_callback_status = false; /* for TTS feedback */ static int g_feedback_rate = 16000; @@ -749,6 +750,8 @@ int vc_mgr_set_demandable_client_rule(const char* rule) if (VC_ERROR_NONE != ret) return ret; + RETVM_IF(NULL == rule, VC_ERROR_INVALID_PARAMETER, TAG_VCM, "[ERROR] Input parameter is NULL"); + vc_state_e state; if (0 != vc_mgr_client_get_client_state(&state)) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available"); @@ -784,6 +787,15 @@ int vc_mgr_unset_demandable_client_rule(void) if (VC_ERROR_NONE != ret) return ret; + vc_state_e state; + if (0 != vc_mgr_client_get_client_state(&state)) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] A handle is not available"); + return VC_ERROR_INVALID_STATE; + } + + /* check state */ + RETVM_IF(state != VC_STATE_READY, VC_ERROR_INVALID_STATE, TAG_VCM, "[ERROR] Invalid State: Current state(%d) is not 'Ready'", state); + vc_info_parser_set_demandable_client(NULL); ret = vc_mgr_tidl_request_demandable_client(g_pid); @@ -1928,6 +1940,11 @@ int vc_mgr_set_selected_results(vc_cmd_list_h vc_cmd_list) } } + if (false == g_all_result_callback_status) { + SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Not in all result callback"); + return VC_ERROR_OPERATION_FAILED; + } + if (NULL != vc_cmd_list) { int event = 0; char* result_text = NULL; @@ -1994,7 +2011,9 @@ static void __vc_mgr_notify_all_result(vc_result_type_e result_type) vc_mgr_client_set_all_result(event, temp_text); vc_mgr_client_use_callback(); + g_all_result_callback_status = true; cb_ret = all_callback(event, vc_cmd_list, temp_text, temp_message, all_user_data); + g_all_result_callback_status = false; vc_mgr_client_not_use_callback(); if (true == vc_mgr_client_get_exclusive_command()) { -- 2.34.1