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 class BNotification; 17 18 19 struct app_info { 20 app_info(); 21 ~app_info(); 22 23 thread_id thread; 24 team_id team; 25 port_id port; 26 uint32 flags; 27 entry_ref ref; 28 char signature[B_MIME_TYPE_LENGTH]; 29 }; 30 31 // app flags 32 #define B_SINGLE_LAUNCH (0x0) 33 #define B_MULTIPLE_LAUNCH (0x1) 34 #define B_EXCLUSIVE_LAUNCH (0x2) 35 #define B_LAUNCH_MASK (0x3) 36 #define B_BACKGROUND_APP (0x4) 37 #define B_ARGV_ONLY (0x8) 38 #define _B_APP_INFO_RESERVED1_ (0x10000000) 39 40 // watching request flags 41 enum { 42 B_REQUEST_LAUNCHED = 0x00000001, 43 B_REQUEST_QUIT = 0x00000002, 44 B_REQUEST_ACTIVATED = 0x00000004, 45 }; 46 47 // notification message "what" 48 enum { 49 B_SOME_APP_LAUNCHED = 'BRAS', 50 B_SOME_APP_QUIT = 'BRAQ', 51 B_SOME_APP_ACTIVATED = 'BRAW', 52 }; 53 54 class BList; 55 56 57 class BRoster { 58 public: 59 BRoster(); 60 ~BRoster(); 61 62 // running apps 63 bool IsRunning(const char *mimeSig) const; 64 bool IsRunning(entry_ref *ref) const; 65 team_id TeamFor(const char *mimeSig) const; 66 team_id TeamFor(entry_ref *ref) const; 67 void GetAppList(BList *teamIDList) const; 68 void GetAppList(const char *sig, BList *teamIDList) const; 69 70 // app infos 71 status_t GetAppInfo(const char *sig, app_info *info) const; 72 status_t GetAppInfo(entry_ref *ref, app_info *info) const; 73 status_t GetRunningAppInfo(team_id team, app_info *info) const; 74 status_t GetActiveAppInfo(app_info *info) const; 75 76 // find app 77 status_t FindApp(const char *mimeType, entry_ref *app) const; 78 status_t FindApp(entry_ref *ref, entry_ref *app) const; 79 80 // broadcast 81 status_t Broadcast(BMessage *message) const; 82 status_t Broadcast(BMessage *message, BMessenger replyTo) const; 83 84 // watching 85 status_t StartWatching(BMessenger target, 86 uint32 eventMask = B_REQUEST_LAUNCHED | B_REQUEST_QUIT) const; 87 status_t StopWatching(BMessenger target) const; 88 89 status_t ActivateApp(team_id team) const; 90 91 // launch app 92 status_t Launch(const char *mimeType, BMessage *initialMessage = 0, 93 team_id *appTeam = 0) const; 94 status_t Launch(const char *mimeType, BList *messageList, 95 team_id *appTeam = 0) const; 96 status_t Launch(const char *mimeType, int argc, char **args, 97 team_id *appTeam = 0) const; 98 status_t Launch(const entry_ref *ref, const BMessage *initialMessage = 0, 99 team_id *appTeam = 0) const; 100 status_t Launch(const entry_ref *ref, const BList *messageList, 101 team_id *appTeam = 0) const; 102 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 103 team_id *appTeam = 0) const; 104 105 // recent documents, folders, apps 106 void GetRecentDocuments(BMessage *refList, int32 maxCount, 107 const char *fileType = 0, 108 const char *appSig = 0) const; 109 void GetRecentDocuments(BMessage *refList, int32 maxCount, 110 const char *fileTypes[], int32 fileTypesCount, 111 const char *appSig = 0) const; 112 void GetRecentFolders(BMessage *refList, int32 maxCount, 113 const char *appSig = 0) const; 114 void GetRecentApps(BMessage *refList, int32 maxCount) const; 115 void AddToRecentDocuments(const entry_ref *doc, 116 const char *appSig = 0) const; 117 void AddToRecentFolders(const entry_ref *folder, 118 const char *appSig = 0) const; 119 120 // notifications 121 status_t Notify(const BNotification& notification, 122 bigtime_t timeout = -1) const; 123 124 // private/reserved stuff starts here 125 class Private; 126 127 private: 128 class ArgVector; 129 friend class Private; 130 131 status_t _ShutDown(bool reboot, bool confirm, bool synchronous); 132 133 status_t _AddApplication(const char *mimeSig, const entry_ref *ref, 134 uint32 flags, team_id team, thread_id thread, 135 port_id port, bool fullReg, uint32 *pToken, 136 team_id *otherTeam) const; 137 status_t _SetSignature(team_id team, const char *mimeSig) const; 138 void _SetThread(team_id team, thread_id thread) const; 139 status_t _SetThreadAndTeam(uint32 entryToken, thread_id thread, 140 team_id team) const; 141 status_t _CompleteRegistration(team_id team, thread_id thread, 142 port_id port) const; 143 bool _IsAppPreRegistered(const entry_ref *ref, team_id team, 144 app_info *info) const; 145 status_t _IsAppRegistered(const entry_ref *ref, team_id team, 146 uint32 token, bool *preRegistered, app_info *info) const; 147 status_t _RemovePreRegApp(uint32 entryToken) const; 148 status_t _RemoveApp(team_id team) const; 149 void _ApplicationCrashed(team_id team); 150 151 status_t _LaunchApp(const char *mimeType, const entry_ref *ref, 152 const BList *messageList, int argc, 153 const char *const *args, 154 team_id *appTeam) const; 155 status_t _UpdateActiveApp(team_id team) const; 156 void _SetAppFlags(team_id team, uint32 flags) const; 157 void _DumpRoster() const; 158 status_t _ResolveApp(const char *inType, entry_ref *ref, entry_ref *appRef, 159 char *appSig, uint32 *appFlags, 160 bool *wasDocument) const; 161 status_t _TranslateRef(entry_ref *ref, BMimeType *appMeta, 162 entry_ref *appRef, BFile *appFile, 163 bool *wasDocument) const; 164 status_t _TranslateType(const char *mimeType, BMimeType *appMeta, 165 entry_ref *appRef, BFile *appFile) const; 166 status_t _GetFileType(const entry_ref *file, BNodeInfo *nodeInfo, 167 char *mimeType) const; 168 status_t _SendToRunning(team_id team, int argc, const char *const *args, 169 const BList *messageList, const entry_ref *ref, 170 bool readyToRun) const; 171 void _InitMessenger(); 172 static status_t _InitMimeMessenger(void* data); 173 BMessenger& _MimeMessenger(); 174 void _AddToRecentApps(const char *appSig) const; 175 void _ClearRecentDocuments() const; 176 void _ClearRecentFolders() const; 177 void _ClearRecentApps() const; 178 void _LoadRecentLists(const char *filename) const; 179 void _SaveRecentLists(const char *filename) const; 180 181 BMessenger fMessenger; 182 BMessenger fMimeMessenger; 183 int32 fMimeMessengerInitOnce; 184 uint32 _reserved[2]; 185 }; 186 187 // global BRoster instance 188 extern const BRoster *be_roster; 189 190 #endif // _ROSTER_H 191