xref: /haiku/src/servers/registrar/TRoster.h (revision 1fe24d0cd0b547a771c00f6fca8f50ba6ca2fb2c)
1 /*
2  * Copyright 2001-2007, Ingo Weinhold, bonefish@users.sf.net.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef T_ROSTER_H
6 #define T_ROSTER_H
7 
8 
9 #include "AppInfoList.h"
10 #include "RecentApps.h"
11 #include "RecentEntries.h"
12 #include "WatchingService.h"
13 
14 #include <Locker.h>
15 #include <MessageQueue.h>
16 #include <Path.h>
17 #include <Roster.h>
18 #include <SupportDefs.h>
19 
20 #include <hash_set>
21 #include <map>
22 
23 
24 #if __GNUC__ >= 4
25 using __gnu_cxx::hash_set;
26 #endif
27 
28 using std::map;
29 
30 class BMessage;
31 class WatchingService;
32 
33 typedef map<int32, BMessageQueue*>	IARRequestMap;
34 
35 class TRoster {
36 public:
37 							TRoster();
38 	virtual					~TRoster();
39 
40 			void			HandleAddApplication(BMessage* request);
41 			void			HandleCompleteRegistration(BMessage* request);
42 			void			HandleIsAppRegistered(BMessage* request);
43 			void			HandleRemovePreRegApp(BMessage* request);
44 			void			HandleRemoveApp(BMessage* request);
45 			void			HandleSetThreadAndTeam(BMessage* request);
46 			void			HandleSetSignature(BMessage* request);
47 			void			HandleGetAppInfo(BMessage* request);
48 			void			HandleGetAppList(BMessage* request);
49 			void			HandleUpdateActiveApp(BMessage* request);
50 			void			HandleBroadcast(BMessage* request);
51 			void			HandleStartWatching(BMessage* request);
52 			void			HandleStopWatching(BMessage* request);
53 			void			HandleGetRecentDocuments(BMessage* request);
54 			void			HandleGetRecentFolders(BMessage* request);
55 			void			HandleGetRecentApps(BMessage* request);
56 			void			HandleAddToRecentDocuments(BMessage* request);
57 			void			HandleAddToRecentFolders(BMessage* request);
58 			void			HandleAddToRecentApps(BMessage* request);
59 			void			HandleLoadRecentLists(BMessage* request);
60 			void			HandleSaveRecentLists(BMessage* request);
61 
62 			void			ClearRecentDocuments();
63 			void			ClearRecentFolders();
64 			void			ClearRecentApps();
65 
66 			status_t		Init();
67 
68 			status_t		AddApp(RosterAppInfo* info);
69 			void			RemoveApp(RosterAppInfo* info);
70 			void			UpdateActiveApp(RosterAppInfo* info);
71 
72 			void			CheckSanity();
73 
74 			void			SetShuttingDown(bool shuttingDown);
75 			status_t		GetShutdownApps(AppInfoList& userApps,
76 								AppInfoList& systemApps,
77 								AppInfoList& backgroundApps,
78 								hash_set<team_id>& vitalSystemApps);
79 
80 			status_t		AddWatcher(Watcher* watcher);
81 			void			RemoveWatcher(Watcher* watcher);
82 
83 private:
84 	// hook functions
85 			void			_AppAdded(RosterAppInfo* info);
86 			void			_AppRemoved(RosterAppInfo* info);
87 			void			_AppActivated(RosterAppInfo* info);
88 			void			_AppDeactivated(RosterAppInfo* info);
89 
90 	// helper functions
91 	static	status_t		_AddMessageAppInfo(BMessage* message,
92 								const app_info* info);
93 	static	status_t		_AddMessageWatchingInfo(BMessage* message,
94 								const app_info* info);
95 			uint32			_NextToken();
96 
97 			void			_AddIARRequest(IARRequestMap& map, int32 key,
98 								BMessage* request);
99 			void			_ReplyToIARRequests(BMessageQueue* requests,
100 								const RosterAppInfo* info);
101 			void			_ReplyToIARRequest(BMessage* request,
102 								const RosterAppInfo* info);
103 
104 			void			_HandleGetRecentEntries(BMessage* request);
105 
106 			void			_ValidateRunning(const entry_ref& ref,
107 								const char* signature);
108 			bool			_IsSystemApp(RosterAppInfo* info) const;
109 
110 			status_t		_LoadRosterSettings(const char* path = NULL);
111 			status_t		_SaveRosterSettings(const char* path = NULL);
112 	static	const char*		kDefaultRosterSettingsFile;
113 
114 private:
115 			BLocker			fLock;
116 			AppInfoList		fRegisteredApps;
117 			AppInfoList		fEarlyPreRegisteredApps;
118 			IARRequestMap	fIARRequestsByID;
119 			IARRequestMap	fIARRequestsByToken;
120 			RosterAppInfo*	fActiveApp;
121 			WatchingService	fWatchingService;
122 			RecentApps		fRecentApps;
123 			RecentEntries	fRecentDocuments;
124 			RecentEntries	fRecentFolders;
125 			uint32			fLastToken;
126 			bool			fShuttingDown;
127 			BPath			fSystemAppPath;
128 			BPath			fSystemServerPath;
129 };
130 
131 #endif	// T_ROSTER_H
132