*/
#include <string.h>
+#include <stdatomic.h>
#include <app_manager.h>
#include <dlog.h>
#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;
+
/* Static variables */
-static volatile bool g_is_thread_canceled = false;
+static atomic_bool g_is_thread_canceled = false;
static char* g_engine_name = NULL;
static int g_engine_update_status = 0;
+static atomic_bool g_is_engine_name_changed = false;
static Ecore_Thread* g_reprepare_thread = NULL;
return "Invalid state";
}
-static char* __get_engine_appid(int mode) {
+static char* __get_engine_appid() {
if (NULL == g_engine_name) {
return NULL;
}
- char* appid = (char*)calloc(256, sizeof(char));
+ char* appid = (char*)calloc(TTS_ENGINE_APPID_LEN, sizeof(char));
if (NULL == appid) {
return NULL;
}
- if (TTS_MODE_DEFAULT == mode) {
- snprintf(appid, 256, "%s", g_engine_name);
- } else if (TTS_MODE_NOTIFICATION == mode) {
- snprintf(appid, 256, "%s-noti", g_engine_name);
- } else if (TTS_MODE_SCREEN_READER == mode) {
- snprintf(appid, 256, "%s-sr", g_engine_name);
- } 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;
- }
-
+ snprintf(appid, TTS_ENGINE_APPID_LEN, "%s", g_engine_name);
return appid;
}
static int __update_engine_name()
{
- if (g_engine_name) {
- free(g_engine_name);
- g_engine_name = NULL;
- }
+ char* new_engine_name = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
+ RETVM_IF(NULL == new_engine_name, TTS_ERROR_OPERATION_FAILED, "[ERROR] Fail to get engine name");
- g_engine_name = vconf_get_str(TTS_ENGINE_DB_DEFAULT);
- if (NULL == g_engine_name) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get engine name");
- return TTS_ERROR_OPERATION_FAILED;
+ 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");
+ free(new_engine_name);
+ return TTS_ERROR_NONE;
}
+ free(g_engine_name);
+ g_engine_name = new_engine_name;
+ g_is_engine_name_changed = true;
+
SLOG(LOG_ERROR, TAG_TTSC, "[INFO] Engine name(%s)", g_engine_name);
return TTS_ERROR_NONE;
}
static Eina_Bool __notify_error_timer_cb(void *data)
{
- int uid = (intptr_t)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. (%d)", 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);
- return EINA_FALSE;
-}
-
-static Eina_Bool __notify_state_timer_cb(void *data)
-{
- int uid = (intptr_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. (%d)", uid);
- } else {
- __client_state_changed_cb(client, client->before_state, client->current_state);
- client->notify_state_timer = NULL;
- }
+ __client_error_cb(client, client->utt_id, client->reason);
+ client->notify_error_timer = NULL;
return EINA_FALSE;
}
return true;
}
-static bool __is_engine_launched(tts_mode_e mode)
+static bool __is_engine_launched()
{
- char* appid = __get_engine_appid(mode);
+ char* appid = __get_engine_appid();
if (NULL == appid) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get engine app ID");
return false;
return is_running;
}
+//LCOV_EXCL_START
static int __pkgmgr_status_cb(uid_t target_uid, int req_id, const char *type, const char *pkgname, const char *key, const char *val, const void *pmsg, void *data)
{
// type (the type of the pkgname)
return 0;
}
+//LCOV_EXCL_STOP
static void __create_pkgmgr_thread(void* data, Ecore_Thread* thread)
{
g_pkgmgr_thread = NULL;
}
+//LCOV_EXCL_START
static void __cancel_pkgmgr_thread(void* data, Ecore_Thread* thread)
{
SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] Cancel pkgmgr thread");
g_is_thread_canceled = false;
g_pkgmgr_thread = NULL;
}
+//LCOV_EXCL_STOP
static void __pkgmgr_thread(void* data)
{
return;
}
+//LCOV_EXCL_START
static void __start_reprepare_thread(void* data, Ecore_Thread* thread)
{
SLOG(LOG_INFO, TAG_TTSC, "[DEBUG] start reprepare thread. engine update status(%d)", g_engine_update_status);
+ if (0 == g_engine_update_status && g_is_engine_name_changed) {
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Reprepare by engine change");
+ return;
+ }
+
int cnt = 0;
while (!g_engine_update_status && cnt < 20) {
SLOG(LOG_WARN, TAG_TTSC, "[WARNING] wait for starting update");
return;
}
+//LCOV_EXCL_STOP
static void __end_reprepare_thread(void* data, Ecore_Thread* thread)
{
GList* clients = tts_client_get_client_list();
if (NULL == clients) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get client list");
+ g_is_engine_name_changed = false;
+ g_reprepare_thread = NULL;
return;
}
}
g_list_free(clients);
+ g_is_engine_name_changed = false;
g_reprepare_thread = NULL;
}
+//LCOV_EXCL_START
static void __cancel_reprepare_thread(void* data, Ecore_Thread* thread)
{
SLOG(LOG_INFO, TAG_TTSC, "[INFO] cancel reprepare thread");
+ g_is_engine_name_changed = false;
g_reprepare_thread = NULL;
}
+//LCOV_EXCL_STOP
static inline void __run_client_reprepare_thread()
{
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;
+ return TTS_ERROR_SCREEN_READER_OFF;
}
- int uid = tts_client_get_uid(client);
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts_h(%p), tts_client(%p), uid(%d)", tts_client_get_handle(client), client, uid);
+ 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);
/* check service engine status */
- bool is_launched = __is_engine_launched(tts_client_get_mode(client));
+ bool is_launched = __is_engine_launched();
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 */
static Eina_Bool __prepare_cb(void *data)
{
- int uid = (intptr_t)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) {
client->prepare_count++;
if (TTS_HELLO_RETRY_COUNT == client->prepare_count) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Stop to prepare, retry count reaches the limit");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare, retry count reaches the limit");
- bool is_launched = __is_engine_launched(tts_client_get_mode(client));
+ bool is_launched = __is_engine_launched();
SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts engine is launched(%d)", is_launched);
client->hello_timer = NULL;
+
+ tts_core_notify_error_async(client, TTS_ERROR_TIMED_OUT, -1, "[ERROR] Fail to prepare. Please call tts_prepare() again.");
+
return EINA_FALSE;
}
static Eina_Bool __prepare_first_cb(void *data)
{
/* send first hello message */
- int uid = (intptr_t)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) {
return EINA_FALSE;
}
-static Eina_Bool __prepare_sync_cb(tts_client_s* client)
+static int __prepare_sync_cb(tts_client_s* client)
{
// TODO: make function duplicated block
- bool is_launched = __is_engine_launched(tts_client_get_mode(client));
+ bool is_launched = __is_engine_launched();
SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts engine is launched(%d)", is_launched);
if (false == is_launched) {
/* check whether engine is updating or not */
if (g_engine_update_status) {
- SLOG(LOG_ERROR, TAG_TTSC, "[DEBUG] cannot prepare due to engine update");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Cannot prepare due to engine update.");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client automatically tries to reprepare asynchrnously.");
__run_client_reprepare_thread();
- return EINA_FALSE;
+ return TTS_ERROR_OPERATION_FAILED;
}
}
+
// TODO: make function duplicated block
- int uid = tts_client_get_uid(client);
- if (0 != tts_ipc_request_hello_sync(uid)) {
- return EINA_TRUE;
+ unsigned int uid = tts_client_get_uid(client);
+ if (TTS_ERROR_NONE != tts_ipc_request_hello_sync(uid)) {
+ return TTS_ERROR_FAIL_TO_SEND_HELLO;
}
SLOG(LOG_INFO, TAG_TTSC, "@@@ Connect daemon");
// TODO: make function duplicated block
/* do request initialize */
- int ret = -1;
bool credential_needed = false;
-
- ret = tts_ipc_request_initialize(uid, &credential_needed);
+ int ret = tts_ipc_request_initialize(uid, &credential_needed);
if (TTS_ERROR_ENGINE_NOT_FOUND == ret || TTS_ERROR_PERMISSION_DENIED == ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", tts_core_covert_error_code(ret));
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize. ret(%d/%s)", ret, get_error_message(ret));
tts_core_notify_error_async(client, ret, -1, NULL);
- return EINA_FALSE;
+ return ret;
} else if (TTS_ERROR_NONE != ret) {
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", tts_core_covert_error_code(ret));
- return EINA_TRUE;
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect. ret(%d/%s)", ret, get_error_message(ret));
+ return TTS_ERROR_FAIL_TO_SEND_HELLO;
} else {
/* success to connect tts-daemon */
client->credential_needed = credential_needed;
}
// TODO: make function duplicated block
- tts_core_notify_state_changed(client, TTS_STATE_READY);
-
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
- return EINA_FALSE;
+ return TTS_ERROR_NONE;
}
static void __engine_changed_cb(keynode_t* key, void* data)
static bool __supported_voice_cb(const char* engine_id, const char* language, int type, void* user_data)
{
- int uid = (intptr_t)user_data;
+ 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);
return (bool)screen_reader;
}
-static inline bool __handle_dbus_request_result(tts_client_s* client, tts_error_e ret, bool* is_prepared)
+static inline bool __is_ipc_retry_needed(tts_client_s* client, tts_error_e ret)
{
if (TTS_ERROR_NONE == ret) {
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success the dbus request");
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success the IPC request");
return false;
- } else if (TTS_ERROR_INVALID_PARAMETER == ret && false == *is_prepared) {
- tts_client_set_current_state(client, TTS_STATE_CREATED);
- if (0 == tts_core_prepare_sync(client)) {
- *is_prepared = true;
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_prepare_sync");
- }
- } else if (TTS_ERROR_TIMED_OUT != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] result : %s", tts_core_covert_error_code(ret));
- return false;
- } else {
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] retry play : %s", tts_core_covert_error_code(ret));
+ }
+
+ if (TTS_ERROR_TIMED_OUT == ret) {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] IPC is failed. Try again. ret(%d/%s)", ret, get_error_message(ret));
usleep(10000);
+ return true;
}
- return true;
+ if (TTS_ERROR_INVALID_PARAMETER == ret && false == tts_client_is_reprepared(client)) {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] IPC is failed by unregistered client. ret(%d/%s)", ret, get_error_message(ret));
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Try to prepare again");
+ tts_client_set_current_state(client, TTS_STATE_CREATED);
+ tts_core_prepare_sync(client);
+ tts_client_set_reprepared(client, true);
+ return true;
+ }
+
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] IPC request is failed. ret(%d/%s)", ret, get_error_message(ret));
+ return false;
}
static inline int __request_add_text(tts_client_s* client, const char* text, const char* language, int voice_type, int speed, int* utt_id)
}
// TODO: If use cpp, remove dupliceated code using command class pattern
- int uid = tts_client_get_uid(client);
+ unsigned int uid = tts_client_get_uid(client);
int ret = -1;
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_add_text(uid, text, convert_language, voice_type, speed, new_utt_id, client->credential);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}
static inline int __request_play(tts_client_s* client)
{
- int uid = tts_client_get_uid(client);
+ unsigned int uid = tts_client_get_uid(client);
int ret = -1;
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_play(uid, client->credential);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}
if (0 != __update_engine_name()) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set engine name into core module");
}
+ g_is_engine_name_changed = false;
/* Register vconfkey callback to detect engine change */
vconf_notify_key_changed(TTS_ENGINE_DB_DEFAULT, __engine_changed_cb, NULL);
if (NULL != g_reprepare_thread && EINA_FALSE == ecore_thread_check(g_reprepare_thread)) {
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Cancel reprepare thread");
ecore_thread_cancel(g_reprepare_thread);
+ ecore_thread_wait(g_reprepare_thread, 0.5); // wait g_reprepare_thread is terminated.
}
if (NULL != g_pkgmgr_thread) {
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) {
return TTS_ERROR_NONE;
}
-int tts_core_notify_state_changed_async(tts_client_s* client, tts_state_e current_state)
-{
- if (false == tts_client_is_valid_client(client)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
- tts_state_e before_state = tts_client_get_current_state(client);
- if (before_state == current_state) {
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] State is not changed. before(%s), current(%s)", __convert_state(before_state), __convert_state(current_state));
- return TTS_ERROR_NONE;
- }
-
- SLOG(LOG_DEBUG, TAG_TTSC, "Notify state changed asynchronously");
- tts_client_set_current_state(client, current_state);
- if (NULL != client->notify_state_timer) {
- ecore_timer_del(client->notify_state_timer);
- }
-
- intptr_t uid = tts_client_get_uid(client);
- client->notify_state_timer = ecore_timer_add(0, __notify_state_timer_cb, (void*)uid);
-
- return TTS_ERROR_NONE;
-}
-
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);
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);
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;
ecore_timer_del(client->notify_error_timer);
}
- intptr_t uid = tts_client_get_uid(client);
+ uintptr_t uid = tts_client_get_uid(client);
client->notify_error_timer = ecore_timer_add(0, __notify_error_timer_cb, (void*)uid);
return TTS_ERROR_NONE;
}
+//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);
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);
return TTS_ERROR_NONE;
}
+//LCOV_EXCL_STOP
+
+int tts_core_notify_screen_reader_changed(tts_client_s* client, bool value)
+{
+ 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);
+
+ tts_screen_reader_changed_cb callback = tts_client_get_screen_reader_changed_cb(client);
+ void* data = tts_client_get_screen_reader_changed_user_data(client);
+
+ if (NULL != callback) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "Notify screen reader changed");
+ tts_client_use_callback(client);
+ callback(tts_client_get_handle(client), value, data);
+ tts_client_not_use_callback(client);
+ } else {
+ SLOG(LOG_WARN, TAG_TTSC, "No registered callback(screen_reader_changed)");
+ }
+
+ return TTS_ERROR_NONE;
+}
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");
+ 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()) {
return false;
}
- tts_mode_e mode = tts_client_get_mode(client);
- if (false == __is_screen_reader_turned_on() && TTS_MODE_SCREEN_READER == mode) {
+ return true;
+}
+
+bool tts_core_check_credential(tts_client_s* client)
+{
+ 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");
return false;
}
return true;
}
+//LCOV_EXCL_START
const char* tts_core_covert_error_code(tts_error_e err)
{
switch (err) {
case TTS_ERROR_AUDIO_POLICY_BLOCKED: return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
case TTS_ERROR_NOT_SUPPORTED_FEATURE: return "TTS_ERROR_NOT_SUPPORTED_FEATURE";
case TTS_ERROR_SERVICE_RESET: return "TTS_ERROR_SERVICE_RESET";
+ case TTS_ERROR_SCREEN_READER_OFF: return "TTS_ERROR_SCREEN_READER_OFF";
default:
return "Invalid error code";
}
return NULL;
}
+//LCOV_EXCL_STOP
-int tts_core_receive_hello(int uid, int ret, int credential_needed)
+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(%d)", 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);
tts_core_notify_error_async(client, ret, -1, NULL);
return TTS_ERROR_OPERATION_FAILED;
- } else if (TTS_ERROR_NONE != ret) {
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", tts_core_covert_error_code(ret));
- return TTS_ERROR_OPERATION_FAILED;
- } else {
+ } else if (TTS_ERROR_ALREADY_INITIALIZED == ret) {
/* success to connect tts-daemon */
if (TTS_CREDENTIAL_NEEDED_ALREADY_INITIALIZED != credential_needed) {
client->credential_needed = credential_needed;
SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%d)", credential_needed);
}
+ } else if (TTS_ERROR_NONE != ret) {
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", tts_core_covert_error_code(ret));
+ return TTS_ERROR_OPERATION_FAILED;
}
- tts_core_notify_state_changed_async(client, TTS_STATE_READY);
+ tts_ipc_request_set_mode(uid, tts_client_get_mode(client));
+
+ tts_core_notify_state_changed(client, TTS_STATE_READY);
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
-const char* tts_core_get_engine_name()
-{
- return g_engine_name;
-}
-
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");
- return TTS_ERROR_INVALID_STATE;
+ return TTS_ERROR_SCREEN_READER_OFF;
}
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Start core_prepare. tts_h(%p), tts_client(%p)", tts_client_get_handle(client), client);
SLOG(LOG_ERROR, TAG_TTSC, "Register timer for __prepare_first_cb");
ecore_thread_main_loop_begin();
- intptr_t uid = tts_client_get_uid(client);
+ uintptr_t uid = tts_client_get_uid(client);
client->hello_timer = ecore_timer_add(0.0, __prepare_first_cb, (void*)uid);
ecore_thread_main_loop_end();
} else {
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.");
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] Start core_prepare_sync. tts_h(%p), tts_client(%p), uid(%d)", tts_client_get_handle(client), client, tts_client_get_uid(client));
+ 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);
int cnt = 0;
while (TTS_CONNECTION_RETRY_COUNT > cnt) {
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;
+ return TTS_ERROR_SCREEN_READER_OFF;
}
- if (EINA_FALSE == __prepare_sync_cb(client)) {
+ int ret = __prepare_sync_cb(client);
+ if (TTS_ERROR_NONE == ret) {
+ SLOG(LOG_INFO, TAG_TTSC, "[INFO] Prepare succeeds. uid(%u)", uid);
break;
}
+ if (TTS_ERROR_FAIL_TO_SEND_HELLO == ret) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DEBUG] Fail to send hello. Try again. uid(%u)", uid);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare. uid(%u), ret(%d/%s)", uid, ret, get_error_message(ret));
+ return ret;
+ }
+
cnt++;
}
return TTS_ERROR_OPERATION_FAILED;
}
+ tts_ipc_request_set_mode(uid, tts_client_get_mode(client));
+ tts_core_notify_state_changed(client, TTS_STATE_READY);
+
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
return TTS_ERROR_NONE;
}
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.");
- int uid = tts_client_get_uid(client);
- SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts_h(%p), tts_client(%p), uid(%d)", tts_client_get_handle(client), client, uid);
+ 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);
if (client->hello_timer) {
ecore_timer_del(client->hello_timer);
client->hello_timer = NULL;
} else {
SLOG(LOG_INFO, TAG_TTSC, "[INFO] Request finalize");
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_finalize(uid);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}
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) {
while (NULL != iter) {
tts_client_s* client = iter->data;
- if (false == tts_client_is_valid_client(client)) {
+ if (true == tts_client_is_valid_client(client)) {
tts_client_set_current_state(client, TTS_STATE_CREATED);
}
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);
- intptr_t uid = tts_client_get_uid(client);
+ uintptr_t uid = tts_client_get_uid(client);
int ret = tts_config_mgr_get_voice_list(engine_id, __supported_voice_cb, (void*)uid);
tts_client_set_supported_voice_cb(client, NULL, NULL);
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);
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);
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.");
- int uid = tts_client_get_uid(client);
- int ret = 0;
- int count = 0;
- bool is_prepared = false;
- while (TTS_RETRY_COUNT > count) {
+ unsigned int uid = tts_client_get_uid(client);
+ int ret = -1;
+ tts_client_set_reprepared(client, false);
+ for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_stop(uid);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
-
- count++;
}
if (TTS_ERROR_NONE != ret) {
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.");
- int uid = tts_client_get_uid(client);
+ unsigned int uid = tts_client_get_uid(client);
int ret = -1;
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_pause(uid);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}
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) {
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.");
- int uid = tts_client_get_uid(client);
+ unsigned int uid = tts_client_get_uid(client);
int ret = -1;
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_add_pcm(uid, event, data, data_size, audio_type, rate);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}
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.");
- int uid = tts_client_get_uid(client);
+ unsigned int uid = tts_client_get_uid(client);
int ret = -1;
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_play_pcm(uid);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}
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.");
- int uid = tts_client_get_uid(client);
+ unsigned int uid = tts_client_get_uid(client);
int ret = -1;
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_stop_pcm(uid);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}
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.");
- int uid = tts_client_get_uid(client);
+ unsigned int uid = tts_client_get_uid(client);
int ret = -1;
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_set_private_data(uid, key, data);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}
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.");
- int uid = tts_client_get_uid(client);
+ unsigned int uid = tts_client_get_uid(client);
int ret = -1;
- bool is_prepared = false;
+ tts_client_set_reprepared(client, false);
for (int count = 0; count < TTS_RETRY_COUNT; count++) {
ret = tts_ipc_request_get_private_data(uid, key, data);
- if (false == __handle_dbus_request_result(client, ret, &is_prepared)) {
+ if (false == __is_ipc_retry_needed(client, ret)) {
break;
}
}