From 29c1e6275b165ce4be2f510209836115478656b1 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Wed, 6 Jul 2022 17:25:05 +0900 Subject: [PATCH 1/1] Fix value for call by reference and simplify codes for logs Change-Id: Ie1ff065388e44e7cfa964e545477f28f7d7e0224 --- client/stt.c | 523 ++++++++++++++++------------------------------------------- 1 file changed, 142 insertions(+), 381 deletions(-) diff --git a/client/stt.c b/client/stt.c index fe2b444..ae31578 100644 --- a/client/stt.c +++ b/client/stt.c @@ -376,7 +376,7 @@ static int __stt_check_handle(stt_h stt, stt_client_s** client) return STT_ERROR_NONE; } -static int __stt_check_precondition(stt_h stt, stt_client_s* client) +static int __stt_check_precondition(stt_h stt, stt_client_s** client) { RETV_IF(0 != __stt_get_feature_enabled(), STT_ERROR_NOT_SUPPORTED); RETV_IF(0 != __stt_check_privilege(), STT_ERROR_PERMISSION_DENIED); @@ -442,10 +442,9 @@ int stt_create(stt_h* stt) int stt_destroy(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Destroy STT"); /* check used callback */ @@ -521,22 +520,14 @@ static bool __stt_config_supported_engine_cb(const char* engine_id, const char* int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported engine"); - if (NULL == callback) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(client->current_state != STT_STATE_CREATED, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); client->supported_engine_cb = callback; client->supported_engine_user_data = user_data; @@ -560,22 +551,14 @@ int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, v int stt_get_engine(stt_h stt, char** engine_id) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Get current engine"); - if (NULL == engine_id) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == engine_id, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(client->current_state != STT_STATE_CREATED, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); int ret = 0; @@ -678,16 +661,8 @@ int stt_set_engine(stt_h stt, const char* engine_id) SLOG(LOG_INFO, TAG_STTC, "===== Set current engine"); - if (NULL == engine_id) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - /* check state */ - if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == engine_id, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(client->current_state != STT_STATE_CREATED, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state); if (NULL != client->current_engine_id) { free(client->current_engine_id); @@ -714,17 +689,13 @@ int stt_set_engine(stt_h stt, const char* engine_id) int stt_set_credential(stt_h stt, const char* credential) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Set credential"); - if (NULL == credential) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - return STT_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == credential, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); /* check state */ if (client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY) { @@ -747,23 +718,14 @@ int stt_set_credential(stt_h stt, const char* credential) int stt_set_private_data(stt_h stt, const char* key, const char* data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Set private data"); - if (NULL == key || NULL == data) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter"); - return STT_ERROR_INVALID_PARAMETER; - } - - /* check state */ - if (STT_STATE_READY != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == key || NULL == data, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter"); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app"); //LCOV_EXCL_LINE @@ -801,23 +763,14 @@ int stt_set_private_data(stt_h stt, const char* key, const char* data) int stt_get_private_data(stt_h stt, const char* key, char** data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Get private data"); - if (NULL == key || NULL == data) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter"); - return STT_ERROR_INVALID_PARAMETER; - } - - /* check state */ - if (STT_STATE_READY != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == key || NULL == data, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter"); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = -1; int count = 0; @@ -858,17 +811,13 @@ int stt_set_server_stt(stt_h stt, const char* key, char* user_data) int ret = -1; stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Set STT server"); - if (NULL == key || NULL == user_data) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter"); - return STT_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == key || NULL == user_data, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter"); if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state); @@ -1032,18 +981,14 @@ static Eina_Bool __stt_connect_daemon(void *data) int stt_prepare(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Prepare STT"); /* check state */ - if (client->current_state != STT_STATE_CREATED) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state); ecore_thread_main_loop_begin(); g_connect_timer = ecore_timer_add(0.02, __stt_connect_daemon, (void*)client); @@ -1058,18 +1003,14 @@ int stt_prepare(stt_h stt) int stt_unprepare(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Unprepare STT"); /* check state */ - if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state); int ret = -1; int count = 0; @@ -1143,17 +1084,13 @@ static bool __stt_config_supported_language_cb(const char* engine_id, const char int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported Language"); - if (NULL == callback) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); int ret; char* current_engine_id = NULL; @@ -1207,17 +1144,13 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac int stt_get_default_language(stt_h stt, char** language) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== Get Default Language"); - if (NULL == language) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == language, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); int ret = 0; ret = stt_config_mgr_get_default_language(language); @@ -1237,15 +1170,11 @@ int stt_get_default_language(stt_h stt, char** language) int stt_get_state(stt_h stt, stt_state_e* state) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (NULL == state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == state, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); *state = client->current_state; @@ -1265,20 +1194,12 @@ int stt_get_state(stt_h stt, stt_state_e* state) int stt_get_error_message(stt_h stt, char** err_msg) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - - if (NULL == err_msg) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - return STT_ERROR_INVALID_PARAMETER; - } - if (false == g_err_callback_status) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This callback should be called during an err_callback"); - return STT_ERROR_OPERATION_FAILED; - } + RETVM_IF(NULL == err_msg, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(false == g_err_callback_status, STT_ERROR_OPERATION_FAILED, "[ERROR] This callback should be called during an err_callback"); if (NULL != client->err_msg) { *err_msg = strdup(client->err_msg); @@ -1296,21 +1217,12 @@ int stt_get_error_message(stt_h stt, char** err_msg) int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (NULL == type || NULL == support) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - /* check state */ - if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == type || NULL == support, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(client->current_state != STT_STATE_READY, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = -1; int count = 0; @@ -1343,10 +1255,9 @@ int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } /* check state */ if (client->current_state != STT_STATE_READY) { @@ -1373,28 +1284,15 @@ int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type) int stt_set_start_sound(stt_h stt, const char* filename) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND"); - if (NULL == filename) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - if (0 != access(filename, F_OK)) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - /* check state */ - if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == filename, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(0 != access(filename, F_OK), STT_ERROR_INVALID_PARAMETER, "[ERROR] File does not exist"); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = -1; int count = 0; @@ -1427,18 +1325,14 @@ int stt_set_start_sound(stt_h stt, const char* filename) int stt_unset_start_sound(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET START SOUND"); /* check state */ - if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = -1; int count = 0; @@ -1471,28 +1365,14 @@ int stt_unset_start_sound(stt_h stt) int stt_set_stop_sound(stt_h stt, const char* filename) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND"); - - if (NULL == filename) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - if (0 != access(filename, F_OK)) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - /* check state */ - if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == filename, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(0 != access(filename, F_OK), STT_ERROR_INVALID_PARAMETER, "[ERROR] File does not exist"); + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = -1; int count = 0; @@ -1525,18 +1405,12 @@ int stt_set_stop_sound(stt_h stt, const char* filename) int stt_unset_stop_sound(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET STOP SOUND"); - - /* check state */ - if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = -1; int count = 0; @@ -1569,23 +1443,14 @@ int stt_unset_stop_sound(stt_h stt) int stt_start(stt_h stt, const char* language, const char* type) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { - return temp; + int tmp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != tmp) { + return tmp; } SLOG(LOG_INFO, TAG_STTC, "===== STT START"); - - /* check state */ - if (client->current_state != STT_STATE_READY) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); - return STT_ERROR_INVALID_STATE; - } - - if (STT_INTERNAL_STATE_NONE != client->internal_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); //LCOV_EXCL_LINE - return STT_ERROR_IN_PROGRESS_TO_RECORDING; - } + RETVM_IF(STT_STATE_READY != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); + RETVM_IF(STT_INTERNAL_STATE_NONE != client->internal_state, STT_ERROR_IN_PROGRESS_TO_RECORDING, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); int ret = -1; char appid[1024] = {0, }; @@ -1604,10 +1469,7 @@ int stt_start(stt_h stt, const char* language, const char* type) temp = strdup(language); } - if (NULL == temp) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); - return STT_ERROR_OUT_OF_MEMORY; - } + RETVM_IF(NULL == temp, STT_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory"); if (true == client->credential_needed && NULL == client->credential) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); //LCOV_EXCL_LINE @@ -1637,18 +1499,12 @@ int stt_start(stt_h stt, const char* language, const char* type) int stt_stop(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== STT STOP"); - - /* check state */ - if (client->current_state != STT_STATE_RECORDING) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", client->current_state); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_RECORDING != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", client->current_state); if (STT_INTERNAL_STATE_STARTING == client->internal_state) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE @@ -1680,10 +1536,9 @@ int stt_stop(stt_h stt) int stt_cancel(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== STT CANCEL"); @@ -1747,20 +1602,12 @@ int __stt_cb_set_volume(unsigned int uid, float volume) int stt_get_recording_volume(stt_h stt, float* volume) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (NULL == volume) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } - - if (STT_STATE_RECORDING != client->current_state) { - SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == volume, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_RECORDING != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); *volume = g_volume_db; @@ -1797,17 +1644,12 @@ bool __stt_result_time_cb(int index, int event, const char* text, long start_tim int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== STT FOREACH DETAILED RESULT"); - - if (NULL == callback) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); client->result_time_cb = callback; client->result_time_user_data = user_data; @@ -1833,12 +1675,7 @@ static void __stt_notify_error(void *data) stt_client_s* client = (stt_client_s*)data; SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error from sttd"); - - /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE - return; - } + RETM_IF(NULL == client, "[ERROR] Fail to notify error : A handle is not valid"); if (NULL == stt_client_get_by_uid(client->uid)) return; @@ -1947,14 +1784,8 @@ static void __stt_notify_state_changed(void *data) stt_client_s* client = (stt_client_s*)data; /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE - return; - } - - if (NULL == stt_client_get_by_uid(client->uid)) { - return; - } + RETM_IF(NULL == client, "[ERROR] Fail to notify error : A handle is not valid"); + RET_IF(NULL == stt_client_get_by_uid(client->uid)); if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) { client->internal_state = STT_INTERNAL_STATE_NONE; @@ -1983,10 +1814,7 @@ static void __stt_notify_state_changed(void *data) int __stt_cb_result(unsigned int uid, int event, char** data, int data_count, const char* msg) { stt_client_s* client = stt_client_get_by_uid(uid); - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid. uid(%u)", uid); //LCOV_EXCL_LINE - return STT_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == client, STT_ERROR_INVALID_PARAMETER, "Handle is NOT valid. uid(%u)", uid); if (NULL != msg) SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result Message = %s", msg); @@ -2049,14 +1877,8 @@ static void __stt_notify_speech_status(void *data) stt_client_s* client = (stt_client_s*)data; /* check handle */ - if (NULL == client) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify speech status : A handle is not valid"); //LCOV_EXCL_LINE - return; - } - - if (NULL == stt_client_get_by_uid(client->uid)) { - return; - } + RETM_IF(NULL == client, "[ERROR] Fail to notify speech status : A handle is not valid"); + RET_IF(NULL == stt_client_get_by_uid(client->uid)); if (NULL != client->speech_status_cb) { stt_client_use_callback(client); @@ -2087,10 +1909,9 @@ int __stt_cb_speech_status(unsigned int uid, int status) int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } if (callback == NULL) return STT_ERROR_INVALID_PARAMETER; @@ -2111,10 +1932,9 @@ int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, int stt_unset_recognition_result_cb(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } if (STT_STATE_CREATED != client->current_state) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); @@ -2132,18 +1952,12 @@ int stt_unset_recognition_result_cb(stt_h stt) int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (NULL == callback) - return STT_ERROR_INVALID_PARAMETER; - - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Set state changed cb"); @@ -2156,15 +1970,11 @@ int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* use int stt_unset_state_changed_cb(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset state changed cb"); @@ -2177,18 +1987,12 @@ int stt_unset_state_changed_cb(stt_h stt) int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - - if (NULL == callback) - return STT_ERROR_INVALID_PARAMETER; - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Set error cb"); @@ -2201,15 +2005,11 @@ int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data) int stt_unset_error_cb(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset error cb"); @@ -2222,18 +2022,12 @@ int stt_unset_error_cb(stt_h stt) int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (NULL == callback) - return STT_ERROR_INVALID_PARAMETER; - - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Set default language changed cb"); @@ -2246,15 +2040,11 @@ int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_ int stt_unset_default_language_changed_cb(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset default language changed cb"); @@ -2267,18 +2057,12 @@ int stt_unset_default_language_changed_cb(stt_h stt) int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (NULL == callback) - return STT_ERROR_INVALID_PARAMETER; - - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Set engine changed cb"); @@ -2291,15 +2075,11 @@ int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* u int stt_unset_engine_changed_cb(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset engine changed cb"); @@ -2313,18 +2093,12 @@ int stt_unset_engine_changed_cb(stt_h stt) int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - - if (NULL == callback) - return STT_ERROR_INVALID_PARAMETER; - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Set speech status cb"); @@ -2337,15 +2111,11 @@ int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* use int stt_unset_speech_status_cb(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } - if (STT_STATE_CREATED != client->current_state) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state); - return STT_ERROR_INVALID_STATE; - } + RETVM_IF(STT_STATE_CREATED != client->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not 'Created'", client->current_state); SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset speech status cb"); @@ -2358,14 +2128,11 @@ int stt_unset_speech_status_cb(stt_h stt) int stt_start_file(stt_h stt, const char* language, const char* type, const char* filepath, stt_audio_type_e audio_type, int sample_rate) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { - return temp; - } - if (NULL == filepath) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); - return STT_ERROR_INVALID_PARAMETER; + int tmp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != tmp) { + return tmp; } + RETVM_IF(NULL == filepath, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL"); SLOG(LOG_INFO, TAG_STTC, "===== STT START FILE"); @@ -2397,10 +2164,7 @@ int stt_start_file(stt_h stt, const char* language, const char* type, const char temp = strdup(language); } - if (NULL == temp) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); - return STT_ERROR_OUT_OF_MEMORY; - } + RETVM_IF(NULL == temp, STT_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory"); if (true == client->credential_needed && NULL == client->credential) { SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); @@ -2430,10 +2194,9 @@ int stt_start_file(stt_h stt, const char* language, const char* type, const char int stt_cancel_file(stt_h stt) { stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } SLOG(LOG_INFO, TAG_STTC, "===== STT CANCEL FILE"); @@ -2598,10 +2361,9 @@ int stt_change_system_volume(stt_h stt, stt_system_volume_event_e volume_event) SLOG(LOG_DEBUG, TAG_STTC, "[STT] Change system volume, volume_event(%d)", volume_event); stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } /* check state */ if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) { @@ -2667,10 +2429,9 @@ int stt_recover_system_volume(stt_h stt) SLOG(LOG_DEBUG, TAG_STTC, "[STT] recover system volume"); stt_client_s* client = NULL; - int temp = __stt_check_precondition(stt, client); - if (STT_ERROR_NONE != temp)) { + int temp = __stt_check_precondition(stt, &client); + if (STT_ERROR_NONE != temp) return temp; - } /* check state */ if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) { -- 2.7.4