From 1951e30a4bc5f3aa2614b4f0133e782f2c400fc1 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 9 Feb 2023 17:20:29 +0900 Subject: [PATCH] Send restart notification when a scheduled restart takes place When a scheduled restart takes place on the agent side, the client application receives a service reset error, canceling all the ongoing operations that are not directly related to the multi-assistant framework. To avoid this problem, added a restart notification signal for letting the clients to know the subsequent dbus name owner change event is caused by a scheduled restart event or not. Change-Id: Id7c3ff404f43e09dfb2488a7402b9afcbc2051f3 --- inc/service_common.h | 1 + inc/service_ipc_dbus.h | 1 + src/service_ipc_dbus.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/service_main.cpp | 1 + 4 files changed, 41 insertions(+) diff --git a/inc/service_common.h b/inc/service_common.h index 58bbf7c..25444d6 100644 --- a/inc/service_common.h +++ b/inc/service_common.h @@ -90,6 +90,7 @@ #define MAS_METHOD_STREAMING_AUDIO_DATA "mas_method_streaming_audio_data" #define MAS_METHOD_WAKEUP_ENGINE_COMMAND "mas_method_wakeup_engine_command" #define MAS_METHOD_ERROR "mas_method_error" +#define MAS_METHOD_RESTART_NOTIFICATION "mas_method_restart_notification" #define MAS_METHOD_SEND_PREPROCESSING_INFORMATION "mas_method_send_preprocessing_information" #define MAS_METHOD_AUDIO_STREAMING_DATA_SECTION "mas_method_audio_streaming_data_section" #define MAS_METHOD_SEND_PREPROCESSING_RESULT "mas_method_send_preprocessing_result" diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h index 900e792..86796fe 100644 --- a/inc/service_ipc_dbus.h +++ b/inc/service_ipc_dbus.h @@ -35,6 +35,7 @@ public: int close_connection(); int send_hello(pid_t pid); int send_error_message(int reason, const char* err_msg); + int send_restart_notification(); int send_streaming_audio_data(std::string appid, int event, void* data, unsigned int data_size); int change_active_state(pid_t pid, int state, const char* wakeup_word, const unsigned char* wakeup_extra_data, size_t wakeup_extra_data_length, diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index 365c3b8..0e30c72 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -217,6 +217,44 @@ int CServiceIpcDbus::send_error_message(int reason, const char* err_msg) return 0; } +int CServiceIpcDbus::send_restart_notification() +{ + if (0 != __dbus_check()) { + return -1; //MAS_ERROR_OPERATION_FAILED; + } + + if (NULL == mConnectionSender) { + MAS_LOGE("[Dbus ERROR] Dbus connection is not available"); + return -1; + } + + DBusMessage* msg = NULL; + + /* create a message */ + msg = dbus_message_new_signal( + MA_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */ + MA_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */ + MAS_METHOD_RESTART_NOTIFICATION); /* name of the signal */ + + if (NULL == msg) { + MAS_LOGE("[Dbus ERROR] Fail to create error message"); + return -1; + } + + dbus_message_set_no_reply(msg, TRUE); + + if (!dbus_connection_send(mConnectionSender, msg, NULL)) { + MAS_LOGE("[Dbus ERROR] <<<< error message : Out Of Memory !"); + } else { + MAS_LOGI("<<<< Send restart notification message"); + dbus_connection_flush(mConnectionSender); + } + + dbus_message_unref(msg); + + return 0; +} + const char *message_port = "ma_streaming_port"; #define STREAMING_BUFFER_SIZE 4096 diff --git a/src/service_main.cpp b/src/service_main.cpp index 874a433..7858a88 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -1464,6 +1464,7 @@ void CServiceMain::app_terminate(void *data) void CServiceMain::app_restart() { + mServiceIpc.send_restart_notification(); service_app_exit(); } -- 2.7.4