X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=server%2Fsttd_server.c;h=5b4e0463755989e52be2e03fc026863dc70d590d;hb=e5c5a41fb4080d3a9ea3bbb92ee0b91312378b4a;hp=b39402f919f32293c1394d761bf1d41418e867ae;hpb=cc4df9c606672153d5102d8f5b9818af0ff0d5fb;p=platform%2Fcore%2Fuifw%2Fstt.git diff --git a/server/sttd_server.c b/server/sttd_server.c old mode 100644 new mode 100755 index b39402f..5b4e046 --- a/server/sttd_server.c +++ b/server/sttd_server.c @@ -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; /* @@ -87,23 +87,23 @@ static void __cancel_recognition_internal() g_recording_timer = NULL; } + int ret = 0; int uid = 0; uid = stt_client_get_current_recognition(); - if (0 != uid) { - /* cancel engine recognition */ - int ret = sttd_engine_agent_recognize_cancel(); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret); - } + app_state_e state = 0; + ret = sttd_client_get_state(uid, &state); - /* change uid state */ - sttd_client_set_state(uid, APP_STATE_READY); - stt_client_unset_current_recognition(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid "); + return; + } - ret = sttdc_send_set_state(uid, (int)APP_STATE_READY); + if (0 != uid && (APP_STATE_PROCESSING == state || APP_STATE_RECORDING == state)) { + /* cancel engine recognition */ + ret = sttd_server_cancel(uid); if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to send state change : result(%d)", ret); + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel : result(%d)", ret); } } else { SLOG(LOG_WARN, TAG_STTD, "[Server WARNING] uid is NOT valid"); @@ -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,17 @@ void __server_recognition_result_callback(stte_result_event_e event, const char* } sttd_config_time_reset(); + int ret = 0; + if (APP_STATE_RECORDING == state) { + ret = sttd_engine_agent_recognize_cancel(); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to cancel: result(%d)", ret); + } + } + + 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 +291,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,16 +333,17 @@ 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) { SLOG(LOG_DEBUG, TAG_STTD, "Begin Speech detected"); + sttdc_send_speech_status(uid, status); } else if (STTE_SPEECH_STATUS_END_POINT_DETECTED == status) { SLOG(LOG_DEBUG, TAG_STTD, "End Speech detected"); ecore_main_loop_thread_safe_call_async(__stop_by_silence, NULL); @@ -345,13 +355,15 @@ 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; + ecore_main_loop_thread_safe_call_async(__cancel_by_error, NULL); + + 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) @@ -363,6 +375,7 @@ void __sttd_server_engine_changed_cb(const char* engine_id, const char* language SLOG(LOG_DEBUG, TAG_STTD, "[Server] New default engine : %s", engine_id); } +#if 0 /* need to change state of app to ready */ int uid; uid = stt_client_get_current_recognition(); @@ -390,6 +403,7 @@ void __sttd_server_engine_changed_cb(const char* engine_id, const char* language ret = sttd_engine_agent_set_silence_detection(support_silence); if (0 != ret) SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to Result(%d)", ret); +#endif return; } @@ -425,57 +439,16 @@ void __sttd_server_silence_changed_cb(bool value, void* user_data) /* * Daemon function */ - -static void __sig_handler(int signo) -{ - /* restore signal handler */ - signal(signo, SIG_DFL); - - /* Send error signal to clients */ - int* client_list = NULL; - int client_count = 0; - int i = 0; - if (0 != sttd_client_get_list(&client_list, &client_count)) { - if (NULL != client_list) { - free(client_list); - client_list = NULL; - } - } - - if (NULL != client_list) { - for (i = 0; i < client_count; i++) { - sttdc_send_error_signal(client_list[i], STTD_ERROR_SERVICE_RESET, "Service Reset"); - } - - free(client_list); - client_list = NULL; - } - - /* invoke signal again */ - raise(signo); -} - -static void __register_sig_handler() -{ - signal(SIGSEGV, __sig_handler); - signal(SIGABRT, __sig_handler); - signal(SIGTERM, __sig_handler); - signal(SIGINT, __sig_handler); - signal(SIGQUIT, __sig_handler); -} - int sttd_initialize(stte_request_callback_s *callback) { int ret = 0; - __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 +484,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; @@ -540,9 +513,7 @@ int sttd_finalize() static void __read_proc() { DIR *dp = NULL; - struct dirent entry; struct dirent *dirp = NULL; - int ret = -1; int tmp; GList *iter = NULL; @@ -559,11 +530,7 @@ static void __read_proc() SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to open proc"); } else { do { - ret = readdir_r(dp, &entry, &dirp); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to readdir"); - break; - } + dirp = readdir(dp); if (NULL != dirp) { tmp = atoi(dirp->d_name); @@ -684,6 +651,7 @@ static Eina_Bool __quit_ecore_loop(void *data) stt_network_finalize(); sttd_finalize(); + sttd_dbus_close_connection(); ecore_main_loop_quit(); SLOG(LOG_DEBUG, TAG_STTD, "");