xref: /haiku/src/servers/registrar/TRoster.h (revision 6bfd06d1ff129f4db4445b978fa3ee9257f239c9)
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>
35*6bfd06d1SIngo Weinhold #include <MessageQueue.h>
36f9fd58ccSIngo Weinhold #include <SupportDefs.h>
37f9fd58ccSIngo Weinhold 
38f9fd58ccSIngo Weinhold #include "AppInfoList.h"
39230719b5STyler Dauwalder #include "RecentApps.h"
40fde0f1b8STyler Dauwalder #include "RecentEntries.h"
417a0335c8SIngo Weinhold #include "WatchingService.h"
42f9fd58ccSIngo Weinhold 
43758b1d0eSIngo Weinhold #if __GNUC__ >= 4
44758b1d0eSIngo Weinhold using __gnu_cxx::hash_set;
45758b1d0eSIngo Weinhold #endif
46758b1d0eSIngo Weinhold 
47758b1d0eSIngo Weinhold using std::map;
48758b1d0eSIngo Weinhold 
49f9fd58ccSIngo Weinhold class BMessage;
507a0335c8SIngo Weinhold class WatchingService;
51f9fd58ccSIngo Weinhold 
52*6bfd06d1SIngo Weinhold typedef map<int32, BMessageQueue*>	IARRequestMap;
531d32138dSIngo Weinhold 
54f9fd58ccSIngo Weinhold class TRoster {
55f9fd58ccSIngo Weinhold public:
56f9fd58ccSIngo Weinhold 	TRoster();
57f9fd58ccSIngo Weinhold 	virtual ~TRoster();
58f9fd58ccSIngo Weinhold 
591d32138dSIngo Weinhold 	void HandleAddApplication(BMessage *request);
601d32138dSIngo Weinhold 	void HandleCompleteRegistration(BMessage *request);
61*6bfd06d1SIngo Weinhold 	void HandleIsAppRegistered(BMessage *request);
621d32138dSIngo Weinhold 	void HandleRemovePreRegApp(BMessage *request);
631d32138dSIngo Weinhold 	void HandleRemoveApp(BMessage *request);
641d32138dSIngo Weinhold 	void HandleSetThreadAndTeam(BMessage *request);
65af8eec40SIngo Weinhold 	void HandleSetSignature(BMessage *request);
66a12aef2bSIngo Weinhold 	void HandleGetAppInfo(BMessage *request);
67a12aef2bSIngo Weinhold 	void HandleGetAppList(BMessage *request);
68a12aef2bSIngo Weinhold 	void HandleActivateApp(BMessage *request);
6956d4d637SIngo Weinhold 	void HandleBroadcast(BMessage *request);
707a0335c8SIngo Weinhold 	void HandleStartWatching(BMessage *request);
717a0335c8SIngo Weinhold 	void HandleStopWatching(BMessage *request);
72230719b5STyler Dauwalder 	void HandleGetRecentDocuments(BMessage *request);
73230719b5STyler Dauwalder 	void HandleGetRecentFolders(BMessage *request);
74230719b5STyler Dauwalder 	void HandleGetRecentApps(BMessage *request);
75230719b5STyler Dauwalder 	void HandleAddToRecentDocuments(BMessage *request);
76230719b5STyler Dauwalder 	void HandleAddToRecentFolders(BMessage *request);
77230719b5STyler Dauwalder 	void HandleAddToRecentApps(BMessage *request);
781bde02aeSTyler Dauwalder 	void HandleLoadRecentLists(BMessage *request);
791bde02aeSTyler Dauwalder 	void HandleSaveRecentLists(BMessage *request);
801bde02aeSTyler Dauwalder 
811bde02aeSTyler Dauwalder 	void ClearRecentDocuments();
821bde02aeSTyler Dauwalder 	void ClearRecentFolders();
831bde02aeSTyler Dauwalder 	void ClearRecentApps();
84a12aef2bSIngo Weinhold 
855e949b7dSIngo Weinhold 	status_t Init();
865e949b7dSIngo Weinhold 
87a12aef2bSIngo Weinhold 	status_t AddApp(RosterAppInfo *info);
88a12aef2bSIngo Weinhold 	void RemoveApp(RosterAppInfo *info);
89a12aef2bSIngo Weinhold 	void ActivateApp(RosterAppInfo *info);
90f9fd58ccSIngo Weinhold 
91b48b6fb5SIngo Weinhold 	void CheckSanity();
92b48b6fb5SIngo Weinhold 
93553ea301SIngo Weinhold 	void SetShuttingDown(bool shuttingDown);
94553ea301SIngo Weinhold 	status_t GetShutdownApps(AppInfoList &userApps, AppInfoList &systemApps,
956b454d97SIngo Weinhold 		AppInfoList &backgroundApps, hash_set<team_id> &vitalSystemApps);
96553ea301SIngo Weinhold 
97553ea301SIngo Weinhold 	status_t AddWatcher(Watcher *watcher);
98553ea301SIngo Weinhold 	void RemoveWatcher(Watcher *watcher);
99553ea301SIngo Weinhold 
100f9fd58ccSIngo Weinhold private:
101a12aef2bSIngo Weinhold 	// hook functions
102a12aef2bSIngo Weinhold 	void _AppAdded(RosterAppInfo *info);
103a12aef2bSIngo Weinhold 	void _AppRemoved(RosterAppInfo *info);
104a12aef2bSIngo Weinhold 	void _AppActivated(RosterAppInfo *info);
105a12aef2bSIngo Weinhold 	void _AppDeactivated(RosterAppInfo *info);
106a12aef2bSIngo Weinhold 
107a12aef2bSIngo Weinhold 	// helper functions
1081d32138dSIngo Weinhold 	static status_t _AddMessageAppInfo(BMessage *message,
1091d32138dSIngo Weinhold 									   const app_info *info);
1107a0335c8SIngo Weinhold 	static status_t _AddMessageWatchingInfo(BMessage *message,
1117a0335c8SIngo Weinhold 											const app_info *info);
1121d32138dSIngo Weinhold 	uint32 _NextToken();
113*6bfd06d1SIngo Weinhold 
114*6bfd06d1SIngo Weinhold 	void _AddIARRequest(IARRequestMap& map, int32 key, BMessage* request);
115*6bfd06d1SIngo Weinhold 	void _ReplyToIARRequests(BMessageQueue *requests,
116*6bfd06d1SIngo Weinhold 		const RosterAppInfo *info);
117*6bfd06d1SIngo Weinhold 	void _ReplyToIARRequest(BMessage *request, const RosterAppInfo *info);
1181d32138dSIngo Weinhold 
119fde0f1b8STyler Dauwalder 	void _HandleGetRecentEntries(BMessage *request);
120fde0f1b8STyler Dauwalder 
121553ea301SIngo Weinhold 	bool _IsSystemApp(RosterAppInfo *info) const;
122553ea301SIngo Weinhold 
1234f03f5d2STyler Dauwalder 	status_t _LoadRosterSettings(const char *path = NULL);
1244f03f5d2STyler Dauwalder 	status_t _SaveRosterSettings(const char *path = NULL);
1254f03f5d2STyler Dauwalder 	static const char *kDefaultRosterSettingsFile;
1264f03f5d2STyler Dauwalder 
1271d32138dSIngo Weinhold private:
128553ea301SIngo Weinhold 	BLocker			fLock;
1291d32138dSIngo Weinhold 	AppInfoList		fRegisteredApps;
1301d32138dSIngo Weinhold 	AppInfoList		fEarlyPreRegisteredApps;
131*6bfd06d1SIngo Weinhold 	IARRequestMap	fIARRequestsByID;
132*6bfd06d1SIngo Weinhold 	IARRequestMap	fIARRequestsByToken;
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