Fix buxton key layer
[platform/core/uifw/stt.git] / server / sttd_server.c
index b39402f..78f64e6 100644 (file)
@@ -24,8 +24,8 @@
 #include "sttd_recorder.h"
 #include "sttd_server.h"
 
-static pthread_mutex_t sttpe_result_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t sttpe_result_time_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t stte_result_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t stte_result_time_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 
 /*
@@ -179,11 +179,11 @@ void __cancel_by_no_record(void *data)
        return;
 }
 
-void __server_recognition_result_callback(stte_result_event_e event, const char* type,
+int __server_recognition_result_callback(stte_result_event_e event, const char* type,
                                        const char** data, int data_count, const char* msg, void *user_data)
 {
        // critical section
-       pthread_mutex_lock(&sttpe_result_mutex);
+       pthread_mutex_lock(&stte_result_mutex);
 
        SLOG(LOG_DEBUG, TAG_STTD, "===== RESULT event[%d] type[%s] data[%p] data_count[%d]", event, type, data, data_count);
 
@@ -195,8 +195,8 @@ void __server_recognition_result_callback(stte_result_event_e event, const char*
                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
                SLOG(LOG_DEBUG, TAG_STTD, "=====");
                SLOG(LOG_DEBUG, TAG_STTD, "  ");
-               pthread_mutex_unlock(&sttpe_result_mutex);
-               return;
+               pthread_mutex_unlock(&stte_result_mutex);
+               return STTD_ERROR_OPERATION_FAILED;
        }
 
        SLOG(LOG_DEBUG, TAG_STTD, "[Server] uid (%d), event(%d)", uid, event);
@@ -285,37 +285,32 @@ void __server_recognition_result_callback(stte_result_event_e event, const char*
 
        SLOG(LOG_DEBUG, TAG_STTD, "=====");
        SLOG(LOG_DEBUG, TAG_STTD, "  ");
-       pthread_mutex_unlock(&sttpe_result_mutex);
+       pthread_mutex_unlock(&stte_result_mutex);
 
-       return;
+       return STTD_ERROR_NONE;
 }
 
 bool __server_result_time_callback(int index, stte_result_time_event_e event, const char* text, long start_time, long end_time, void* user_data)
 {
-       pthread_mutex_lock(&sttpe_result_time_mutex);
+       pthread_mutex_lock(&stte_result_time_mutex);
 
        SLOG(LOG_DEBUG, TAG_STTD, "[Server] index(%d) event(%d) text(%s) start(%ld) end(%ld)",
                index, event, text, start_time, end_time);
 
-       if (0 == index) {
-               int ret;
-               ret = sttd_config_time_add(index, (int)event, text, start_time, end_time);
-               if (0 != ret) {
-                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add time info");
-                       pthread_mutex_unlock(&sttpe_result_time_mutex);
-                       return false;
-               }
-       } else {
-               pthread_mutex_unlock(&sttpe_result_time_mutex);
+       int ret;
+       ret = sttd_config_time_add(index, (int)event, text, start_time, end_time);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to add time info");
+               pthread_mutex_unlock(&stte_result_time_mutex);
                return false;
        }
 
-       pthread_mutex_unlock(&sttpe_result_time_mutex);
+       pthread_mutex_unlock(&stte_result_time_mutex);
 
        return true;
 }
 
-void __server_speech_status_callback(stte_speech_status_e status, void *user_param)
+int __server_speech_status_callback(stte_speech_status_e status, void *user_param)
 {
        SLOG(LOG_DEBUG, TAG_STTD, "===== Speech status detected Callback");
 
@@ -324,12 +319,12 @@ void __server_speech_status_callback(stte_speech_status_e status, void *user_par
                app_state_e state;
                if (0 != sttd_client_get_state(uid, &state)) {
                        SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is not valid ");
-                       return;
+                       return STTD_ERROR_OPERATION_FAILED;
                }
 
                if (APP_STATE_RECORDING != state) {
                        SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Current state is not recording");
-                       return;
+                       return STTD_ERROR_INVALID_STATE;
                }
 
                if (STTE_SPEECH_STATUS_BEGINNING_POINT_DETECTED == status) {
@@ -345,13 +340,13 @@ void __server_speech_status_callback(stte_speech_status_e status, void *user_par
        SLOG(LOG_DEBUG, TAG_STTD, "=====");
        SLOG(LOG_DEBUG, TAG_STTD, "  ");
 
-       return;
+       return STTD_ERROR_NONE;
 }
 
-void __server_error_callback(stte_error_e error, const char* msg)
+int __server_error_callback(stte_error_e error, const char* msg)
 {
        SLOG(LOG_DEBUG, TAG_STTD, "[Server] Error Callback is called");
-       return;
+       return STTD_ERROR_NONE;
 }
 
 void __sttd_server_engine_changed_cb(const char* engine_id, const char* language, bool support_silence, bool need_credential, void* user_data)
@@ -470,12 +465,12 @@ int sttd_initialize(stte_request_callback_s *callback)
 
        __register_sig_handler();
 
-       if (0 != pthread_mutex_init(&sttpe_result_mutex, NULL)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to initialize sttpe result mutex.");
+       if (0 != pthread_mutex_init(&stte_result_mutex, NULL)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to initialize stte result mutex.");
        }
 
-       if (0 != pthread_mutex_init(&sttpe_result_time_mutex, NULL)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to initialize sttpe sttpe_result_time_mutex.");
+       if (0 != pthread_mutex_init(&stte_result_time_mutex, NULL)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to initialize stte stte_result_time_mutex.");
        }
 
        if (sttd_config_initialize(__sttd_server_engine_changed_cb, __sttd_server_language_changed_cb,
@@ -511,12 +506,12 @@ int sttd_initialize(stte_request_callback_s *callback)
 
 int sttd_finalize()
 {
-       if (0 != pthread_mutex_destroy(&sttpe_result_mutex)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy sttpe result mutex.");
+       if (0 != pthread_mutex_destroy(&stte_result_mutex)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy stte result mutex.");
        }
 
-       if (0 != pthread_mutex_destroy(&sttpe_result_time_mutex)) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy sttpe_result_time_mutex.");
+       if (0 != pthread_mutex_destroy(&stte_result_time_mutex)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy stte_result_time_mutex.");
        }
 
        GList *iter = NULL;