From: Wonnam Jang Date: Tue, 21 Jun 2016 08:34:15 +0000 (-0700) Subject: Merge "Add restore logic when daemon get signal" into tizen X-Git-Tag: accepted/tizen/common/20160627.192316~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=62e8705f6cd83006e2775e0a7d385205caa9325a;hp=92017b6f070a81bd74e1ba8a184b9105b3059eb2;p=platform%2Fcore%2Fuifw%2Fstt.git Merge "Add restore logic when daemon get signal" into tizen --- diff --git a/client/stt.c b/client/stt.c index fa4dd9c..3211123 100644 --- a/client/stt.c +++ b/client/stt.c @@ -168,6 +168,7 @@ static const char* __stt_get_error_code(stt_error_e err) case STT_ERROR_ENGINE_NOT_FOUND: return "STT_ERROR_ENGINE_NOT_FOUND"; case STT_ERROR_OPERATION_FAILED: return "STT_ERROR_OPERATION_FAILED"; case STT_ERROR_NOT_SUPPORTED_FEATURE: return "STT_ERROR_NOT_SUPPORTED_FEATURE"; + case STT_ERROR_SERVICE_RESET: return "STT_ERROR_SERVICE_RESET"; default: return "Invalid error code"; } @@ -1664,6 +1665,15 @@ int __stt_cb_error(int uid, int reason, char* err_msg) SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null"); } + if (STT_ERROR_SERVICE_RESET == reason) { + SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset"); + + client->current_state = STT_STATE_CREATED; + if (0 != stt_prepare(client->stt)) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare"); + } + } + return 0; } diff --git a/include/stt.h b/include/stt.h index 883d504..c283827 100755 --- a/include/stt.h +++ b/include/stt.h @@ -56,7 +56,8 @@ typedef enum { STT_ERROR_IN_PROGRESS_TO_READY = TIZEN_ERROR_STT | 0x07, /**< Progress to ready is not finished */ STT_ERROR_IN_PROGRESS_TO_RECORDING = TIZEN_ERROR_STT | 0x08, /**< Progress to recording is not finished */ STT_ERROR_IN_PROGRESS_TO_PROCESSING = TIZEN_ERROR_STT | 0x09, /**< Progress to processing is not finished */ - STT_ERROR_RECORDING_TIMED_OUT = TIZEN_ERROR_STT | 0x10 /**< Recording timed out */ + STT_ERROR_RECORDING_TIMED_OUT = TIZEN_ERROR_STT | 0x10, /**< Recording timed out */ + STT_ERROR_SERVICE_RESET = TIZEN_ERROR_STT | 0x11 /**< Service reset */ } stt_error_e; /** diff --git a/server/sttd_main.h b/server/sttd_main.h index 31655dc..3f709d1 100644 --- a/server/sttd_main.h +++ b/server/sttd_main.h @@ -54,7 +54,8 @@ typedef enum { STTD_ERROR_OPERATION_FAILED = TIZEN_ERROR_STT | 0x04, /**< Operation failed */ STTD_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_STT | 0x05, /**< Not supported feature of current engine */ STTD_ERROR_NO_SPEECH = TIZEN_ERROR_STT | 0x06, /**< No speech while recording */ - STTD_ERROR_RECORDING_TIMED_OUT = TIZEN_ERROR_STT | 0x10 /**< Recording timed out */ + STTD_ERROR_RECORDING_TIMED_OUT = TIZEN_ERROR_STT | 0x10, /**< Recording timed out */ + STTD_ERROR_SERVICE_RESET = TIZEN_ERROR_STT | 0x11 /**< Service reset */ } stt_error_e; typedef enum { diff --git a/server/sttd_server.c b/server/sttd_server.c index 47bea93..7a7d2b4 100644 --- a/server/sttd_server.c +++ b/server/sttd_server.c @@ -424,10 +424,46 @@ 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); + } + + 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); + } + + /* 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() { 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."); }