From: Suyeon Hwang Date: Fri, 13 Nov 2020 08:03:36 +0000 (+0900) Subject: Fix state getter function to return current state directly X-Git-Tag: submit/tizen/20210628.060348~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d051390f4b210f11ff292d6c36597e5df42395b;p=platform%2Fcore%2Fuifw%2Ftts.git Fix state getter function to return current state directly This patch fixes getter of current state directyly return the state value to make clearer and safer checking current state. Change-Id: Ibd31affec7ab047607aa4469f2247623492bc9d8 Signed-off-by: Suyeon Hwang --- diff --git a/client/tts.c b/client/tts.c index ed7464cd..a30f92ba 100644 --- a/client/tts.c +++ b/client/tts.c @@ -184,7 +184,8 @@ static Eina_Bool __reconnect_by_engine_changed(void* data) return EINA_FALSE; } - if (TTS_STATE_READY != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_READY != current_state) { usleep(10000); return EINA_TRUE; } @@ -219,14 +220,15 @@ void _tts_config_engine_changed_cb(const char* engine_id, const char* setting, c /* When the default engine is changed, please unload the old engine and load the new one. */ int ret = -1; - if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_PAUSED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_PLAYING == current_state || TTS_STATE_PAUSED == current_state) { ret = tts_stop(tts); if (0 != ret) { SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] TTS client stopping..."); } ecore_idler_add(__reconnect_by_engine_changed, (void*)tts); - } else if (TTS_STATE_READY == client->current_state) { + } else if (TTS_STATE_READY == current_state) { ret = tts_unprepare(tts); if (0 != ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare for setting a new engine... (%d)", ret); @@ -370,8 +372,13 @@ int tts_destroy(tts_h tts) int ret = -1; int count = 0; - /* check state */ - switch (client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_INVALID == current_state) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid"); + return TTS_ERROR_INVALID_PARAMETER; + } + + switch (current_state) { case TTS_STATE_PAUSED: case TTS_STATE_PLAYING: case TTS_STATE_READY: @@ -502,11 +509,9 @@ int tts_set_mode(tts_h tts, tts_mode_e mode) return TTS_ERROR_INVALID_PARAMETER; } - /* check state */ - if (client->current_state != TTS_STATE_CREATED) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'"); - SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); - SLOG(LOG_DEBUG, TAG_TTSC, " "); return TTS_ERROR_INVALID_STATE; } @@ -554,11 +559,9 @@ int tts_get_mode(tts_h tts, tts_mode_e* mode) return TTS_ERROR_INVALID_PARAMETER; } - /* check state */ - if (client->current_state != TTS_STATE_CREATED) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'"); - SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); - SLOG(LOG_DEBUG, TAG_TTSC, " "); return TTS_ERROR_INVALID_STATE; } @@ -593,8 +596,9 @@ int tts_set_credential(tts_h tts, const char* credential) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state); + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state && TTS_STATE_READY != current_state) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid"); return TTS_ERROR_INVALID_STATE; } @@ -628,8 +632,9 @@ int tts_set_server_tts(tts_h tts, const char* credential) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state && TTS_STATE_READY != client->current_state) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid (%d).", client->current_state); + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state && TTS_STATE_READY != current_state) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid"); return TTS_ERROR_INVALID_STATE; } @@ -710,10 +715,9 @@ int tts_prepare(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - /* check state */ - if (client->current_state != TTS_STATE_CREATED) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'"); - SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); return TTS_ERROR_INVALID_STATE; } @@ -744,10 +748,9 @@ int tts_prepare_sync(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - /* check state */ - if (client->current_state != TTS_STATE_CREATED) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'CREATED'"); - SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); return TTS_ERROR_INVALID_STATE; } @@ -778,8 +781,8 @@ int tts_unprepare(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - /* check state */ - if (client->current_state != TTS_STATE_READY) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_READY != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid State: Current state is not 'READY'"); return TTS_ERROR_INVALID_STATE; } @@ -902,7 +905,8 @@ int tts_get_max_text_size(tts_h tts, unsigned int* size) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_READY != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_READY != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get max text count : Current state is NOT 'READY'."); return TTS_ERROR_INVALID_STATE; } @@ -936,16 +940,21 @@ int tts_get_state(tts_h tts, tts_state_e* state) return TTS_ERROR_INVALID_PARAMETER; } - *state = client->current_state; + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_INVALID == current_state) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] client is invalid"); + return TTS_ERROR_INVALID_PARAMETER; + } - switch (*state) { + switch (current_state) { case TTS_STATE_CREATED: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Created'"); break; - case TTS_STATE_READY: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Ready'"); break; + case TTS_STATE_READY: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Ready'"); break; case TTS_STATE_PLAYING: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Playing'"); break; - case TTS_STATE_PAUSED: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Paused'"); break; - default: SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid value"); break; + case TTS_STATE_PAUSED: SLOG(LOG_INFO, TAG_TTSC, "Current state is 'Paused'"); break; } + *state = current_state; + return TTS_ERROR_NONE; } @@ -1041,7 +1050,8 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED == current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'."); return TTS_ERROR_INVALID_STATE; } @@ -1267,7 +1277,8 @@ int tts_play_async(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid."); return TTS_ERROR_INVALID_STATE; } @@ -1324,7 +1335,8 @@ int tts_play(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid."); return TTS_ERROR_INVALID_STATE; } @@ -1457,7 +1469,8 @@ int tts_stop_aync(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED == current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'."); return TTS_ERROR_INVALID_STATE; } @@ -1507,7 +1520,8 @@ int tts_stop(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED == current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Current state is 'CREATED'."); return TTS_ERROR_INVALID_STATE; } @@ -1634,9 +1648,9 @@ int tts_pause_async(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_PLAYING != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_PLAYING != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running."); - SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); return TTS_ERROR_INVALID_STATE; } @@ -1657,7 +1671,6 @@ int tts_pause_async(tts_h tts) ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); - return TTS_ERROR_NONE; } //LCOV_EXCL_STOP @@ -1685,9 +1698,9 @@ int tts_pause(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_PLAYING != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_PLAYING != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[Error] The Current state is NOT 'playing'. So this request should be not running."); - SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); return TTS_ERROR_INVALID_STATE; } @@ -1764,7 +1777,8 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_READY != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_READY != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'"); return TTS_ERROR_INVALID_STATE; } @@ -1833,7 +1847,8 @@ int tts_get_private_data(tts_h tts, const char* key, char** data) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_READY != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_READY != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid state : Current state is NOT 'READY'"); return TTS_ERROR_INVALID_STATE; } @@ -1898,7 +1913,8 @@ int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* use return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set state changed cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -1922,7 +1938,8 @@ int tts_unset_state_changed_cb(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset state changed cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -1951,7 +1968,8 @@ int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, v return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt started cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -1976,7 +1994,8 @@ int tts_unset_utterance_started_cb(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt started cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2006,7 +2025,8 @@ int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callbac return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set utt completed cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2031,7 +2051,8 @@ int tts_unset_utterance_completed_cb(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset utt completed cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2060,7 +2081,8 @@ int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set error cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2085,7 +2107,8 @@ int tts_unset_error_cb(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset error cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2115,7 +2138,8 @@ int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb cal return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set default voice changed cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2140,7 +2164,8 @@ int tts_unset_default_voice_changed_cb(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset default voice changed cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2170,7 +2195,8 @@ int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* u return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Set engine changed cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2195,7 +2221,8 @@ int tts_unset_engine_changed_cb(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED != client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Unset engine changed cb : Current state is not 'Created'."); return TTS_ERROR_INVALID_STATE; } @@ -2232,7 +2259,8 @@ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED == current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid."); return TTS_ERROR_INVALID_STATE; } @@ -2306,7 +2334,8 @@ int tts_play_pcm(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_PLAYING == client->current_state || TTS_STATE_CREATED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_PLAYING == current_state || TTS_STATE_CREATED == current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid."); return TTS_ERROR_INVALID_STATE; } @@ -2381,7 +2410,8 @@ int tts_stop_pcm(tts_h tts) return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_CREATED == client->current_state) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED == current_state) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid."); return TTS_ERROR_INVALID_STATE; } @@ -2457,15 +2487,15 @@ int tts_repeat(tts_h tts, char** text_repeat, int* utt_id) *utt_id = -1; tts_client_s* client = tts_client_get(tts); - if (NULL == client) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid."); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); return TTS_ERROR_INVALID_PARAMETER; } - if (TTS_STATE_READY != client->current_state) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid. (%d)", client->current_state); + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_READY != current_state) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] The current state is invalid. (%d)", current_state); return TTS_ERROR_INVALID_STATE; } diff --git a/client/tts_client.c b/client/tts_client.c index eb202c68..6bdd4e39 100644 --- a/client/tts_client.c +++ b/client/tts_client.c @@ -25,7 +25,7 @@ static GList *g_client_list = NULL; static pthread_mutex_t g_allocated_handle_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_client_list_mutex = PTHREAD_MUTEX_INITIALIZER; -/* private functions */ + static int __client_generate_uid(int pid) { int uid = 0; @@ -404,15 +404,13 @@ void tts_client_set_current_state(tts_client_s* client, tts_state_e state) client->current_state = state; } -int tts_client_get_current_state(tts_client_s* client, tts_state_e* state) +tts_state_e tts_client_get_current_state(tts_client_s* client) { - if (NULL == client || false == tts_client_is_valid(client->uid) || NULL == state) { - return TTS_ERROR_INVALID_PARAMETER; + if (NULL == client || false == tts_client_is_valid(client->uid)) { + return TTS_STATE_INVALID; } - *state = client->current_state; - - return TTS_ERROR_NONE; + return client->current_state; } void tts_client_set_state_changed_cb(tts_client_s* client, tts_state_changed_cb callback, void* user_data) diff --git a/client/tts_client.h b/client/tts_client.h index 8340e61d..dca7647a 100644 --- a/client/tts_client.h +++ b/client/tts_client.h @@ -25,6 +25,9 @@ extern "C" { #endif + +#define TTS_STATE_INVALID -1 + typedef struct { /* base info */ tts_h tts; @@ -102,7 +105,7 @@ int tts_client_get_mode_client_count(tts_mode_e mode); GList* tts_client_get_client_list(); void tts_client_set_current_state(tts_client_s* client, tts_state_e state); -int tts_client_get_current_state(tts_client_s* client, tts_state_e* state); +tts_state_e tts_client_get_current_state(tts_client_s* client); void tts_client_set_state_changed_cb(tts_client_s* client, tts_state_changed_cb callback, void* user_data); void tts_client_set_utterance_started_cb(tts_client_s* client, tts_utterance_started_cb callback, void* user_data); diff --git a/client/tts_core.c b/client/tts_core.c index 779058b2..4c66a354 100644 --- a/client/tts_core.c +++ b/client/tts_core.c @@ -62,6 +62,7 @@ static const char* __tts_get_error_code(tts_error_e err) return NULL; } +// TODO: make tts_util? or tts_log? static const char* __convert_state(tts_state_e state) { switch (state) { @@ -430,8 +431,8 @@ static int __send_hello_msg(tts_client_s* client) return TTS_ERROR_INVALID_PARAMETER; } - /* check state */ - if (client->current_state == TTS_STATE_READY) { + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_READY == current_state) { SLOG(LOG_INFO, TAG_TTSC, "[INFO] TTS client has been already connected to tts service"); //LCOV_EXCL_LINE return TTS_ERROR_INVALID_STATE; } @@ -827,18 +828,12 @@ int tts_core_notify_engine_changed(tts_client_s* client, const char* engine_id, int tts_core_set_current_state(tts_client_s* client, tts_state_e state) { - /* check handle */ - if (NULL == client || false == tts_client_is_valid(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); + tts_state_e before_state = tts_client_get_current_state(client); + if (TTS_STATE_INVALID == before_state) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is invalid."); return TTS_ERROR_INVALID_PARAMETER; } - tts_state_e before_state = TTS_STATE_CREATED; - if (0 != tts_client_get_current_state(client, &before_state)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get before state."); - return TTS_ERROR_OPERATION_FAILED; - } - SLOG(LOG_DEBUG, TAG_TTSC, "State changed to (%s).", __convert_state(state)); tts_client_set_current_state(client, state); __client_state_changed_cb(client, before_state, state); @@ -854,8 +849,9 @@ int tts_core_receive_hello(int uid, int ret, int credential_needed) return TTS_ERROR_OPERATION_FAILED; } - if (TTS_STATE_CREATED != client->current_state) { - SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts client is already prepared"); + tts_state_e current_state = tts_client_get_current_state(client); + if (TTS_STATE_CREATED != current_state) { + SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts client is already READY"); return TTS_ERROR_NONE; } @@ -880,7 +876,7 @@ int tts_core_receive_hello(int uid, int ret, int credential_needed) } } - tts_core_notify_state_changed_async(client, client->current_state, TTS_STATE_READY); + tts_core_notify_state_changed_async(client, current_state, TTS_STATE_READY); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); return TTS_ERROR_NONE; diff --git a/client/tts_dbus.c b/client/tts_dbus.c index 2c89c860..dd8aae65 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -107,13 +107,13 @@ static int __tts_cb_set_state(int uid, int state) } tts_state_e state_from_daemon = (tts_state_e)state; - - if (client->current_state == state_from_daemon) { - SLOG(LOG_DEBUG, TAG_TTSC, "Current state has already been %d", client->current_state); + tts_state_e current_state = tts_client_get_current_state(client); + if (current_state == state_from_daemon) { + SLOG(LOG_DEBUG, TAG_TTSC, "Current state has already been %d", current_state); return 0; } - tts_core_notify_state_changed_async(client, client->current_state, state_from_daemon); + tts_core_notify_state_changed_async(client, current_state, state_from_daemon); return 0; } diff --git a/client/tts_tidl.c b/client/tts_tidl.c index 8b855e2a..581c541d 100644 --- a/client/tts_tidl.c +++ b/client/tts_tidl.c @@ -93,13 +93,13 @@ static int __tts_cb_set_state(int uid, int state) } tts_state_e state_from_daemon = (tts_state_e)state; - - if (client->current_state == state_from_daemon) { - SLOG(LOG_DEBUG, TAG_TTSC, "Current state has already been %d", client->current_state); + tts_state_e current_state = tts_client_get_current_state(client); + if (current_state == state_from_daemon) { + SLOG(LOG_DEBUG, TAG_TTSC, "Current state has already been %d", current_state); return 0; } - tts_core_notify_state_changed_async(client, client->current_state, state_from_daemon); + tts_core_notify_state_changed_async(client, current_state, state_from_daemon); return 0; }