xref: /haiku/src/servers/registrar/TRoster.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
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 #if __GNUC__ >= 4
43 using __gnu_cxx::hash_set;
44 #endif
45 
46 using std::map;
47 
48 class BMessage;
49 class WatchingService;
50 
51 struct IAPRRequest {
52 	entry_ref	ref;
53 	team_id		team;
54 	BMessage	*request;
55 };
56 
57 typedef map<team_id, IAPRRequest>	IAPRRequestMap;
58 
59 class TRoster {
60 public:
61 	TRoster();
62 	virtual ~TRoster();
63 
64 	void HandleAddApplication(BMessage *request);
65 	void HandleCompleteRegistration(BMessage *request);
66 	void HandleIsAppPreRegistered(BMessage *request);
67 	void HandleRemovePreRegApp(BMessage *request);
68 	void HandleRemoveApp(BMessage *request);
69 	void HandleSetThreadAndTeam(BMessage *request);
70 	void HandleSetSignature(BMessage *request);
71 	void HandleGetAppInfo(BMessage *request);
72 	void HandleGetAppList(BMessage *request);
73 	void HandleActivateApp(BMessage *request);
74 	void HandleBroadcast(BMessage *request);
75 	void HandleStartWatching(BMessage *request);
76 	void HandleStopWatching(BMessage *request);
77 	void HandleGetRecentDocuments(BMessage *request);
78 	void HandleGetRecentFolders(BMessage *request);
79 	void HandleGetRecentApps(BMessage *request);
80 	void HandleAddToRecentDocuments(BMessage *request);
81 	void HandleAddToRecentFolders(BMessage *request);
82 	void HandleAddToRecentApps(BMessage *request);
83 	void HandleLoadRecentLists(BMessage *request);
84 	void HandleSaveRecentLists(BMessage *request);
85 
86 	void ClearRecentDocuments();
87 	void ClearRecentFolders();
88 	void ClearRecentApps();
89 
90 	status_t Init();
91 
92 	status_t AddApp(RosterAppInfo *info);
93 	void RemoveApp(RosterAppInfo *info);
94 	void ActivateApp(RosterAppInfo *info);
95 
96 	void CheckSanity();
97 
98 	void SetShuttingDown(bool shuttingDown);
99 	status_t GetShutdownApps(AppInfoList &userApps, AppInfoList &systemApps,
100 		AppInfoList &backgroundApps, hash_set<team_id> &vitalSystemApps);
101 
102 	status_t AddWatcher(Watcher *watcher);
103 	void RemoveWatcher(Watcher *watcher);
104 
105 private:
106 	// hook functions
107 	void _AppAdded(RosterAppInfo *info);
108 	void _AppRemoved(RosterAppInfo *info);
109 	void _AppActivated(RosterAppInfo *info);
110 	void _AppDeactivated(RosterAppInfo *info);
111 
112 	// helper functions
113 	static status_t _AddMessageAppInfo(BMessage *message,
114 									   const app_info *info);
115 	static status_t _AddMessageWatchingInfo(BMessage *message,
116 											const app_info *info);
117 	uint32 _NextToken();
118 	void _ReplyToIAPRRequest(BMessage *request, const RosterAppInfo *info);
119 
120 	void _HandleGetRecentEntries(BMessage *request);
121 
122 	bool _IsSystemApp(RosterAppInfo *info) const;
123 
124 	status_t _LoadRosterSettings(const char *path = NULL);
125 	status_t _SaveRosterSettings(const char *path = NULL);
126 	static const char *kDefaultRosterSettingsFile;
127 
128 private:
129 	BLocker			fLock;
130 	AppInfoList		fRegisteredApps;
131 	AppInfoList		fEarlyPreRegisteredApps;
132 	IAPRRequestMap	fIAPRRequests;
133 	RosterAppInfo	*fActiveApp;
134 	WatchingService	fWatchingService;
135 	RecentApps		fRecentApps;
136 	RecentEntries	fRecentDocuments;
137 	RecentEntries	fRecentFolders;
138 	uint32			fLastToken;
139 	bool			fShuttingDown;
140 };
141 
142 #endif	// T_ROSTER_H
143