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