1c2f641f2SAxel Dörfler/*
2c2f641f2SAxel Dörfler * Copyright 2001-2007, Ingo Weinhold, bonefish@users.sf.net.
3c2f641f2SAxel Dörfler * Distributed under the terms of the MIT License.
4c2f641f2SAxel Dörfler */
5f9fd58ccSIngo Weinhold#ifndef T_ROSTER_H
6f9fd58ccSIngo Weinhold#define T_ROSTER_H
7f9fd58ccSIngo Weinhold
8f9fd58ccSIngo Weinhold
9f9fd58ccSIngo Weinhold#include "AppInfoList.h"
10230719b5STyler Dauwalder#include "RecentApps.h"
11fde0f1b8STyler Dauwalder#include "RecentEntries.h"
127a0335c8SIngo Weinhold#include "WatchingService.h"
13f9fd58ccSIngo Weinhold
14c2f641f2SAxel Dörfler#include <Locker.h>
15c2f641f2SAxel Dörfler#include <MessageQueue.h>
16323b6546SOliver Tappe#include <Path.h>
17c8e7c8efSAxel Dörfler#include <Roster.h>
18c2f641f2SAxel Dörfler#include <SupportDefs.h>
19c2f641f2SAxel Dörfler
20c2f641f2SAxel Dörfler#include <hash_set>
21c2f641f2SAxel Dörfler#include <map>
22c2f641f2SAxel Dörfler
23c2f641f2SAxel Dörfler
24758b1d0eSIngo Weinhold#if __GNUC__ >= 4
25758b1d0eSIngo Weinholdusing __gnu_cxx::hash_set;
26758b1d0eSIngo Weinhold#endif
27758b1d0eSIngo Weinhold
28758b1d0eSIngo Weinholdusing std::map;
29758b1d0eSIngo Weinhold
30f9fd58ccSIngo Weinholdclass BMessage;
317a0335c8SIngo Weinholdclass WatchingService;
32f9fd58ccSIngo Weinhold
336bfd06d1SIngo Weinholdtypedef map<int32, BMessageQueue*>	IARRequestMap;
341d32138dSIngo Weinhold
35f9fd58ccSIngo Weinholdclass TRoster {
36f9fd58ccSIngo Weinholdpublic:
37c8e7c8efSAxel Dörfler							TRoster();
38c8e7c8efSAxel Dörfler	virtual					~TRoster();
39c8e7c8efSAxel Dörfler
40c8e7c8efSAxel Dörfler			void			HandleAddApplication(BMessage* request);
41c8e7c8efSAxel Dörfler			void			HandleCompleteRegistration(BMessage* request);
42c8e7c8efSAxel Dörfler			void			HandleIsAppRegistered(BMessage* request);
43c8e7c8efSAxel Dörfler			void			HandleRemovePreRegApp(BMessage* request);
44c8e7c8efSAxel Dörfler			void			HandleRemoveApp(BMessage* request);
45c8e7c8efSAxel Dörfler			void			HandleSetThreadAndTeam(BMessage* request);
46c8e7c8efSAxel Dörfler			void			HandleSetSignature(BMessage* request);
47c8e7c8efSAxel Dörfler			void			HandleGetAppInfo(BMessage* request);
48c8e7c8efSAxel Dörfler			void			HandleGetAppList(BMessage* request);
49c8e7c8efSAxel Dörfler			void			HandleUpdateActiveApp(BMessage* request);
50c8e7c8efSAxel Dörfler			void			HandleBroadcast(BMessage* request);
51c8e7c8efSAxel Dörfler			void			HandleStartWatching(BMessage* request);
52c8e7c8efSAxel Dörfler			void			HandleStopWatching(BMessage* request);
53c8e7c8efSAxel Dörfler			void			HandleGetRecentDocuments(BMessage* request);
54c8e7c8efSAxel Dörfler			void			HandleGetRecentFolders(BMessage* request);
55c8e7c8efSAxel Dörfler			void			HandleGetRecentApps(BMessage* request);
56c8e7c8efSAxel Dörfler			void			HandleAddToRecentDocuments(BMessage* request);
57c8e7c8efSAxel Dörfler			void			HandleAddToRecentFolders(BMessage* request);
58c8e7c8efSAxel Dörfler			void			HandleAddToRecentApps(BMessage* request);
59c8e7c8efSAxel Dörfler			void			HandleLoadRecentLists(BMessage* request);
60c8e7c8efSAxel Dörfler			void			HandleSaveRecentLists(BMessage* request);
61c8e7c8efSAxel Dörfler
6204209cddSczeidler			void			HandleRestartAppServer(BMessage* request);
6304209cddSczeidler
64c8e7c8efSAxel Dörfler			void			ClearRecentDocuments();
65c8e7c8efSAxel Dörfler			void			ClearRecentFolders();
66c8e7c8efSAxel Dörfler			void			ClearRecentApps();
67c8e7c8efSAxel Dörfler
68c8e7c8efSAxel Dörfler			status_t		Init();
69c8e7c8efSAxel Dörfler
70c8e7c8efSAxel Dörfler			status_t		AddApp(RosterAppInfo* info);
71c8e7c8efSAxel Dörfler			void			RemoveApp(RosterAppInfo* info);
72c8e7c8efSAxel Dörfler			void			UpdateActiveApp(RosterAppInfo* info);
73c8e7c8efSAxel Dörfler
74c8e7c8efSAxel Dörfler			void			CheckSanity();
75c8e7c8efSAxel Dörfler
76c8e7c8efSAxel Dörfler			void			SetShuttingDown(bool shuttingDown);
77c8e7c8efSAxel Dörfler			status_t		GetShutdownApps(AppInfoList& userApps,
78c8e7c8efSAxel Dörfler								AppInfoList& systemApps,
79c8e7c8efSAxel Dörfler								AppInfoList& backgroundApps,
80c8e7c8efSAxel Dörfler								hash_set<team_id>& vitalSystemApps);
816899a856SJérôme Duval			status_t		AddAppInfo(AppInfoList& apps, team_id team);
82c8e7c8efSAxel Dörfler
83c8e7c8efSAxel Dörfler			status_t		AddWatcher(Watcher* watcher);
84c8e7c8efSAxel Dörfler			void			RemoveWatcher(Watcher* watcher);
85553ea301SIngo Weinhold
861d32138dSIngo Weinholdprivate:
87a12aef2bSIngo Weinhold	// hook functions
88c8e7c8efSAxel Dörfler			void			_AppAdded(RosterAppInfo* info);
89c8e7c8efSAxel Dörfler			void			_AppRemoved(RosterAppInfo* info);
90c8e7c8efSAxel Dörfler			void			_AppActivated(RosterAppInfo* info);
91c8e7c8efSAxel Dörfler			void			_AppDeactivated(RosterAppInfo* info);
92a12aef2bSIngo Weinhold
93a12aef2bSIngo Weinhold	// helper functions
94c8e7c8efSAxel Dörfler	static	status_t		_AddMessageAppInfo(BMessage* message,
95c8e7c8efSAxel Dörfler								const app_info* info);
96c8e7c8efSAxel Dörfler	static	status_t		_AddMessageWatchingInfo(BMessage* message,
97c8e7c8efSAxel Dörfler								const app_info* info);
98c8e7c8efSAxel Dörfler			uint32			_NextToken();
99c8e7c8efSAxel Dörfler
100c8e7c8efSAxel Dörfler			void			_AddIARRequest(IARRequestMap& map, int32 key,
101c8e7c8efSAxel Dörfler								BMessage* request);
102c8e7c8efSAxel Dörfler			void			_ReplyToIARRequests(BMessageQueue* requests,
103c8e7c8efSAxel Dörfler								const RosterAppInfo* info);
104c8e7c8efSAxel Dörfler			void			_ReplyToIARRequest(BMessage* request,
105c8e7c8efSAxel Dörfler								const RosterAppInfo* info);
106c8e7c8efSAxel Dörfler
107c8e7c8efSAxel Dörfler			void			_HandleGetRecentEntries(BMessage* request);
108c8e7c8efSAxel Dörfler
109c8e7c8efSAxel Dörfler			void			_ValidateRunning(const entry_ref& ref,
110c8e7c8efSAxel Dörfler								const char* signature);
111c8e7c8efSAxel Dörfler			bool			_IsSystemApp(RosterAppInfo* info) const;
112c8e7c8efSAxel Dörfler
113c8e7c8efSAxel Dörfler			status_t		_LoadRosterSettings(const char* path = NULL);
114c8e7c8efSAxel Dörfler			status_t		_SaveRosterSettings(const char* path = NULL);
115c8e7c8efSAxel Dörfler	static	const char*		kDefaultRosterSettingsFile;
116c8e7c8efSAxel Dörfler
117f9fd58ccSIngo Weinholdprivate:
118c8e7c8efSAxel Dörfler			BLocker			fLock;
119c8e7c8efSAxel Dörfler			AppInfoList		fRegisteredApps;
120c8e7c8efSAxel Dörfler			AppInfoList		fEarlyPreRegisteredApps;
121c8e7c8efSAxel Dörfler			IARRequestMap	fIARRequestsByID;
122c8e7c8efSAxel Dörfler			IARRequestMap	fIARRequestsByToken;
123c8e7c8efSAxel Dörfler			RosterAppInfo*	fActiveApp;
124c8e7c8efSAxel Dörfler			WatchingService	fWatchingService;
125c8e7c8efSAxel Dörfler			RecentApps		fRecentApps;
126c8e7c8efSAxel Dörfler			RecentEntries	fRecentDocuments;
127c8e7c8efSAxel Dörfler			RecentEntries	fRecentFolders;
128c8e7c8efSAxel Dörfler			uint32			fLastToken;
129c8e7c8efSAxel Dörfler			bool			fShuttingDown;
130323b6546SOliver Tappe			BPath			fSystemAppPath;
131323b6546SOliver Tappe			BPath			fSystemServerPath;
132f9fd58ccSIngo Weinhold};
133f9fd58ccSIngo Weinhold
134f9fd58ccSIngo Weinhold#endif	// T_ROSTER_H
135