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 { 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 151 status_t _AddApplication(const char* signature, 152 const entry_ref* ref, uint32 flags, 153 team_id team, thread_id thread, 154 port_id port, bool fullRegistration, 155 uint32* pToken, team_id* otherTeam) const; 156 157 status_t _SetSignature(team_id team, 158 const char* signature) const; 159 160 void _SetThread(team_id team, 161 thread_id thread) const; 162 163 status_t _SetThreadAndTeam(uint32 entryToken, 164 thread_id thread, team_id team) const; 165 166 status_t _CompleteRegistration(team_id team, 167 thread_id thread, port_id port) const; 168 169 bool _IsAppPreRegistered(const entry_ref* ref, 170 team_id team, app_info* info) const; 171 172 status_t _IsAppRegistered(const entry_ref* ref, 173 team_id team, uint32 token, 174 bool* preRegistered, app_info* info) const; 175 176 status_t _RemovePreRegApp(uint32 entryToken) const; 177 status_t _RemoveApp(team_id team) const; 178 179 void _ApplicationCrashed(team_id team); 180 181 status_t _LaunchApp(const char* mimeType, 182 const entry_ref* ref, 183 const BList* messageList, int argc, 184 const char* const* args, 185 team_id* appTeam) const; 186 187 status_t _UpdateActiveApp(team_id team) const; 188 189 void _SetAppFlags(team_id team, uint32 flags) const; 190 191 void _DumpRoster() const; 192 193 status_t _ResolveApp(const char* inType, entry_ref* ref, 194 entry_ref* appRef, 195 char* signature, 196 uint32* appFlags, 197 bool* wasDocument) const; 198 199 status_t _TranslateRef(entry_ref* ref, 200 BMimeType* appMeta, entry_ref* appRef, 201 BFile* appFile, bool* wasDocument) const; 202 203 status_t _TranslateType(const char* mimeType, 204 BMimeType* appMeta, entry_ref* appRef, 205 BFile* appFile) const; 206 207 status_t _GetFileType(const entry_ref* file, 208 BNodeInfo* nodeInfo, char* mimeType) const; 209 status_t _SendToRunning(team_id team, int argc, 210 const char* const* args, 211 const BList* messageList, 212 const entry_ref* ref, 213 bool readyToRun) const; 214 215 void _InitMessenger(); 216 217 static status_t _InitMimeMessenger(void* data); 218 219 BMessenger& _MimeMessenger(); 220 221 void _AddToRecentApps(const char* signature) const; 222 223 void _ClearRecentDocuments() const; 224 void _ClearRecentFolders() const; 225 void _ClearRecentApps() const; 226 void _LoadRecentLists(const char* filename) const; 227 void _SaveRecentLists(const char* filename) const; 228 229 BMessenger fMessenger; 230 BMessenger fMimeMessenger; 231 int32 fMimeMessengerInitOnce; 232 uint32 _reserved[2]; 233 }; 234 235 // global BRoster instance 236 extern const BRoster* be_roster; 237 238 239 #endif // _ROSTER_H 240