From c9dcb5488c429e76e8b02ee18df10f453548a4ba Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 19 Apr 2021 14:42:16 +0900 Subject: [PATCH] Make function to access mode of client Change-Id: Ia64ecbc1865f68c9be1f3575fe43140dd0548a83 Signed-off-by: Suyeon Hwang --- client/tts.c | 31 ++++++++++++++++--------------- client/tts_client.c | 18 ++++++++++++++++++ client/tts_client.h | 3 +++ client/tts_core.c | 14 ++++++++------ client/tts_dbus.c | 40 ++++++++++++++++++++++------------------ client/tts_tidl.c | 11 ++++++----- 6 files changed, 73 insertions(+), 44 deletions(-) diff --git a/client/tts.c b/client/tts.c index f537b08..d3e32fd 100644 --- a/client/tts.c +++ b/client/tts.c @@ -374,9 +374,10 @@ int tts_destroy(tts_h tts) SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader(%d)", ret); } - SLOG(LOG_INFO, TAG_TTSC, "[INFO] g_screen_reader(%s), client->mode(%d)", (true == g_screen_reader) ? "True" : "False", client->mode); + tts_mode_e mode = tts_client_get_mode(client); + SLOG(LOG_INFO, TAG_TTSC, "[INFO] g_screen_reader(%s), mode(%d)", (true == g_screen_reader) ? "True" : "False", mode); - if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode)) { + if (!(false == g_screen_reader && TTS_MODE_SCREEN_READER == mode)) { do { ret = tts_ipc_request_finalize(client->uid); if (0 != ret) { @@ -397,7 +398,7 @@ int tts_destroy(tts_h tts) } } while (0 != ret); } else { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, client->mode); + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : g_sr(%d) mode(%d)", g_screen_reader, mode); ret = tts_ipc_stop_listening(client->uid); if (0 != ret) { @@ -489,7 +490,7 @@ int tts_set_mode(tts_h tts, tts_mode_e mode) return TTS_ERROR_INVALID_STATE; } - client->mode = mode; + tts_client_set_mode(client, mode); if (TTS_MODE_SCREEN_READER == mode) { int ret; @@ -533,7 +534,7 @@ int tts_get_mode(tts_h tts, tts_mode_e* mode) return TTS_ERROR_INVALID_STATE; } - *mode = client->mode; + *mode = tts_client_get_mode(client); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); return TTS_ERROR_NONE; @@ -994,7 +995,7 @@ int tts_add_text(tts_h tts, const char* text, const char* language, int voice_ty } int ret = -1; - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { /* check screen reader option one more time */ ret = __tts_recheck_screen_reader(); if (0 != ret) { @@ -1163,7 +1164,7 @@ int tts_play_async(tts_h tts) return TTS_ERROR_INVALID_STATE; } - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { /* check screen reader vconf one more time */ int ret = -1; ret = __tts_recheck_screen_reader(); @@ -1212,7 +1213,7 @@ int tts_play(tts_h tts) return TTS_ERROR_INVALID_STATE; } - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { /* check screen reader option one more time */ ret = __tts_recheck_screen_reader(); if (0 != ret) { @@ -1337,7 +1338,7 @@ int tts_stop_aync(tts_h tts) return TTS_ERROR_INVALID_STATE; } - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { /* check screen reader option one more time */ int ret = __tts_recheck_screen_reader(); if (0 != ret) { @@ -1379,7 +1380,7 @@ int tts_stop(tts_h tts) } int ret = -1; - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { /* check screen reader option one more time */ ret = __tts_recheck_screen_reader(); if (0 != ret) { @@ -1498,7 +1499,7 @@ int tts_pause_async(tts_h tts) return TTS_ERROR_INVALID_STATE; } - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { /* check screen reader option one more time */ int ret = __tts_recheck_screen_reader(); if (0 != ret) { @@ -1539,7 +1540,7 @@ int tts_pause(tts_h tts) } int ret = -1; - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { ret = __tts_recheck_screen_reader(); if (0 != ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); @@ -2067,7 +2068,7 @@ int tts_add_pcm(tts_h tts, int event, const void* data, unsigned int data_size, } int ret = -1; - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { ret = __tts_recheck_screen_reader(); if (0 != ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); @@ -2133,7 +2134,7 @@ int tts_play_pcm(tts_h tts) } int ret = -1; - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { ret = __tts_recheck_screen_reader(); if (0 != ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); @@ -2200,7 +2201,7 @@ int tts_stop_pcm(tts_h tts) } int ret = -1; - if (false == g_screen_reader && TTS_MODE_SCREEN_READER == client->mode) { + if (false == g_screen_reader && TTS_MODE_SCREEN_READER == tts_client_get_mode(client)) { ret = __tts_recheck_screen_reader(); if (0 != ret) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret); diff --git a/client/tts_client.c b/client/tts_client.c index 46fb13e..cdc2935 100644 --- a/client/tts_client.c +++ b/client/tts_client.c @@ -417,6 +417,24 @@ bool tts_client_is_listening_started(int uid) return client->start_listening; } +void tts_client_set_mode(tts_client_s* client, tts_mode_e mode) +{ + if (false == tts_client_is_valid_client(client)) { + return; + } + + client->mode = mode; +} + +tts_mode_e tts_client_get_mode(tts_client_s* client) +{ + if (false == tts_client_is_valid_client(client)) { + return INVALID_HANDLE; + } + + return client->mode; +} + void tts_client_set_error_message(tts_client_s* client, const char* error_message) { if (false == tts_client_is_valid_client(client)) { diff --git a/client/tts_client.h b/client/tts_client.h index 0212ed3..705c76c 100644 --- a/client/tts_client.h +++ b/client/tts_client.h @@ -112,6 +112,9 @@ tts_state_e tts_client_get_current_state(tts_client_s* client); void tts_client_set_start_listening(int uid, bool is_listening_started); bool tts_client_is_listening_started(int uid); +void tts_client_set_mode(tts_client_s* client, tts_mode_e mode); +tts_mode_e tts_client_get_mode(tts_client_s* client); + void tts_client_set_error_message(tts_client_s* client, const char* error_message); const char* tts_client_get_error_message(tts_client_s* client); diff --git a/client/tts_core.c b/client/tts_core.c index e2ab7e9..6ba299a 100644 --- a/client/tts_core.c +++ b/client/tts_core.c @@ -93,6 +93,7 @@ static char* __get_engine_appid(int mode) { } else if (TTS_MODE_INTERRUPT == mode) { snprintf(appid, 256, "%s-interrupt", g_engine_name); } else { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] mode is not valid. mode(%d)", mode); free(appid); return NULL; } @@ -442,7 +443,7 @@ static int __send_hello_msg(tts_client_s* client) SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts_h(%p), tts_client(%p), uid(%d)", tts_client_get_handle(client), client, client->uid); /* check service engine status */ - bool is_launched = __is_engine_launched(client->mode); + bool is_launched = __is_engine_launched(tts_client_get_mode(client)); SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts engine is launched(%d)", is_launched); if (false == is_launched) { /* If engine is NOT launched, check whether engine is updating or not */ @@ -486,7 +487,7 @@ static Eina_Bool __prepare_cb(void *data) if (TTS_HELLO_RETRY_COUNT == client->prepare_count) { SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Stop to prepare, retry count reaches the limit"); - bool is_launched = __is_engine_launched(client->mode); + bool is_launched = __is_engine_launched(tts_client_get_mode(client)); SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts engine is launched(%d)", is_launched); client->hello_timer = NULL; @@ -523,7 +524,7 @@ static Eina_Bool __prepare_first_cb(void *data) static Eina_Bool __prepare_sync_cb(tts_client_s* client) { // TODO: make function duplicated block - bool is_launched = __is_engine_launched(client->mode); + bool is_launched = __is_engine_launched(tts_client_get_mode(client)); SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts engine is launched(%d)", is_launched); if (false == is_launched) { @@ -955,12 +956,13 @@ int tts_core_unprepare(tts_client_s* client, bool is_screen_reader_on) client->hello_timer = NULL; } - SLOG(LOG_INFO, TAG_TTSC, "[INFO] screen_reader(%s), client->mode(%d)", (true == is_screen_reader_on) ? "True" : "False", client->mode); + tts_mode_e mode = tts_client_get_mode(client); + SLOG(LOG_INFO, TAG_TTSC, "[INFO] screen_reader(%s), mode(%d)", (true == is_screen_reader_on) ? "True" : "False", mode); int ret = -1; int count = 0; - if (false == is_screen_reader_on && TTS_MODE_SCREEN_READER == client->mode) { - SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : is_screen_reader(%d) mode(%d)", is_screen_reader_on, client->mode); + if (false == is_screen_reader_on && TTS_MODE_SCREEN_READER == mode) { + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Do not request finalize : is_screen_reader(%d) mode(%d)", is_screen_reader_on, mode); ret = tts_ipc_stop_listening(client->uid); if (0 != ret) { diff --git a/client/tts_dbus.c b/client/tts_dbus.c index b14b5c8..9b0a21b 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -95,13 +95,14 @@ static int __tts_dbus_add_match(int uid) } if (TTS_ERROR_SERVICE_RESET != client->reason) { - if (TTS_MODE_DEFAULT == client->mode) { + tts_mode_e mode = tts_client_get_mode(client); + if (TTS_MODE_DEFAULT == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_NOTIFICATION == client->mode) { + } else if (TTS_MODE_NOTIFICATION == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_SCREEN_READER == client->mode) { + } else if (TTS_MODE_SCREEN_READER == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_INTERRUPT == client->mode) { + } else if (TTS_MODE_INTERRUPT == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE); } @@ -431,7 +432,7 @@ int tts_dbus_stop_listening(int uid) return TTS_ERROR_INVALID_PARAMETER; } - return __tts_dbus_remove_match(client->mode); + return __tts_dbus_remove_match(tts_client_get_mode(client)); } int tts_dbus_reconnect() @@ -482,25 +483,26 @@ DBusMessage* __tts_dbus_make_message(int uid, const char* method) DBusMessage* msg; - if (TTS_MODE_DEFAULT == client->mode) { + tts_mode_e mode = tts_client_get_mode(client); + if (TTS_MODE_DEFAULT == mode) { msg = dbus_message_new_method_call( TTS_SERVER_SERVICE_NAME, TTS_SERVER_SERVICE_OBJECT_PATH, TTS_SERVER_SERVICE_INTERFACE, method); - } else if (TTS_MODE_NOTIFICATION == client->mode) { + } else if (TTS_MODE_NOTIFICATION == mode) { msg = dbus_message_new_method_call( TTS_NOTI_SERVER_SERVICE_NAME, TTS_NOTI_SERVER_SERVICE_OBJECT_PATH, TTS_NOTI_SERVER_SERVICE_INTERFACE, method); - } else if (TTS_MODE_SCREEN_READER == client->mode) { + } else if (TTS_MODE_SCREEN_READER == mode) { msg = dbus_message_new_method_call( TTS_SR_SERVER_SERVICE_NAME, TTS_SR_SERVER_SERVICE_OBJECT_PATH, TTS_SR_SERVER_SERVICE_INTERFACE, method); - } else if (TTS_MODE_INTERRUPT == client->mode) { + } else if (TTS_MODE_INTERRUPT == mode) { msg = dbus_message_new_method_call( TTS_INTERRUPT_SERVER_SERVICE_NAME, TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH, @@ -656,13 +658,14 @@ int tts_dbus_request_initialize(int uid, bool* credential_needed) } if (TTS_ERROR_SERVICE_RESET != client->reason) { - if (TTS_MODE_DEFAULT == client->mode) { + tts_mode_e mode = tts_client_get_mode(client); + if (TTS_MODE_DEFAULT == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_NOTIFICATION == client->mode) { + } else if (TTS_MODE_NOTIFICATION == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_SCREEN_READER == client->mode) { + } else if (TTS_MODE_SCREEN_READER == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE); - } else if (TTS_MODE_INTERRUPT == client->mode) { + } else if (TTS_MODE_INTERRUPT == mode) { snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE); } dbus_bus_add_match(g_conn_listener, rule_err, &err); @@ -700,14 +703,15 @@ int tts_dbus_request_finalize(int uid) } /* remove a rule for daemon error */ - SLOG(LOG_INFO, TAG_TTSC, "[INFO] Remove match, mode(%d)", client->mode); - if (TTS_MODE_DEFAULT == client->mode) { + tts_mode_e mode = tts_client_get_mode(client); + SLOG(LOG_INFO, TAG_TTSC, "[INFO] Remove match, mode(%d)", mode); + if (TTS_MODE_DEFAULT == mode) { __tts_dbus_remove_match(TTS_MODE_DEFAULT); - } else if (TTS_MODE_NOTIFICATION == client->mode) { + } else if (TTS_MODE_NOTIFICATION == mode) { __tts_dbus_remove_match(TTS_MODE_NOTIFICATION); - } else if (TTS_MODE_SCREEN_READER == client->mode) { + } else if (TTS_MODE_SCREEN_READER == mode) { __tts_dbus_remove_match(TTS_MODE_SCREEN_READER); - } else if (TTS_MODE_INTERRUPT == client->mode) { + } else if (TTS_MODE_INTERRUPT == mode) { __tts_dbus_remove_match(TTS_MODE_INTERRUPT); } diff --git a/client/tts_tidl.c b/client/tts_tidl.c index c26e1b7..f5117c2 100644 --- a/client/tts_tidl.c +++ b/client/tts_tidl.c @@ -158,7 +158,7 @@ static void __on_connected(rpc_port_proxy_tts_h h, void *user_data) } tts->connected = true; - if (0 != rpc_port_proxy_tts_invoke_set_mode(tts->rpc_h, client->mode)) { + if (0 != rpc_port_proxy_tts_invoke_set_mode(tts->rpc_h, tts_client_get_mode(client))) { SLOG(LOG_ERROR, TAG_TTSC, "Failed to set mode"); return; } @@ -235,15 +235,16 @@ int tts_tidl_open_connection(int uid) } if (TTS_ERROR_SERVICE_RESET != client->reason) { - if (TTS_MODE_DEFAULT == client->mode) { + tts_mode_e mode = tts_client_get_mode(client); + if (TTS_MODE_DEFAULT == mode) { strcat(engine_mode, engine_name); - } else if (TTS_MODE_NOTIFICATION == client->mode) { + } else if (TTS_MODE_NOTIFICATION == mode) { strcat(engine_mode, engine_name); strcat(engine_mode, TTS_NOTI_SERVER_MODE); - } else if (TTS_MODE_SCREEN_READER == client->mode) { + } else if (TTS_MODE_SCREEN_READER == mode) { strcat(engine_mode, engine_name); strcat(engine_mode, TTS_SR_SERVER_MODE); - } else if (TTS_MODE_INTERRUPT == client->mode) { + } else if (TTS_MODE_INTERRUPT == mode) { strcat(engine_mode, engine_name); strcat(engine_mode, TTS_INTERRUPT_SERVER_MODE); } -- 2.7.4