1 /* 2 * Copyright 2001-2015 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _ROSTER_H 6 #define _ROSTER_H 7 8 9 #include <Entry.h> 10 #include <Messenger.h> 11 #include <OS.h> 12 13 class BFile; 14 class BMimeType; 15 class BNodeInfo; 16 17 18 struct app_info { 19 app_info(); 20 ~app_info(); 21 22 thread_id thread; 23 team_id team; 24 port_id port; 25 uint32 flags; 26 entry_ref ref; 27 char signature[B_MIME_TYPE_LENGTH]; 28 }; 29 30 // app flags 31 #define B_SINGLE_LAUNCH (0x0) 32 #define B_MULTIPLE_LAUNCH (0x1) 33 #define B_EXCLUSIVE_LAUNCH (0x2) 34 #define B_LAUNCH_MASK (0x3) 35 #define B_BACKGROUND_APP (0x4) 36 #define B_ARGV_ONLY (0x8) 37 #define _B_APP_INFO_RESERVED1_ (0x10000000) 38 39 // watching request flags 40 enum watching_request_flags { 41 B_REQUEST_LAUNCHED = 0x00000001, 42 B_REQUEST_QUIT = 0x00000002, 43 B_REQUEST_ACTIVATED = 0x00000004, 44 }; 45 46 // notification message "what" 47 enum { 48 B_SOME_APP_LAUNCHED = 'BRAS', 49 B_SOME_APP_QUIT = 'BRAQ', 50 B_SOME_APP_ACTIVATED = 'BRAW', 51 }; 52 53 class BList; 54 55 56 class BRoster { 57 public: 58 BRoster(); 59 ~BRoster(); 60 61 // running apps 62 bool IsRunning(const char* signature) const; 63 bool IsRunning(entry_ref* ref) const; 64 65 team_id TeamFor(const char* signature) const; 66 team_id TeamFor(entry_ref* ref) const; 67 68 void GetAppList(BList* teamIDList) const; 69 void GetAppList(const char* signature, 70 BList* teamIDList) const; 71 72 // app infos 73 status_t GetAppInfo(const char* signature, 74 app_info* info) const; 75 status_t GetAppInfo(entry_ref* ref, 76 app_info* info) const; 77 78 status_t GetRunningAppInfo(team_id team, 79 app_info* info) const; 80 status_t GetActiveAppInfo(app_info* info) const; 81 82 // find app 83 status_t FindApp(const char* mimeType, 84 entry_ref* app) const; 85 status_t FindApp(entry_ref* ref, entry_ref* app) const; 86 87 // broadcast 88 status_t Broadcast(BMessage* message) const; 89 status_t Broadcast(BMessage* message, 90 BMessenger replyTo) const; 91 92 // watching 93 status_t StartWatching(BMessenger target, 94 uint32 eventMask 95 = B_REQUEST_LAUNCHED 96 | B_REQUEST_QUIT) const; 97 status_t StopWatching(BMessenger target) const; 98 99 status_t ActivateApp(team_id team) const; 100 101 // launch app 102 status_t Launch(const char* mimeType, 103 BMessage* initialMessage = NULL, 104 team_id* _appTeam = NULL) const; 105 status_t Launch(const char* mimeType, BList* messageList, 106 team_id* _appTeam = NULL) const; 107 status_t Launch(const char* mimeType, int argc, 108 const char* const* args, 109 team_id* _appTeam = NULL) const; 110 status_t Launch(const entry_ref* ref, 111 const BMessage* initialMessage = NULL, 112 team_id* _appTeam = NULL) const; 113 status_t Launch(const entry_ref* ref, 114 const BList* messageList, 115 team_id* _appTeam = NULL) const; 116 status_t Launch(const entry_ref* ref, int argc, 117 const char* const* args, 118 team_id* _appTeam = NULL) const; 119 120 // recent documents, folders, apps 121 void GetRecentDocuments(BMessage* refList, 122 int32 maxCount, const char* fileType = NULL, 123 const char* signature = NULL) const; 124 void GetRecentDocuments(BMessage* refList, 125 int32 maxCount, const char* fileTypes[], 126 int32 fileTypesCount, 127 const char* signature = NULL) const; 128 129 void GetRecentFolders(BMessage* refList, 130 int32 maxCount, 131 const char* signature = NULL) const; 132 133 void GetRecentApps(BMessage* refList, 134 int32 maxCount) const; 135 136 void AddToRecentDocuments(const entry_ref* document, 137 const char* signature = NULL) const; 138 void AddToRecentFolders(const entry_ref* folder, 139 const char* signature = NULL) const; 140 141 // private/reserved stuff starts here 142 class Private; 143 144 private: 145 class ArgVector; 146 friend class Private; 147 148 status_t _ShutDown(bool reboot, bool confirm, 149 bool synchronous); 150 status_t _IsShutDownInProgress(bool* inProgress); 151 152 status_t _AddApplication(const char* signature, 153 const entry_ref* ref, uint32 flags, 154 team_id team, thread_id thread, 155 port_id port, bool fullRegistration, 156 uint32* pToken, team_id* otherTeam) const; 157 158 status_t _SetSignature(team_id team, 159 const char* signature) const; 160 161 void _SetThread(team_id team, 162 thread_id thread) const; 163 164 status_t _SetThreadAndTeam(uint32 entryToken, 165 thread_id thread, team_id team, 166 port_id* _port) const; 167 168 status_t _CompleteRegistration(team_id team, 169 thread_id thread, port_id port) const; 170 171 bool _IsAppPreRegistered(const entry_ref* ref, 172 team_id team, app_info* info) const; 173 174 status_t _IsAppRegistered(const entry_ref* ref, 175 team_id team, uint32 token, 176 bool* preRegistered, app_info* info) const; 177 178 status_t _RemovePreRegApp(uint32 entryToken) const; 179 status_t _RemoveApp(team_id team) const; 180 181 void _ApplicationCrashed(team_id team); 182 183 status_t _LaunchApp(const char* mimeType, 184 const entry_ref* ref, 185 const BList* messageList, int argc, 186 const char* const* args, 187 const char** environment, 188 team_id* _appTeam, thread_id* _appThread, 189 port_id* _appPort, uint32* _appToken, 190 bool launchSuspended) const; 191 192 status_t _UpdateActiveApp(team_id team) const; 193 194 void _SetAppFlags(team_id team, uint32 flags) const; 195 196 void _DumpRoster() const; 197 198 status_t _ResolveApp(const char* inType, entry_ref* ref, 199 entry_ref* appRef, 200 char* signature, 201 uint32* appFlags, 202 bool* wasDocument) const; 203 204 status_t _TranslateRef(entry_ref* ref, 205 BMimeType* appMeta, entry_ref* appRef, 206 BFile* appFile, bool* wasDocument) const; 207 208 status_t _TranslateType(const char* mimeType, 209 BMimeType* appMeta, entry_ref* appRef, 210 BFile* appFile) const; 211 212 status_t _GetFileType(const entry_ref* file, 213 BNodeInfo* nodeInfo, char* mimeType) const; 214 status_t _SendToRunning(team_id team, int argc, 215 const char* const* args, 216 const BList* messageList, 217 const entry_ref* ref, 218 bool readyToRun) const; 219 220 void _SetWithoutRegistrar(bool noRegistrar); 221 222 void _InitMessenger(); 223 224 static status_t _InitMimeMessenger(void* data); 225 226 BMessenger& _MimeMessenger(); 227 228 void _AddToRecentApps(const char* signature) const; 229 230 void _ClearRecentDocuments() const; 231 void _ClearRecentFolders() const; 232 void _ClearRecentApps() const; 233 void _LoadRecentLists(const char* filename) const; 234 void _SaveRecentLists(const char* filename) const; 235 236 BMessenger fMessenger; 237 BMessenger fMimeMessenger; 238 int32 fMimeMessengerInitOnce; 239 bool fNoRegistrar; 240 uint32 _reserved[1]; 241 }; 242 243 // global BRoster instance 244 extern const BRoster* be_roster; 245 246 247 #endif // _ROSTER_H 248