From feeb4b5d93ebae9cf068c7e184854c873597505d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 21 Dec 2019 17:27:33 +0100 Subject: [PATCH] RosterPrivate: add IsShutDownInProgress() enable to check whether a shutdown process is in progress. Change-Id: I8efdddb3caa80e9fd188f202b6e92a888a7608e5 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2042 Reviewed-by: waddlesplash --- headers/os/app/Roster.h | 1 + headers/private/app/RegistrarDefs.h | 1 + headers/private/app/RosterPrivate.h | 2 ++ src/kits/app/Roster.cpp | 37 +++++++++++++++++++++++++++++ src/servers/registrar/Registrar.cpp | 19 +++++++++++++++ src/servers/registrar/Registrar.h | 1 + 6 files changed, 61 insertions(+) diff --git a/headers/os/app/Roster.h b/headers/os/app/Roster.h index 5127e5a8ee..6d08702ad2 100644 --- a/headers/os/app/Roster.h +++ b/headers/os/app/Roster.h @@ -147,6 +147,7 @@ private: status_t _ShutDown(bool reboot, bool confirm, bool synchronous); + status_t _IsShutDownInProgress(bool* inProgress); status_t _AddApplication(const char* signature, const entry_ref* ref, uint32 flags, diff --git a/headers/private/app/RegistrarDefs.h b/headers/private/app/RegistrarDefs.h index 4df6c3d776..0bb5d8545b 100644 --- a/headers/private/app/RegistrarDefs.h +++ b/headers/private/app/RegistrarDefs.h @@ -46,6 +46,7 @@ enum { B_REG_GET_CLIPBOARD_MESSENGER = 'rgcm', B_REG_GET_DISK_DEVICE_MESSENGER = 'rgdm', B_REG_SHUT_DOWN = 'rgsh', + B_REG_IS_SHUT_DOWN_IN_PROGRESS = 'rgsi', // roster requests B_REG_ADD_APP = 'rgaa', diff --git a/headers/private/app/RosterPrivate.h b/headers/private/app/RosterPrivate.h index 251476640b..bba25972bf 100644 --- a/headers/private/app/RosterPrivate.h +++ b/headers/private/app/RosterPrivate.h @@ -39,6 +39,8 @@ class BRoster::Private { status_t ShutDown(bool reboot, bool confirm, bool synchronous) { return fRoster->_ShutDown(reboot, confirm, synchronous); } + status_t IsShutDownInProgress(bool* inProgress) + { return fRoster->_IsShutDownInProgress(inProgress); } // needed by BApplication diff --git a/src/kits/app/Roster.cpp b/src/kits/app/Roster.cpp index 1c1d2381cd..7fc3ec86dd 100644 --- a/src/kits/app/Roster.cpp +++ b/src/kits/app/Roster.cpp @@ -1343,6 +1343,43 @@ BRoster::_ShutDown(bool reboot, bool confirm, bool synchronous) } +/*! Checks whether a shutdown process is in progress. + + \param inProgress: Pointer to a pre-allocated bool to be filled in + by this method, indicating whether or not a shutdown process + is in progress. + \return A status code, \c B_OK on success or another error code in case + something went wrong. +*/ +status_t +BRoster::_IsShutDownInProgress(bool* inProgress) +{ + status_t error = B_OK; + + // compose the request message + BMessage request(B_REG_IS_SHUT_DOWN_IN_PROGRESS); + + // send the request + BMessage reply; + if (error == B_OK) + error = fMessenger.SendMessage(&request, &reply); + + // evaluate the reply + if (error == B_OK) { + if (reply.what == B_REG_SUCCESS) { + if (inProgress != NULL + && reply.FindBool("in-progress", inProgress) != B_OK) { + error = B_ERROR; + } + } else if (reply.FindInt32("error", &error) != B_OK) + error = B_ERROR; + } + + return error; +} + + + /*! (Pre-)Registers an application with the registrar. This methods is invoked either to register or to pre-register an diff --git a/src/servers/registrar/Registrar.cpp b/src/servers/registrar/Registrar.cpp index e5283b2415..29321ab036 100644 --- a/src/servers/registrar/Registrar.cpp +++ b/src/servers/registrar/Registrar.cpp @@ -248,6 +248,13 @@ Registrar::_MessageReceived(BMessage *message) _HandleShutDown(message); break; } + case B_REG_IS_SHUT_DOWN_IN_PROGRESS: + { + PRINT("B_REG_IS_SHUT_DOWN_IN_PROGRESS\n"); + + _HandleIsShutDownInProgress(message); + break; + } case B_REG_TEAM_DEBUGGER_ALERT: { if (fShutdownProcess != NULL) @@ -416,6 +423,18 @@ Registrar::_HandleShutDown(BMessage *request) } +/*! \brief Handle a is shut down in progress request message. + \param request The request to be handled. +*/ +void +Registrar::_HandleIsShutDownInProgress(BMessage *request) +{ + BMessage reply(B_REG_SUCCESS); + reply.AddBool("in-progress", fShutdownProcess != NULL); + request->SendReply(&reply); +} + + // #pragma mark - diff --git a/src/servers/registrar/Registrar.h b/src/servers/registrar/Registrar.h index 302bc769ce..978c468edd 100644 --- a/src/servers/registrar/Registrar.h +++ b/src/servers/registrar/Registrar.h @@ -58,6 +58,7 @@ public: private: void _MessageReceived(BMessage *message); void _HandleShutDown(BMessage *message); + void _HandleIsShutDownInProgress(BMessage *message); TRoster *fRoster; ClipboardHandler *fClipboardHandler;