From 65b2a63943b0362f20ff8656e5d2af5e5146c185 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Tue, 17 May 2016 14:30:02 +0900 Subject: [PATCH] Add function to get error message Change-Id: Iefcd76189ba1f16133a6e55f10aefd0d21036c55 Signed-off-by: Wonnam Jang --- client/stt.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- client/stt_client.c | 7 +++++++ client/stt_client.h | 1 + client/stt_dbus.c | 6 +++--- include/stt.h | 22 ++++++++++++++++++++++ server/sttd_dbus.c | 2 +- 6 files changed, 80 insertions(+), 5 deletions(-) mode change 100755 => 100644 client/stt.c mode change 100755 => 100644 client/stt_client.h mode change 100755 => 100644 client/stt_dbus.c mode change 100755 => 100644 include/stt.h mode change 100755 => 100644 server/sttd_dbus.c diff --git a/client/stt.c b/client/stt.c old mode 100755 new mode 100644 index 442b1c3..eddd3fd --- a/client/stt.c +++ b/client/stt.c @@ -37,6 +37,8 @@ static float g_volume_db = 0; static int g_feature_enabled = -1; +static bool g_err_callback_status = false; + const char* stt_tag() { return "sttc"; @@ -761,6 +763,41 @@ int stt_get_state(stt_h stt, stt_state_e* state) return STT_ERROR_NONE; } +int stt_get_error_message(stt_h stt, char** err_msg) +{ + if (0 != __stt_get_feature_enabled()) { + return STT_ERROR_NOT_SUPPORTED; + } + + if (NULL == stt || NULL == err_msg) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); + return STT_ERROR_INVALID_PARAMETER; + } + + if (false == g_err_callback_status) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This callback should be called during an err_callback"); + return STT_ERROR_OPERATION_FAILED; + } + + stt_client_s* client = stt_client_get(stt); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get error msg : A handle is not valid"); + return STT_ERROR_INVALID_PARAMETER; + } + + if (NULL != client->err_msg) { + *err_msg = strdup(client->err_msg); + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Error msg (NULL)"); + } + + SLOG(LOG_DEBUG, TAG_STTC, "====="); + SLOG(LOG_DEBUG, TAG_STTC, " "); + + return STT_ERROR_NONE; +} + int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support) { if (0 != __stt_get_feature_enabled()) { @@ -1475,7 +1512,9 @@ static Eina_Bool __stt_notify_error(void *data) if (NULL != client->error_cb) { stt_client_use_callback(client); + g_err_callback_status = true; client->error_cb(client->stt, client->reason, client->error_user_data); + g_err_callback_status = false; stt_client_not_use_callback(client); SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is called : reason [%d]", client->reason); } else { @@ -1485,7 +1524,7 @@ static Eina_Bool __stt_notify_error(void *data) return EINA_FALSE; } -int __stt_cb_error(int uid, int reason) +int __stt_cb_error(int uid, int reason, char* err_msg) { stt_client_s* client = stt_client_get_by_uid(uid); if (NULL == client) { @@ -1495,6 +1534,12 @@ int __stt_cb_error(int uid, int reason) client->reason = reason; client->internal_state = STT_INTERNAL_STATE_NONE; + if (NULL != client->err_msg) { + free(client->err_msg); + client->err_msg = NULL; + } + client->err_msg = strdup(err_msg); + SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0"); if (NULL != client->error_cb) { diff --git a/client/stt_client.c b/client/stt_client.c index 7a4a24b..9244b87 100644 --- a/client/stt_client.c +++ b/client/stt_client.c @@ -79,6 +79,9 @@ int stt_client_new(stt_h* stt) client->data_count = 0; client->msg = NULL; + client->reason = 0; + client->err_msg = NULL; + client->before_state = STT_STATE_CREATED; client->current_state = STT_STATE_CREATED; @@ -121,6 +124,10 @@ int stt_client_destroy(stt_h stt) free(data->current_engine_id); } + if (NULL != data->err_msg) { + free(data->err_msg); + } + free(data); free(stt); diff --git a/client/stt_client.h b/client/stt_client.h old mode 100755 new mode 100644 index 9a1ad35..2600ce2 --- a/client/stt_client.h +++ b/client/stt_client.h @@ -76,6 +76,7 @@ typedef struct { /* error data */ int reason; + char* err_msg; } stt_client_s; diff --git a/client/stt_dbus.c b/client/stt_dbus.c old mode 100755 new mode 100644 index 2981b98..fc5d0e5 --- a/client/stt_dbus.c +++ b/client/stt_dbus.c @@ -27,7 +27,7 @@ static DBusConnection* g_conn_sender = NULL; static DBusConnection* g_conn_listener = NULL; -extern int __stt_cb_error(int uid, int reason); +extern int __stt_cb_error(int uid, int reason, char* err_msg); extern int __stt_cb_result(int uid, int event, char** data, int data_count, const char* msg); @@ -259,8 +259,8 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle SLOG(LOG_ERROR, TAG_STTC, "<<<< stt Get Error message : Get arguments error (%s)", err.message); dbus_error_free(&err); } else { - SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt Get Error message : uid(%d), reason(%d), msg(%s)", uid, reason, err_msg); - __stt_cb_error(uid, reason); + SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt Get Error message : uid(%d), reason(%d), err_msg(%s)", uid, reason, (NULL == err_msg) ? "NULL" : err_msg); + __stt_cb_error(uid, reason, err_msg); } SLOG(LOG_DEBUG, TAG_STTC, "====="); diff --git a/include/stt.h b/include/stt.h old mode 100755 new mode 100644 index cb5fb23..6e8a4a9 --- a/include/stt.h +++ b/include/stt.h @@ -517,6 +517,28 @@ int stt_get_default_language(stt_h stt, char** language); int stt_get_state(stt_h stt, stt_state_e* state); /** + * @brief Gets the current error message. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/recorder + * @remarks This function should be called during an stt 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] stt The STT handle + * @param[out] err_msg The current error message + * + * @return 0 on success, otherwise a negative error value + * @retval #STT_ERROR_NONE Successful + * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported + * @retval #STT_ERROR_OPERATION_FAILED Operation failure + * + * @see stt_set_error_cb() + * @see stt_unset_error_cb() +*/ +int stt_get_error_message(stt_h stt, char** err_msg); + +/** * @brief Checks whether the recognition type is supported. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public diff --git a/server/sttd_dbus.c b/server/sttd_dbus.c old mode 100755 new mode 100644 index a74e046..f6aa112 --- a/server/sttd_dbus.c +++ b/server/sttd_dbus.c @@ -334,7 +334,7 @@ int sttdc_send_error_signal(int uid, int reason, const char *err_msg) if (!dbus_connection_send(g_conn_sender, msg, NULL)) { SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] <<<< error message : Out Of Memory !"); } else { - SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send error message : uid(%d), reason(%d), err_msg(%s)", uid, reason, err_msg); + SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send error message : uid(%d), reason(%d), err_msg(%s)", uid, reason, (NULL == err_msg) ? "NULL" : err_msg); dbus_connection_flush(g_conn_sender); } -- 2.7.4