From f563ec9ab8009a202f4c682cdacf39566b794d68 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Tue, 14 Jun 2016 15:50:33 +0900 Subject: [PATCH] Add restore logic when daemon get signal Change-Id: I59b6cb9ff71ab67716333354a6ad6351ba6c3ae3 Signed-off-by: Kwangyoun Kim --- client/tts.c | 10 ++++++++++ client/tts_dbus.c | 2 +- include/tts.h | 3 ++- server/ttsd_dbus.c | 5 +++-- server/ttsd_main.h | 3 ++- server/ttsd_server.c | 29 +++++++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/client/tts.c b/client/tts.c index 4bd0740..19684fc 100644 --- a/client/tts.c +++ b/client/tts.c @@ -83,6 +83,7 @@ static const char* __tts_get_error_code(tts_error_e err) case TTS_ERROR_OPERATION_FAILED: return "TTS_ERROR_OPERATION_FAILED"; case TTS_ERROR_AUDIO_POLICY_BLOCKED: return "TTS_ERROR_AUDIO_POLICY_BLOCKED"; case TTS_ERROR_NOT_SUPPORTED_FEATURE: return "TTS_ERROR_NOT_SUPPORTED_FEATURE"; + case TTS_ERROR_SERVICE_RESET: return "TTS_ERROR_SERVICE_RESET"; default: return "Invalid error code"; } @@ -1630,6 +1631,15 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg) SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error "); } + if (TTS_ERROR_SERVICE_RESET == reason) { + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset"); + + client->current_state = TTS_STATE_CREATED; + if (0 != tts_prepare(client->tts)) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare"); + } + } + return 0; } diff --git a/client/tts_dbus.c b/client/tts_dbus.c index b8725c6..b0ab133 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -121,7 +121,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle DBUS_TYPE_INT32, &uid, DBUS_TYPE_INT32, &uttid, DBUS_TYPE_INT32, &reason, - DBUS_TYPE_INT32, &err_msg, + DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); if (dbus_error_is_set(&err)) { diff --git a/include/tts.h b/include/tts.h index c49acab..71f99fb 100644 --- a/include/tts.h +++ b/include/tts.h @@ -51,7 +51,8 @@ typedef enum { TTS_ERROR_ENGINE_NOT_FOUND = TIZEN_ERROR_TTS | 0x03, /**< No available engine */ TTS_ERROR_OPERATION_FAILED = TIZEN_ERROR_TTS | 0x04, /**< Operation failed */ TTS_ERROR_AUDIO_POLICY_BLOCKED = TIZEN_ERROR_TTS | 0x05, /**< Audio policy blocked */ - TTS_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_TTS | 0x06 /**< Not supported feature of current engine*/ + TTS_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_TTS | 0x06, /**< Not supported feature of current engine*/ + TTS_ERROR_SERVICE_RESET = TIZEN_ERROR_TTS | 0x07 /**< Service reset */ } tts_error_e; /** diff --git a/server/ttsd_dbus.c b/server/ttsd_dbus.c index a089213..60b2799 100644 --- a/server/ttsd_dbus.c +++ b/server/ttsd_dbus.c @@ -48,6 +48,7 @@ const char* __ttsd_get_error_code(ttsd_error_e err) case TTSD_ERROR_OPERATION_FAILED: return "TTS_ERROR_OPERATION_FAILED"; case TTSD_ERROR_AUDIO_POLICY_BLOCKED: return "TTS_ERROR_AUDIO_POLICY_BLOCKED"; case TTSD_ERROR_NOT_SUPPORTED_FEATURE: return "TTSD_ERROR_NOT_SUPPORTED_FEATURE"; + case TTSD_ERROR_SERVICE_RESET: return "TTSD_ERROR_SERVICE_RESET"; default: return "Invalid error code"; } @@ -197,7 +198,7 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason, char* err_ DBUS_TYPE_INT32, &uid, DBUS_TYPE_INT32, &uttid, DBUS_TYPE_INT32, &reason, - DBUS_TYPE_INT32, &err_msg, + DBUS_TYPE_STRING, &err_msg, DBUS_TYPE_INVALID); dbus_message_set_no_reply(msg, TRUE); @@ -205,7 +206,7 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason, char* err_ if (!dbus_connection_send(g_conn_sender, msg, NULL)) { SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] <<<< error message : Out Of Memory !"); } else { - SLOG(LOG_DEBUG, get_tag(), "<<<< Send error message : uid(%d), reason(%s), uttid(%d), err_msg(%d)", + SLOG(LOG_DEBUG, get_tag(), "<<<< Send error message : uid(%d), reason(%s), uttid(%d), err_msg(%s)", uid, __ttsd_get_error_code(reason), uttid, (NULL == err_msg) ? "NULL" : err_msg); dbus_connection_flush(g_conn_sender); } diff --git a/server/ttsd_main.h b/server/ttsd_main.h index d5c6291..d440129 100644 --- a/server/ttsd_main.h +++ b/server/ttsd_main.h @@ -50,7 +50,8 @@ typedef enum { TTSD_ERROR_ENGINE_NOT_FOUND = TIZEN_ERROR_TTS | 0x03, /**< No available engine */ TTSD_ERROR_OPERATION_FAILED = TIZEN_ERROR_TTS | 0x04, /**< Operation failed */ TTSD_ERROR_AUDIO_POLICY_BLOCKED = TIZEN_ERROR_TTS | 0x05, /**< Audio policy blocked */ - TTSD_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_TTS | 0x06 /**< Not supported feature of current engine*/ + TTSD_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_TTS | 0x06, /**< Not supported feature of current engine*/ + TTSD_ERROR_SERVICE_RESET = TIZEN_ERROR_TTS | 0x07 /**< Service reset */ } ttsd_error_e; typedef enum { diff --git a/server/ttsd_server.c b/server/ttsd_server.c index f3343cc..4addebd 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -407,9 +407,38 @@ void __screen_reader_changed_cb(bool value) /* * Server APIs */ +static bool __send_reset_signal(int pid, int uid, app_state_e state, void* user_data) +{ + ttsdc_send_error_message(pid, uid, -1, TTSD_ERROR_SERVICE_RESET, "TTS service reset"); + return true; +} + +static void __sig_handler(int signo) +{ + /* restore signal handler */ + signal(signo, SIG_DFL); + + /* Send error signal via foreach clients */ + ttsd_data_foreach_clients(__send_reset_signal, 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 ttsd_initialize() { + /* Register signal handler */ + __register_sig_handler(); + if (ttsd_config_initialize(__config_changed_cb)) { SLOG(LOG_ERROR, get_tag(), "[Server WARNING] Fail to initialize config."); } -- 2.7.4