From a0518813c834102e5297f5aaecb443d4a7abc88c Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Tue, 17 May 2016 19:43:32 +0900 Subject: [PATCH] Add function to get error message Change-Id: I62061aa8bb9a4fca04d096ba08f30f7c30db9eb9 Signed-off-by: Wonnam Jang --- client/tts.c | 42 +++++++++++++++++++++++++++++++++++++++++- client/tts_client.h | 1 + client/tts_dbus.c | 10 ++++++---- include/tts.h | 21 +++++++++++++++++++++ server/ttsd_dbus.c | 13 +++++++------ server/ttsd_dbus.h | 2 +- 6 files changed, 77 insertions(+), 12 deletions(-) mode change 100755 => 100644 client/tts.c mode change 100755 => 100644 client/tts_client.h mode change 100755 => 100644 include/tts.h diff --git a/client/tts.c b/client/tts.c old mode 100755 new mode 100644 index 2127439..5adac65 --- a/client/tts.c +++ b/client/tts.c @@ -31,6 +31,8 @@ static bool g_screen_reader; static int g_feature_enabled = -1; +static bool g_err_callback_status = false; + /* Function definition */ static Eina_Bool __tts_notify_state_changed(void *data); static Eina_Bool __tts_notify_error(void *data); @@ -737,6 +739,37 @@ int tts_get_speed_range(tts_h tts, int* min, int* normal, int* max) return TTS_ERROR_NONE; } +int tts_get_error_message(tts_h tts, char** err_msg) +{ + if(0 != __tts_get_feature_enabled()) { + return TTS_ERROR_NOT_SUPPORTED; + } + + if (NULL == tts || NULL == err_msg) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input parameter is null"); + return TTS_ERROR_INVALID_PARAMETER; + } + + tts_client_s* client = tts_client_get(tts); + + if (NULL == client) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get state : A handle is not valid"); + return TTS_ERROR_INVALID_PARAMETER; + } + + if (NULL != client->err_msg) { + *err_msg = strdup(client->err_msg); + SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (%s)", *err_msg); + } else { + SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Error msg (NULL)"); + } + + SLOG(LOG_DEBUG, TAG_TTSC, "====="); + SLOG(LOG_DEBUG, TAG_TTSC, " "); + + return TTS_ERROR_NONE; +} + 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()) { @@ -1399,7 +1432,9 @@ static Eina_Bool __tts_notify_error(void *data) if (NULL != client->error_cb) { SLOG(LOG_DEBUG, TAG_TTSC, "Call callback function of error"); tts_client_use_callback(client); + g_err_callback_status = true; client->error_cb(client->tts, client->utt_id, client->reason, client->error_user_data); + g_err_callback_status = false; tts_client_not_use_callback(client); } else { SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error "); @@ -1408,7 +1443,7 @@ static Eina_Bool __tts_notify_error(void *data) return EINA_FALSE; } -int __tts_cb_error(int uid, tts_error_e reason, int utt_id) +int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg) { tts_client_s* client = tts_client_get_by_uid(uid); @@ -1419,6 +1454,11 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id) client->utt_id = utt_id; client->reason = reason; + if (NULL != client->err_msg) { + free(client->err_msg); + client->err_msg = NULL; + } + client->err_msg = strdup(err_msg); /* call callback function */ if (NULL != client->error_cb) { diff --git a/client/tts_client.h b/client/tts_client.h old mode 100755 new mode 100644 index 5a2520e..0ffd4b8 --- a/client/tts_client.h +++ b/client/tts_client.h @@ -57,6 +57,7 @@ typedef struct { /* callback data */ int utt_id; int reason; + char* err_msg; /* connection */ Ecore_Timer* conn_timer; diff --git a/client/tts_dbus.c b/client/tts_dbus.c index ffe5742..0008e75 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -32,7 +32,7 @@ static DBusConnection* g_conn_listener = NULL; static Ecore_Fd_Handler* g_dbus_fd_handler = NULL; -extern int __tts_cb_error(int uid, tts_error_e reason, int utt_id); +extern int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char *err_msg); extern int __tts_cb_set_state(int uid, int state); @@ -115,20 +115,22 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle int uid; int uttid; int reason; + char* err_msg; dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INT32, &uttid, DBUS_TYPE_INT32, &reason, + DBUS_TYPE_INT32, &err_msg, DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Error message - Get arguments error (%s)", err.message); 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); + __tts_cb_error(uid, reason, uttid, err_msg); - if (0 == __tts_cb_error(uid, reason, uttid)) { - SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Error message : uid(%d), error(%d), uttid(%d)", uid, reason, uttid); } } /* TTSD_SIGNAL_ERROR */ diff --git a/include/tts.h b/include/tts.h old mode 100755 new mode 100644 index b7c2073..c895f24 --- a/include/tts.h +++ b/include/tts.h @@ -432,6 +432,27 @@ 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); /** + * @brief Gets the current error message. + * @since_tizen 3.0 + * @privlevel public + * @remarks This function should be called during an tts error callback. If not, the error as operation failure will be returned. \n + * If the function succeeds, @a err_msg must be released using free() when it is no longer required. + * + * @param[in] tts The TTS handle + * @param[out] err_msg The current error message + * + * @return 0 on success, otherwise a negative error value + * @retval #TTS_ERROR_NONE Successful + * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported + * @retval #TTS_ERROR_OPERATION_FAILED Operation failure + * + * @see tts_set_error_cb() + * @see tts_unset_error_cb() +*/ +int tts_get_error_message(tts_h tts, char** err_msg); + +/** * @brief Adds a text to the queue. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * diff --git a/server/ttsd_dbus.c b/server/ttsd_dbus.c index 3702575..025d93d 100644 --- a/server/ttsd_dbus.c +++ b/server/ttsd_dbus.c @@ -172,7 +172,7 @@ int ttsdc_send_set_state_message(int pid, int uid, int state) return ttsdc_send_message(pid, uid, state, TTSD_METHOD_SET_STATE); } -int ttsdc_send_error_message(int pid, int uid, int uttid, int reason) +int ttsdc_send_error_message(int pid, int uid, int uttid, int reason, char* err_msg) { if (NULL == g_conn_sender) { SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] Dbus connection is not available"); @@ -193,9 +193,10 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason) } dbus_message_append_args(msg, - DBUS_TYPE_INT32, &uid, - DBUS_TYPE_INT32, &uttid, - DBUS_TYPE_INT32, &reason, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_INT32, &uttid, + DBUS_TYPE_INT32, &reason, + DBUS_TYPE_INT32, &err_msg, DBUS_TYPE_INVALID); dbus_message_set_no_reply(msg, TRUE); @@ -203,8 +204,8 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason) if (!dbus_connection_send(g_conn_sender, msg, NULL)) { SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] <<<< error message : Out Of Memory !"); } else { - SLOG(LOG_DEBUG, get_tag(), "<<<< Send error message : uid(%d), reason(%s), uttid(%d)", - uid, __ttsd_get_error_code(reason), uttid); + SLOG(LOG_DEBUG, get_tag(), "<<<< Send error message : uid(%d), reason(%s), uttid(%d), err_msg(%d)", + uid, __ttsd_get_error_code(reason), uttid, (NULL == err_msg) ? "NULL" : err_msg); dbus_connection_flush(g_conn_sender); } diff --git a/server/ttsd_dbus.h b/server/ttsd_dbus.h index 478441e..4e95e17 100644 --- a/server/ttsd_dbus.h +++ b/server/ttsd_dbus.h @@ -29,7 +29,7 @@ int ttsdc_send_utt_start_message(int pid, int uid, int uttid); int ttsdc_send_utt_finish_message(int pid, int uid, int uttid); -int ttsdc_send_error_message(int pid, int uid, int uttid, int reason); +int ttsdc_send_error_message(int pid, int uid, int uttid, int reason, char* err_msg); int ttsdc_send_set_state_message(int pid, int uid, int state); -- 2.7.4