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