#include <dlfcn.h>
#include <dirent.h>
+#include <stdatomic.h>
#include "stt_defs.h"
#include "stt_engine.h"
} sttengine_info_s;
/** stt engine agent init */
-static bool g_agent_init;
+static atomic_bool g_agent_init;
static sttengine_info_s* g_engine_info = NULL;
static bool g_default_silence_detected;
/** callback functions */
-static result_callback g_result_cb = NULL;
-static result_time_callback g_result_time_cb = NULL;
-static speech_status_callback g_speech_status_cb = NULL;
-static error_callback g_error_cb = NULL;
+static _Atomic result_callback g_result_cb = NULL;
+static _Atomic result_time_callback g_result_time_cb = NULL;
+static _Atomic speech_status_callback g_speech_status_cb = NULL;
+static _Atomic error_callback g_error_cb = NULL;
/** callback functions */
static bool __result_time_cb(int index, stte_result_time_event_e event, const char* text,
__engine_agent_clear_engine(g_engine_info);
}
+ g_agent_init = false;
+
g_result_cb = NULL;
g_speech_status_cb = NULL;
g_error_cb = NULL;
g_result_time_cb = NULL;
- g_agent_init = false;
-
return 0;
}
int sttd_engine_agent_unload_current_engine()
{
- if (false == g_agent_init) {
- SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Not Initialized ");
- return STTD_ERROR_OPERATION_FAILED;
- }
+ RETVM_IF(false == g_agent_init, STTD_ERROR_OPERATION_FAILED, "[Engine Agent ERROR] Not Initialized");
/* Remove client */
__engine_agent_check_engine_unload();
SLOG(LOG_INFO, TAG_STTD, "[Server] ============================");
+ RETVM_IF(NULL == g_result_cb, STTD_ERROR_OPERATION_FAILED, "[Server ERROR] Callback is not set.");
+
ret = g_result_cb(event, type, result, result_count, msg, user_data);
#ifdef AUDIO_CREATE_ON_START
int sttd_engine_agent_send_error(stte_error_e error, const char* msg)
{
+ RETVM_IF(false == g_agent_init, STTD_ERROR_OPERATION_FAILED, "[Engine Agent ERROR] Not Initialized");
+
/* check uid */
unsigned int uid = stt_client_get_current_recognition();
- char* err_msg = NULL;
- int ret = STTD_ERROR_NONE;
-
-
- if (NULL != msg) {
- err_msg = strdup(msg);
- }
-
- ret = sttdc_send_error_signal(uid, error, err_msg);
+ int ret = sttdc_send_error_signal(uid, error, msg);
if (0 != ret) {
- SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info.");
+ SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send error info. (%d/%s)", ret, get_error_message(ret));
}
- if (NULL != err_msg) {
- free(err_msg);
- err_msg = NULL;
- }
+ RETVM_IF(NULL == g_error_cb, STTD_ERROR_OPERATION_FAILED, "[Server ERROR] Callback is not set.");
- ret = g_error_cb(error, msg);
-
- return ret;
+ return g_error_cb(error, msg);
}
int sttd_engine_agent_send_speech_status(stte_speech_status_e status, void* user_data)
{
- int ret = STTD_ERROR_NONE;
RETVM_IF(false == g_agent_init, STTD_ERROR_OPERATION_FAILED, "[Engine Agent ERROR] Not Initialized");
+ RETVM_IF(NULL == g_speech_status_cb, STTD_ERROR_OPERATION_FAILED, "[Server ERROR] Callback is not set.");
- ret = g_speech_status_cb(status, user_data);
- return ret;
+ return g_speech_status_cb(status, user_data);
}
static bool __result_time_cb(int index, stte_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
{
+ RETVM_IF(false == g_agent_init, false, "[Engine Agent ERROR] Not Initialized");
+ RETVM_IF(NULL == g_result_time_cb, false, "[Server ERROR] Callback is not set.");
+
return g_result_time_cb(index, event, text, start_time, end_time, user_data);
}