1 /* 2 * Copyright 2001-2014 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 char* *args, team_id* appTeam = NULL) const; 109 status_t Launch(const entry_ref* ref, 110 const BMessage* initialMessage = NULL, 111 team_id* appTeam = NULL) const; 112 status_t Launch(const entry_ref* ref, 113 const BList* messageList, 114 team_id* appTeam = NULL) const; 115 status_t Launch(const entry_ref* ref, int argc, 116 const char* const* args, 117 team_id* appTeam = NULL) const; 118 119 // recent documents, folders, apps 120 void GetRecentDocuments(BMessage* refList, 121 int32 maxCount, const char* fileType = NULL, 122 const char* signature = NULL) const; 123 void GetRecentDocuments(BMessage* refList, 124 int32 maxCount, const char* fileTypes[], 125 int32 fileTypesCount, 126 const char* signature = NULL) const; 127 128 void GetRecentFolders(BMessage* refList, 129 int32 maxCount, 130 const char* signature = NULL) const; 131 132 void GetRecentApps(BMessage* refList, 133 int32 maxCount) const; 134 135 void AddToRecentDocuments(const entry_ref* document, 136 const char* signature = NULL) const; 137 void AddToRecentFolders(const entry_ref* folder, 138 const char* signature = NULL) const; 139 140 // private/reserved stuff starts here 141 class Private; 142 143 private: 144 class ArgVector; 145 friend class Private; 146 147 status_t _ShutDown(bool reboot, bool confirm, 148 bool synchronous); 149 150 status_t _AddApplication(const char* signature, 151 const entry_ref* ref, uint32 flags, 152 team_id team, thread_id thread, 153 port_id port, bool fullRegistration, 154 uint32* pToken, team_id* otherTeam) const; 155 156 status_t _SetSignature(team_id team, 157 const char* signature) const; 158 159 void _SetThread(team_id team, 160 thread_id thread) const; 161 162 status_t _SetThreadAndTeam(uint32 entryToken, 163 thread_id thread, team_id team) const; 164 165 status_t _CompleteRegistration(team_id team, 166 thread_id thread, port_id port) const; 167 168 bool _IsAppPreRegistered(const entry_ref* ref, 169 team_id team, app_info* info) const; 170 171 status_t _IsAppRegistered(const entry_ref* ref, 172 team_id team, uint32 token, 173 bool* preRegistered, app_info* info) const; 174 175 status_t _RemovePreRegApp(uint32 entryToken) const; 176 status_t _RemoveApp(team_id team) const; 177 178 void _ApplicationCrashed(team_id team); 179 180 status_t _LaunchApp(const char* mimeType, 181 const entry_ref* ref, 182 const BList* messageList, int argc, 183 const char* const* args, 184 team_id* appTeam) const; 185 186 status_t _UpdateActiveApp(team_id team) const; 187 188 void _SetAppFlags(team_id team, uint32 flags) const; 189 190 void _DumpRoster() const; 191 192 status_t _ResolveApp(const char* inType, entry_ref* ref, 193 entry_ref* appRef, 194 char* signature, 195 uint32* appFlags, 196 bool* wasDocument) const; 197 198 status_t _TranslateRef(entry_ref* ref, 199 BMimeType* appMeta, entry_ref* appRef, 200 BFile* appFile, bool* wasDocument) const; 201 202 status_t _TranslateType(const char* mimeType, 203 BMimeType* appMeta, entry_ref* appRef, 204 BFile* appFile) const; 205 206 status_t _GetFileType(const entry_ref* file, 207 BNodeInfo* nodeInfo, char* mimeType) const; 208 status_t _SendToRunning(team_id team, int argc, 209 const char* const* args, 210 const BList* messageList, 211 const entry_ref* ref, 212 bool readyToRun) const; 213 214 void _InitMessenger(); 215 216 static status_t _InitMimeMessenger(void* data); 217 218 BMessenger& _MimeMessenger(); 219 220 void _AddToRecentApps(const char* signature) const; 221 222 void _ClearRecentDocuments() const; 223 void _ClearRecentFolders() const; 224 void _ClearRecentApps() const; 225 void _LoadRecentLists(const char* filename) const; 226 void _SaveRecentLists(const char* filename) const; 227 228 BMessenger fMessenger; 229 BMessenger fMimeMessenger; 230 int32 fMimeMessengerInitOnce; 231 uint32 _reserved[2]; 232 }; 233 234 // global BRoster instance 235 extern const BRoster* be_roster; 236 237 238 #endif // _ROSTER_H 239