Add codes to check precondition with state 56/277656/3
authorwn.jang <wn.jang@samsung.com>
Tue, 12 Jul 2022 00:14:10 +0000 (09:14 +0900)
committerwn.jang <wn.jang@samsung.com>
Tue, 12 Jul 2022 08:38:21 +0000 (17:38 +0900)
Change-Id: I474382205ba3f479d7696fed8e06c8f61bfc5a90

client/stt.c

index ae31578..a5afb3e 100644 (file)
@@ -362,6 +362,20 @@ void __stt_config_engine_changed_cb(const char* engine_id, const char* setting,
        return;
 }
 
+static const char* __stt_get_state_string(stt_state_e state)
+{
+       //LCOV_EXCL_START
+       switch (state) {
+       case STT_STATE_CREATED:                 return "STT_STATE_CREATED";
+       case STT_STATE_READY:           return "STT_STATE_READY";
+       case STT_STATE_RECORDING:               return "STT_STATE_RECORDING";
+       case STT_STATE_PROCESSING:      return "STT_STATE_PROCESSING";
+       default:
+               return "Invalid State";
+       }
+       //LCOV_EXCL_STOP
+}
+
 static int __stt_check_handle(stt_h stt, stt_client_s** client)
 {
        RETVM_IF(NULL == stt, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
@@ -384,6 +398,16 @@ static int __stt_check_precondition(stt_h stt, stt_client_s** client)
        return STT_ERROR_NONE;
 }
 
+static int __stt_check_precondition_with_state(stt_h stt, stt_client_s** client, stt_state_e state)
+{
+       int ret = __stt_check_precondition(stt, client);
+       if (STT_ERROR_NONE != ret)
+               return ret;
+       const char* state_string = __stt_get_state_string(state);
+       RETVM_IF(state != (*client)->current_state, STT_ERROR_INVALID_STATE, "[ERROR] Current state(%d) is not %s", (*client)->current_state, state_string);
+       return STT_ERROR_NONE;
+}
+
 int stt_create(stt_h* stt)
 {
        RETV_IF(0 != __stt_get_feature_enabled(), STT_ERROR_NOT_SUPPORTED);
@@ -520,15 +544,13 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
+       RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
 
        SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported engine");
 
-       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;
 
@@ -551,14 +573,12 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       SLOG(LOG_INFO, TAG_STTC, "===== Get current engine");
-
        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);
+       SLOG(LOG_INFO, TAG_STTC, "===== Get current engine");
 
        int ret = 0;
 
@@ -718,14 +738,12 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       SLOG(LOG_INFO, TAG_STTC, "===== Set private data");
-
        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);
+       SLOG(LOG_INFO, TAG_STTC, "===== Set private data");
 
        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
@@ -763,14 +781,12 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       SLOG(LOG_INFO, TAG_STTC, "===== Get private data");
-
        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);
+       SLOG(LOG_INFO, TAG_STTC, "===== Get private data");
 
        int ret = -1;
        int count = 0;
@@ -981,15 +997,12 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        SLOG(LOG_INFO, TAG_STTC, "===== Prepare STT");
 
-       /* check 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);
        ecore_thread_main_loop_end();
@@ -1003,15 +1016,12 @@ int stt_prepare(stt_h stt)
 int stt_unprepare(stt_h stt)
 {
        stt_client_s* client = NULL;
-       int temp = __stt_check_precondition(stt, &client);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        SLOG(LOG_INFO, TAG_STTC, "===== Unprepare STT");
 
-       /* check 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;
        while (0 != ret) {
@@ -1088,9 +1098,8 @@ int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callbac
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported Language");
-
        RETVM_IF(NULL == callback, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
+       SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported Language");
 
        int ret;
        char* current_engine_id = NULL;
@@ -1148,9 +1157,8 @@ int stt_get_default_language(stt_h stt, char** language)
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       SLOG(LOG_INFO, TAG_STTC, "===== Get Default Language");
-
        RETVM_IF(NULL == language, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
+       SLOG(LOG_INFO, TAG_STTC, "===== Get Default Language");
 
        int ret = 0;
        ret = stt_config_mgr_get_default_language(language);
@@ -1217,12 +1225,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        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;
@@ -1255,16 +1262,10 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       /* 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;
-       }
-
        SLOG(LOG_INFO, TAG_STTC, "===== Set silence detection, supported(%d), type(%d)", client->silence_supported, type);
 
        if (true == client->silence_supported) {
@@ -1283,16 +1284,16 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND");
-
        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);
+
+       SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND");
 
        int ret = -1;
        int count = 0;
@@ -1325,15 +1326,12 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET START SOUND");
 
-       /* check 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;
        while (0 != ret) {
@@ -1364,15 +1362,15 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND");
        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);
+       SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND");
 
        int ret = -1;
        int count = 0;
@@ -1405,12 +1403,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET STOP SOUND");
-       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;
@@ -1443,14 +1440,12 @@ 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 tmp = __stt_check_precondition(stt, &client);
-       if (STT_ERROR_NONE != tmp) {
+       int tmp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
+       if (STT_ERROR_NONE != tmp)
                return tmp;
-       }
 
-       SLOG(LOG_INFO, TAG_STTC, "===== STT START");
-       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);
+       SLOG(LOG_INFO, TAG_STTC, "===== STT START");
 
        int ret = -1;
        char appid[1024] = {0, };
@@ -1499,12 +1494,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_RECORDING);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        SLOG(LOG_INFO, TAG_STTC, "===== STT STOP");
-       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
@@ -1602,12 +1596,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_RECORDING);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        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;
 
@@ -1909,18 +1902,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       if (callback == NULL)
-               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");
        SLOG(LOG_INFO, TAG_STTC, "[INFO] Set recognition result cb");
 
        client->recognition_result_cb = callback;
@@ -1932,15 +1918,10 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        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;
-       }
-
        SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset recognition result cb");
 
        client->recognition_result_cb = NULL;
@@ -1952,13 +1933,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        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");
 
        client->state_changed_cb = callback;
@@ -1970,12 +1949,10 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       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");
 
        client->state_changed_cb = NULL;
@@ -1987,13 +1964,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        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");
 
        client->error_cb = callback;
@@ -2005,12 +1980,10 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       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");
 
        client->error_cb = NULL;
@@ -2022,13 +1995,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        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");
 
        client->default_lang_changed_cb = callback;
@@ -2040,12 +2011,10 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       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");
 
        client->default_lang_changed_cb = NULL;
@@ -2057,13 +2026,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        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");
 
        client->engine_changed_cb = callback;
@@ -2075,12 +2042,10 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       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");
 
        client->engine_changed_cb = NULL;
@@ -2093,13 +2058,11 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
        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");
 
        client->speech_status_cb = callback;
@@ -2111,12 +2074,10 @@ 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);
+       int temp = __stt_check_precondition_with_state(stt, &client, STT_STATE_CREATED);
        if (STT_ERROR_NONE != temp)
                return temp;
 
-       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");
 
        client->speech_status_cb = NULL;
@@ -2128,20 +2089,13 @@ 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 tmp = __stt_check_precondition(stt, &client);
-       if (STT_ERROR_NONE != tmp) {
+       int tmp = __stt_check_precondition_with_state(stt, &client, STT_STATE_READY);
+       if (STT_ERROR_NONE != tmp)
                return tmp;
-       }
-       RETVM_IF(NULL == filepath, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
 
+       RETVM_IF(NULL == filepath, STT_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is NULL");
        SLOG(LOG_INFO, TAG_STTC, "===== STT START FILE");
 
-       /* 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);
                return STT_ERROR_IN_PROGRESS_TO_RECORDING;