1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: Roster.h 23 // Author: Ingo Weinhold (bonefish@users.sf.net) 24 // Description: BRoster class lets you launch apps and keeps 25 // track of apps that are running. 26 // Global be_roster represents the default BRoster. 27 // app_info structure provides info for a running app. 28 //------------------------------------------------------------------------------ 29 30 #ifndef _ROSTER_H 31 #define _ROSTER_H 32 33 #include <BeBuild.h> 34 #include <Messenger.h> 35 #include <Mime.h> 36 #include <Clipboard.h> 37 38 class BList; 39 class BMessage; 40 class BNodeInfo; 41 42 /*-------------------------------------------------------------*/ 43 /* --------- app_info Struct and Values ------------------------ */ 44 45 struct app_info { 46 app_info(); 47 ~app_info(); 48 49 thread_id thread; 50 team_id team; 51 port_id port; 52 uint32 flags; 53 entry_ref ref; 54 char signature[B_MIME_TYPE_LENGTH]; 55 }; 56 57 #define B_LAUNCH_MASK (0x3) 58 59 #define B_SINGLE_LAUNCH (0x0) 60 #define B_MULTIPLE_LAUNCH (0x1) 61 #define B_EXCLUSIVE_LAUNCH (0x2) 62 63 #define B_BACKGROUND_APP (0x4) 64 #define B_ARGV_ONLY (0x8) 65 #define _B_APP_INFO_RESERVED1_ (0x10000000) 66 67 68 enum { 69 B_REQUEST_LAUNCHED = 0x00000001, 70 B_REQUEST_QUIT = 0x00000002, 71 B_REQUEST_ACTIVATED = 0x00000004 72 }; 73 74 enum { 75 B_SOME_APP_LAUNCHED = 'BRAS', 76 B_SOME_APP_QUIT = 'BRAQ', 77 B_SOME_APP_ACTIVATED = 'BRAW' 78 }; 79 80 /*-------------------------------------------------------------*/ 81 /* --------- BRoster class----------------------------------- */ 82 83 class BRoster { 84 public: 85 BRoster(); 86 ~BRoster(); 87 88 /* Querying for apps */ 89 bool IsRunning(const char *mimeSig) const; 90 bool IsRunning(entry_ref *ref) const; 91 team_id TeamFor(const char *mimeSig) const; 92 team_id TeamFor(entry_ref *ref) const; 93 void GetAppList(BList *teamIDList) const; 94 void GetAppList(const char *sig, BList *teamIDList) const; 95 status_t GetAppInfo(const char *sig, app_info *info) const; 96 status_t GetAppInfo(entry_ref *ref, app_info *info) const; 97 status_t GetRunningAppInfo(team_id team, app_info *info) const; 98 status_t GetActiveAppInfo(app_info *info) const; 99 status_t FindApp(const char *mimeType, entry_ref *app) const; 100 status_t FindApp(entry_ref *ref, entry_ref *app) const; 101 102 /* Launching, activating, and broadcasting to apps */ 103 status_t Broadcast(BMessage *message) const; 104 status_t Broadcast(BMessage *message, BMessenger replyTo) const; 105 status_t StartWatching(BMessenger target, 106 uint32 eventMask = B_REQUEST_LAUNCHED | B_REQUEST_QUIT) const; 107 status_t StopWatching(BMessenger target) const; 108 status_t ActivateApp(team_id team) const; 109 110 status_t Launch(const char *mimeType, BMessage *initialMessage = NULL, 111 team_id *appTeam = NULL) const; 112 status_t Launch(const char *mimeType, BList *messageList, 113 team_id *appTeam = NULL) const; 114 status_t Launch(const char *mimeType, int argc, char **args, 115 team_id *appTeam = NULL) const; 116 status_t Launch(const entry_ref *ref, 117 const BMessage *initialMessage = NULL, 118 team_id *app_team = NULL) const; 119 status_t Launch(const entry_ref *ref, const BList *messageList, 120 team_id *appTeam = NULL) const; 121 status_t Launch(const entry_ref *ref, int argc, const char * const *args, 122 team_id *appTeam = NULL) const; 123 124 /* Recent document and app support */ 125 void GetRecentDocuments(BMessage *refList, int32 maxCount, 126 const char *fileType = NULL, 127 const char *appSig = NULL) const; 128 void GetRecentDocuments(BMessage *refList, int32 maxCount, 129 const char *fileTypes[], int32 fileTypesCount, 130 const char *appSig = NULL) const; 131 void GetRecentFolders(BMessage *refList, int32 maxCount, 132 const char *appSig = NULL) const; 133 void GetRecentApps(BMessage *refList, int32 maxCount) const; 134 135 void AddToRecentDocuments(const entry_ref *doc, 136 const char *appSig = NULL) const; 137 void AddToRecentFolders(const entry_ref *folder, 138 const char *appSig = NULL) const; 139 140 /*----- Private or reserved ------------------------------*/ 141 class Private; 142 143 private: 144 friend class Private; 145 146 class ArgVector; 147 148 enum mtarget { 149 MAIN_MESSENGER, 150 MIME_MESSENGER, 151 USE_GIVEN 152 }; 153 154 status_t _StartWatching(mtarget target, BMessenger *rosterMess, 155 uint32 what, BMessenger notify, 156 uint32 event_mask) const; 157 status_t _StopWatching(mtarget target, BMessenger *rosterMess, uint32 what, 158 BMessenger notify) const; 159 status_t AddApplication(const char *mimeSig, const entry_ref *ref, 160 uint32 flags, team_id team, thread_id thread, 161 port_id port, bool fullReg, uint32 *token, 162 team_id *otherTeam) const; 163 status_t SetSignature(team_id team, const char *mimeSig) const; 164 void SetThread(team_id team, thread_id thread) const; 165 status_t SetThreadAndTeam(uint32 entryToken, thread_id thread, 166 team_id team) const; 167 status_t CompleteRegistration(team_id team, thread_id thread, 168 port_id port) const; 169 bool IsAppPreRegistered(const entry_ref *ref, team_id team, 170 app_info *info) const; 171 status_t RemovePreRegApp(uint32 entryToken) const; 172 status_t RemoveApp(team_id team) const; 173 174 status_t xLaunchAppPrivate(const char *mimeType, const entry_ref *ref, 175 const BList *messageList, int argc, 176 const char *const* args, 177 team_id *appTeam) const; 178 bool UpdateActiveApp(team_id team) const; 179 void SetAppFlags(team_id team, uint32 flags) const; 180 void DumpRoster() const; 181 status_t resolve_app(const char *inType, entry_ref *ref, 182 entry_ref *appRef, char *appSig, uint32 *appFlags, 183 bool *wasDocument) const; 184 status_t translate_ref(entry_ref *ref, BMimeType *appMeta, 185 entry_ref *appRef, BFile *appFile, 186 bool *wasDocument) const; 187 status_t translate_type(const char *mimeType, BMimeType *appMeta, 188 entry_ref *appRef, BFile *appFile) const; 189 status_t sniff_file(const entry_ref *file, BNodeInfo *nodeInfo, 190 char *mimeType) const; 191 status_t send_to_running(team_id team, int argc, const char *const *args, 192 const BList *messageList, const entry_ref *ref, 193 bool readyToRun) const; 194 void InitMessengers(); 195 196 void AddToRecentApps(const char *appSig) const; 197 void ClearRecentDocuments() const; 198 void ClearRecentFolders() const; 199 void ClearRecentApps() const; 200 void LoadRecentLists(const char *file) const; 201 void SaveRecentLists(const char *file) const; 202 203 BMessenger fMess; 204 BMessenger fMimeMess; 205 uint32 _fReserved[3]; 206 }; 207 208 /*-----------------------------------------------------*/ 209 /*----- Global be_roster ------------------------------*/ 210 211 extern _IMPEXP_BE const BRoster *be_roster; 212 213 /*-----------------------------------------------------*/ 214 /*-----------------------------------------------------*/ 215 216 #endif /* _ROSTER_H */ 217