Add file name checker and Fix dbus type and bt return
[platform/core/uifw/stt.git] / server / sttd_server.c
index b39402f..ea462df 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);
@@ -217,6 +217,9 @@ void __server_recognition_result_callback(stte_result_event_e event, const char*
                sttd_config_time_save();
                sttd_config_time_reset();
 
+               sttd_client_set_state(uid, APP_STATE_READY);
+               stt_client_unset_current_recognition();
+
                if (NULL == data || 0 == data_count) {
                        if (0 != sttdc_send_result(uid, event, NULL, 0, msg)) {
                                SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result");
@@ -238,8 +241,8 @@ void __server_recognition_result_callback(stte_result_event_e event, const char*
                }
 
                /* change state of uid */
-               sttd_client_set_state(uid, APP_STATE_READY);
-               stt_client_unset_current_recognition();
+//             sttd_client_set_state(uid, APP_STATE_READY);
+//             stt_client_unset_current_recognition();
 
        } else if (STTE_RESULT_EVENT_PARTIAL_RESULT == event) {
                SLOG(LOG_DEBUG, TAG_STTD, "[Server] The partial result from engine is event[%d] data_count[%d]", event,  data_count);
@@ -266,6 +269,9 @@ void __server_recognition_result_callback(stte_result_event_e event, const char*
                }
                sttd_config_time_reset();
 
+               sttd_client_set_state(uid, APP_STATE_READY);
+               stt_client_unset_current_recognition();
+
                if (0 != sttdc_send_result(uid, event, NULL, 0, msg)) {
                        SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send result ");
 
@@ -277,45 +283,40 @@ void __server_recognition_result_callback(stte_result_event_e event, const char*
                }
 
                /* change state of uid */
-               sttd_client_set_state(uid, APP_STATE_READY);
-               stt_client_unset_current_recognition();
+//             sttd_client_set_state(uid, APP_STATE_READY);
+//             stt_client_unset_current_recognition();
        } else {
                /* nothing */
        }
 
        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 +325,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 +346,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 +471,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 +512,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;