Remove sttd_engine_agent.h from stt_engine.c 18/239118/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 22 Jul 2020 02:30:57 +0000 (11:30 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 22 Jul 2020 02:30:57 +0000 (11:30 +0900)
stt_engine.c produces the circular dependency problem by including sttd_engine_agent.h.

This patch removes sttd_engine_agent.h from stt_engine.c to remove circular depedency.
To remove sttd_engine_agent.h, this patch also changes and removes some functions in stt_engine.c.

Change-Id: I815660e70d9094f20c8b17f380a5e4e7bc3eb4d2
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
common/stt_engine.c
common/stt_engine.h
server/stte.c

index 014863f..e55cb70 100644 (file)
@@ -19,7 +19,6 @@
 #include <stdbool.h>
 
 #include "stt_engine.h"
-#include "sttd_engine_agent.h"
 #include "stt_defs.h"
 
 
@@ -785,43 +784,20 @@ int stt_engine_set_recognition_result_cb(stt_engine_result_cb result_cb, void* u
        return 0;
 }
 
-int stt_engine_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
-                               const char* msg, void* time_info, void* user_data)
+int stt_engine_get_recognition_result_cb(stt_engine_result_cb* result_cb)
 {
-       if (NULL == type || NULL == result) {
+       if (NULL == result_cb) {
                SLOG(LOG_ERROR, TAG_STTE, "[Engine ERROR] Invalid parameter");
+               return STTE_ERROR_INVALID_PARAMETER;
        }
 
-       int ret = STTE_ERROR_NONE;
        if (false == __stt_get_engine_from()) {
-               ret = sttd_engine_agent_send_result(event, type, result, result_count, msg, time_info, user_data);
-               if (0 != ret) {
-                       SLOG(LOG_ERROR, TAG_STTE, "[Engine ERROR] Fail to send result");
-               }
-       } else {
-               ret = g_result_cb(event, type, result, result_count, msg, time_info, user_data);
+               SLOG(LOG_ERROR, TAG_STTE, "[Engine ERROR] Engine is not loaded from file");
+               return STTE_ERROR_NOT_SUPPORTED;
        }
-       return ret;
-}
 
-int stt_engine_send_error(stte_error_e error, const char* msg)
-{
-       int ret = STTE_ERROR_NONE;
-       ret = sttd_engine_agent_send_error(error, msg);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTE, "[Engine ERROR] Fail to send error info");
-       }
-       return ret;
-}
-
-int stt_engine_send_speech_status(stte_speech_status_e status, void* user_data)
-{
-       int ret = STTE_ERROR_NONE;
-       ret = sttd_engine_agent_send_speech_status(status, user_data);
-       if (0 != ret) {
-               SLOG(LOG_ERROR, TAG_STTE, "[Engine ERROR] Fail to send speech status");
-       }
-       return ret;
+       *result_cb = g_result_cb;
+       return STTE_ERROR_NONE;
 }
 
 int stt_engine_set_private_data_set_cb(stte_private_data_set_cb private_data_set_cb, void* user_data)
index 9ae9f6c..dff60a5 100644 (file)
@@ -82,19 +82,14 @@ int stt_engine_foreach_result_time(void* time_info, stte_result_time_cb callback
 
 
 /* File recognition */
-int stt_engine_recognize_start_file(const char* lang, const char* recognition_type, 
+int stt_engine_recognize_start_file(const char* lang, const char* recognition_type,
                                const char* filepath, stte_audio_type_e audio_type, int sample_rate, void* user_param);
 
 int stt_engine_recognize_cancel_file();
 
 int stt_engine_set_recognition_result_cb(stt_engine_result_cb result_cb, void* user_data);
 
-int stt_engine_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
-                               const char* msg, void* time_info, void* user_data);
-
-int stt_engine_send_error(stte_error_e error, const char* msg);
-
-int stt_engine_send_speech_status(stte_speech_status_e status, void* user_data);
+int stt_engine_get_recognition_result_cb(stt_engine_result_cb* result_cb);
 
 int stt_engine_set_private_data_set_cb(stte_private_data_set_cb private_data_set_cb, void* user_data);
 
index 48ddc0f..c2b1ae1 100755 (executable)
@@ -20,6 +20,7 @@
 #include "stt_network.h"
 #include "sttd_dbus.h"
 #include "sttd_server.h"
+#include "sttd_engine_agent.h"
 
 #include "stte.h"
 
@@ -92,8 +93,15 @@ int stte_send_result(stte_result_event_e event, const char* type, const char** r
        }
 
        int ret = STTE_ERROR_NONE;
-       ret = stt_engine_send_result(event, type, result, result_count, msg, time_info, user_data);
-       if (0 != ret) {
+       stt_engine_result_cb result_cb = NULL;
+       ret = stt_engine_get_recognition_result_cb(&result_cb);
+       if (STTE_ERROR_NONE == ret && NULL != result_cb) {
+               ret = result_cb(event, type, result, result_count, msg, time_info, user_data);
+       } else {
+               ret = sttd_engine_agent_send_result(event, type, result, result_count, msg, time_info, user_data);
+       }
+
+       if (STTE_ERROR_NONE != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result");
        }
        return ret;
@@ -102,7 +110,7 @@ int stte_send_result(stte_result_event_e event, const char* type, const char** r
 int stte_send_error(stte_error_e error, const char* msg)
 {
        int ret = STTE_ERROR_NONE;
-       ret = stt_engine_send_error(error, msg);
+       ret = sttd_engine_agent_send_error(error, msg);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info");
        }
@@ -112,7 +120,7 @@ int stte_send_error(stte_error_e error, const char* msg)
 int stte_send_speech_status(stte_speech_status_e status, void* user_data)
 {
        int ret = STTE_ERROR_NONE;
-       ret = stt_engine_send_speech_status(status, user_data);
+       ret = sttd_engine_agent_send_speech_status(status, user_data);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send speech status");
        }