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