xref: /haiku/src/servers/registrar/TRoster.h (revision 55b40aa53a835472ec7952b138ae4256203d02e4)
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 <MessageQueue.h>
36 #include <SupportDefs.h>
37 
38 #include "AppInfoList.h"
39 #include "RecentApps.h"
40 #include "RecentEntries.h"
41 #include "WatchingService.h"
42 
43 #if __GNUC__ >= 4
44 using __gnu_cxx::hash_set;
45 #endif
46 
47 using std::map;
48 
49 class BMessage;
50 class WatchingService;
51 
52 typedef map<int32, BMessageQueue*>	IARRequestMap;
53 
54 class TRoster {
55 public:
56 	TRoster();
57 	virtual ~TRoster();
58 
59 	void HandleAddApplication(BMessage *request);
60 	void HandleCompleteRegistration(BMessage *request);
61 	void HandleIsAppRegistered(BMessage *request);
62 	void HandleRemovePreRegApp(BMessage *request);
63 	void HandleRemoveApp(BMessage *request);
64 	void HandleSetThreadAndTeam(BMessage *request);
65 	void HandleSetSignature(BMessage *request);
66 	void HandleGetAppInfo(BMessage *request);
67 	void HandleGetAppList(BMessage *request);
68 	void HandleActivateApp(BMessage *request);
69 	void HandleBroadcast(BMessage *request);
70 	void HandleStartWatching(BMessage *request);
71 	void HandleStopWatching(BMessage *request);
72 	void HandleGetRecentDocuments(BMessage *request);
73 	void HandleGetRecentFolders(BMessage *request);
74 	void HandleGetRecentApps(BMessage *request);
75 	void HandleAddToRecentDocuments(BMessage *request);
76 	void HandleAddToRecentFolders(BMessage *request);
77 	void HandleAddToRecentApps(BMessage *request);
78 	void HandleLoadRecentLists(BMessage *request);
79 	void HandleSaveRecentLists(BMessage *request);
80 
81 	void ClearRecentDocuments();
82 	void ClearRecentFolders();
83 	void ClearRecentApps();
84 
85 	status_t Init();
86 
87 	status_t AddApp(RosterAppInfo *info);
88 	void RemoveApp(RosterAppInfo *info);
89 	void ActivateApp(RosterAppInfo *info);
90 
91 	void CheckSanity();
92 
93 	void SetShuttingDown(bool shuttingDown);
94 	status_t GetShutdownApps(AppInfoList &userApps, AppInfoList &systemApps,
95 		AppInfoList &backgroundApps, hash_set<team_id> &vitalSystemApps);
96 
97 	status_t AddWatcher(Watcher *watcher);
98 	void RemoveWatcher(Watcher *watcher);
99 
100 private:
101 	// hook functions
102 	void _AppAdded(RosterAppInfo *info);
103 	void _AppRemoved(RosterAppInfo *info);
104 	void _AppActivated(RosterAppInfo *info);
105 	void _AppDeactivated(RosterAppInfo *info);
106 
107 	// helper functions
108 	static status_t _AddMessageAppInfo(BMessage *message,
109 									   const app_info *info);
110 	static status_t _AddMessageWatchingInfo(BMessage *message,
111 											const app_info *info);
112 	uint32 _NextToken();
113 
114 	void _AddIARRequest(IARRequestMap& map, int32 key, BMessage* request);
115 	void _ReplyToIARRequests(BMessageQueue *requests,
116 		const RosterAppInfo *info);
117 	void _ReplyToIARRequest(BMessage *request, const RosterAppInfo *info);
118 
119 	void _HandleGetRecentEntries(BMessage *request);
120 
121 	bool _IsSystemApp(RosterAppInfo *info) const;
122 
123 	status_t _LoadRosterSettings(const char *path = NULL);
124 	status_t _SaveRosterSettings(const char *path = NULL);
125 	static const char *kDefaultRosterSettingsFile;
126 
127 private:
128 	BLocker			fLock;
129 	AppInfoList		fRegisteredApps;
130 	AppInfoList		fEarlyPreRegisteredApps;
131 	IARRequestMap	fIARRequestsByID;
132 	IARRequestMap	fIARRequestsByToken;
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