2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net.
3 * Distributed under the terms of the MIT License.
5 * Manages the shutdown process.
7 #ifndef SHUTDOWN_PROCESS_H
8 #define SHUTDOWN_PROCESS_H
15 #include "AppInfoList.h"
16 #include "EventMaskWatcher.h"
17 #include "RosterAppInfo.h"
20 using __gnu_cxx::hash_set
;
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
{
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
);
43 void _SendReply(status_t error
);
45 void _NegativeQuitRequestReply(thread_id thread
);
47 void _PrepareShutdownMessage(BMessage
& message
) const;
50 status_t
_PushEvent(uint32 eventType
, team_id team
,
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
,
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(
70 void _SetShutdownWindowKillButtonEnabled(
72 void _SetShutdownWindowWaitForShutdown();
73 void _SetShutdownWindowWaitForAbortedOK();
75 static status_t
_WorkerEntry(void* data
);
78 void _WorkerDoShutdown();
79 bool _WaitForApp(team_id team
, AppInfoList
* list
,
81 void _QuitApps(AppInfoList
& list
, bool systemApps
);
82 void _QuitBackgroundApps();
83 void _WaitForBackgroundApps();
84 void _KillBackgroundApps();
86 void _QuitBlockingApp(AppInfoList
& list
, team_id team
,
87 const char* appName
, bool cancelAllowed
);
88 void _DisplayAbortingApp(team_id team
);
89 void _WaitForDebuggedTeams();
94 struct InternalEventList
;
95 class QuitRequestReplyHandler
;
98 friend class QuitRequestReplyHandler
;
101 // protects fields shared by looper
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
;
117 status_t fShutdownError
;
120 bool fRequestReplySent
;
121 ShutdownWindow
* fWindow
;
124 #endif // SHUTDOWN_PROCESS_H