1 /* 2 * Copyright 2001-2007, Ingo Weinhold, bonefish@users.sf.net. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef T_ROSTER_H 6 #define T_ROSTER_H 7 8 9 #include "AppInfoList.h" 10 #include "RecentApps.h" 11 #include "RecentEntries.h" 12 #include "WatchingService.h" 13 14 #include <Locker.h> 15 #include <MessageQueue.h> 16 #include <SupportDefs.h> 17 18 #include <hash_set> 19 #include <map> 20 21 22 #if __GNUC__ >= 4 23 using __gnu_cxx::hash_set; 24 #endif 25 26 using std::map; 27 28 class BMessage; 29 class WatchingService; 30 31 typedef map<int32, BMessageQueue*> IARRequestMap; 32 33 class TRoster { 34 public: 35 TRoster(); 36 virtual ~TRoster(); 37 38 void HandleAddApplication(BMessage *request); 39 void HandleCompleteRegistration(BMessage *request); 40 void HandleIsAppRegistered(BMessage *request); 41 void HandleRemovePreRegApp(BMessage *request); 42 void HandleRemoveApp(BMessage *request); 43 void HandleSetThreadAndTeam(BMessage *request); 44 void HandleSetSignature(BMessage *request); 45 void HandleGetAppInfo(BMessage *request); 46 void HandleGetAppList(BMessage *request); 47 void HandleUpdateActiveApp(BMessage *request); 48 void HandleBroadcast(BMessage *request); 49 void HandleStartWatching(BMessage *request); 50 void HandleStopWatching(BMessage *request); 51 void HandleGetRecentDocuments(BMessage *request); 52 void HandleGetRecentFolders(BMessage *request); 53 void HandleGetRecentApps(BMessage *request); 54 void HandleAddToRecentDocuments(BMessage *request); 55 void HandleAddToRecentFolders(BMessage *request); 56 void HandleAddToRecentApps(BMessage *request); 57 void HandleLoadRecentLists(BMessage *request); 58 void HandleSaveRecentLists(BMessage *request); 59 60 void ClearRecentDocuments(); 61 void ClearRecentFolders(); 62 void ClearRecentApps(); 63 64 status_t Init(); 65 66 status_t AddApp(RosterAppInfo *info); 67 void RemoveApp(RosterAppInfo *info); 68 void UpdateActiveApp(RosterAppInfo *info); 69 70 void CheckSanity(); 71 72 void SetShuttingDown(bool shuttingDown); 73 status_t GetShutdownApps(AppInfoList &userApps, AppInfoList &systemApps, 74 AppInfoList &backgroundApps, hash_set<team_id> &vitalSystemApps); 75 76 status_t AddWatcher(Watcher *watcher); 77 void RemoveWatcher(Watcher *watcher); 78 79 private: 80 // hook functions 81 void _AppAdded(RosterAppInfo *info); 82 void _AppRemoved(RosterAppInfo *info); 83 void _AppActivated(RosterAppInfo *info); 84 void _AppDeactivated(RosterAppInfo *info); 85 86 // helper functions 87 static status_t _AddMessageAppInfo(BMessage* message, const app_info* info); 88 static status_t _AddMessageWatchingInfo(BMessage* message, 89 const app_info* info); 90 uint32 _NextToken(); 91 92 void _AddIARRequest(IARRequestMap& map, int32 key, BMessage* request); 93 void _ReplyToIARRequests(BMessageQueue* requests, 94 const RosterAppInfo* info); 95 void _ReplyToIARRequest(BMessage* request, const RosterAppInfo* info); 96 97 void _HandleGetRecentEntries(BMessage* request); 98 99 void _ValidateRunning(const entry_ref& ref, const char* signature); 100 bool _IsSystemApp(RosterAppInfo* info) const; 101 102 status_t _LoadRosterSettings(const char *path = NULL); 103 status_t _SaveRosterSettings(const char *path = NULL); 104 static const char *kDefaultRosterSettingsFile; 105 106 private: 107 BLocker fLock; 108 AppInfoList fRegisteredApps; 109 AppInfoList fEarlyPreRegisteredApps; 110 IARRequestMap fIARRequestsByID; 111 IARRequestMap fIARRequestsByToken; 112 RosterAppInfo* fActiveApp; 113 WatchingService fWatchingService; 114 RecentApps fRecentApps; 115 RecentEntries fRecentDocuments; 116 RecentEntries fRecentFolders; 117 uint32 fLastToken; 118 bool fShuttingDown; 119 }; 120 121 #endif // T_ROSTER_H 122