2005-07-03 21:17:40 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Manages the shutdown process.
|
|
|
|
*/
|
|
|
|
#ifndef SHUTDOWN_PROCESS_H
|
|
|
|
#define SHUTDOWN_PROCESS_H
|
|
|
|
|
|
|
|
#include <hash_set>
|
|
|
|
|
|
|
|
#include <Looper.h>
|
|
|
|
|
|
|
|
#include "AppInfoList.h"
|
|
|
|
#include "EventMaskWatcher.h"
|
|
|
|
|
|
|
|
class EventQueue;
|
|
|
|
class TRoster;
|
|
|
|
|
|
|
|
// Note: EventMaskWatcher is inherited public due to a gcc bug/C++ feature:
|
|
|
|
// Once cast into a Watcher dynamic_cast<>()ing it back into an
|
|
|
|
// EventMaskWatcher fails otherwise.
|
|
|
|
class ShutdownProcess : public BLooper, public EventMaskWatcher {
|
|
|
|
public:
|
|
|
|
ShutdownProcess(TRoster *roster, EventQueue *eventQueue);
|
|
|
|
~ShutdownProcess();
|
|
|
|
|
|
|
|
status_t Init(BMessage *request);
|
|
|
|
|
|
|
|
virtual void MessageReceived(BMessage *message);
|
|
|
|
|
|
|
|
static void SendReply(BMessage *request, status_t error);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void _NegativeQuitRequestReply(thread_id thread);
|
|
|
|
|
|
|
|
void _PrepareShutdownMessage(BMessage &message) const;
|
|
|
|
status_t _ShutDown();
|
|
|
|
|
|
|
|
status_t _PushEvent(uint32 eventType, team_id team, int32 phase);
|
|
|
|
status_t _GetNextEvent(uint32 &eventType, team_id &team, int32 &phase,
|
|
|
|
bool block);
|
|
|
|
|
|
|
|
void _SetPhase(int32 phase);
|
|
|
|
void _ScheduleTimeoutEvent(bigtime_t timeout, team_id team = -1);
|
|
|
|
|
|
|
|
bool _LockAppLists();
|
|
|
|
void _UnlockAppLists();
|
|
|
|
|
2005-07-06 14:29:42 +04:00
|
|
|
void _InitShutdownWindow();
|
|
|
|
void _SetShowShutdownWindow(bool show);
|
|
|
|
void _AddShutdownWindowApps(AppInfoList &infos);
|
|
|
|
void _RemoveShutdownWindowApp(team_id team);
|
|
|
|
void _SetShutdownWindowCurrentApp(team_id team);
|
|
|
|
void _SetShutdownWindowText(const char *text);
|
|
|
|
void _SetShutdownWindowCancelButtonEnabled(bool enabled);
|
|
|
|
void _SetShutdownWindowKillButtonEnabled(bool enabled);
|
|
|
|
void _SetShutdownWindowWaitForShutdown();
|
|
|
|
|
2005-07-03 21:17:40 +04:00
|
|
|
static status_t _WorkerEntry(void *data);
|
|
|
|
status_t _Worker();
|
|
|
|
|
|
|
|
void _WorkerDoShutdown();
|
2005-07-06 18:28:11 +04:00
|
|
|
void _QuitApps(AppInfoList &list, bool disableCancel);
|
2005-07-03 21:17:40 +04:00
|
|
|
void _QuitNonApps();
|
|
|
|
|
|
|
|
private:
|
|
|
|
class TimeoutEvent;
|
|
|
|
class InternalEvent;
|
|
|
|
struct InternalEventList;
|
|
|
|
class QuitRequestReplyHandler;
|
2005-07-06 14:29:42 +04:00
|
|
|
class ShutdownWindow;
|
2005-07-03 21:17:40 +04:00
|
|
|
|
|
|
|
friend class QuitRequestReplyHandler;
|
|
|
|
|
|
|
|
BLocker fWorkerLock; // protects fields shared by looper
|
|
|
|
// and worker
|
|
|
|
BMessage *fRequest;
|
|
|
|
TRoster *fRoster;
|
|
|
|
EventQueue *fEventQueue;
|
|
|
|
hash_set<team_id> fVitalSystemApps;
|
|
|
|
AppInfoList fSystemApps;
|
|
|
|
AppInfoList fUserApps;
|
|
|
|
TimeoutEvent *fTimeoutEvent;
|
|
|
|
InternalEventList *fInternalEvents;
|
|
|
|
sem_id fInternalEventSemaphore;
|
|
|
|
QuitRequestReplyHandler *fQuitRequestReplyHandler;
|
|
|
|
thread_id fWorker;
|
|
|
|
int32 fCurrentPhase;
|
|
|
|
status_t fShutdownError;
|
|
|
|
bool fHasGUI;
|
2005-07-06 14:29:42 +04:00
|
|
|
ShutdownWindow *fWindow;
|
2005-07-03 21:17:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SHUTDOWN_PROCESS_H
|