Prevent state change even if no recognition result callback is registered 78/271578/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 23 Feb 2022 06:00:17 +0000 (15:00 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 23 Feb 2022 06:00:17 +0000 (15:00 +0900)
Current code changes the state to ready when the result comes from the server without registered
recognition result callback. However, this behavior can make difference between client state and
real server state.

To handle this potential issue, this patch prevents the state change in this case. By this change,
client state is always matched with server state.

Change-Id: I4df2438fb09d00185318b487b8f233ba0918798b
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/stt.c
client/stt_client.c
client/stt_client.h

index 94c9af67e1694f2d05aedd4dc96950cc4bf9afb0..d6fbafbd4ca0187eaa971338d9e13e982fb0f37e 100644 (file)
@@ -2110,57 +2110,35 @@ static void __stt_notify_state_changed(void *data)
        return;
 }
 
-static Eina_Bool __stt_notify_result(void *data)
+int __stt_cb_result(unsigned int uid, int event, char** data, int data_count, const char* msg)
 {
-       stt_client_s* client = (stt_client_s*)data;
-
-       /* check handle */
+       stt_client_s* client = stt_client_get_by_uid(uid);
        if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
-               return EINA_FALSE;
+               SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid. uid(%u)", uid); //LCOV_EXCL_LINE
+               return STT_ERROR_INVALID_PARAMETER;
        }
 
-       if (NULL == stt_client_get_by_uid(client->uid)) {
-               return EINA_FALSE;
+       if (NULL != msg)
+               SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result Message = %s", msg);
+
+       for (int i = 0; i < data_count; i++) {
+               if (NULL != data[i])
+                       SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
        }
 
        if (NULL != client->recognition_result_cb) {
                stt_client_use_callback(client);
-               client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count,
-                       client->msg, client->recognition_result_user_data);
+               client->recognition_result_cb(client->stt, event, (const char**)data, data_count,
+                       msg, client->recognition_result_user_data);
                stt_client_not_use_callback(client);
                SLOG(LOG_INFO, TAG_STTC, "client recognition result callback called");
        } else {
                SLOG(LOG_WARN, TAG_STTC, "[WARNING] User recognition result callback is NULL");
        }
 
-       if (NULL != client->msg) {
-               free(client->msg);
-               client->msg = NULL;
-       }
-
-       if (NULL != client->data_list) {
-               char **temp = NULL;
-               temp = client->data_list;
-
-               int i = 0;
-               for (i = 0; i < client->data_count; i++) {
-                       if (NULL != temp[i]) {
-                               free(temp[i]);
-                               temp[i] = NULL;
-                       } else {
-                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
-                       }
-               }
-               free(client->data_list);
-               client->data_list = NULL;
-       }
-
-       client->data_count = 0;
-
        stt_config_mgr_remove_time_info_file();
 
-       if (STT_RESULT_EVENT_FINAL_RESULT == client->event || STT_RESULT_EVENT_ERROR == client->event) {
+       if (STT_RESULT_EVENT_FINAL_RESULT == event || STT_RESULT_EVENT_ERROR == event) {
                client->before_state = client->current_state;
                client->current_state = STT_STATE_READY;
 
@@ -2171,59 +2149,6 @@ static Eina_Bool __stt_notify_result(void *data)
                }
        }
 
-       return EINA_FALSE;
-}
-
-int __stt_cb_result(unsigned int uid, int event, char** data, int data_count, const char* msg)
-{
-       stt_client_s* client = NULL;
-
-       client = stt_client_get_by_uid(uid);
-       if (NULL == client) {
-               SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid"); //LCOV_EXCL_LINE
-               return STT_ERROR_INVALID_PARAMETER;
-       }
-
-       if (NULL != msg)
-               SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result Message = %s", msg);
-
-       int i = 0;
-       for (i = 0; i < data_count; i++) {
-               if (NULL != data[i])
-                       SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
-       }
-
-       if (NULL != client->recognition_result_cb) {
-               client->event = event;
-               if (NULL != msg) {
-                       client->msg = strdup(msg);
-               }
-
-               client->data_count = data_count;
-
-               if (data_count > 0) {
-                       char **temp = NULL;
-                       temp = (char**)calloc(data_count, sizeof(char*));
-                       if (NULL == temp) {
-                               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
-                               return STT_ERROR_OUT_OF_MEMORY;
-                       }
-
-                       for (i = 0; i < data_count; i++) {
-                               if (NULL != data[i])
-                                       temp[i] = strdup(data[i]);
-                               else
-                                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
-                       }
-
-                       client->data_list = temp;
-               }
-       } else {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
-       }
-
-       __stt_notify_result(client);
-
        return STT_ERROR_NONE;
 }
 
index 95e76c6d117d74a0f579386ac3a6dd612608c7ca..9a07d528de52a58e8eb6230701f8beee34278e38 100644 (file)
@@ -77,11 +77,6 @@ int stt_client_new(stt_h* stt)
        client->silence_supported = false;
        client->silence = STT_OPTION_SILENCE_DETECTION_AUTO;
 
-       client->event = 0;
-       client->data_list = NULL;
-       client->data_count = 0;
-       client->msg = NULL;
-
        client->reason = 0;
        client->err_msg = NULL;
 
index f90094b011f1ad16dc0c7d641d84799def4ffa17..12a1b285c60386d8f37d31ba2f10fecdee114219 100644 (file)
@@ -79,12 +79,6 @@ typedef struct {
        /* mutex */
        int             cb_ref_count;
 
-       /* result data */
-       int     event;
-       char**  data_list;
-       int     data_count;
-       char*   msg;
-
        /* error data */
        int     reason;
        char*   err_msg;