vfs: check userland buffers before reading them.
[haiku.git] / headers / build / os / app / Roster.h
blob25f40d9b5a2f414c3d3721468e27627678ece997
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:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
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.
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
32 #include <Entry.h>
33 #include <Messenger.h>
34 #include <OS.h>
36 // app_info
37 struct app_info {
38 app_info();
39 ~app_info();
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];
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)
58 // watching request flags
59 enum {
60 B_REQUEST_LAUNCHED = 0x00000001,
61 B_REQUEST_QUIT = 0x00000002,
62 B_REQUEST_ACTIVATED = 0x00000004,
65 // notification message "what"
66 enum {
67 B_SOME_APP_LAUNCHED = 'BRAS',
68 B_SOME_APP_QUIT = 'BRAQ',
69 B_SOME_APP_ACTIVATED = 'BRAW',
72 class BFile;
73 class BList;
74 class BMimeType;
75 class BNodeInfo;
77 // BRoster
78 class BRoster {
79 public:
80 BRoster();
81 ~BRoster();
83 // running apps
84 bool IsRunning(const char *mimeSig) const;
85 bool IsRunning(entry_ref *ref) const;
86 team_id TeamFor(const char *mimeSig) const;
87 team_id TeamFor(entry_ref *ref) const;
88 void GetAppList(BList *teamIDList) const;
89 void GetAppList(const char *sig, BList *teamIDList) const;
91 // app infos
92 status_t GetAppInfo(const char *sig, app_info *info) const;
93 status_t GetAppInfo(entry_ref *ref, app_info *info) const;
94 status_t GetRunningAppInfo(team_id team, app_info *info) const;
95 status_t GetActiveAppInfo(app_info *info) const;
97 // find app
98 status_t FindApp(const char *mimeType, entry_ref *app) const;
99 status_t FindApp(entry_ref *ref, entry_ref *app) const;
101 // broadcast
102 status_t Broadcast(BMessage *message) const;
103 status_t Broadcast(BMessage *message, BMessenger replyTo) const;
105 // watching
106 status_t StartWatching(BMessenger target,
107 uint32 eventMask = B_REQUEST_LAUNCHED
108 | B_REQUEST_QUIT) const;
109 status_t StopWatching(BMessenger target) const;
111 status_t ActivateApp(team_id team) const;
113 // launch app
114 status_t Launch(const char *mimeType, BMessage *initialMessage = 0,
115 team_id *appTeam = 0) const;
116 status_t Launch(const char *mimeType, BList *messageList,
117 team_id *appTeam = 0) const;
118 status_t Launch(const char *mimeType, int argc, char **args,
119 team_id *appTeam = 0) const;
120 status_t Launch(const entry_ref *ref, const BMessage *initialMessage = 0,
121 team_id *appTeam = 0) const;
122 status_t Launch(const entry_ref *ref, const BList *messageList,
123 team_id *appTeam = 0) const;
124 status_t Launch(const entry_ref *ref, int argc, const char * const *args,
125 team_id *appTeam = 0) const;
127 // recent documents, folders, apps
128 void GetRecentDocuments(BMessage *refList, int32 maxCount,
129 const char *fileType = 0,
130 const char *appSig = 0) const;
131 void GetRecentDocuments(BMessage *refList, int32 maxCount,
132 const char *fileTypes[], int32 fileTypesCount,
133 const char *appSig = 0) const;
134 void GetRecentFolders(BMessage *refList, int32 maxCount,
135 const char *appSig = 0) const;
136 void GetRecentApps(BMessage *refList, int32 maxCount) const;
137 void AddToRecentDocuments(const entry_ref *doc,
138 const char *appSig = 0) const;
139 void AddToRecentFolders(const entry_ref *folder,
140 const char *appSig = 0) const;
142 // private/reserved stuff starts here
143 class Private;
145 private:
146 class ArgVector;
147 friend class Private;
149 status_t ShutDown(bool reboot, bool confirm, bool synchronous);
151 status_t AddApplication(const char *mimeSig, const entry_ref *ref,
152 uint32 flags, team_id team, thread_id thread,
153 port_id port, bool fullReg, uint32 *pToken,
154 team_id *otherTeam) const;
155 status_t SetSignature(team_id team, const char *mimeSig) const;
156 void SetThread(team_id team, thread_id thread) const;
157 status_t SetThreadAndTeam(uint32 entryToken, thread_id thread,
158 team_id team) const;
159 status_t CompleteRegistration(team_id team, thread_id thread,
160 port_id port) const;
161 bool IsAppPreRegistered(const entry_ref *ref, team_id team,
162 app_info *info) const;
163 status_t RemovePreRegApp(uint32 entryToken) const;
164 status_t RemoveApp(team_id team) const;
165 status_t xLaunchAppPrivate(const char *mimeType, const entry_ref *ref,
166 const BList *messageList, int argc,
167 const char *const *args,
168 team_id *appTeam) const;
169 bool UpdateActiveApp(team_id team) const;
170 void SetAppFlags(team_id team, uint32 flags) const;
171 void DumpRoster() const;
172 status_t resolve_app(const char *inType, entry_ref *ref, entry_ref *appRef,
173 char *appSig, uint32 *appFlags,
174 bool *wasDocument) const;
175 status_t translate_ref(entry_ref *ref, BMimeType *appMeta,
176 entry_ref *appRef, BFile *appFile,
177 bool *wasDocument) const;
178 status_t translate_type(const char *mimeType, BMimeType *appMeta,
179 entry_ref *appRef, BFile *appFile) const;
180 status_t sniff_file(const entry_ref *file, BNodeInfo *nodeInfo,
181 char *mimeType) const;
182 status_t send_to_running(team_id team, int argc, const char *const *args,
183 const BList *messageList, const entry_ref *ref,
184 bool readyToRun) const;
185 void InitMessengers();
186 void AddToRecentApps(const char *appSig) const;
187 void ClearRecentDocuments() const;
188 void ClearRecentFolders() const;
189 void ClearRecentApps() const;
190 void LoadRecentLists(const char *filename) const;
191 void SaveRecentLists(const char *filename) const;
193 BMessenger fMess;
194 BMessenger fMimeMess;
195 uint32 _reserved[3];
198 // global BRoster instance
199 extern const BRoster *be_roster;
201 #endif // _ROSTER_H