1 /* 2 * Copyright 2001-2009, Haiku, Inc. 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 *mimeSig) const; 63 bool IsRunning(entry_ref *ref) const; 64 team_id TeamFor(const char *mimeSig) const; 65 team_id TeamFor(entry_ref *ref) const; 66 void GetAppList(BList *teamIDList) const; 67 void GetAppList(const char *sig, BList *teamIDList) const; 68 69 // app infos 70 status_t GetAppInfo(const char *sig, app_info *info) const; 71 status_t GetAppInfo(entry_ref *ref, app_info *info) const; 72 status_t GetRunningAppInfo(team_id team, app_info *info) const; 73 status_t GetActiveAppInfo(app_info *info) const; 74 75 // find app 76 status_t FindApp(const char *mimeType, entry_ref *app) const; 77 status_t FindApp(entry_ref *ref, entry_ref *app) const; 78 79 // broadcast 80 status_t Broadcast(BMessage *message) const; 81 status_t Broadcast(BMessage *message, BMessenger replyTo) const; 82 83 // watching 84 status_t StartWatching(BMessenger target, 85 uint32 eventMask = B_REQUEST_LAUNCHED | B_REQUEST_QUIT) const; 86 status_t StopWatching(BMessenger target) const; 87 88 status_t ActivateApp(team_id team) const; 89 90 // launch app 91 status_t Launch(const char *mimeType, BMessage *initialMessage = 0, 92 team_id *appTeam = 0) const; 93 status_t Launch(const char *mimeType, BList *messageList, 94 team_id *appTeam = 0) const; 95 status_t Launch(const char *mimeType, int argc, char **args, 96 team_id *appTeam = 0) const; 97 status_t Launch(const entry_ref *ref, const BMessage *initialMessage = 0, 98 team_id *appTeam = 0) const; 99 status_t Launch(const entry_ref *ref, const BList *messageList, 100 team_id *appTeam = 0) const; 101 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 102 team_id *appTeam = 0) const; 103 104 // recent documents, folders, apps 105 void GetRecentDocuments(BMessage *refList, int32 maxCount, 106 const char *fileType = 0, 107 const char *appSig = 0) const; 108 void GetRecentDocuments(BMessage *refList, int32 maxCount, 109 const char *fileTypes[], int32 fileTypesCount, 110 const char *appSig = 0) const; 111 void GetRecentFolders(BMessage *refList, int32 maxCount, 112 const char *appSig = 0) const; 113 void GetRecentApps(BMessage *refList, int32 maxCount) const; 114 void AddToRecentDocuments(const entry_ref *doc, 115 const char *appSig = 0) const; 116 void AddToRecentFolders(const entry_ref *folder, 117 const char *appSig = 0) const; 118 119 // private/reserved stuff starts here 120 class Private; 121 122 private: 123 class ArgVector; 124 friend class Private; 125 126 status_t _ShutDown(bool reboot, bool confirm, bool synchronous); 127 128 status_t _AddApplication(const char *mimeSig, const entry_ref *ref, 129 uint32 flags, team_id team, thread_id thread, 130 port_id port, bool fullReg, uint32 *pToken, 131 team_id *otherTeam) const; 132 status_t _SetSignature(team_id team, const char *mimeSig) const; 133 void _SetThread(team_id team, thread_id thread) const; 134 status_t _SetThreadAndTeam(uint32 entryToken, thread_id thread, 135 team_id team) const; 136 status_t _CompleteRegistration(team_id team, thread_id thread, 137 port_id port) const; 138 bool _IsAppPreRegistered(const entry_ref *ref, team_id team, 139 app_info *info) const; 140 status_t _IsAppRegistered(const entry_ref *ref, team_id team, 141 uint32 token, bool *preRegistered, app_info *info) const; 142 status_t _RemovePreRegApp(uint32 entryToken) const; 143 status_t _RemoveApp(team_id team) const; 144 void _ApplicationCrashed(team_id team); 145 146 status_t _LaunchApp(const char *mimeType, const entry_ref *ref, 147 const BList *messageList, int argc, 148 const char *const *args, 149 team_id *appTeam) const; 150 status_t _UpdateActiveApp(team_id team) const; 151 void _SetAppFlags(team_id team, uint32 flags) const; 152 void _DumpRoster() const; 153 status_t _ResolveApp(const char *inType, entry_ref *ref, entry_ref *appRef, 154 char *appSig, uint32 *appFlags, 155 bool *wasDocument) const; 156 status_t _TranslateRef(entry_ref *ref, BMimeType *appMeta, 157 entry_ref *appRef, BFile *appFile, 158 bool *wasDocument) const; 159 status_t _TranslateType(const char *mimeType, BMimeType *appMeta, 160 entry_ref *appRef, BFile *appFile) const; 161 status_t _GetFileType(const entry_ref *file, BNodeInfo *nodeInfo, 162 char *mimeType) const; 163 status_t _SendToRunning(team_id team, int argc, const char *const *args, 164 const BList *messageList, const entry_ref *ref, 165 bool readyToRun) const; 166 void _InitMessenger(); 167 static status_t _InitMimeMessenger(void* data); 168 BMessenger& _MimeMessenger(); 169 void _AddToRecentApps(const char *appSig) const; 170 void _ClearRecentDocuments() const; 171 void _ClearRecentFolders() const; 172 void _ClearRecentApps() const; 173 void _LoadRecentLists(const char *filename) const; 174 void _SaveRecentLists(const char *filename) const; 175 176 BMessenger fMessenger; 177 BMessenger fMimeMessenger; 178 int32 fMimeMessengerInitOnce; 179 uint32 _reserved[2]; 180 }; 181 182 // global BRoster instance 183 extern const BRoster *be_roster; 184 185 #endif // _ROSTER_H 186