Add restore logic when daemon get signal 30/74430/1
authorKwangyoun Kim <ky85.kim@samsung.com>
Tue, 14 Jun 2016 07:48:47 +0000 (16:48 +0900)
committerKwangyoun Kim <ky85.kim@samsung.com>
Tue, 14 Jun 2016 07:49:15 +0000 (16:49 +0900)
Change-Id: I3b656d7d591fdc8e5d45ccf72876aed190f67b04
Signed-off-by: Kwangyoun Kim <ky85.kim@samsung.com>
client/stt.c
include/stt.h
server/sttd_main.h
server/sttd_server.c

index fa4dd9c..3211123 100644 (file)
@@ -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;
 }
 
index 9fecdaa..3076e8d 100644 (file)
@@ -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;
 
 /**
index 31655dc..3f709d1 100644 (file)
@@ -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 {
index 47bea93..7a7d2b4 100644 (file)
@@ -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.");
        }