vfs: check userland buffers before reading them.
[haiku.git] / src / servers / registrar / ShutdownProcess.h
blobbc60f66999dbdae9cff5348b7c0af42a9f5205c6
1 /*
2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
5 * Manages the shutdown process.
6 */
7 #ifndef SHUTDOWN_PROCESS_H
8 #define SHUTDOWN_PROCESS_H
10 #include <hash_set>
12 #include <Locker.h>
13 #include <Looper.h>
15 #include "AppInfoList.h"
16 #include "EventMaskWatcher.h"
17 #include "RosterAppInfo.h"
19 #if __GNUC__ >= 4
20 using __gnu_cxx::hash_set;
21 #endif
24 class EventQueue;
25 class TRoster;
27 // Note: EventMaskWatcher is inherited public due to a gcc bug/C++ feature:
28 // Once cast into a Watcher dynamic_cast<>()ing it back into an
29 // EventMaskWatcher fails otherwise.
30 class ShutdownProcess : public BLooper, public EventMaskWatcher {
31 public:
32 ShutdownProcess(TRoster* roster,
33 EventQueue* eventQueue);
34 virtual ~ShutdownProcess();
36 status_t Init(BMessage* request);
38 virtual void MessageReceived(BMessage* message);
40 static void SendReply(BMessage* request, status_t error);
42 private:
43 void _SendReply(status_t error);
45 void _NegativeQuitRequestReply(thread_id thread);
47 void _PrepareShutdownMessage(BMessage& message) const;
48 status_t _ShutDown();
50 status_t _PushEvent(uint32 eventType, team_id team,
51 int32 phase);
52 status_t _GetNextEvent(uint32& eventType, team_id& team,
53 int32& phase, bool block);
55 void _SetPhase(int32 phase);
56 void _ScheduleTimeoutEvent(bigtime_t timeout,
57 team_id team = -1);
59 bool _LockAppLists();
60 void _UnlockAppLists();
62 void _InitShutdownWindow();
63 void _SetShowShutdownWindow(bool show);
64 void _AddShutdownWindowApps(AppInfoList& infos);
65 void _RemoveShutdownWindowApp(team_id team);
66 void _SetShutdownWindowCurrentApp(team_id team);
67 void _SetShutdownWindowText(const char* text);
68 void _SetShutdownWindowCancelButtonEnabled(
69 bool enabled);
70 void _SetShutdownWindowKillButtonEnabled(
71 bool enabled);
72 void _SetShutdownWindowWaitForShutdown();
73 void _SetShutdownWindowWaitForAbortedOK();
75 static status_t _WorkerEntry(void* data);
76 status_t _Worker();
78 void _WorkerDoShutdown();
79 bool _WaitForApp(team_id team, AppInfoList* list,
80 bool systemApps);
81 void _QuitApps(AppInfoList& list, bool systemApps);
82 void _QuitBackgroundApps();
83 void _WaitForBackgroundApps();
84 void _KillBackgroundApps();
85 void _QuitNonApps();
86 void _QuitBlockingApp(AppInfoList& list, team_id team,
87 const char* appName, bool cancelAllowed);
88 void _DisplayAbortingApp(team_id team);
89 void _WaitForDebuggedTeams();
91 private:
92 class TimeoutEvent;
93 class InternalEvent;
94 struct InternalEventList;
95 class QuitRequestReplyHandler;
96 class ShutdownWindow;
98 friend class QuitRequestReplyHandler;
100 BLocker fWorkerLock;
101 // protects fields shared by looper
102 // and worker
103 BMessage* fRequest;
104 TRoster* fRoster;
105 EventQueue* fEventQueue;
106 hash_set<team_id> fVitalSystemApps;
107 AppInfoList fSystemApps;
108 AppInfoList fUserApps;
109 AppInfoList fBackgroundApps;
110 hash_set<team_id> fDebuggedTeams;
111 TimeoutEvent* fTimeoutEvent;
112 InternalEventList* fInternalEvents;
113 sem_id fInternalEventSemaphore;
114 QuitRequestReplyHandler* fQuitRequestReplyHandler;
115 thread_id fWorker;
116 int32 fCurrentPhase;
117 status_t fShutdownError;
118 bool fHasGUI;
119 bool fReboot;
120 bool fRequestReplySent;
121 ShutdownWindow* fWindow;
124 #endif // SHUTDOWN_PROCESS_H