Add function to get error message 52/69852/3 accepted/tizen/common/20160518.124958 accepted/tizen/ivi/20160518.090417 accepted/tizen/mobile/20160518.090400 accepted/tizen/tv/20160518.090406 accepted/tizen/wearable/20160518.090348 submit/tizen/20160518.015114
authorWonnam Jang <wn.jang@samsung.com>
Tue, 17 May 2016 05:30:02 +0000 (14:30 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Tue, 17 May 2016 11:02:32 +0000 (20:02 +0900)
Change-Id: Iefcd76189ba1f16133a6e55f10aefd0d21036c55
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
client/stt.c [changed mode: 0755->0644]
client/stt_client.c
client/stt_client.h [changed mode: 0755->0644]
client/stt_dbus.c [changed mode: 0755->0644]
include/stt.h [changed mode: 0755->0644]
server/sttd_dbus.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 442b1c3..eddd3fd
@@ -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) {
index 7a4a24b..9244b87 100644 (file)
@@ -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);
 
old mode 100755 (executable)
new mode 100644 (file)
index 9a1ad35..2600ce2
@@ -76,6 +76,7 @@ typedef struct {
        
        /* error data */
        int     reason;
+       char*   err_msg;
 } stt_client_s;
 
 
old mode 100755 (executable)
new mode 100644 (file)
index 2981b98..fc5d0e5
@@ -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, "=====");
old mode 100755 (executable)
new mode 100644 (file)
index cb5fb23..6e8a4a9
@@ -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
old mode 100755 (executable)
new mode 100644 (file)
index a74e046..f6aa112
@@ -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);
        }