#include "tts_internal.h"
-static bool g_screen_reader;
-
static int g_feature_enabled = -1;
static int g_max_text_size = -1;
return code;
}
-static int __tts_recheck_screen_reader()
-{
- SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Check screen reader again");
-
- int ret = -1;
- int screen_reader = 0;
-
- ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
- return TTS_ERROR_INVALID_STATE;
- } else {
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] Current screen reader status(%d)", screen_reader);
- g_screen_reader = (bool)screen_reader;
- }
-
- return TTS_ERROR_NONE;
-}
-
//LCOV_EXCL_START
void __tts_config_voice_changed_cb(const char* before_lang, int before_voice_type, const char* language, int voice_type, bool auto_voice, void* user_data)
{
while (NULL != iter) {
data = iter->data;
+ // TODO: add client validation check code
tts_core_notify_default_voice_changed(data, before_lang, before_voice_type, language, voice_type);
/* Check whether language is changed or not. If it is changed, make 'text_repeat' NULL */
client->hello_timer = NULL;
}
- int ret = -1;
- int count = 0;
-
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");
case TTS_STATE_PAUSED:
case TTS_STATE_PLAYING:
case TTS_STATE_READY:
- // TODO: fix to core_unprepare
- ret = __tts_recheck_screen_reader();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader(%d)", ret);
- }
-
- 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 == mode)) {
- do {
- ret = tts_ipc_request_finalize(client->uid);
- if (0 != ret) {
- //LCOV_EXCL_START
- if (TTS_ERROR_TIMED_OUT != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", __tts_get_error_code(ret));
- break;
- } else {
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry finalize");
- usleep(10000);
- count++;
- if (TTS_RETRY_COUNT == count) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
- break;
- }
- }
- //LCOV_EXCL_STOP
- }
- } while (0 != ret);
- } else {
- 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) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to remove match : %s", __tts_get_error_code(ret));
- }
+ if (0 != tts_core_unprepare(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to unprepare");
}
-
- tts_client_set_current_state(client, TTS_STATE_CREATED);
-
case TTS_STATE_CREATED:
/* Unset registered callbacks */
tts_client_unset_all_cb(client);
return TTS_ERROR_NONE;
}
-//LCOV_EXCL_START
-void __tts_screen_reader_changed_cb(bool value)
-{
- g_screen_reader = value;
-}
-//LCOV_EXCL_STOP
-
int tts_set_mode(tts_h tts, tts_mode_e mode)
{
if (0 != __tts_get_feature_enabled()) {
return TTS_ERROR_INVALID_STATE;
}
- tts_client_set_mode(client, mode);
-
- if (TTS_MODE_SCREEN_READER == mode) {
- int ret;
- ret = __tts_recheck_screen_reader();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[Config ERROR] Fail to get screen reader(%d)", ret);
- return TTS_ERROR_OPERATION_FAILED;
- }
- tts_config_set_screen_reader_callback(client->uid, __tts_screen_reader_changed_cb);
- } else {
- tts_config_unset_screen_reader_callback(client->uid);
+ int ret = tts_core_set_mode(client, mode);
+ if (TTS_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set mode to client. ret(%d)", ret);
+ return ret;
}
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
client->credential = strdup(credential);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
-
return TTS_ERROR_NONE;
}
}
SLOG(LOG_INFO, TAG_TTSC, "@@@ Unprepare TTS");
-
- int ret = -1;
- ret = __tts_recheck_screen_reader();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader(%d)", ret);
- }
-
- ret = tts_core_unprepare(client, g_screen_reader);
+ int ret = tts_core_unprepare(client);
if (0 != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] tts_core_unprepare is failed(%s)", __tts_get_error_code(ret));
return ret;
return TTS_ERROR_INVALID_STATE;
}
- int ret = -1;
- 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) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
if (true == client->credential_needed && NULL == client->credential) {
}
/* do request */
- ret = -1;
+ int ret = -1;
int count = 0;
bool is_prepared = false;
while (0 != ret) {
return TTS_ERROR_INVALID_STATE;
}
- 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();
- if (0 != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
if (true == client->credential_needed && NULL == client->credential) {
return TTS_ERROR_INVALID_STATE;
}
- 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) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
if (true == client->credential_needed && NULL == client->credential) {
return TTS_ERROR_INVALID_STATE;
}
- 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) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
ecore_main_loop_thread_safe_call_async(__tts_stop_async, (void*)tts);
return TTS_ERROR_INVALID_STATE;
}
- int ret = -1;
- 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) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
- ret = -1;
+ int ret = -1;
int count = 0;
bool is_prepared = false;
while (0 != ret) {
return TTS_ERROR_INVALID_STATE;
}
- 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) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
ecore_main_loop_thread_safe_call_async(__tts_pause_async, (void*)tts);
return TTS_ERROR_INVALID_STATE;
}
- int ret = -1;
- 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);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
- ret = -1;
+ int ret = -1;
int count = 0;
bool is_prepared = false;
while (0 != ret) {
return TTS_ERROR_INVALID_STATE;
}
- int ret = -1;
- 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);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
- ret = -1;
+ int ret = -1;
int count = 0;
bool is_prepared = false;
while (0 != ret) {
return TTS_ERROR_INVALID_STATE;
}
- int ret = -1;
- 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);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
- ret = -1;
+ int ret = -1;
int count = 0;
bool is_prepared = false;
while (0 != ret) {
return TTS_ERROR_INVALID_STATE;
}
- int ret = -1;
- 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);
- return TTS_ERROR_INVALID_STATE;
- } else {
- if (false == g_screen_reader) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
- return TTS_ERROR_INVALID_STATE;
- }
- }
+ if (false == tts_core_check_screen_reader(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is not available");
+ return TTS_ERROR_INVALID_STATE;
}
- ret = -1;
+ int ret = -1;
int count = 0;
bool is_prepared = false;
while (0 != ret) {
/* Static variables */
static volatile bool g_is_thread_canceled = false;
+static bool g_is_screen_reader_on = false;
+
static char* g_engine_name = NULL;
static int g_engine_update_status = 0;
usleep(50000);
cnt++;
+ // TODO: fix way to exit thread safely
/* Checking thread is canceled or not */
if (ecore_thread_check(g_reprepare_thread)) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] client thread is canceled. Exit");
while (g_engine_update_status && (NULL != g_pkgmgr)) {
usleep(200000);
+ // TODO: fix way to exit thread safely
/* Checking thread is canceled or not */
if (ecore_thread_check(g_reprepare_thread)) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] client thread is canceled. Exit");
return false;
}
+static int __update_screen_reader_state()
+{
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Update screen reader state");
+
+ int ret = -1;
+ int screen_reader = 0;
+ ret = vconf_get_bool(TTS_ACCESSIBILITY_KEY, &screen_reader);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Current screen reader status(%d)", screen_reader);
+ g_is_screen_reader_on = (bool)screen_reader;
+
+ return TTS_ERROR_NONE;
+}
+
+//LCOV_EXCL_START
+static void __screen_reader_state_changed_cb(bool value)
+{
+ g_is_screen_reader_on = value;
+}
+//LCOV_EXCL_STOP
+
/* Public functions */
int tts_core_initialize()
{
return TTS_ERROR_NONE;
}
+int tts_core_set_mode(tts_client_s* client, tts_mode_e mode)
+{
+ if (false == tts_client_is_valid_client(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] client is not valid");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ int uid = client->uid;
+ tts_client_set_mode(client, mode);
+ if (TTS_MODE_SCREEN_READER == mode) {
+ if (0 != __update_screen_reader_state()) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader state");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+ tts_config_set_screen_reader_callback(uid, __screen_reader_state_changed_cb);
+ } else {
+ tts_config_unset_screen_reader_callback(uid);
+ }
+
+ return TTS_ERROR_NONE;
+}
+
bool tts_core_is_valid_text(const char* text)
{
if (NULL == text) {
return true;
}
+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;
+ }
+
+ tts_mode_e mode = tts_client_get_mode(client);
+ if (false == g_is_screen_reader_on && TTS_MODE_SCREEN_READER == mode) {
+ /* check screen reader option one more time */
+ int ret = __update_screen_reader_state();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get screen reader vconf(%d)", ret);
+ return false;
+ }
+
+ if (false == g_is_screen_reader_on) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Screen reader option is NOT available.");
+ return false;
+ }
+ }
+
+ return true;
+}
+
int tts_core_receive_hello(int uid, int ret, int credential_needed)
{
tts_client_s* client = tts_client_get_by_uid(uid);
return TTS_ERROR_NONE;
}
-int tts_core_unprepare(tts_client_s* client, bool is_screen_reader_on)
+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.");
client->hello_timer = NULL;
}
+ __update_screen_reader_state();
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);
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] screen_reader(%s), mode(%d)", (true == g_is_screen_reader_on) ? "True" : "False", mode);
int ret = -1;
int count = 0;
- 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);
+ if (false == g_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)", g_is_screen_reader_on, mode);
ret = tts_ipc_stop_listening(client->uid);
if (0 != ret) {