Added a boolean "synchronous" parameter to BRoster::Shutdown(). Used in the

Deskbar to initiate the shutdown process asynchronously. Couldn't test it,
because opening the Be menu doesn't work:
***PANIC: BW: Can't find view with ID: 19 !***



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13722 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2005-07-17 16:37:11 +00:00
parent f0da8b3052
commit 2fd4a0411b
8 changed files with 50 additions and 33 deletions
+6 -1
View File
@@ -66,7 +66,9 @@ shut down
target: registrar app looper (preferred handler) target: registrar app looper (preferred handler)
message: B_REG_SHUT_DOWN message: B_REG_SHUT_DOWN
"reboot": B_BOOL_TYPE "reboot": B_BOOL_TYPE
"confirm": B_BOOL_TYPE
"synchronously": B_BOOL_TYPE
reply: standard success reply: standard success
on error: - B_NO_REPLY (fatal) on error: - B_NO_REPLY (fatal)
- standard error (fatal) - standard error (fatal)
@@ -74,6 +76,9 @@ on error: - B_NO_REPLY (fatal)
message fields: message fields:
- "reboot": If true, the system reboots instead of turning the power off. - "reboot": If true, the system reboots instead of turning the power off.
- "confirm": If true, the user will be asked to confirm to shut down the system. - "confirm": If true, the user will be asked to confirm to shut down the system.
- "synchronously": If true, the request sender gets a reply only, if the
shutdown process fails. Otherwise the reply will be sent
right before asking the user for confirmation (if desired).
----------------------------------------------------------------------- -----------------------------------------------------------------------
+1 -1
View File
@@ -143,7 +143,7 @@ private:
class ArgVector; class ArgVector;
friend class Private; friend class Private;
status_t ShutDown(bool reboot, bool confirm); status_t ShutDown(bool reboot, bool confirm, bool synchronous);
status_t AddApplication(const char *mimeSig, const entry_ref *ref, status_t AddApplication(const char *mimeSig, const entry_ref *ref,
uint32 flags, team_id team, thread_id thread, uint32 flags, team_id team, thread_id thread,
+2 -2
View File
@@ -20,8 +20,8 @@ public:
status_t SendTo(BMessage *message, BMessage *reply, bool mime); status_t SendTo(BMessage *message, BMessage *reply, bool mime);
bool IsMessengerValid(bool mime) const; bool IsMessengerValid(bool mime) const;
status_t ShutDown(bool reboot, bool confirm) status_t ShutDown(bool reboot, bool confirm, bool synchronous)
{ return fRoster->ShutDown(reboot, confirm); } { return fRoster->ShutDown(reboot, confirm, synchronous); }
// needed by BApplication // needed by BApplication
+9 -25
View File
@@ -462,20 +462,17 @@ TBarApp::MessageReceived(BMessage *message)
break; break;
#if __HAIKU__ #if __HAIKU__
case CMD_REBOOT_SYSTEM:
case CMD_SUSPEND_SYSTEM: case CMD_SUSPEND_SYSTEM:
break;
case CMD_REBOOT_SYSTEM:
case CMD_SHUTDOWN_SYSTEM: { case CMD_SHUTDOWN_SYSTEM: {
// TODO: Deskbar cannot quit because BRoster::Private::Shutdown() is synchronous, bool reboot = (message->what == CMD_REBOOT_SYSTEM);
// so we launch a thread which does the shutdown, this should be reworked so BRoster roster;
// that we can simply send a message to the roster and be done with it BRoster::Private rosterPrivate(roster);
void* cookie = message->what == CMD_SHUTDOWN_SYSTEM ? NULL : (void*)1; status_t error = rosterPrivate.ShutDown(reboot, true, false);
thread_id thread = spawn_thread(_shutdown, "shutdown thread", B_NORMAL_PRIORITY, cookie); if (error != B_OK)
if (thread >= B_OK) { fprintf(stderr, "Shutdown failed: %s\n", strerror(error));
status_t ret = resume_thread(thread);
if (ret < B_OK)
fprintf(stderr, "error resuming shutdown thread: %s\n", strerror(ret));
} else
fprintf(stderr, "error spawning shutdown thread: %s\n", strerror(thread));
break; break;
} }
@@ -667,19 +664,6 @@ TBarApp::ShowConfigWindow()
} }
} }
#if __HAIKU__
// _shutdown
int32
TBarApp::_shutdown(void* cookie)
{
BRoster roster;
BRoster::Private rosterPrivate(roster);
status_t error = rosterPrivate.ShutDown(cookie != NULL, false);
fprintf(stderr, "Shutdown failed: %s\n", strerror(error));
return 0;
}
#endif // __HAIKU__
// #pragma mark - // #pragma mark -
+1 -1
View File
@@ -174,7 +174,7 @@ main(int argc, char **argv)
} else { } else {
BRoster roster; BRoster roster;
BRoster::Private rosterPrivate(roster); BRoster::Private rosterPrivate(roster);
status_t error = rosterPrivate.ShutDown(gReboot, askUser); status_t error = rosterPrivate.ShutDown(gReboot, askUser, true);
fprintf(stderr, "Shutdown failed: %s\n", strerror(error)); fprintf(stderr, "Shutdown failed: %s\n", strerror(error));
return 2; return 2;
} }
+7 -2
View File
@@ -1269,12 +1269,15 @@ BRoster::AddToRecentFolders(const entry_ref *folder, const char *appSig) const
// ShutDown // ShutDown
/*! \brief Shuts down the system. /*! \brief Shuts down the system.
When the method succeeds, it doesn't return. When \c synchronous is \c true and the method succeeds, it doesn't return.
\param reboot If \c true, the system will be rebooted instead of being \param reboot If \c true, the system will be rebooted instead of being
powered off. powered off.
\param confirm If \c true, the user will be asked to confirm to shut down \param confirm If \c true, the user will be asked to confirm to shut down
the system. the system.
\param synchronous If \c false, the method will return as soon as the
shutdown process has been initiated successfully (or an error
occurred). Otherwise the method doesn't return, if successfully.
\return \return
- \c B_SHUTTING_DOWN, when there's already a shutdown process in - \c B_SHUTTING_DOWN, when there's already a shutdown process in
progress, progress,
@@ -1282,7 +1285,7 @@ BRoster::AddToRecentFolders(const entry_ref *folder, const char *appSig) const
- another error code in case something went wrong. - another error code in case something went wrong.
*/ */
status_t status_t
BRoster::ShutDown(bool reboot, bool confirm) BRoster::ShutDown(bool reboot, bool confirm, bool synchronous)
{ {
status_t error = B_OK; status_t error = B_OK;
@@ -1292,6 +1295,8 @@ BRoster::ShutDown(bool reboot, bool confirm)
error = request.AddBool("reboot", reboot); error = request.AddBool("reboot", reboot);
if (error == B_OK) if (error == B_OK)
error = request.AddBool("confirm", confirm); error = request.AddBool("confirm", confirm);
if (error == B_OK)
error = request.AddBool("synchronous", synchronous);
// send the request // send the request
BMessage reply; BMessage reply;
+21 -1
View File
@@ -607,6 +607,7 @@ ShutdownProcess::ShutdownProcess(TRoster *roster, EventQueue *eventQueue)
fShutdownError(B_ERROR), fShutdownError(B_ERROR),
fHasGUI(false), fHasGUI(false),
fReboot(false), fReboot(false),
fRequestReplySent(false),
fWindow(NULL) fWindow(NULL)
{ {
} }
@@ -656,7 +657,7 @@ ShutdownProcess::~ShutdownProcess()
} }
// send a reply to the request and delete it // send a reply to the request and delete it
SendReply(fRequest, fShutdownError); _SendReply(fShutdownError);
delete fRequest; delete fRequest;
} }
@@ -856,6 +857,16 @@ ShutdownProcess::SendReply(BMessage *request, status_t error)
} }
} }
// _SendReply
void
ShutdownProcess::_SendReply(status_t error)
{
if (!fRequestReplySent) {
SendReply(fRequest, error);
fRequestReplySent = true;
}
}
// _SetPhase // _SetPhase
void void
ShutdownProcess::_SetPhase(int32 phase) ShutdownProcess::_SetPhase(int32 phase)
@@ -1216,6 +1227,15 @@ ShutdownProcess::_WorkerDoShutdown()
{ {
PRINT(("ShutdownProcess::_WorkerDoShutdown()\n")); PRINT(("ShutdownProcess::_WorkerDoShutdown()\n"));
// If we are here, the shutdown process has been initiated successfully,
// that is, if an asynchronous BRoster::Shutdown() was requested, we
// notify the caller at this point.
bool synchronously;
if (fRequest->FindBool("synchronously", &synchronously) == B_OK
&& !synchronously) {
_SendReply(B_OK);
}
// ask the user to confirm the shutdown, if desired // ask the user to confirm the shutdown, if desired
bool askUser; bool askUser;
if (fHasGUI && fRequest->FindBool("confirm", &askUser) == B_OK && askUser) { if (fHasGUI && fRequest->FindBool("confirm", &askUser) == B_OK && askUser) {
+3
View File
@@ -32,6 +32,8 @@ public:
static void SendReply(BMessage *request, status_t error); static void SendReply(BMessage *request, status_t error);
private: private:
void _SendReply(status_t error);
void _NegativeQuitRequestReply(thread_id thread); void _NegativeQuitRequestReply(thread_id thread);
void _PrepareShutdownMessage(BMessage &message) const; void _PrepareShutdownMessage(BMessage &message) const;
@@ -98,6 +100,7 @@ private:
status_t fShutdownError; status_t fShutdownError;
bool fHasGUI; bool fHasGUI;
bool fReboot; bool fReboot;
bool fRequestReplySent;
ShutdownWindow *fWindow; ShutdownWindow *fWindow;
}; };