xref: /haiku/src/servers/registrar/TRoster.h (revision af8eec40804a3851d6820bacca1e456a14a48172)
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 <map>
32 
33 #include <SupportDefs.h>
34 
35 #include "AppInfoList.h"
36 
37 class BMessage;
38 
39 struct IAPRRequest {
40 	entry_ref	ref;
41 	team_id		team;
42 	BMessage	*request;
43 };
44 
45 typedef map<team_id, IAPRRequest>	IAPRRequestMap;
46 
47 // For strategic reasons, as TRoster appears in the BMessenger header.
48 namespace BPrivate {
49 
50 class TRoster {
51 public:
52 	TRoster();
53 	virtual ~TRoster();
54 
55 	void HandleAddApplication(BMessage *request);
56 	void HandleCompleteRegistration(BMessage *request);
57 	void HandleIsAppPreRegistered(BMessage *request);
58 	void HandleRemovePreRegApp(BMessage *request);
59 	void HandleRemoveApp(BMessage *request);
60 	void HandleSetThreadAndTeam(BMessage *request);
61 	void HandleSetSignature(BMessage *request);
62 	void HandleGetAppInfo(BMessage *request);
63 	void HandleGetAppList(BMessage *request);
64 	void HandleActivateApp(BMessage *request);
65 
66 	status_t Init();
67 
68 	status_t AddApp(RosterAppInfo *info);
69 	void RemoveApp(RosterAppInfo *info);
70 	void ActivateApp(RosterAppInfo *info);
71 
72 private:
73 	// hook functions
74 	void _AppAdded(RosterAppInfo *info);
75 	void _AppRemoved(RosterAppInfo *info);
76 	void _AppActivated(RosterAppInfo *info);
77 	void _AppDeactivated(RosterAppInfo *info);
78 
79 	// helper functions
80 	static status_t _AddMessageAppInfo(BMessage *message,
81 									   const app_info *info);
82 	uint32 _NextToken();
83 	void _ReplyToIAPRRequest(BMessage *request, const RosterAppInfo *info);
84 
85 private:
86 	AppInfoList		fRegisteredApps;
87 	AppInfoList		fEarlyPreRegisteredApps;
88 	IAPRRequestMap	fIAPRRequests;
89 	RosterAppInfo	*fActiveApp;
90 	uint32			fLastToken;
91 };
92 
93 };	// namespace BPrivate
94 
95 // Only the registrar code uses this header. No need to hide TRoster in the
96 // namespace.
97 using BPrivate::TRoster;
98 
99 #endif	// T_ROSTER_H
100