xref: /haiku/headers/os/app/Roster.h (revision 1bd963b6c27017324c3589c8ea29d635e1552b7f)
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:		Roster.h
23 //	Author:			Ingo Weinhold (bonefish@users.sf.net)
24 //	Description:	BRoster class lets you launch apps and keeps
25 //					track of apps that are running.
26 //					Global be_roster represents the default BRoster.
27 //					app_info structure provides info for a running app.
28 //------------------------------------------------------------------------------
29 
30 #ifndef _ROSTER_H
31 #define _ROSTER_H
32 
33 #include <BeBuild.h>
34 #include <Messenger.h>
35 #include <Mime.h>
36 #include <Clipboard.h>
37 
38 class BList;
39 class BMessage;
40 class BNodeInfo;
41 
42 // TODO: relocate these private prototypes
43 extern "C" int	_init_roster_();
44 extern "C" int	_delete_roster_();
45 status_t _send_to_roster_(BMessage *message, BMessage *reply, bool mime);
46 bool _is_valid_roster_mess_(bool mime);
47 
48 namespace BPrivate {
49 	void init_registrar_roster(BMessenger mainMessenger,
50 							   BMessenger mimeMessenger);
51 }
52 
53 /*-------------------------------------------------------------*/
54 /* --------- app_info Struct and Values ------------------------ */
55 
56 struct app_info {
57 	app_info();
58 	~app_info();
59 
60 	thread_id	thread;
61 	team_id		team;
62 	port_id		port;
63 	uint32		flags;
64 	entry_ref	ref;
65 	char		signature[B_MIME_TYPE_LENGTH];
66 };
67 
68 #define B_LAUNCH_MASK				(0x3)
69 
70 #define B_SINGLE_LAUNCH				(0x0)
71 #define B_MULTIPLE_LAUNCH			(0x1)
72 #define B_EXCLUSIVE_LAUNCH			(0x2)
73 
74 #define B_BACKGROUND_APP			(0x4)
75 #define B_ARGV_ONLY					(0x8)
76 #define _B_APP_INFO_RESERVED1_		(0x10000000)
77 
78 
79 enum {
80 	B_REQUEST_LAUNCHED	= 0x00000001,
81 	B_REQUEST_QUIT		= 0x00000002,
82 	B_REQUEST_ACTIVATED	= 0x00000004
83 };
84 
85 enum {
86 	B_SOME_APP_LAUNCHED		= 'BRAS',
87 	B_SOME_APP_QUIT			= 'BRAQ',
88 	B_SOME_APP_ACTIVATED	= 'BRAW'
89 };
90 
91 /*-------------------------------------------------------------*/
92 /* --------- BRoster class----------------------------------- */
93 
94 class BRoster {
95 public:
96 	BRoster();
97 	~BRoster();
98 
99 	/* Querying for apps */
100 	bool IsRunning(const char *mimeSig) const;
101 	bool IsRunning(entry_ref *ref) const;
102 	team_id TeamFor(const char *mimeSig) const;
103 	team_id TeamFor(entry_ref *ref) const;
104 	void GetAppList(BList *teamIDList) const;
105 	void GetAppList(const char *sig, BList *teamIDList) const;
106 	status_t GetAppInfo(const char *sig, app_info *info) const;
107 	status_t GetAppInfo(entry_ref *ref, app_info *info) const;
108 	status_t GetRunningAppInfo(team_id team, app_info *info) const;
109 	status_t GetActiveAppInfo(app_info *info) const;
110 	status_t FindApp(const char *mimeType, entry_ref *app) const;
111 	status_t FindApp(entry_ref *ref, entry_ref *app) const;
112 
113 	/* Launching, activating, and broadcasting to apps */
114 	status_t Broadcast(BMessage *msg) const;
115 	status_t Broadcast(BMessage *msg, BMessenger replyTo) const;
116 	status_t StartWatching(BMessenger target,
117 		uint32 eventMask = B_REQUEST_LAUNCHED | B_REQUEST_QUIT) const;
118 	status_t StopWatching(BMessenger target) const;
119 	status_t ActivateApp(team_id team) const;
120 
121 	status_t Launch(const char *mimeType, BMessage *initialMsgs = NULL,
122 					team_id *appTeam = NULL) const;
123 	status_t Launch(const char *mimeType, BList *messageList,
124 					team_id *appTeam = NULL) const;
125 	status_t Launch(const char *mimeType, int argc, char **args,
126 					team_id *appTeam = NULL) const;
127 	status_t Launch(const entry_ref *ref,
128 					const BMessage *initialMessage = NULL,
129 					team_id *app_team = NULL) const;
130 	status_t Launch(const entry_ref *ref, const BList *messageList,
131 					team_id *appTeam = NULL) const;
132 	status_t Launch(const entry_ref *ref, int argc, const char * const *args,
133 					team_id *appTeam = NULL) const;
134 
135 	/* Recent document and app support */
136 	void GetRecentDocuments(BMessage *refList, int32 maxCount,
137 							const char *ofType = NULL,
138 							const char *openedByAppSig = NULL) const;
139 	void GetRecentDocuments(BMessage *refList, int32 maxCount,
140 							const char *ofTypeList[], int32 ofTypeListCount,
141 							const char *openedByAppSig = NULL) const;
142 	void GetRecentFolders(BMessage *refList, int32 maxCount,
143 						  const char *openedByAppSig = NULL) const;
144 	void GetRecentApps(BMessage *refList, int32 maxCount) const;
145 
146 	void AddToRecentDocuments(const entry_ref *doc,
147 							  const char *appSig = NULL) const;
148 	void AddToRecentFolders(const entry_ref *folder,
149 							const char *appSig = NULL) const;
150 
151 /*----- Private or reserved ------------------------------*/
152 private:
153 	friend class BApplication;
154 	friend class BWindow;
155 	friend class _BAppCleanup_;
156 	friend int	_init_roster_();
157 	friend status_t _send_to_roster_(BMessage *, BMessage *, bool);
158 	friend bool _is_valid_roster_mess_(bool);
159 	friend status_t BMimeType::StartWatching(BMessenger);
160 	friend status_t BMimeType::StopWatching(BMessenger);
161 	friend status_t BClipboard::StartWatching(BMessenger);
162 	friend status_t BClipboard::StopWatching(BMessenger);
163 	friend void BPrivate::init_registrar_roster(BMessenger, BMessenger);
164 
165 	enum mtarget {
166 		MAIN_MESSENGER,
167 		MIME_MESSENGER,
168 		USE_GIVEN
169 	};
170 
171 	status_t _StartWatching(mtarget target, BMessenger *rosterMess,
172 							uint32 what, BMessenger notify,
173 							uint32 event_mask) const;
174 	status_t _StopWatching(mtarget target, BMessenger *rosterMess, uint32 what,
175 						   BMessenger notify) const;
176 	status_t AddApplication(const char *mimeSig, const entry_ref *ref,
177 							uint32 flags, team_id team, thread_id thread,
178 							port_id port, bool fullReg, uint32 *token,
179 							team_id *otherTeam) const;
180 	void SetSignature(team_id team, const char *mimeSig) const;
181 	void SetThread(team_id team, thread_id thread) const;
182 	status_t SetThreadAndTeam(uint32 entryToken, thread_id thread,
183 							  team_id team) const;
184 	status_t CompleteRegistration(team_id team, thread_id thread,
185 								  port_id port) const;
186 	bool IsAppPreRegistered(const entry_ref *ref, team_id team,
187 							app_info *info) const;
188 	status_t RemovePreRegApp(uint32 entryToken) const;
189 	status_t RemoveApp(team_id team) const;
190 
191 	status_t xLaunchAppPrivate(const char *mimeSig, const entry_ref *ref,
192 							   BList* msgList, int cargs, char **args,
193 							   team_id *appTeam) const;
194 	bool UpdateActiveApp(team_id team) const;
195 	void SetAppFlags(team_id team, uint32 flags) const;
196 	void DumpRoster() const;
197 	status_t resolve_app(const char *inType, const entry_ref *ref,
198 						 entry_ref *appRef, char *appSig, uint32 *appFlags,
199 						 bool *wasDocument) const;
200 	status_t translate_ref(const entry_ref *ref, BMimeType *appMeta,
201 						   entry_ref *appRef, BFile *appFile,
202 						   bool *wasDocument) const;
203 	status_t translate_type(const char *mimeType, BMimeType *appMeta,
204 							entry_ref *appRef, BFile *appFile) const;
205 	status_t sniff_file(const entry_ref *file, BNodeInfo *nodeInfo,
206 						char *mimeType) const;
207 	bool is_wildcard(const char *sig) const;
208 	status_t get_unique_supporting_app(const BMessage *apps,
209 									   char *outSig) const;
210 	status_t get_random_supporting_app(const BMessage *apps,
211 									   char *outSig) const;
212 	char **build_arg_vector(char **args, int *pargs, const entry_ref *appRef,
213 							const entry_ref *docRef) const;
214 	status_t send_to_running(team_id team, const entry_ref *appRef,
215 							 int cargs, char **args, const BList *msgList,
216 							 const entry_ref *ref) const;
217 	void InitMessengers();
218 
219 	BMessenger	fMess;
220 	BMessenger	fMimeMess;
221 	uint32		_fReserved[3];
222 };
223 
224 /*-----------------------------------------------------*/
225 /*----- Global be_roster ------------------------------*/
226 
227 extern _IMPEXP_BE const BRoster *be_roster;
228 
229 /*-----------------------------------------------------*/
230 /*-----------------------------------------------------*/
231 
232 #endif /* _ROSTER_H */
233