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 <Path.h> 17 #include <Roster.h> 18 #include <SupportDefs.h> 19 20 #include <hash_set> 21 #include <map> 22 23 24 #if __GNUC__ >= 4 25 using __gnu_cxx::hash_set; 26 #endif 27 28 using std::map; 29 30 class BMessage; 31 class WatchingService; 32 33 typedef map<int32, BMessageQueue*> IARRequestMap; 34 35 class TRoster { 36 public: 37 TRoster(); 38 virtual ~TRoster(); 39 40 void HandleAddApplication(BMessage* request); 41 void HandleCompleteRegistration(BMessage* request); 42 void HandleIsAppRegistered(BMessage* request); 43 void HandleRemovePreRegApp(BMessage* request); 44 void HandleRemoveApp(BMessage* request); 45 void HandleSetThreadAndTeam(BMessage* request); 46 void HandleSetSignature(BMessage* request); 47 void HandleGetAppInfo(BMessage* request); 48 void HandleGetAppList(BMessage* request); 49 void HandleUpdateActiveApp(BMessage* request); 50 void HandleBroadcast(BMessage* request); 51 void HandleStartWatching(BMessage* request); 52 void HandleStopWatching(BMessage* request); 53 void HandleGetRecentDocuments(BMessage* request); 54 void HandleGetRecentFolders(BMessage* request); 55 void HandleGetRecentApps(BMessage* request); 56 void HandleAddToRecentDocuments(BMessage* request); 57 void HandleAddToRecentFolders(BMessage* request); 58 void HandleAddToRecentApps(BMessage* request); 59 void HandleLoadRecentLists(BMessage* request); 60 void HandleSaveRecentLists(BMessage* request); 61 62 void HandleRestartAppServer(BMessage* request); 63 64 void ClearRecentDocuments(); 65 void ClearRecentFolders(); 66 void ClearRecentApps(); 67 68 status_t Init(); 69 70 status_t AddApp(RosterAppInfo* info); 71 void RemoveApp(RosterAppInfo* info); 72 void UpdateActiveApp(RosterAppInfo* info); 73 74 void CheckSanity(); 75 76 void SetShuttingDown(bool shuttingDown); 77 status_t GetShutdownApps(AppInfoList& userApps, 78 AppInfoList& systemApps, 79 AppInfoList& backgroundApps, 80 hash_set<team_id>& vitalSystemApps); 81 status_t AddAppInfo(AppInfoList& apps, team_id team); 82 83 status_t AddWatcher(Watcher* watcher); 84 void RemoveWatcher(Watcher* watcher); 85 86 private: 87 // hook functions 88 void _AppAdded(RosterAppInfo* info); 89 void _AppRemoved(RosterAppInfo* info); 90 void _AppActivated(RosterAppInfo* info); 91 void _AppDeactivated(RosterAppInfo* info); 92 93 // helper functions 94 static status_t _AddMessageAppInfo(BMessage* message, 95 const app_info* info); 96 static status_t _AddMessageWatchingInfo(BMessage* message, 97 const app_info* info); 98 uint32 _NextToken(); 99 100 void _AddIARRequest(IARRequestMap& map, int32 key, 101 BMessage* request); 102 void _ReplyToIARRequests(BMessageQueue* requests, 103 const RosterAppInfo* info); 104 void _ReplyToIARRequest(BMessage* request, 105 const RosterAppInfo* info); 106 107 void _HandleGetRecentEntries(BMessage* request); 108 109 void _ValidateRunning(const entry_ref& ref, 110 const char* signature); 111 bool _IsSystemApp(RosterAppInfo* info) const; 112 113 status_t _LoadRosterSettings(const char* path = NULL); 114 status_t _SaveRosterSettings(const char* path = NULL); 115 static const char* kDefaultRosterSettingsFile; 116 117 private: 118 BLocker fLock; 119 AppInfoList fRegisteredApps; 120 AppInfoList fEarlyPreRegisteredApps; 121 IARRequestMap fIARRequestsByID; 122 IARRequestMap fIARRequestsByToken; 123 RosterAppInfo* fActiveApp; 124 WatchingService fWatchingService; 125 RecentApps fRecentApps; 126 RecentEntries fRecentDocuments; 127 RecentEntries fRecentFolders; 128 uint32 fLastToken; 129 bool fShuttingDown; 130 BPath fSystemAppPath; 131 BPath fSystemServerPath; 132 }; 133 134 #endif // T_ROSTER_H 135