* Style cleanup, added missing copyrights.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30743 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-05-13 08:58:32 +00:00
parent 7cec697c0b
commit 1c38b061f8
2 changed files with 192 additions and 201 deletions
+124 -141
View File
@@ -1,8 +1,14 @@
/* /*
* Copyright 2005-2008, Ingo Weinhold, [email protected]. * Copyright 2005-2008, Ingo Weinhold, [email protected].
* Copyright 2006-2009, Axel Dörfler, [email protected].
* Copyright 2006-2008, Stephan Aßmus.
* Copyright 2006, Ryan Leavengood.
*
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "ShutdownProcess.h"
#include <new> #include <new>
#include <string.h> #include <string.h>
@@ -28,9 +34,7 @@
#include <TokenSpace.h> #include <TokenSpace.h>
#include <util/DoublyLinkedList.h> #include <util/DoublyLinkedList.h>
#ifdef __HAIKU__
#include <syscalls.h> #include <syscalls.h>
#endif
#include "AppInfoListMessagingTargetSet.h" #include "AppInfoListMessagingTargetSet.h"
#include "Debug.h" #include "Debug.h"
@@ -39,7 +43,6 @@
#include "MessageEvent.h" #include "MessageEvent.h"
#include "Registrar.h" #include "Registrar.h"
#include "RosterAppInfo.h" #include "RosterAppInfo.h"
#include "ShutdownProcess.h"
#include "TRoster.h" #include "TRoster.h"
using std::nothrow; using std::nothrow;
@@ -98,16 +101,14 @@ enum {
}; };
// inverse_compare_by_registration_time static bool
static inverse_compare_by_registration_time(const RosterAppInfo* info1,
bool const RosterAppInfo* info2)
inverse_compare_by_registration_time(const RosterAppInfo *info1,
const RosterAppInfo *info2)
{ {
return (info2->registration_time < info1->registration_time); return (info2->registration_time < info1->registration_time);
} }
// throw_error
/*! \brief Used to avoid type matching problems when throwing a constant. /*! \brief Used to avoid type matching problems when throwing a constant.
*/ */
static inline static inline
@@ -117,10 +118,10 @@ throw_error(status_t error)
throw error; throw error;
} }
// TimeoutEvent
class ShutdownProcess::TimeoutEvent : public MessageEvent { class ShutdownProcess::TimeoutEvent : public MessageEvent {
public: public:
TimeoutEvent(BHandler *target) TimeoutEvent(BHandler* target)
: MessageEvent(0, target, MSG_PHASE_TIMED_OUT) : MessageEvent(0, target, MSG_PHASE_TIMED_OUT)
{ {
SetAutoDelete(false); SetAutoDelete(false);
@@ -139,7 +140,7 @@ public:
fMessage.ReplaceInt32("team", team); fMessage.ReplaceInt32("team", team);
} }
static int32 GetMessagePhase(BMessage *message) static int32 GetMessagePhase(BMessage* message)
{ {
int32 phase; int32 phase;
if (message->FindInt32("phase", &phase) != B_OK) if (message->FindInt32("phase", &phase) != B_OK)
@@ -148,7 +149,7 @@ public:
return phase; return phase;
} }
static int32 GetMessageTeam(BMessage *message) static int32 GetMessageTeam(BMessage* message)
{ {
team_id team; team_id team;
if (message->FindInt32("team", &team) != B_OK) if (message->FindInt32("team", &team) != B_OK)
@@ -159,14 +160,14 @@ public:
}; };
// InternalEvent
class ShutdownProcess::InternalEvent class ShutdownProcess::InternalEvent
: public DoublyLinkedListLinkImpl<InternalEvent> { : public DoublyLinkedListLinkImpl<InternalEvent> {
public: public:
InternalEvent(uint32 type, team_id team, int32 phase) InternalEvent(uint32 type, team_id team, int32 phase)
: fType(type), :
fTeam(team), fType(type),
fPhase(phase) fTeam(team),
fPhase(phase)
{ {
} }
@@ -181,21 +182,19 @@ private:
}; };
// InternalEventList
struct ShutdownProcess::InternalEventList : DoublyLinkedList<InternalEvent> { struct ShutdownProcess::InternalEventList : DoublyLinkedList<InternalEvent> {
}; };
// QuitRequestReplyHandler
class ShutdownProcess::QuitRequestReplyHandler : public BHandler { class ShutdownProcess::QuitRequestReplyHandler : public BHandler {
public: public:
QuitRequestReplyHandler(ShutdownProcess *shutdownProcess) QuitRequestReplyHandler(ShutdownProcess* shutdownProcess)
: BHandler("shutdown quit reply handler"), : BHandler("shutdown quit reply handler"),
fShutdownProcess(shutdownProcess) fShutdownProcess(shutdownProcess)
{ {
} }
virtual void MessageReceived(BMessage *message) virtual void MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_REPLY: case B_REPLY:
@@ -222,7 +221,6 @@ private:
}; };
// ShutdownWindow
class ShutdownProcess::ShutdownWindow : public BWindow { class ShutdownProcess::ShutdownWindow : public BWindow {
public: public:
ShutdownWindow() ShutdownWindow()
@@ -230,14 +228,14 @@ public:
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_MINIMIZABLE B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_MINIMIZABLE
| B_NOT_ZOOMABLE | B_NOT_CLOSABLE, B_ALL_WORKSPACES), | B_NOT_ZOOMABLE | B_NOT_CLOSABLE, B_ALL_WORKSPACES),
fKillAppMessage(NULL), fKillAppMessage(NULL),
fCurrentApp(-1) fCurrentApp(-1)
{ {
} }
~ShutdownWindow() ~ShutdownWindow()
{ {
for (int32 i = 0; AppInfo *info = (AppInfo*)fAppInfos.ItemAt(i); i++) { for (int32 i = 0; AppInfo* info = (AppInfo*)fAppInfos.ItemAt(i); i++) {
delete info; delete info;
} }
} }
@@ -279,7 +277,7 @@ public:
return B_NO_MEMORY; return B_NO_MEMORY;
fRootView->AddChild(fKillAppButton); fRootView->AddChild(fKillAppButton);
BMessage *message = new BMessage(MSG_KILL_APPLICATION); BMessage* message = new BMessage(MSG_KILL_APPLICATION);
if (!message) if (!message)
return B_NO_MEMORY; return B_NO_MEMORY;
message->AddInt32("team", -1); message->AddInt32("team", -1);
@@ -406,9 +404,9 @@ public:
return B_OK; return B_OK;
} }
status_t AddApp(team_id team, BBitmap *miniIcon, BBitmap *largeIcon) status_t AddApp(team_id team, BBitmap* miniIcon, BBitmap* largeIcon)
{ {
AppInfo *info = new(nothrow) AppInfo; AppInfo* info = new(nothrow) AppInfo;
if (!info) { if (!info) {
delete miniIcon; delete miniIcon;
delete largeIcon; delete largeIcon;
@@ -436,13 +434,13 @@ public:
if (team == fCurrentApp) if (team == fCurrentApp)
SetCurrentApp(-1); SetCurrentApp(-1);
AppInfo *info = (AppInfo*)fAppInfos.RemoveItem(index); AppInfo* info = (AppInfo*)fAppInfos.RemoveItem(index);
delete info; delete info;
} }
void SetCurrentApp(team_id team) void SetCurrentApp(team_id team)
{ {
AppInfo *info = (team >= 0 ? _AppInfoFor(team) : NULL); AppInfo* info = (team >= 0 ? _AppInfoFor(team) : NULL);
fCurrentApp = team; fCurrentApp = team;
fRootView->SetAppInfo(info); fRootView->SetAppInfo(info);
@@ -450,7 +448,7 @@ public:
fKillAppMessage->ReplaceInt32("team", team); fKillAppMessage->ReplaceInt32("team", team);
} }
void SetText(const char *text) void SetText(const char* text)
{ {
fTextView->SetText(text); fTextView->SetText(text);
} }
@@ -513,7 +511,7 @@ private:
if (team < 0) if (team < 0)
return -1; return -1;
for (int32 i = 0; AppInfo *info = (AppInfo*)fAppInfos.ItemAt(i); i++) { for (int32 i = 0; AppInfo* info = (AppInfo*)fAppInfos.ItemAt(i); i++) {
if (info->team == team) if (info->team == team)
return i; return i;
} }
@@ -521,7 +519,7 @@ private:
return -1; return -1;
} }
AppInfo *_AppInfoFor(team_id team) AppInfo* _AppInfoFor(team_id team)
{ {
int32 index = _AppInfoIndexOf(team); int32 index = _AppInfoIndexOf(team);
return (index >= 0 ? (AppInfo*)fAppInfos.ItemAt(index) : NULL); return (index >= 0 ? (AppInfo*)fAppInfos.ItemAt(index) : NULL);
@@ -529,9 +527,10 @@ private:
class TAlertView : public BView { class TAlertView : public BView {
public: public:
TAlertView(BRect frame, const char *name, uint32 resizeMask, uint32 flags) TAlertView(BRect frame, const char* name, uint32 resizeMask,
uint32 flags)
: BView(frame, name, resizeMask, flags | B_WILL_DRAW), : BView(frame, name, resizeMask, flags | B_WILL_DRAW),
fAppInfo(NULL) fAppInfo(NULL)
{ {
} }
@@ -554,7 +553,7 @@ private:
} }
} }
void SetAppInfo(AppInfo *info) void SetAppInfo(AppInfo* info)
{ {
fAppInfo = info; fAppInfo = info;
Invalidate(); Invalidate();
@@ -566,42 +565,43 @@ private:
private: private:
BList fAppInfos; BList fAppInfos;
TAlertView *fRootView; TAlertView* fRootView;
BTextView *fTextView; BTextView* fTextView;
BButton *fKillAppButton; BButton* fKillAppButton;
BButton *fCancelShutdownButton; BButton* fCancelShutdownButton;
BButton *fRebootSystemButton; BButton* fRebootSystemButton;
BButton *fAbortedOKButton; BButton* fAbortedOKButton;
BMessage *fKillAppMessage; BMessage* fKillAppMessage;
team_id fCurrentApp; team_id fCurrentApp;
}; };
// #pragma mark - // #pragma mark -
// constructor
ShutdownProcess::ShutdownProcess(TRoster *roster, EventQueue *eventQueue) ShutdownProcess::ShutdownProcess(TRoster* roster, EventQueue* eventQueue)
: BLooper("shutdown process"), :
EventMaskWatcher(BMessenger(this), B_REQUEST_QUIT), BLooper("shutdown process"),
fWorkerLock("worker lock"), EventMaskWatcher(BMessenger(this), B_REQUEST_QUIT),
fRequest(NULL), fWorkerLock("worker lock"),
fRoster(roster), fRequest(NULL),
fEventQueue(eventQueue), fRoster(roster),
fTimeoutEvent(NULL), fEventQueue(eventQueue),
fInternalEvents(NULL), fTimeoutEvent(NULL),
fInternalEventSemaphore(-1), fInternalEvents(NULL),
fQuitRequestReplyHandler(NULL), fInternalEventSemaphore(-1),
fWorker(-1), fQuitRequestReplyHandler(NULL),
fCurrentPhase(INVALID_PHASE), fWorker(-1),
fShutdownError(B_ERROR), fCurrentPhase(INVALID_PHASE),
fHasGUI(false), fShutdownError(B_ERROR),
fReboot(false), fHasGUI(false),
fRequestReplySent(false), fReboot(false),
fWindow(NULL) fRequestReplySent(false),
fWindow(NULL)
{ {
} }
// destructor
ShutdownProcess::~ShutdownProcess() ShutdownProcess::~ShutdownProcess()
{ {
// terminate the GUI // terminate the GUI
@@ -642,7 +642,7 @@ ShutdownProcess::~ShutdownProcess()
// delete all internal events and the queue // delete all internal events and the queue
if (fInternalEvents) { if (fInternalEvents) {
while (InternalEvent *event = fInternalEvents->First()) { while (InternalEvent* event = fInternalEvents->First()) {
fInternalEvents->Remove(event); fInternalEvents->Remove(event);
delete event; delete event;
} }
@@ -655,9 +655,9 @@ ShutdownProcess::~ShutdownProcess()
delete fRequest; delete fRequest;
} }
// Init
status_t status_t
ShutdownProcess::Init(BMessage *request) ShutdownProcess::Init(BMessage* request)
{ {
PRINT(("ShutdownProcess::Init()\n")); PRINT(("ShutdownProcess::Init()\n"));
@@ -729,9 +729,9 @@ ShutdownProcess::Init(BMessage *request)
return B_OK; return B_OK;
} }
// MessageReceived
void void
ShutdownProcess::MessageReceived(BMessage *message) ShutdownProcess::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case B_SOME_APP_QUIT: case B_SOME_APP_QUIT:
@@ -748,7 +748,7 @@ ShutdownProcess::MessageReceived(BMessage *message)
// remove the app info from the respective list // remove the app info from the respective list
int32 phase; int32 phase;
RosterAppInfo *info; RosterAppInfo* info;
{ {
BAutolock _(fWorkerLock); BAutolock _(fWorkerLock);
@@ -778,7 +778,7 @@ ShutdownProcess::MessageReceived(BMessage *message)
// get the phase the event is intended for // get the phase the event is intended for
int32 phase = TimeoutEvent::GetMessagePhase(message); int32 phase = TimeoutEvent::GetMessagePhase(message);
team_id team = TimeoutEvent::GetMessageTeam(message);; team_id team = TimeoutEvent::GetMessageTeam(message);;
PRINT(("MSG_PHASE_TIMED_OUT: phase: %ld, team: %ld\n", phase, team)); PRINT(("MSG_PHASE_TIMED_OUT: phase: %ld, team: %ld\n", phase, team));
BAutolock _(fWorkerLock); BAutolock _(fWorkerLock);
@@ -857,9 +857,9 @@ PRINT(("MSG_PHASE_TIMED_OUT: phase: %ld, team: %ld\n", phase, team));
} }
} }
// SendReply
void void
ShutdownProcess::SendReply(BMessage *request, status_t error) ShutdownProcess::SendReply(BMessage* request, status_t error)
{ {
if (error == B_OK) { if (error == B_OK) {
BMessage reply(B_REG_SUCCESS); BMessage reply(B_REG_SUCCESS);
@@ -871,7 +871,7 @@ ShutdownProcess::SendReply(BMessage *request, status_t error)
} }
} }
// _SendReply
void void
ShutdownProcess::_SendReply(status_t error) ShutdownProcess::_SendReply(status_t error)
{ {
@@ -881,7 +881,7 @@ ShutdownProcess::_SendReply(status_t error)
} }
} }
// _SetPhase
void void
ShutdownProcess::_SetPhase(int32 phase) ShutdownProcess::_SetPhase(int32 phase)
{ {
@@ -896,7 +896,7 @@ ShutdownProcess::_SetPhase(int32 phase)
fEventQueue->RemoveEvent(fTimeoutEvent); fEventQueue->RemoveEvent(fTimeoutEvent);
} }
// _ScheduleTimeoutEvent
void void
ShutdownProcess::_ScheduleTimeoutEvent(bigtime_t timeout, team_id team) ShutdownProcess::_ScheduleTimeoutEvent(bigtime_t timeout, team_id team)
{ {
@@ -914,7 +914,7 @@ ShutdownProcess::_ScheduleTimeoutEvent(bigtime_t timeout, team_id team)
fEventQueue->AddEvent(fTimeoutEvent); fEventQueue->AddEvent(fTimeoutEvent);
} }
// _SetShowShutdownWindow
void void
ShutdownProcess::_SetShowShutdownWindow(bool show) ShutdownProcess::_SetShowShutdownWindow(bool show)
{ {
@@ -930,7 +930,7 @@ ShutdownProcess::_SetShowShutdownWindow(bool show)
} }
} }
// _InitShutdownWindow
void void
ShutdownProcess::_InitShutdownWindow() ShutdownProcess::_InitShutdownWindow()
{ {
@@ -959,15 +959,15 @@ ShutdownProcess::_InitShutdownWindow()
} }
} }
// _AddShutdownWindowApps
void void
ShutdownProcess::_AddShutdownWindowApps(AppInfoList &infos) ShutdownProcess::_AddShutdownWindowApps(AppInfoList& infos)
{ {
if (!fHasGUI) if (!fHasGUI)
return; return;
for (AppInfoList::Iterator it = infos.It(); it.IsValid(); ++it) { for (AppInfoList::Iterator it = infos.It(); it.IsValid(); ++it) {
RosterAppInfo *info = *it; RosterAppInfo* info = *it;
// init an app file info // init an app file info
BFile file; BFile file;
@@ -995,7 +995,7 @@ ShutdownProcess::_AddShutdownWindowApps(AppInfoList &infos)
#endif #endif
// mini icon // mini icon
BBitmap *miniIcon = new(nothrow) BBitmap(BRect(0, 0, 15, 15), format); BBitmap* miniIcon = new(nothrow) BBitmap(BRect(0, 0, 15, 15), format);
if (miniIcon != NULL) { if (miniIcon != NULL) {
error = miniIcon->InitCheck(); error = miniIcon->InitCheck();
if (error == B_OK) if (error == B_OK)
@@ -1007,7 +1007,7 @@ ShutdownProcess::_AddShutdownWindowApps(AppInfoList &infos)
} }
// mini icon // mini icon
BBitmap *largeIcon = new(nothrow) BBitmap(BRect(0, 0, 31, 31), format); BBitmap* largeIcon = new(nothrow) BBitmap(BRect(0, 0, 31, 31), format);
if (largeIcon != NULL) { if (largeIcon != NULL) {
error = largeIcon->InitCheck(); error = largeIcon->InitCheck();
if (error == B_OK) if (error == B_OK)
@@ -1027,7 +1027,7 @@ ShutdownProcess::_AddShutdownWindowApps(AppInfoList &infos)
} }
} }
// _RemoveShutdownWindowApp
void void
ShutdownProcess::_RemoveShutdownWindowApp(team_id team) ShutdownProcess::_RemoveShutdownWindowApp(team_id team)
{ {
@@ -1038,7 +1038,7 @@ ShutdownProcess::_RemoveShutdownWindowApp(team_id team)
} }
} }
// _SetShutdownWindowCurrentApp
void void
ShutdownProcess::_SetShutdownWindowCurrentApp(team_id team) ShutdownProcess::_SetShutdownWindowCurrentApp(team_id team)
{ {
@@ -1049,9 +1049,9 @@ ShutdownProcess::_SetShutdownWindowCurrentApp(team_id team)
} }
} }
// _SetShutdownWindowText
void void
ShutdownProcess::_SetShutdownWindowText(const char *text) ShutdownProcess::_SetShutdownWindowText(const char* text)
{ {
if (fHasGUI) { if (fHasGUI) {
BAutolock _(fWindow); BAutolock _(fWindow);
@@ -1060,7 +1060,7 @@ ShutdownProcess::_SetShutdownWindowText(const char *text)
} }
} }
// _SetShutdownWindowCancelButtonEnabled
void void
ShutdownProcess::_SetShutdownWindowCancelButtonEnabled(bool enabled) ShutdownProcess::_SetShutdownWindowCancelButtonEnabled(bool enabled)
{ {
@@ -1071,7 +1071,7 @@ ShutdownProcess::_SetShutdownWindowCancelButtonEnabled(bool enabled)
} }
} }
// _SetShutdownWindowKillButtonEnabled
void void
ShutdownProcess::_SetShutdownWindowKillButtonEnabled(bool enabled) ShutdownProcess::_SetShutdownWindowKillButtonEnabled(bool enabled)
{ {
@@ -1082,7 +1082,7 @@ ShutdownProcess::_SetShutdownWindowKillButtonEnabled(bool enabled)
} }
} }
// _SetShutdownWindowWaitForShutdown
void void
ShutdownProcess::_SetShutdownWindowWaitForShutdown() ShutdownProcess::_SetShutdownWindowWaitForShutdown()
{ {
@@ -1093,7 +1093,7 @@ ShutdownProcess::_SetShutdownWindowWaitForShutdown()
} }
} }
// _SetShutdownWindowWaitForAbortedOK
void void
ShutdownProcess::_SetShutdownWindowWaitForAbortedOK() ShutdownProcess::_SetShutdownWindowWaitForAbortedOK()
{ {
@@ -1104,7 +1104,7 @@ ShutdownProcess::_SetShutdownWindowWaitForAbortedOK()
} }
} }
// _NegativeQuitRequestReply
void void
ShutdownProcess::_NegativeQuitRequestReply(thread_id thread) ShutdownProcess::_NegativeQuitRequestReply(thread_id thread)
{ {
@@ -1116,9 +1116,9 @@ ShutdownProcess::_NegativeQuitRequestReply(thread_id thread)
_PushEvent(ABORT_EVENT, thread, fCurrentPhase); _PushEvent(ABORT_EVENT, thread, fCurrentPhase);
} }
// _PrepareShutdownMessage
void void
ShutdownProcess::_PrepareShutdownMessage(BMessage &message) const ShutdownProcess::_PrepareShutdownMessage(BMessage& message) const
{ {
message.what = B_QUIT_REQUESTED; message.what = B_QUIT_REQUESTED;
message.AddBool("_shutdown_", true); message.AddBool("_shutdown_", true);
@@ -1126,26 +1126,19 @@ ShutdownProcess::_PrepareShutdownMessage(BMessage &message) const
BMessage::Private(message).SetReply(BMessenger(fQuitRequestReplyHandler)); BMessage::Private(message).SetReply(BMessenger(fQuitRequestReplyHandler));
} }
// _ShutDown
status_t status_t
ShutdownProcess::_ShutDown() ShutdownProcess::_ShutDown()
{ {
PRINT(("Invoking _kern_shutdown(%d)\n", fReboot)); PRINT(("Invoking _kern_shutdown(%d)\n", fReboot));
RETURN_ERROR(_kern_shutdown(fReboot));
#ifdef __HAIKU__
RETURN_ERROR(_kern_shutdown(fReboot));
#else
// we can't do anything on R5
return B_ERROR;
#endif
} }
// _PushEvent
status_t status_t
ShutdownProcess::_PushEvent(uint32 eventType, team_id team, int32 phase) ShutdownProcess::_PushEvent(uint32 eventType, team_id team, int32 phase)
{ {
InternalEvent *event = new(nothrow) InternalEvent(eventType, team, phase); InternalEvent* event = new(nothrow) InternalEvent(eventType, team, phase);
if (!event) { if (!event) {
ERROR(("ShutdownProcess::_PushEvent(): Failed to create event!\n")); ERROR(("ShutdownProcess::_PushEvent(): Failed to create event!\n"));
@@ -1160,9 +1153,9 @@ ShutdownProcess::_PushEvent(uint32 eventType, team_id team, int32 phase)
return B_OK; return B_OK;
} }
// _GetNextEvent
status_t status_t
ShutdownProcess::_GetNextEvent(uint32 &eventType, thread_id &team, int32 &phase, ShutdownProcess::_GetNextEvent(uint32& eventType, thread_id& team, int32& phase,
bool block) bool block)
{ {
while (true) { while (true) {
@@ -1187,7 +1180,7 @@ ShutdownProcess::_GetNextEvent(uint32 &eventType, thread_id &team, int32 &phase,
// get the event // get the event
BAutolock _(fWorkerLock); BAutolock _(fWorkerLock);
InternalEvent *event = fInternalEvents->Head(); InternalEvent* event = fInternalEvents->Head();
fInternalEvents->Remove(event); fInternalEvents->Remove(event);
eventType = event->Type(); eventType = event->Type();
@@ -1210,14 +1203,14 @@ ShutdownProcess::_GetNextEvent(uint32 &eventType, thread_id &team, int32 &phase,
return B_OK; return B_OK;
} }
// _WorkerEntry
status_t status_t
ShutdownProcess::_WorkerEntry(void *data) ShutdownProcess::_WorkerEntry(void* data)
{ {
return ((ShutdownProcess*)data)->_Worker(); return ((ShutdownProcess*)data)->_Worker();
} }
// _Worker
status_t status_t
ShutdownProcess::_Worker() ShutdownProcess::_Worker()
{ {
@@ -1239,7 +1232,7 @@ ShutdownProcess::_Worker()
return B_OK; return B_OK;
} }
// _WorkerDoShutdown
void void
ShutdownProcess::_WorkerDoShutdown() ShutdownProcess::_WorkerDoShutdown()
{ {
@@ -1333,25 +1326,23 @@ ShutdownProcess::_WorkerDoShutdown()
break; break;
} while (event != REBOOT_SYSTEM_EVENT); } while (event != REBOOT_SYSTEM_EVENT);
#ifdef __HAIKU__
_kern_shutdown(true); _kern_shutdown(true);
#endif
} }
// either there's no GUI or reboot failed: we enter the kernel debugger // either there's no GUI or reboot failed: we enter the kernel debugger
// instead // instead
#ifdef __HAIKU__ #ifdef __HAIKU__
// TODO: Introduce the syscall. // TODO: Introduce the syscall.
// while (true) { // while (true) {
// _kern_kernel_debugger("The system is shut down. It's now safe to turn " // _kern_kernel_debugger("The system is shut down. It's now safe to turn "
// "off the computer."); // "off the computer.");
// } // }
#endif #endif
} }
bool bool
ShutdownProcess::_WaitForApp(team_id team, AppInfoList *list, bool systemApps) ShutdownProcess::_WaitForApp(team_id team, AppInfoList* list, bool systemApps)
{ {
uint32 event; uint32 event;
do { do {
@@ -1393,7 +1384,7 @@ ShutdownProcess::_WaitForApp(team_id team, AppInfoList *list, bool systemApps)
void void
ShutdownProcess::_QuitApps(AppInfoList &list, bool systemApps) ShutdownProcess::_QuitApps(AppInfoList& list, bool systemApps)
{ {
PRINT(("ShutdownProcess::_QuitApps(%s)\n", PRINT(("ShutdownProcess::_QuitApps(%s)\n",
(systemApps ? "system" : "user"))); (systemApps ? "system" : "user")));
@@ -1453,7 +1444,7 @@ ShutdownProcess::_QuitApps(AppInfoList &list, bool systemApps)
{ {
BAutolock _(fWorkerLock); BAutolock _(fWorkerLock);
if (!list.IsEmpty()) { if (!list.IsEmpty()) {
RosterAppInfo *info = *list.It(); RosterAppInfo* info = *list.It();
team = info->team; team = info->team;
port = info->port; port = info->port;
strcpy(appName, info->ref.name); strcpy(appName, info->ref.name);
@@ -1493,7 +1484,7 @@ ShutdownProcess::_QuitApps(AppInfoList &list, bool systemApps)
// This is a system app: remove it from the list // This is a system app: remove it from the list
BAutolock _(fWorkerLock); BAutolock _(fWorkerLock);
if (RosterAppInfo *info = list.InfoFor(team)) { if (RosterAppInfo* info = list.InfoFor(team)) {
list.RemoveInfo(info); list.RemoveInfo(info);
delete info; delete info;
} }
@@ -1502,7 +1493,7 @@ ShutdownProcess::_QuitApps(AppInfoList &list, bool systemApps)
} }
} }
// _QuitBackgroundApps
void void
ShutdownProcess::_QuitBackgroundApps() ShutdownProcess::_QuitBackgroundApps()
{ {
@@ -1535,7 +1526,7 @@ ShutdownProcess::_QuitBackgroundApps()
PRINT(("ShutdownProcess::_QuitBackgroundApps() done\n")); PRINT(("ShutdownProcess::_QuitBackgroundApps() done\n"));
} }
// _WaitForBackgroundApps
void void
ShutdownProcess::_WaitForBackgroundApps() ShutdownProcess::_WaitForBackgroundApps()
{ {
@@ -1569,7 +1560,7 @@ ShutdownProcess::_WaitForBackgroundApps()
PRINT(("ShutdownProcess::_WaitForBackgroundApps() done\n")); PRINT(("ShutdownProcess::_WaitForBackgroundApps() done\n"));
} }
// _KillBackgroundApps
void void
ShutdownProcess::_KillBackgroundApps() ShutdownProcess::_KillBackgroundApps()
{ {
@@ -1590,12 +1581,12 @@ ShutdownProcess::_KillBackgroundApps()
// get the first team to kill // get the first team to kill
team_id team = -1; team_id team = -1;
char appName[B_FILE_NAME_LENGTH]; char appName[B_FILE_NAME_LENGTH];
AppInfoList &list = fBackgroundApps; AppInfoList& list = fBackgroundApps;
{ {
BAutolock _(fWorkerLock); BAutolock _(fWorkerLock);
if (!list.IsEmpty()) { if (!list.IsEmpty()) {
RosterAppInfo *info = *list.It(); RosterAppInfo* info = *list.It();
team = info->team; team = info->team;
strcpy(appName, info->ref.name); strcpy(appName, info->ref.name);
} }
@@ -1613,7 +1604,7 @@ ShutdownProcess::_KillBackgroundApps()
} }
} }
// _QuitNonApps
void void
ShutdownProcess::_QuitNonApps() ShutdownProcess::_QuitNonApps()
{ {
@@ -1661,10 +1652,10 @@ ShutdownProcess::_QuitNonApps()
PRINT(("ShutdownProcess::_QuitNonApps() done\n")); PRINT(("ShutdownProcess::_QuitNonApps() done\n"));
} }
// _QuitBlockingApp
void void
ShutdownProcess::_QuitBlockingApp(AppInfoList &list, team_id team, ShutdownProcess::_QuitBlockingApp(AppInfoList& list, team_id team,
const char *appName, bool cancelAllowed) const char* appName, bool cancelAllowed)
{ {
bool debugged = false; bool debugged = false;
bool modal = false; bool modal = false;
@@ -1737,14 +1728,14 @@ ShutdownProcess::_QuitBlockingApp(AppInfoList &list, team_id team,
{ {
BAutolock _(fWorkerLock); BAutolock _(fWorkerLock);
if (RosterAppInfo *info = list.InfoFor(team)) { if (RosterAppInfo* info = list.InfoFor(team)) {
list.RemoveInfo(info); list.RemoveInfo(info);
delete info; delete info;
} }
} }
} }
// _DisplayAbortingApp
void void
ShutdownProcess::_DisplayAbortingApp(team_id team) ShutdownProcess::_DisplayAbortingApp(team_id team)
{ {
@@ -1754,7 +1745,7 @@ ShutdownProcess::_DisplayAbortingApp(team_id team)
{ {
BAutolock _(fWorkerLock); BAutolock _(fWorkerLock);
RosterAppInfo *info = fUserApps.InfoFor(team); RosterAppInfo* info = fUserApps.InfoFor(team);
if (!info) if (!info)
info = fSystemApps.InfoFor(team); info = fSystemApps.InfoFor(team);
if (!info) if (!info)
@@ -1774,8 +1765,8 @@ ShutdownProcess::_DisplayAbortingApp(team_id team)
// compose the text to be displayed // compose the text to be displayed
char buffer[1024]; char buffer[1024];
snprintf(buffer, sizeof(buffer), "Application \"%s\" has aborted the shutdown " snprintf(buffer, sizeof(buffer), "Application \"%s\" has aborted the "
"process.", appName); "shutdown process.", appName);
// set up the window // set up the window
_SetShutdownWindowCurrentApp(team); _SetShutdownWindowCurrentApp(team);
@@ -1802,14 +1793,6 @@ ShutdownProcess::_DisplayAbortingApp(team_id team)
// stop waiting when the user hit the cancel button // stop waiting when the user hit the cancel button
if (event == ABORT_EVENT && phase == ABORTED_PHASE && eventTeam < 0) if (event == ABORT_EVENT && phase == ABORTED_PHASE && eventTeam < 0)
break; break;
// This doesn't give us anything; it will just prevent us to see which
// app was responsible after all...
#if 0
// also stop when the responsible app quit
if ((event == APP_QUIT_EVENT) && eventTeam == team)
break;
#endif
} }
} }
+68 -60
View File
@@ -9,6 +9,7 @@
#include <hash_set> #include <hash_set>
#include <Locker.h>
#include <Looper.h> #include <Looper.h>
#include "AppInfoList.h" #include "AppInfoList.h"
@@ -28,58 +29,64 @@ class TRoster;
// EventMaskWatcher fails otherwise. // EventMaskWatcher fails otherwise.
class ShutdownProcess : public BLooper, public EventMaskWatcher { class ShutdownProcess : public BLooper, public EventMaskWatcher {
public: public:
ShutdownProcess(TRoster *roster, EventQueue *eventQueue); ShutdownProcess(TRoster* roster,
~ShutdownProcess(); EventQueue* eventQueue);
virtual ~ShutdownProcess();
status_t Init(BMessage *request); status_t Init(BMessage* request);
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage* message);
static void SendReply(BMessage *request, status_t error); static void SendReply(BMessage* request, status_t error);
private: private:
void _SendReply(status_t error); 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;
status_t _ShutDown(); status_t _ShutDown();
status_t _PushEvent(uint32 eventType, team_id team, int32 phase); status_t _PushEvent(uint32 eventType, team_id team,
status_t _GetNextEvent(uint32 &eventType, team_id &team, int32 &phase, int32 phase);
bool block); status_t _GetNextEvent(uint32& eventType, team_id& team,
int32& phase, bool block);
void _SetPhase(int32 phase); void _SetPhase(int32 phase);
void _ScheduleTimeoutEvent(bigtime_t timeout, team_id team = -1); void _ScheduleTimeoutEvent(bigtime_t timeout,
team_id team = -1);
bool _LockAppLists(); bool _LockAppLists();
void _UnlockAppLists(); void _UnlockAppLists();
void _InitShutdownWindow(); void _InitShutdownWindow();
void _SetShowShutdownWindow(bool show); void _SetShowShutdownWindow(bool show);
void _AddShutdownWindowApps(AppInfoList &infos); void _AddShutdownWindowApps(AppInfoList& infos);
void _RemoveShutdownWindowApp(team_id team); void _RemoveShutdownWindowApp(team_id team);
void _SetShutdownWindowCurrentApp(team_id team); void _SetShutdownWindowCurrentApp(team_id team);
void _SetShutdownWindowText(const char *text); void _SetShutdownWindowText(const char* text);
void _SetShutdownWindowCancelButtonEnabled(bool enabled); void _SetShutdownWindowCancelButtonEnabled(
void _SetShutdownWindowKillButtonEnabled(bool enabled); bool enabled);
void _SetShutdownWindowWaitForShutdown(); void _SetShutdownWindowKillButtonEnabled(
void _SetShutdownWindowWaitForAbortedOK(); bool enabled);
void _SetShutdownWindowWaitForShutdown();
void _SetShutdownWindowWaitForAbortedOK();
static status_t _WorkerEntry(void *data); static status_t _WorkerEntry(void* data);
status_t _Worker(); status_t _Worker();
void _WorkerDoShutdown(); void _WorkerDoShutdown();
bool _WaitForApp(team_id team, AppInfoList *list, bool systemApps); bool _WaitForApp(team_id team, AppInfoList* list,
void _QuitApps(AppInfoList &list, bool systemApps); bool systemApps);
void _QuitBackgroundApps(); void _QuitApps(AppInfoList& list, bool systemApps);
void _WaitForBackgroundApps(); void _QuitBackgroundApps();
void _KillBackgroundApps(); void _WaitForBackgroundApps();
void _QuitNonApps(); void _KillBackgroundApps();
void _QuitBlockingApp(AppInfoList &list, team_id team, const char *appName, void _QuitNonApps();
bool cancelAllowed); void _QuitBlockingApp(AppInfoList& list, team_id team,
void _DisplayAbortingApp(team_id team); const char* appName, bool cancelAllowed);
void _WaitForDebuggedTeams(); void _DisplayAbortingApp(team_id team);
void _WaitForDebuggedTeams();
private: private:
class TimeoutEvent; class TimeoutEvent;
@@ -90,27 +97,28 @@ private:
friend class QuitRequestReplyHandler; friend class QuitRequestReplyHandler;
BLocker fWorkerLock; // protects fields shared by looper BLocker fWorkerLock;
// and worker // protects fields shared by looper
BMessage *fRequest; // and worker
TRoster *fRoster; BMessage* fRequest;
EventQueue *fEventQueue; TRoster* fRoster;
hash_set<team_id> fVitalSystemApps; EventQueue* fEventQueue;
AppInfoList fSystemApps; hash_set<team_id> fVitalSystemApps;
AppInfoList fUserApps; AppInfoList fSystemApps;
AppInfoList fBackgroundApps; AppInfoList fUserApps;
hash_set<team_id> fDebuggedTeams; AppInfoList fBackgroundApps;
TimeoutEvent *fTimeoutEvent; hash_set<team_id> fDebuggedTeams;
InternalEventList *fInternalEvents; TimeoutEvent* fTimeoutEvent;
sem_id fInternalEventSemaphore; InternalEventList* fInternalEvents;
QuitRequestReplyHandler *fQuitRequestReplyHandler; sem_id fInternalEventSemaphore;
thread_id fWorker; QuitRequestReplyHandler* fQuitRequestReplyHandler;
int32 fCurrentPhase; thread_id fWorker;
status_t fShutdownError; int32 fCurrentPhase;
bool fHasGUI; status_t fShutdownError;
bool fReboot; bool fHasGUI;
bool fRequestReplySent; bool fReboot;
ShutdownWindow *fWindow; bool fRequestReplySent;
ShutdownWindow* fWindow;
}; };
#endif // SHUTDOWN_PROCESS_H #endif // SHUTDOWN_PROCESS_H