Because tts_ipc layer is added, error handling code is duplicated.
To remove duplicated code, this patch unifies the functions for handling error from server.
Change-Id: Icc5a43cc8d66a956ef8aa050c01b718454ea8be7
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
if (0 != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to play tts : %s", __tts_get_error_code(ret));
- tts_core_notify_error_async(client, -1, ret);
+ tts_core_notify_error_async(client, ret, -1, NULL);
return;
}
if (0 != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to stop tts : %s", __tts_get_error_code(ret));
- tts_core_notify_error_async(client, -1, ret);
+ tts_core_notify_error_async(client, ret, -1, NULL);
return;
}
if (0 != ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to pause tts : %s", __tts_get_error_code(ret));
- tts_core_notify_error_async(data, -1, ret);
+ tts_core_notify_error_async(client, ret, -1, NULL);
return;
}
if (TTS_ERROR_ENGINE_NOT_FOUND == ret || TTS_ERROR_PERMISSION_DENIED == ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
- tts_core_notify_error_async(client, -1, ret);
+ tts_core_notify_error_async(client, ret, -1, NULL);
return EINA_FALSE;
} else if (TTS_ERROR_NONE != ret) {
return TTS_ERROR_NONE;
}
-int tts_core_notify_error(tts_client_s* client, int utt_id, tts_error_e reason)
-{
- if (false == tts_client_is_valid_client(client)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
- SLOG(LOG_DEBUG, TAG_TTSC, "Error data : utt_id(%d) reason(%s)", utt_id, __tts_get_error_code(reason));
- __client_error_cb(client, utt_id, reason);
-
- return TTS_ERROR_NONE;
-}
-
-int tts_core_notify_error_async(tts_client_s* client, int utt_id, tts_error_e reason)
+int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int utt_id, char* err_msg)
{
if (false == tts_client_is_valid_client(client)) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Handle is not valid.");
SLOG(LOG_DEBUG, TAG_TTSC, "Error data : utt_id(%d) reason(%s)", utt_id, __tts_get_error_code(reason));
client->utt_id = utt_id;
client->reason = reason;
+ tts_client_set_error_message(client, err_msg);
SLOG(LOG_DEBUG, TAG_TTSC, "Notify error asynchronously");
if (NULL != client->notify_error_timer) {
if (TTS_ERROR_ENGINE_NOT_FOUND == ret || TTS_ERROR_PERMISSION_DENIED == ret) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
- tts_core_notify_error_async(client, -1, ret);
+ tts_core_notify_error_async(client, ret, -1, NULL);
return TTS_ERROR_OPERATION_FAILED;
} else if (TTS_ERROR_NONE != ret) {
return TTS_ERROR_NONE;
}
+
+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;
+ }
+
+ if (g_list_length(client_list) > 0) {
+ GList *iter = g_list_first(client_list);
+ while (NULL != iter) {
+ tts_client_s *client = iter->data;
+ if (false == tts_client_is_valid_client(client)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
+ } else {
+ tts_core_notify_error_async(client, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
+ }
+
+ iter = g_list_next(iter);
+ }
+ }
+
+ g_list_free(client_list);
+
+ SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+ tts_core_reprepare();
+
+ return TTS_ERROR_NONE;
+}
int tts_core_notify_state_changed_async(tts_client_s* client, tts_state_e before_state, tts_state_e current_state);
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);
-int tts_core_notify_error(tts_client_s* client, int utt_id, tts_error_e reason);
-int tts_core_notify_error_async(tts_client_s* client, int utt_id, tts_error_e reason);
+int tts_core_notify_error_async(tts_client_s* client, tts_error_e reason, int utt_id, char* err_msg);
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);
int tts_core_notify_engine_changed(tts_client_s* client, const char* engine_id, const char* language, int voice_type, bool need_credential);
int tts_core_foreach_supported_voices(tts_client_s* client, const char* engine_id, tts_supported_voice_cb callback, void* user_data);
-// called by tts_dbus.c
+// called by tts_ipc
int tts_core_receive_hello(int uid, int ret, int credential_needed);
-
+int tts_core_handle_service_reset();
#ifdef __cplusplus
}
static volatile int g_connected_client = 0;
-static int __handle_service_reset()
-{
- GList* client_list = NULL;
- 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;
- }
-
- if (g_list_length(client_list) > 0) {
- GList *iter = g_list_first(client_list);
- while (NULL != iter) {
- tts_client_s *client = iter->data;
- if (false == tts_client_is_valid_client(client)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
- } else {
- tts_client_set_error_message(client, "Daemon Reset");
- tts_core_notify_error_async(client, -1, TTS_ERROR_SERVICE_RESET);
- }
-
- iter = g_list_next(iter);
- }
- }
-
- g_list_free(client_list);
-
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
- tts_core_reprepare();
-
- return TTS_ERROR_NONE;
-}
-
-static int __handle_service_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
-{
- tts_client_s* client = tts_client_get_by_uid(uid);
- if (NULL == client) {
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] uid is not valid");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
- tts_client_set_error_message(client, err_msg);
- tts_core_notify_error_async(client, utt_id, reason);
-
- return TTS_ERROR_NONE;
-}
static int __tts_cb_set_state(int uid, int state)
{
dbus_error_free(&err);
} else {
SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Error message : uid(%d), error(%d), uttid(%d), err_msg(%s)", uid, reason, uttid, (NULL == err_msg) ? "NULL" : err_msg);
- __handle_service_error(uid, reason, uttid, err_msg);
+ tts_core_notify_error_async(tts_client_get_by_uid(uid), reason, uttid, err_msg);
}
} /* TTSD_SIGNAL_ERROR */
else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) {
SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Owner Changed");
- __handle_service_reset();
+ tts_core_handle_service_reset();
SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
} /* NameOwnerChanged */
#define MAXSLEEP 128
-static int __handle_service_reset()
-{
- GList* client_list = NULL;
- 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;
- }
-
- if (g_list_length(client_list) > 0) {
- GList *iter = g_list_first(client_list);
- while (NULL != iter) {
- tts_client_s *client = iter->data;
- if (false == tts_client_is_valid_client(client)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
- } else {
- tts_client_set_error_message(client, "Daemon Reset");
- tts_core_notify_error_async(client, -1, TTS_ERROR_SERVICE_RESET);
- }
-
- iter = g_list_next(iter);
- }
- }
-
- g_list_free(client_list);
-
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
- tts_core_reprepare();
-
- return TTS_ERROR_NONE;
-}
-
-static int __handle_service_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
-{
- tts_client_s* client = tts_client_get_by_uid(uid);
- if (NULL == client) {
- SLOG(LOG_WARN, TAG_TTSC, "[WARNING] uid is not valid");
- return TTS_ERROR_INVALID_PARAMETER;
- }
-
- tts_client_set_error_message(client, err_msg);
- tts_core_notify_error_async(client, utt_id, reason);
-
- return TTS_ERROR_NONE;
-}
static int __tts_cb_set_state(int uid, int state)
{
bundle_get_str(msg, TTS_BUNDLE_UTTID, &uttid);
bundle_get_str(msg, TTS_BUNDLE_ERR_MSG, &err_msg);
if (reason && uttid) {
- __handle_service_error(uid, atoi(reason), atoi(uttid), err_msg);
+ tts_core_notify_error_async(client, atoi(reason), atoi(uttid), err_msg);
}
}
else {
tts->connected = false;
if (tts_client_is_listening_started(uid)) {
- __handle_service_reset();
+ tts_core_handle_service_reset();
SLOG(LOG_DEBUG, TAG_TTSC, "Disconnected from server");
ecore_main_loop_thread_safe_call_async(__reconnect, (void*)uid);
if (!client)
return;
- __handle_service_error(uid, TTS_ERROR_PERMISSION_DENIED, client->utt_id, "Rejected");
+ tts_core_notify_error_async(client, TTS_ERROR_PERMISSION_DENIED, client->utt_id, "Rejected");
SLOG(LOG_DEBUG, TAG_TTSC, "Rejected from server");
}