xref: /haiku/src/servers/registrar/TRoster.h (revision 29aa57037d97141c18fa70e9c037508d95a1403d)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		TRoster.h
23 //	Author:			Ingo Weinhold (bonefish@users.sf.net)
24 //	Description:	TRoster is the incarnation of The Roster. It manages the
25 //					running applications.
26 //------------------------------------------------------------------------------
27 
28 #ifndef T_ROSTER_H
29 #define T_ROSTER_H
30 
31 #include <hash_set>
32 #include <map>
33 
34 #include <Locker.h>
35 #include <SupportDefs.h>
36 
37 #include "AppInfoList.h"
38 #include "RecentApps.h"
39 #include "RecentEntries.h"
40 #include "WatchingService.h"
41 
42 class BMessage;
43 class WatchingService;
44 
45 struct IAPRRequest {
46 	entry_ref	ref;
47 	team_id		team;
48 	BMessage	*request;
49 };
50 
51 typedef map<team_id, IAPRRequest>	IAPRRequestMap;
52 
53 class TRoster {
54 public:
55 	TRoster();
56 	virtual ~TRoster();
57 
58 	void HandleAddApplication(BMessage *request);
59 	void HandleCompleteRegistration(BMessage *request);
60 	void HandleIsAppPreRegistered(BMessage *request);
61 	void HandleRemovePreRegApp(BMessage *request);
62 	void HandleRemoveApp(BMessage *request);
63 	void HandleSetThreadAndTeam(BMessage *request);
64 	void HandleSetSignature(BMessage *request);
65 	void HandleGetAppInfo(BMessage *request);
66 	void HandleGetAppList(BMessage *request);
67 	void HandleActivateApp(BMessage *request);
68 	void HandleBroadcast(BMessage *request);
69 	void HandleStartWatching(BMessage *request);
70 	void HandleStopWatching(BMessage *request);
71 	void HandleGetRecentDocuments(BMessage *request);
72 	void HandleGetRecentFolders(BMessage *request);
73 	void HandleGetRecentApps(BMessage *request);
74 	void HandleAddToRecentDocuments(BMessage *request);
75 	void HandleAddToRecentFolders(BMessage *request);
76 	void HandleAddToRecentApps(BMessage *request);
77 	void HandleLoadRecentLists(BMessage *request);
78 	void HandleSaveRecentLists(BMessage *request);
79 
80 	void ClearRecentDocuments();
81 	void ClearRecentFolders();
82 	void ClearRecentApps();
83 
84 	status_t Init();
85 
86 	status_t AddApp(RosterAppInfo *info);
87 	void RemoveApp(RosterAppInfo *info);
88 	void ActivateApp(RosterAppInfo *info);
89 
90 	void CheckSanity();
91 
92 	void SetShuttingDown(bool shuttingDown);
93 	status_t GetShutdownApps(AppInfoList &userApps, AppInfoList &systemApps,
94 		AppInfoList &backgroundApps, hash_set<team_id> &vitalSystemApps);
95 
96 	status_t AddWatcher(Watcher *watcher);
97 	void RemoveWatcher(Watcher *watcher);
98 
99 private:
100 	// hook functions
101 	void _AppAdded(RosterAppInfo *info);
102 	void _AppRemoved(RosterAppInfo *info);
103 	void _AppActivated(RosterAppInfo *info);
104 	void _AppDeactivated(RosterAppInfo *info);
105 
106 	// helper functions
107 	static status_t _AddMessageAppInfo(BMessage *message,
108 									   const app_info *info);
109 	static status_t _AddMessageWatchingInfo(BMessage *message,
110 											const app_info *info);
111 	uint32 _NextToken();
112 	void _ReplyToIAPRRequest(BMessage *request, const RosterAppInfo *info);
113 
114 	void _HandleGetRecentEntries(BMessage *request);
115 
116 	bool _IsSystemApp(RosterAppInfo *info) const;
117 
118 	status_t _LoadRosterSettings(const char *path = NULL);
119 	status_t _SaveRosterSettings(const char *path = NULL);
120 	static const char *kDefaultRosterSettingsFile;
121 
122 private:
123 	BLocker			fLock;
124 	AppInfoList		fRegisteredApps;
125 	AppInfoList		fEarlyPreRegisteredApps;
126 	IAPRRequestMap	fIAPRRequests;
127 	RosterAppInfo	*fActiveApp;
128 	WatchingService	fWatchingService;
129 	RecentApps		fRecentApps;
130 	RecentEntries	fRecentDocuments;
131 	RecentEntries	fRecentFolders;
132 	uint32			fLastToken;
133 	bool			fShuttingDown;
134 };
135 
136 #endif	// T_ROSTER_H
137