xref: /haiku/headers/os/app/Roster.h (revision e6b30aee0fd7a23d6a6baab9f3718945a0cd838a)
1 /*
2  * Copyright 2001-2007, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold (bonefish@users.sf.net)
7  */
8 #ifndef _ROSTER_H
9 #define _ROSTER_H
10 
11 
12 #include <Entry.h>
13 #include <Messenger.h>
14 #include <OS.h>
15 
16 class BFile;
17 class BMimeType;
18 class BNodeInfo;
19 
20 
21 struct app_info {
22 	app_info();
23 	~app_info();
24 
25 	thread_id	thread;
26 	team_id		team;
27 	port_id		port;
28 	uint32		flags;
29 	entry_ref	ref;
30 	char		signature[B_MIME_TYPE_LENGTH];
31 };
32 
33 // app flags
34 #define B_SINGLE_LAUNCH			(0x0)
35 #define B_MULTIPLE_LAUNCH		(0x1)
36 #define B_EXCLUSIVE_LAUNCH		(0x2)
37 #define B_LAUNCH_MASK			(0x3)
38 #define B_BACKGROUND_APP		(0x4)
39 #define B_ARGV_ONLY				(0x8)
40 #define _B_APP_INFO_RESERVED1_	(0x10000000)
41 
42 // watching request flags
43 enum {
44 	B_REQUEST_LAUNCHED	= 0x00000001,
45 	B_REQUEST_QUIT		= 0x00000002,
46 	B_REQUEST_ACTIVATED	= 0x00000004,
47 };
48 
49 // notification message "what"
50 enum {
51 	B_SOME_APP_LAUNCHED		= 'BRAS',
52 	B_SOME_APP_QUIT			= 'BRAQ',
53 	B_SOME_APP_ACTIVATED	= 'BRAW',
54 };
55 
56 class BList;
57 
58 
59 class BRoster {
60 	public:
61 		BRoster();
62 		~BRoster();
63 
64 		// running apps
65 		bool IsRunning(const char *mimeSig) const;
66 		bool IsRunning(entry_ref *ref) const;
67 		team_id TeamFor(const char *mimeSig) const;
68 		team_id TeamFor(entry_ref *ref) const;
69 		void GetAppList(BList *teamIDList) const;
70 		void GetAppList(const char *sig, BList *teamIDList) const;
71 
72 		// app infos
73 		status_t GetAppInfo(const char *sig, app_info *info) const;
74 		status_t GetAppInfo(entry_ref *ref, app_info *info) const;
75 		status_t GetRunningAppInfo(team_id team, app_info *info) const;
76 		status_t GetActiveAppInfo(app_info *info) const;
77 
78 		// find app
79 		status_t FindApp(const char *mimeType, entry_ref *app) const;
80 		status_t FindApp(entry_ref *ref, entry_ref *app) const;
81 
82 		// broadcast
83 		status_t Broadcast(BMessage *message) const;
84 		status_t Broadcast(BMessage *message, BMessenger replyTo) const;
85 
86 		// watching
87 		status_t StartWatching(BMessenger target,
88 					uint32 eventMask = B_REQUEST_LAUNCHED | B_REQUEST_QUIT) const;
89 		status_t StopWatching(BMessenger target) const;
90 
91 		status_t ActivateApp(team_id team) const;
92 
93 		// launch app
94 		status_t Launch(const char *mimeType, BMessage *initialMessage = 0,
95 					team_id *appTeam = 0) const;
96 		status_t Launch(const char *mimeType, BList *messageList,
97 					team_id *appTeam = 0) const;
98 		status_t Launch(const char *mimeType, int argc, char **args,
99 					team_id *appTeam = 0) const;
100 		status_t Launch(const entry_ref *ref, const BMessage *initialMessage = 0,
101 					team_id *appTeam = 0) const;
102 		status_t Launch(const entry_ref *ref, const BList *messageList,
103 					team_id *appTeam = 0) const;
104 		status_t Launch(const entry_ref *ref, int argc, const char * const *args,
105 					team_id *appTeam = 0) const;
106 
107 		// recent documents, folders, apps
108 		void GetRecentDocuments(BMessage *refList, int32 maxCount,
109 					const char *fileType = 0,
110 					const char *appSig = 0) const;
111 		void GetRecentDocuments(BMessage *refList, int32 maxCount,
112 					const char *fileTypes[], int32 fileTypesCount,
113 					const char *appSig = 0) const;
114 		void GetRecentFolders(BMessage *refList, int32 maxCount,
115 					const char *appSig = 0) const;
116 		void GetRecentApps(BMessage *refList, int32 maxCount) const;
117 		void AddToRecentDocuments(const entry_ref *doc,
118 					const char *appSig = 0) const;
119 		void AddToRecentFolders(const entry_ref *folder,
120 					const char *appSig = 0) const;
121 
122 		// private/reserved stuff starts here
123 		class Private;
124 
125 	private:
126 		class ArgVector;
127 		friend class Private;
128 
129 		status_t _ShutDown(bool reboot, bool confirm, bool synchronous);
130 
131 		status_t _AddApplication(const char *mimeSig, const entry_ref *ref,
132 					uint32 flags, team_id team, thread_id thread,
133 					port_id port, bool fullReg, uint32 *pToken,
134 					team_id *otherTeam) const;
135 		status_t _SetSignature(team_id team, const char *mimeSig) const;
136 		void _SetThread(team_id team, thread_id thread) const;
137 		status_t _SetThreadAndTeam(uint32 entryToken, thread_id thread,
138 					team_id team) const;
139 		status_t _CompleteRegistration(team_id team, thread_id thread,
140 					port_id port) const;
141 		bool _IsAppPreRegistered(const entry_ref *ref, team_id team,
142 					app_info *info) const;
143 		status_t _IsAppRegistered(const entry_ref *ref, team_id team,
144 					uint32 token, bool *preRegistered, app_info *info) const;
145 		status_t _RemovePreRegApp(uint32 entryToken) const;
146 		status_t _RemoveApp(team_id team) const;
147 		void _ApplicationCrashed(team_id team);
148 
149 		status_t _LaunchApp(const char *mimeType, const entry_ref *ref,
150 					const BList *messageList, int argc,
151 					const char *const *args,
152 					team_id *appTeam) const;
153 		status_t _UpdateActiveApp(team_id team) const;
154 		void _SetAppFlags(team_id team, uint32 flags) const;
155 		void _DumpRoster() const;
156 		status_t _ResolveApp(const char *inType, entry_ref *ref, entry_ref *appRef,
157 					char *appSig, uint32 *appFlags,
158 					bool *wasDocument) const;
159 		status_t _TranslateRef(entry_ref *ref, BMimeType *appMeta,
160 					entry_ref *appRef, BFile *appFile,
161 					bool *wasDocument) const;
162 		status_t _TranslateType(const char *mimeType, BMimeType *appMeta,
163 					entry_ref *appRef, BFile *appFile) const;
164 		status_t _SniffFile(const entry_ref *file, BNodeInfo *nodeInfo,
165 					char *mimeType) const;
166 		status_t _SendToRunning(team_id team, int argc, const char *const *args,
167 					const BList *messageList, const entry_ref *ref,
168 					bool readyToRun) const;
169 		void _InitMessengers();
170 		void _AddToRecentApps(const char *appSig) const;
171 		void _ClearRecentDocuments() const;
172 		void _ClearRecentFolders() const;
173 		void _ClearRecentApps() const;
174 		void _LoadRecentLists(const char *filename) const;
175 		void _SaveRecentLists(const char *filename) const;
176 
177 		BMessenger	fMessenger;
178 		BMessenger	fMimeMessenger;
179 		uint32		_reserved[3];
180 };
181 
182 // global BRoster instance
183 extern const BRoster *be_roster;
184 
185 #endif	// _ROSTER_H
186