From 41cf232aa28543dd932152268a51fd1639d3a7a1 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Wed, 13 Jul 2022 19:38:18 +0900 Subject: [PATCH] Use condition check macro for line coverage - Issue: It is tough to cover error handling code through unit test. - Solution: Actually, all conditional statement for checking error is invoked, but the problem is that the code for when error occurs is not invoked. some error handling codes are covered, but others are not covered only through unit tests. So this patch changes conditional check code to macro version. It still works as same as before, but the code is compressed into one line, so all line is covered. Change-Id: I268908220eb27258d19661b9907e83bffea008da Signed-off-by: Suyeon Hwang --- client/tts.c | 172 +++++++++++++------------------------------------ client/tts_core.c | 178 +++++++++++---------------------------------------- client/tts_ipc.c | 188 ++++++++++-------------------------------------------- 3 files changed, 116 insertions(+), 422 deletions(-) diff --git a/client/tts.c b/client/tts.c index 1745727..6cfdd52 100644 --- a/client/tts.c +++ b/client/tts.c @@ -201,9 +201,7 @@ static void __tts_config_screen_reader_changed_cb(bool value, void* user_data) int tts_create(tts_h* tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS"); @@ -294,9 +292,7 @@ int tts_create(tts_h* tts) int tts_destroy(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS"); @@ -374,9 +370,7 @@ int tts_destroy(tts_h tts) int tts_set_mode(tts_h tts, tts_mode_e mode) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Set TTS mode(%d)", mode); @@ -396,9 +390,7 @@ int tts_set_mode(tts_h tts, tts_mode_e mode) int tts_get_mode(tts_h tts, tts_mode_e* mode) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get TTS mode"); @@ -418,9 +410,7 @@ int tts_get_mode(tts_h tts, tts_mode_e* mode) int tts_set_credential(tts_h tts, const char* credential) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); RETVM_IF(NULL == credential, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null"); @@ -438,9 +428,7 @@ int tts_set_credential(tts_h tts, const char* credential) int tts_set_server_tts(tts_h tts, const char* credential) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -493,9 +481,7 @@ int tts_set_server_tts(tts_h tts, const char* credential) int tts_prepare(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -516,9 +502,7 @@ int tts_prepare(tts_h tts) int tts_prepare_sync(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -539,9 +523,7 @@ int tts_prepare_sync(tts_h tts) int tts_unprepare(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -564,9 +546,7 @@ int tts_unprepare(tts_h tts) int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, void* user_data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Foreach supported voices"); @@ -597,9 +577,7 @@ int tts_foreach_supported_voices(tts_h tts, tts_supported_voice_cb callback, voi int tts_get_default_voice(tts_h tts, char** lang, int* vctype) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice"); @@ -623,9 +601,7 @@ int tts_get_default_voice(tts_h tts, char** lang, int* vctype) int tts_get_max_text_size(tts_h tts, unsigned int* size) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); RETVM_IF(NULL == size, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get max text count : Input parameter is null"); @@ -647,9 +623,7 @@ int tts_get_max_text_size(tts_h tts, unsigned int* size) int tts_get_state(tts_h tts, tts_state_e* state) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); RETVM_IF(NULL == state, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Get state : Input parameter is null"); @@ -673,9 +647,7 @@ int tts_get_state(tts_h tts, tts_state_e* state) int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); RETVM_IF(NULL == min || NULL == normal || NULL == max, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null"); @@ -691,9 +663,7 @@ int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max) int tts_get_error_message(tts_h tts, char** err_msg) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); RETVM_IF(NULL == err_msg, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null"); @@ -715,9 +685,7 @@ int tts_get_error_message(tts_h tts, char** err_msg) int tts_check_screen_reader_on(tts_h tts, bool* is_on) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); RETVM_IF(NULL == is_on, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input parameter is null"); @@ -737,9 +705,7 @@ int tts_check_screen_reader_on(tts_h tts, bool* is_on) int tts_add_text(tts_h tts, const char* text, const char* language, int voice_type, int speed, int* utt_id) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Add text: text(%s), language(%s), type(%d)", (NULL == text) ? "NULL" : text, (NULL == language) ? "NULL" : language, voice_type); @@ -788,9 +754,7 @@ static void __tts_play_async(void *data) int tts_play_async(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Play asynchronously tts"); @@ -812,9 +776,7 @@ int tts_play_async(tts_h tts) int tts_play(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Play tts"); @@ -858,9 +820,7 @@ static void __tts_stop_async(void *data) int tts_stop_aync(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Stop asynchronously tts"); @@ -881,9 +841,7 @@ int tts_stop_aync(tts_h tts) int tts_stop(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop tts"); @@ -926,9 +884,7 @@ static void __tts_pause_async(void *data) int tts_pause_async(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Pause asynchronously tts"); @@ -948,9 +904,7 @@ int tts_pause_async(tts_h tts) //LCOV_EXCL_STOP int tts_pause(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Pause tts"); @@ -974,9 +928,7 @@ int tts_pause(tts_h tts) int tts_set_private_data(tts_h tts, const char* key, const char* data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Set private data, key(%s), data(%s)", key, data); @@ -1005,9 +957,7 @@ int tts_set_private_data(tts_h tts, const char* key, const char* data) int tts_get_private_data(tts_h tts, const char* key, char** data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Get private data, key(%s)", key); @@ -1031,9 +981,7 @@ int tts_get_private_data(tts_h tts, const char* key, char** data) int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* user_data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1051,9 +999,7 @@ int tts_set_state_changed_cb(tts_h tts, tts_state_changed_cb callback, void* use int tts_unset_state_changed_cb(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1069,9 +1015,7 @@ int tts_unset_state_changed_cb(tts_h tts) int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, void* user_data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1090,9 +1034,7 @@ int tts_set_utterance_started_cb(tts_h tts, tts_utterance_started_cb callback, v int tts_unset_utterance_started_cb(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1109,9 +1051,7 @@ int tts_unset_utterance_started_cb(tts_h tts) int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callback, void* user_data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1130,9 +1070,7 @@ int tts_set_utterance_completed_cb(tts_h tts, tts_utterance_completed_cb callbac int tts_unset_utterance_completed_cb(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1148,9 +1086,7 @@ int tts_unset_utterance_completed_cb(tts_h tts) int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1169,9 +1105,7 @@ int tts_set_error_cb(tts_h tts, tts_error_cb callback, void* user_data) int tts_unset_error_cb(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1188,9 +1122,7 @@ int tts_unset_error_cb(tts_h tts) int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb callback, void* user_data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1209,9 +1141,7 @@ int tts_set_default_voice_changed_cb(tts_h tts, tts_default_voice_changed_cb cal int tts_unset_default_voice_changed_cb(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1228,9 +1158,7 @@ int tts_unset_default_voice_changed_cb(tts_h tts) int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* user_data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1249,9 +1177,7 @@ int tts_set_engine_changed_cb(tts_h tts, tts_engine_changed_cb callback, void* u int tts_unset_engine_changed_cb(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1268,9 +1194,7 @@ int tts_unset_engine_changed_cb(tts_h tts) int tts_set_screen_reader_changed_cb(tts_h tts, tts_screen_reader_changed_cb callback, void* user_data) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1289,9 +1213,7 @@ int tts_set_screen_reader_changed_cb(tts_h tts, tts_screen_reader_changed_cb cal int tts_unset_screen_reader_changed_cb(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); tts_client_s* client = tts_client_get(tts); RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] A handle is not valid. tts(%p)", tts); @@ -1308,9 +1230,7 @@ int tts_unset_screen_reader_changed_cb(tts_h tts) int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int audio_type, int rate) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Add pcm tts"); @@ -1334,9 +1254,7 @@ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, int tts_play_pcm(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Play pcm tts"); @@ -1360,9 +1278,7 @@ int tts_play_pcm(tts_h tts) int tts_stop_pcm(tts_h tts) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Stop pcm tts"); @@ -1386,9 +1302,7 @@ int tts_stop_pcm(tts_h tts) int tts_repeat(tts_h tts, char** text_repeat, int* utt_id) { - if (0 != __tts_get_feature_enabled()) { - return TTS_ERROR_NOT_SUPPORTED; - } + RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED); SLOG(LOG_INFO, TAG_TTSC, "@@@ Repeat TTS"); diff --git a/client/tts_core.c b/client/tts_core.c index 63f5c8c..0e51157 100644 --- a/client/tts_core.c +++ b/client/tts_core.c @@ -22,6 +22,7 @@ #include "tts_defs.h" #include "tts_core.h" #include "tts_ipc.h" +#include "tts_dlog.h" static const int TTS_ERROR_FAIL_TO_SEND_HELLO = TIZEN_ERROR_TTS | 0xFF; @@ -77,10 +78,7 @@ static char* __get_engine_appid() { static int __update_engine_name() { char* new_engine_name = vconf_get_str(TTS_ENGINE_DB_DEFAULT); - if (NULL == new_engine_name) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get engine name"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(NULL == new_engine_name, TTS_ERROR_OPERATION_FAILED, "[ERROR] Fail to get engine name"); if (NULL != g_engine_name && 0 == strncmp(g_engine_name, new_engine_name, TTS_ENGINE_APPID_LEN)) { SLOG(LOG_INFO, TAG_TTSC, "[INFO] engine name is same"); @@ -130,12 +128,10 @@ static Eina_Bool __notify_error_timer_cb(void *data) { unsigned int uid = (uintptr_t)data; tts_client_s* client = tts_client_get_by_uid(uid); - if (NULL == client) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] UID is not valid. (%u)", uid); - } else { - __client_error_cb(client, client->utt_id, client->reason); - client->notify_error_timer = NULL; - } + RETVM_IF(NULL == client, EINA_FALSE, "[ERROR] uid(%u) is not valid.", uid); + + __client_error_cb(client, client->utt_id, client->reason); + client->notify_error_timer = NULL; return EINA_FALSE; } @@ -448,10 +444,7 @@ static Eina_Bool __prepare_cb(void *data) { unsigned int uid = (uintptr_t)data; tts_client_s* client = tts_client_get_by_uid(uid); - if (NULL == client) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return EINA_FALSE; - } + RETVM_IF(NULL == client, EINA_FALSE, "[ERROR] uid(%u) is not valid.", uid); int ret = __send_hello_msg(client); if (ret != TTS_ERROR_NONE) { @@ -482,10 +475,7 @@ static Eina_Bool __prepare_first_cb(void *data) /* send first hello message */ unsigned int uid = (uintptr_t)data; tts_client_s* client = tts_client_get_by_uid(uid); - if (NULL == client) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return EINA_FALSE; - } + RETVM_IF(NULL == client, EINA_FALSE, "[ERROR] uid(%u) is not valid.", uid); int ret = __send_hello_msg(client); if (ret != TTS_ERROR_NONE) { @@ -561,10 +551,7 @@ static bool __supported_voice_cb(const char* engine_id, const char* language, in { unsigned int uid = (uintptr_t)user_data; tts_client_s* client = tts_client_get_by_uid(uid); - if (NULL == client) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Uid is not valid. (%d)", uid); - return false; - } + RETVM_IF(NULL == client, false, "[ERROR] uid(%u) is not valid.", uid); /* call callback function */ tts_supported_voice_cb callback = tts_client_get_supported_voice_cb(client); @@ -729,10 +716,7 @@ int tts_core_deinitialize() int tts_core_notify_state_changed(tts_client_s* client, tts_state_e current_state) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is invalid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); tts_state_e before_state = tts_client_get_current_state(client); if (before_state == current_state) { @@ -749,10 +733,7 @@ int tts_core_notify_state_changed(tts_client_s* client, tts_state_e current_stat int tts_core_notify_utt_started(tts_client_s* client, int utt_id) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); client->utt_id = utt_id; SLOG(LOG_DEBUG, TAG_TTSC, "Utterance started data : utt_id(%d)", client->utt_id); @@ -774,10 +755,7 @@ int tts_core_notify_utt_started(tts_client_s* client, int utt_id) int tts_core_notify_utt_completeted(tts_client_s* client, int utt_id) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); client->utt_id = utt_id; SLOG(LOG_DEBUG, TAG_TTSC, "Utterance completed data : utt_id(%d)", utt_id); @@ -799,10 +777,7 @@ int tts_core_notify_utt_completeted(tts_client_s* client, int utt_id) int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int utt_id, const char* err_msg) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); SLOG(LOG_DEBUG, TAG_TTSC, "Error data : utt_id(%d) reason(%s)", utt_id, tts_core_covert_error_code(reason)); client->utt_id = utt_id; @@ -823,10 +798,7 @@ int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int ut //LCOV_EXCL_START int tts_core_notify_default_voice_changed(tts_client_s* client, const char* before_lang, int before_voice_type, const char* language, int voice_type) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); SLOG(LOG_DEBUG, TAG_TTSC, "Default voice changed data : before_lang(%s), before_voice_type(%d), language(%s), voice_type(%d)", before_lang, before_voice_type, language, voice_type); @@ -848,10 +820,7 @@ int tts_core_notify_default_voice_changed(tts_client_s* client, const char* befo int tts_core_notify_engine_changed(tts_client_s* client, const char* engine_id, const char* language, int voice_type, bool need_credential) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); SLOG(LOG_DEBUG, TAG_TTSC, "Engine changed data : engine_id(%s) language(%s), voicd_type(%d), need_credential(%d)", engine_id, language, voice_type, need_credential); @@ -874,10 +843,7 @@ int tts_core_notify_engine_changed(tts_client_s* client, const char* engine_id, int tts_core_notify_screen_reader_changed(tts_client_s* client, bool value) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); SLOG(LOG_DEBUG, TAG_TTSC, "Screen reader is changed. Current status(%d)", value); @@ -940,10 +906,7 @@ bool tts_core_is_valid_text(const char* text) bool tts_core_check_screen_reader(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] client is not valid"); - return false; - } + RETVM_IF(false == tts_client_is_valid_client(client), false, "[ERROR] Client is invalid."); tts_mode_e mode = tts_client_get_mode(client); if (TTS_MODE_SCREEN_READER == mode && false == __is_screen_reader_turned_on()) { @@ -955,10 +918,7 @@ bool tts_core_check_screen_reader(tts_client_s* client) bool tts_core_check_credential(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] client is not valid"); - return false; - } + RETVM_IF(false == tts_client_is_valid_client(client), false, "[ERROR] Client is invalid."); if (true == client->credential_needed && NULL == tts_client_get_credential_key(client)) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Do not have app credential for this engine"); @@ -997,16 +957,10 @@ const char* tts_core_covert_error_code(tts_error_e err) int tts_core_receive_hello(unsigned int uid, int ret, int credential_needed) { tts_client_s* client = tts_client_get_by_uid(uid); - if (NULL == client) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get TTS client or ignore this uid(%u)", uid); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(NULL == client, TTS_ERROR_OPERATION_FAILED, "Fail to get TTS client or ignore this uid(%u)", uid); 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; - } + RETVM_IF(TTS_STATE_CREATED != current_state, TTS_ERROR_NONE, "[INFO] tts client is already READY"); if (client->hello_timer) { ecore_timer_del(client->hello_timer); @@ -1039,10 +993,7 @@ int tts_core_receive_hello(unsigned int uid, int ret, int credential_needed) int tts_core_prepare(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); if (false == tts_core_check_screen_reader(client)) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available"); @@ -1066,10 +1017,7 @@ int tts_core_prepare(tts_client_s* client) int tts_core_prepare_sync(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); SLOG(LOG_INFO, TAG_TTSC, "[INFO] Start core_prepare_sync. tts_h(%p), tts_client(%p), uid(%u)", tts_client_get_handle(client), client, uid); @@ -1110,10 +1058,7 @@ int tts_core_prepare_sync(tts_client_s* client) int tts_core_unprepare(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts_h(%p), tts_client(%p), uid(%u)", tts_client_get_handle(client), client, uid); @@ -1152,10 +1097,7 @@ int tts_core_unprepare(tts_client_s* client) int tts_core_reprepare() { GList* clients = tts_client_get_client_list(); - if (NULL == clients) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(NULL == clients, TTS_ERROR_OPERATION_FAILED, "[ERROR] Fail to get client list"); GList *iter = NULL; if (g_list_length(clients) > 0) { @@ -1179,10 +1121,7 @@ int tts_core_reprepare() int tts_core_foreach_supported_voices(tts_client_s* client, const char* engine_id, tts_supported_voice_cb callback, void* user_data) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] client is not valid"); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); tts_client_set_supported_voice_cb(client, callback, user_data); uintptr_t uid = tts_client_get_uid(client); @@ -1200,10 +1139,7 @@ int tts_core_foreach_supported_voices(tts_client_s* client, const char* engine_i int tts_core_handle_service_reset() { GList* client_list = tts_client_get_client_list(); - if (NULL == client_list) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(NULL == client_list, TTS_ERROR_OPERATION_FAILED, "[ERROR] Fail to get client list"); if (g_list_length(client_list) > 0) { GList *iter = g_list_first(client_list); @@ -1229,15 +1165,8 @@ int tts_core_handle_service_reset() int tts_core_add_text(tts_client_s* client, const char* text, const char* language, int voice_type, int speed, int* utt_id) { - if (NULL == text || NULL == utt_id) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Parameter is invalid."); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == text || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Parameter is invalid."); + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); tts_client_set_repeat_text(client, text); @@ -1255,20 +1184,14 @@ int tts_core_add_text(tts_client_s* client, const char* text, const char* langua int tts_core_play(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); return __request_play(client); } int tts_core_stop(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); int ret = -1; @@ -1290,10 +1213,7 @@ int tts_core_stop(tts_client_s* client) int tts_core_pause(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); int ret = -1; @@ -1316,15 +1236,8 @@ int tts_core_pause(tts_client_s* client) int tts_core_repeat(tts_client_s* client, char** text_repeat, int* utt_id) { - if (NULL == text_repeat || NULL == utt_id) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Parameter is invalid."); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(NULL == text_repeat || NULL == utt_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Parameter is invalid."); + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); const char* repeat_text = tts_client_get_repeat_text(client); if (NULL == repeat_text) { @@ -1355,10 +1268,7 @@ int tts_core_repeat(tts_client_s* client, char** text_repeat, int* utt_id) int tts_core_add_pcm(tts_client_s* client, int event, const void* data, unsigned int data_size, int audio_type, int rate) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); int ret = -1; @@ -1381,10 +1291,7 @@ int tts_core_add_pcm(tts_client_s* client, int event, const void* data, unsigned int tts_core_play_pcm(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); int ret = -1; @@ -1407,10 +1314,7 @@ int tts_core_play_pcm(tts_client_s* client) int tts_core_stop_pcm(tts_client_s* client) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); int ret = -1; @@ -1433,10 +1337,7 @@ int tts_core_stop_pcm(tts_client_s* client) int tts_core_set_private_data(tts_client_s* client, const char* key, const char* data) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); int ret = -1; @@ -1459,10 +1360,7 @@ int tts_core_set_private_data(tts_client_s* client, const char* key, const char* int tts_core_get_private_data(tts_client_s* client, const char* key, char** data) { - if (false == tts_client_is_valid_client(client)) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid."); - return TTS_ERROR_INVALID_PARAMETER; - } + RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid."); unsigned int uid = tts_client_get_uid(client); int ret = -1; diff --git a/client/tts_ipc.c b/client/tts_ipc.c index d69ef30..2e3c5db 100644 --- a/client/tts_ipc.c +++ b/client/tts_ipc.c @@ -13,6 +13,7 @@ #include "tts_ipc.h" #include "tts_dbus.h" #include "tts_tidl.h" +#include "tts_dlog.h" typedef enum { @@ -80,15 +81,8 @@ int tts_ipc_open_connection(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_open_connection"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] IPC method is not set"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[OPEN_CONNECTION](uid); } @@ -97,15 +91,8 @@ int tts_ipc_close_connection(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_close_connection"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[CLOSE_CONNECTION](uid); } @@ -114,15 +101,8 @@ int tts_ipc_stop_listening(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_stop_listening"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[STOP_LISTENING](uid); } @@ -131,15 +111,8 @@ int tts_ipc_request_hello(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_hello"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_HELLO](uid); } @@ -148,15 +121,8 @@ int tts_ipc_request_hello_sync(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_hello_sync"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_HELLO_SYNC](uid); } @@ -165,15 +131,8 @@ int tts_ipc_request_initialize(unsigned int uid, bool* credential_needed) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_initialize"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_INITIALIZE](uid, credential_needed); } @@ -182,15 +141,8 @@ int tts_ipc_request_finalize(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_finalize"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_FINALIZE](uid); } @@ -199,15 +151,8 @@ int tts_ipc_request_add_text(unsigned int uid, const char* text, const char* lan { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_add_text"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_ADD_TEXT](uid, text, lang, vctype, speed, uttid, credential); } @@ -216,15 +161,8 @@ int tts_ipc_request_set_private_data(unsigned int uid, const char* key, const ch { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_set_private_data"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_SET_PRIVATE_DATA](uid, key, data); } @@ -233,15 +171,8 @@ int tts_ipc_request_get_private_data(unsigned int uid, const char* key, char** d { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_get_private_data"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_GET_PRIVATE_DATA](uid, key, data); } @@ -250,15 +181,8 @@ int tts_ipc_request_play(unsigned int uid, const char* credential) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_play"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_PLAY](uid, credential); } @@ -267,15 +191,8 @@ int tts_ipc_request_stop(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_stop"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_STOP](uid); } @@ -284,15 +201,8 @@ int tts_ipc_request_pause(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_pause"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_PAUSE](uid); } @@ -301,15 +211,8 @@ int tts_ipc_request_play_pcm(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_play_pcm"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_PLAY_PCM](uid); } @@ -318,15 +221,8 @@ int tts_ipc_request_stop_pcm(unsigned int uid) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_stop_pcm"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_STOP_PCM](uid); } @@ -335,15 +231,8 @@ int tts_ipc_request_add_pcm(unsigned int uid, int event, const char* data, int d { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_add_pcm"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_ADD_PCM](uid, event, data, data_size, audio_type, rate); } @@ -352,15 +241,8 @@ int tts_ipc_request_set_mode(unsigned int uid, tts_mode_e mode) { SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_set_mode"); - if (false == tts_client_is_valid_uid(uid)) { - SLOG(LOG_ERROR, TAG_TTSC, "Fail to get tts_client with uid(%d)", uid); - return TTS_ERROR_INVALID_PARAMETER; - } - - if (NULL == g_vtable) { - SLOG(LOG_ERROR, TAG_TTSC, "g_vtable is NULL"); - return TTS_ERROR_OPERATION_FAILED; - } + RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid); + RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set"); return g_vtable[REQUEST_SET_MODE](uid, mode); } -- 2.7.4