xref: /haiku/src/servers/registrar/TRoster.h (revision 758b1d0e05fe1042cce6e00d194a147802d4f9be)
1f9fd58ccSIngo Weinhold //------------------------------------------------------------------------------
2f9fd58ccSIngo Weinhold //	Copyright (c) 2001-2002, OpenBeOS
3f9fd58ccSIngo Weinhold //
4f9fd58ccSIngo Weinhold //	Permission is hereby granted, free of charge, to any person obtaining a
5f9fd58ccSIngo Weinhold //	copy of this software and associated documentation files (the "Software"),
6f9fd58ccSIngo Weinhold //	to deal in the Software without restriction, including without limitation
7f9fd58ccSIngo Weinhold //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8f9fd58ccSIngo Weinhold //	and/or sell copies of the Software, and to permit persons to whom the
9f9fd58ccSIngo Weinhold //	Software is furnished to do so, subject to the following conditions:
10f9fd58ccSIngo Weinhold //
11f9fd58ccSIngo Weinhold //	The above copyright notice and this permission notice shall be included in
12f9fd58ccSIngo Weinhold //	all copies or substantial portions of the Software.
13f9fd58ccSIngo Weinhold //
14f9fd58ccSIngo Weinhold //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15f9fd58ccSIngo Weinhold //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16f9fd58ccSIngo Weinhold //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17f9fd58ccSIngo Weinhold //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18f9fd58ccSIngo Weinhold //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19f9fd58ccSIngo Weinhold //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20f9fd58ccSIngo Weinhold //	DEALINGS IN THE SOFTWARE.
21f9fd58ccSIngo Weinhold //
22f9fd58ccSIngo Weinhold //	File Name:		TRoster.h
23f9fd58ccSIngo Weinhold //	Author:			Ingo Weinhold (bonefish@users.sf.net)
24f9fd58ccSIngo Weinhold //	Description:	TRoster is the incarnation of The Roster. It manages the
25f9fd58ccSIngo Weinhold //					running applications.
26f9fd58ccSIngo Weinhold //------------------------------------------------------------------------------
27f9fd58ccSIngo Weinhold 
28f9fd58ccSIngo Weinhold #ifndef T_ROSTER_H
29f9fd58ccSIngo Weinhold #define T_ROSTER_H
30f9fd58ccSIngo Weinhold 
31553ea301SIngo Weinhold #include <hash_set>
321d32138dSIngo Weinhold #include <map>
331d32138dSIngo Weinhold 
34553ea301SIngo Weinhold #include <Locker.h>
35f9fd58ccSIngo Weinhold #include <SupportDefs.h>
36f9fd58ccSIngo Weinhold 
37f9fd58ccSIngo Weinhold #include "AppInfoList.h"
38230719b5STyler Dauwalder #include "RecentApps.h"
39fde0f1b8STyler Dauwalder #include "RecentEntries.h"
407a0335c8SIngo Weinhold #include "WatchingService.h"
41f9fd58ccSIngo Weinhold 
42*758b1d0eSIngo Weinhold #if __GNUC__ >= 4
43*758b1d0eSIngo Weinhold using __gnu_cxx::hash_set;
44*758b1d0eSIngo Weinhold #endif
45*758b1d0eSIngo Weinhold 
46*758b1d0eSIngo Weinhold using std::map;
47*758b1d0eSIngo Weinhold 
48f9fd58ccSIngo Weinhold class BMessage;
497a0335c8SIngo Weinhold class WatchingService;
50f9fd58ccSIngo Weinhold 
511d32138dSIngo Weinhold struct IAPRRequest {
521d32138dSIngo Weinhold 	entry_ref	ref;
531d32138dSIngo Weinhold 	team_id		team;
541d32138dSIngo Weinhold 	BMessage	*request;
551d32138dSIngo Weinhold };
561d32138dSIngo Weinhold 
571d32138dSIngo Weinhold typedef map<team_id, IAPRRequest>	IAPRRequestMap;
581d32138dSIngo Weinhold 
59f9fd58ccSIngo Weinhold class TRoster {
60f9fd58ccSIngo Weinhold public:
61f9fd58ccSIngo Weinhold 	TRoster();
62f9fd58ccSIngo Weinhold 	virtual ~TRoster();
63f9fd58ccSIngo Weinhold 
641d32138dSIngo Weinhold 	void HandleAddApplication(BMessage *request);
651d32138dSIngo Weinhold 	void HandleCompleteRegistration(BMessage *request);
661d32138dSIngo Weinhold 	void HandleIsAppPreRegistered(BMessage *request);
671d32138dSIngo Weinhold 	void HandleRemovePreRegApp(BMessage *request);
681d32138dSIngo Weinhold 	void HandleRemoveApp(BMessage *request);
691d32138dSIngo Weinhold 	void HandleSetThreadAndTeam(BMessage *request);
70af8eec40SIngo Weinhold 	void HandleSetSignature(BMessage *request);
71a12aef2bSIngo Weinhold 	void HandleGetAppInfo(BMessage *request);
72a12aef2bSIngo Weinhold 	void HandleGetAppList(BMessage *request);
73a12aef2bSIngo Weinhold 	void HandleActivateApp(BMessage *request);
7456d4d637SIngo Weinhold 	void HandleBroadcast(BMessage *request);
757a0335c8SIngo Weinhold 	void HandleStartWatching(BMessage *request);
767a0335c8SIngo Weinhold 	void HandleStopWatching(BMessage *request);
77230719b5STyler Dauwalder 	void HandleGetRecentDocuments(BMessage *request);
78230719b5STyler Dauwalder 	void HandleGetRecentFolders(BMessage *request);
79230719b5STyler Dauwalder 	void HandleGetRecentApps(BMessage *request);
80230719b5STyler Dauwalder 	void HandleAddToRecentDocuments(BMessage *request);
81230719b5STyler Dauwalder 	void HandleAddToRecentFolders(BMessage *request);
82230719b5STyler Dauwalder 	void HandleAddToRecentApps(BMessage *request);
831bde02aeSTyler Dauwalder 	void HandleLoadRecentLists(BMessage *request);
841bde02aeSTyler Dauwalder 	void HandleSaveRecentLists(BMessage *request);
851bde02aeSTyler Dauwalder 
861bde02aeSTyler Dauwalder 	void ClearRecentDocuments();
871bde02aeSTyler Dauwalder 	void ClearRecentFolders();
881bde02aeSTyler Dauwalder 	void ClearRecentApps();
89a12aef2bSIngo Weinhold 
905e949b7dSIngo Weinhold 	status_t Init();
915e949b7dSIngo Weinhold 
92a12aef2bSIngo Weinhold 	status_t AddApp(RosterAppInfo *info);
93a12aef2bSIngo Weinhold 	void RemoveApp(RosterAppInfo *info);
94a12aef2bSIngo Weinhold 	void ActivateApp(RosterAppInfo *info);
95f9fd58ccSIngo Weinhold 
96b48b6fb5SIngo Weinhold 	void CheckSanity();
97b48b6fb5SIngo Weinhold 
98553ea301SIngo Weinhold 	void SetShuttingDown(bool shuttingDown);
99553ea301SIngo Weinhold 	status_t GetShutdownApps(AppInfoList &userApps, AppInfoList &systemApps,
1006b454d97SIngo Weinhold 		AppInfoList &backgroundApps, hash_set<team_id> &vitalSystemApps);
101553ea301SIngo Weinhold 
102553ea301SIngo Weinhold 	status_t AddWatcher(Watcher *watcher);
103553ea301SIngo Weinhold 	void RemoveWatcher(Watcher *watcher);
104553ea301SIngo Weinhold 
105f9fd58ccSIngo Weinhold private:
106a12aef2bSIngo Weinhold 	// hook functions
107a12aef2bSIngo Weinhold 	void _AppAdded(RosterAppInfo *info);
108a12aef2bSIngo Weinhold 	void _AppRemoved(RosterAppInfo *info);
109a12aef2bSIngo Weinhold 	void _AppActivated(RosterAppInfo *info);
110a12aef2bSIngo Weinhold 	void _AppDeactivated(RosterAppInfo *info);
111a12aef2bSIngo Weinhold 
112a12aef2bSIngo Weinhold 	// helper functions
1131d32138dSIngo Weinhold 	static status_t _AddMessageAppInfo(BMessage *message,
1141d32138dSIngo Weinhold 									   const app_info *info);
1157a0335c8SIngo Weinhold 	static status_t _AddMessageWatchingInfo(BMessage *message,
1167a0335c8SIngo Weinhold 											const app_info *info);
1171d32138dSIngo Weinhold 	uint32 _NextToken();
1181d32138dSIngo Weinhold 	void _ReplyToIAPRRequest(BMessage *request, const RosterAppInfo *info);
1191d32138dSIngo Weinhold 
120fde0f1b8STyler Dauwalder 	void _HandleGetRecentEntries(BMessage *request);
121fde0f1b8STyler Dauwalder 
122553ea301SIngo Weinhold 	bool _IsSystemApp(RosterAppInfo *info) const;
123553ea301SIngo Weinhold 
1244f03f5d2STyler Dauwalder 	status_t _LoadRosterSettings(const char *path = NULL);
1254f03f5d2STyler Dauwalder 	status_t _SaveRosterSettings(const char *path = NULL);
1264f03f5d2STyler Dauwalder 	static const char *kDefaultRosterSettingsFile;
1274f03f5d2STyler Dauwalder 
1281d32138dSIngo Weinhold private:
129553ea301SIngo Weinhold 	BLocker			fLock;
1301d32138dSIngo Weinhold 	AppInfoList		fRegisteredApps;
1311d32138dSIngo Weinhold 	AppInfoList		fEarlyPreRegisteredApps;
1321d32138dSIngo Weinhold 	IAPRRequestMap	fIAPRRequests;
133a12aef2bSIngo Weinhold 	RosterAppInfo	*fActiveApp;
1347a0335c8SIngo Weinhold 	WatchingService	fWatchingService;
135230719b5STyler Dauwalder 	RecentApps		fRecentApps;
136fde0f1b8STyler Dauwalder 	RecentEntries	fRecentDocuments;
137fde0f1b8STyler Dauwalder 	RecentEntries	fRecentFolders;
1381d32138dSIngo Weinhold 	uint32			fLastToken;
139553ea301SIngo Weinhold 	bool			fShuttingDown;
140f9fd58ccSIngo Weinhold };
141f9fd58ccSIngo Weinhold 
142f9fd58ccSIngo Weinhold #endif	// T_ROSTER_H
143