xref: /haiku/headers/os/app/Roster.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
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 #ifndef _ROSTER_H
30 #define _ROSTER_H
31 
32 #include <Entry.h>
33 #include <Messenger.h>
34 #include <OS.h>
35 
36 // app_info
37 struct app_info {
38 	app_info();
39 	~app_info();
40 
41 	thread_id	thread;
42 	team_id		team;
43 	port_id		port;
44 	uint32		flags;
45 	entry_ref	ref;
46 	char		signature[B_MIME_TYPE_LENGTH];
47 };
48 
49 // app flags
50 #define B_SINGLE_LAUNCH			(0x0)
51 #define B_MULTIPLE_LAUNCH		(0x1)
52 #define B_EXCLUSIVE_LAUNCH		(0x2)
53 #define B_LAUNCH_MASK			(0x3)
54 #define B_BACKGROUND_APP		(0x4)
55 #define B_ARGV_ONLY				(0x8)
56 #define _B_APP_INFO_RESERVED1_	(0x10000000)
57 
58 // watching request flags
59 enum {
60 	B_REQUEST_LAUNCHED	= 0x00000001,
61 	B_REQUEST_QUIT		= 0x00000002,
62 	B_REQUEST_ACTIVATED	= 0x00000004,
63 };
64 
65 // notification message "what"
66 enum {
67 	B_SOME_APP_LAUNCHED		= 'BRAS',
68 	B_SOME_APP_QUIT			= 'BRAQ',
69 	B_SOME_APP_ACTIVATED	= 'BRAW',
70 };
71 
72 class BList;
73 
74 // BRoster
75 class BRoster {
76 public:
77 	BRoster();
78 	~BRoster();
79 
80 	// running apps
81 	bool IsRunning(const char *mimeSig) const;
82 	bool IsRunning(entry_ref *ref) const;
83 	team_id TeamFor(const char *mimeSig) const;
84 	team_id TeamFor(entry_ref *ref) const;
85 	void GetAppList(BList *teamIDList) const;
86 	void GetAppList(const char *sig, BList *teamIDList) const;
87 
88 	// app infos
89 	status_t GetAppInfo(const char *sig, app_info *info) const;
90 	status_t GetAppInfo(entry_ref *ref, app_info *info) const;
91 	status_t GetRunningAppInfo(team_id team, app_info *info) const;
92 	status_t GetActiveAppInfo(app_info *info) const;
93 
94 	// find app
95 	status_t FindApp(const char *mimeType, entry_ref *app) const;
96 	status_t FindApp(entry_ref *ref, entry_ref *app) const;
97 
98 	// broadcast
99 	status_t Broadcast(BMessage *message) const;
100 	status_t Broadcast(BMessage *message, BMessenger replyTo) const;
101 
102 	// watching
103 	status_t StartWatching(BMessenger target,
104 						   uint32 eventMask = B_REQUEST_LAUNCHED
105 											  | B_REQUEST_QUIT) const;
106 	status_t StopWatching(BMessenger target) const;
107 
108 	status_t ActivateApp(team_id team) const;
109 
110 	// launch app
111 	status_t Launch(const char *mimeType, BMessage *initialMessage = 0,
112 					team_id *appTeam = 0) const;
113 	status_t Launch(const char *mimeType, BList *messageList,
114 					team_id *appTeam = 0) const;
115 	status_t Launch(const char *mimeType, int argc, char **args,
116 					team_id *appTeam = 0) const;
117 	status_t Launch(const entry_ref *ref, const BMessage *initialMessage = 0,
118 					team_id *appTeam = 0) const;
119 	status_t Launch(const entry_ref *ref, const BList *messageList,
120 					team_id *appTeam = 0) const;
121 	status_t Launch(const entry_ref *ref, int argc, const char * const *args,
122 					team_id *appTeam = 0) const;
123 
124 	// recent documents, folders, apps
125 	void GetRecentDocuments(BMessage *refList, int32 maxCount,
126 							const char *fileType = 0,
127 							const char *appSig = 0) const;
128 	void GetRecentDocuments(BMessage *refList, int32 maxCount,
129 							const char *fileTypes[], int32 fileTypesCount,
130 							const char *appSig = 0) const;
131 	void GetRecentFolders(BMessage *refList, int32 maxCount,
132 						  const char *appSig = 0) const;
133 	void GetRecentApps(BMessage *refList, int32 maxCount) const;
134 	void AddToRecentDocuments(const entry_ref *doc,
135 							  const char *appSig = 0) const;
136 	void AddToRecentFolders(const entry_ref *folder,
137 							const char *appSig = 0) const;
138 
139 	// private/reserved stuff starts here
140 	class Private;
141 
142 private:
143 	class ArgVector;
144 	friend class Private;
145 
146 	status_t AddApplication(const char *mimeSig, const entry_ref *ref,
147 							uint32 flags, team_id team, thread_id thread,
148 							port_id port, bool fullReg, uint32 *pToken,
149 							team_id *otherTeam) const;
150 	status_t SetSignature(team_id team, const char *mimeSig) const;
151 	void SetThread(team_id team, thread_id thread) const;
152 	status_t SetThreadAndTeam(uint32 entryToken, thread_id thread,
153 							  team_id team) const;
154 	status_t CompleteRegistration(team_id team, thread_id thread,
155 								  port_id port) const;
156 	bool IsAppPreRegistered(const entry_ref *ref, team_id team,
157 							app_info *info) const;
158 	status_t RemovePreRegApp(uint32 entryToken) const;
159 	status_t RemoveApp(team_id team) const;
160 	status_t xLaunchAppPrivate(const char *mimeType, const entry_ref *ref,
161 							   const BList *messageList, int argc,
162 							   const char *const *args,
163 							   team_id *appTeam) const;
164 	bool UpdateActiveApp(team_id team) const;
165 	void SetAppFlags(team_id team, uint32 flags) const;
166 	void DumpRoster() const;
167 	status_t resolve_app(const char *inType, entry_ref *ref, entry_ref *appRef,
168 						 char *appSig, uint32 *appFlags,
169 						 bool *wasDocument) const;
170 	status_t translate_ref(entry_ref *ref, BMimeType *appMeta,
171 						   entry_ref *appRef, BFile *appFile,
172 						   bool *wasDocument) const;
173 	status_t translate_type(const char *mimeType, BMimeType *appMeta,
174 							entry_ref *appRef, BFile *appFile) const;
175 	status_t sniff_file(const entry_ref *file, BNodeInfo *nodeInfo,
176 						char *mimeType) const;
177 	status_t send_to_running(team_id team, int argc, const char *const *args,
178 							 const BList *messageList, const entry_ref *ref,
179 							 bool readyToRun) const;
180 	void InitMessengers();
181 	void AddToRecentApps(const char *appSig) const;
182 	void ClearRecentDocuments() const;
183 	void ClearRecentFolders() const;
184 	void ClearRecentApps() const;
185 	void LoadRecentLists(const char *filename) const;
186 	void SaveRecentLists(const char *filename) const;
187 
188 	BMessenger	fMess;
189 	BMessenger	fMimeMess;
190 	uint32		_reserved[3];
191 };
192 
193 // global BRoster instance
194 extern const BRoster *be_roster;
195 
196 #endif	// _ROSTER_H
197