1 /* 2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. 3 * Distributed under the terms of the MIT License. 4 * 5 * Manages the shutdown process. 6 */ 7 #ifndef SHUTDOWN_PROCESS_H 8 #define SHUTDOWN_PROCESS_H 9 10 #include <hash_set> 11 12 #include <Looper.h> 13 14 #include "AppInfoList.h" 15 #include "EventMaskWatcher.h" 16 17 class EventQueue; 18 class TRoster; 19 20 // Note: EventMaskWatcher is inherited public due to a gcc bug/C++ feature: 21 // Once cast into a Watcher dynamic_cast<>()ing it back into an 22 // EventMaskWatcher fails otherwise. 23 class ShutdownProcess : public BLooper, public EventMaskWatcher { 24 public: 25 ShutdownProcess(TRoster *roster, EventQueue *eventQueue); 26 ~ShutdownProcess(); 27 28 status_t Init(BMessage *request); 29 30 virtual void MessageReceived(BMessage *message); 31 32 static void SendReply(BMessage *request, status_t error); 33 34 private: 35 void _NegativeQuitRequestReply(thread_id thread); 36 37 void _PrepareShutdownMessage(BMessage &message) const; 38 status_t _ShutDown(); 39 40 status_t _PushEvent(uint32 eventType, team_id team, int32 phase); 41 status_t _GetNextEvent(uint32 &eventType, team_id &team, int32 &phase, 42 bool block); 43 44 void _SetPhase(int32 phase); 45 void _ScheduleTimeoutEvent(bigtime_t timeout, team_id team = -1); 46 47 bool _LockAppLists(); 48 void _UnlockAppLists(); 49 50 void _InitShutdownWindow(); 51 void _SetShowShutdownWindow(bool show); 52 void _AddShutdownWindowApps(AppInfoList &infos); 53 void _RemoveShutdownWindowApp(team_id team); 54 void _SetShutdownWindowCurrentApp(team_id team); 55 void _SetShutdownWindowText(const char *text); 56 void _SetShutdownWindowCancelButtonEnabled(bool enabled); 57 void _SetShutdownWindowKillButtonEnabled(bool enabled); 58 void _SetShutdownWindowWaitForShutdown(); 59 60 static status_t _WorkerEntry(void *data); 61 status_t _Worker(); 62 63 void _WorkerDoShutdown(); 64 void _QuitApps(AppInfoList &list, bool disableCancel); 65 void _QuitNonApps(); 66 67 private: 68 class TimeoutEvent; 69 class InternalEvent; 70 struct InternalEventList; 71 class QuitRequestReplyHandler; 72 class ShutdownWindow; 73 74 friend class QuitRequestReplyHandler; 75 76 BLocker fWorkerLock; // protects fields shared by looper 77 // and worker 78 BMessage *fRequest; 79 TRoster *fRoster; 80 EventQueue *fEventQueue; 81 hash_set<team_id> fVitalSystemApps; 82 AppInfoList fSystemApps; 83 AppInfoList fUserApps; 84 TimeoutEvent *fTimeoutEvent; 85 InternalEventList *fInternalEvents; 86 sem_id fInternalEventSemaphore; 87 QuitRequestReplyHandler *fQuitRequestReplyHandler; 88 thread_id fWorker; 89 int32 fCurrentPhase; 90 status_t fShutdownError; 91 bool fHasGUI; 92 ShutdownWindow *fWindow; 93 }; 94 95 #endif // SHUTDOWN_PROCESS_H 96