1 // ServerManager.h 2 3 #ifndef NET_FS_SERVER_MANAGER_H 4 #define NET_FS_SERVER_MANAGER_H 5 6 #include "Locker.h" 7 8 class ExtendedServerInfo; 9 class NetAddress; 10 11 // ServerManager 12 class ServerManager { 13 public: 14 class Listener; 15 16 public: 17 ServerManager(Listener* listener); 18 ~ServerManager(); 19 20 status_t Init(); 21 void Uninit(); 22 23 void Run(); 24 25 ExtendedServerInfo* GetServerInfo(const NetAddress& address); 26 status_t AddServer(const NetAddress& address); 27 void RemoveServer(const NetAddress& address); 28 29 private: 30 struct ServerInfoMap; 31 class ServerInfoTask; 32 friend class ServerInfoTask; 33 34 static int32 _BroadcastListenerEntry(void* data); 35 int32 _BroadcastListener(); 36 status_t _InitBroadcastListener(); 37 void _TerminateBroadcastListener(); 38 39 void _ServerAdded(ExtendedServerInfo* serverInfo); 40 void _ServerUpdated(ExtendedServerInfo* serverInfo); 41 void _AddingServerFailed( 42 ExtendedServerInfo* serverInfo); 43 void _UpdatingServerFailed( 44 ExtendedServerInfo* serverInfo); 45 void _RemoveServer(ExtendedServerInfo* serverInfo); 46 47 private: 48 Locker fLock; 49 ServerInfoMap* fServerInfos; 50 thread_id fBroadcastListener; 51 int32 fBroadcastListenerSocket; 52 Listener* fListener; 53 volatile bool fTerminating; 54 }; 55 56 // Listener 57 class ServerManager::Listener { 58 public: Listener()59 Listener() {} 60 virtual ~Listener(); 61 62 virtual void ServerAdded(ExtendedServerInfo* serverInfo) = 0; 63 virtual void ServerUpdated(ExtendedServerInfo* oldInfo, 64 ExtendedServerInfo* newInfo) = 0; 65 virtual void ServerRemoved( 66 ExtendedServerInfo* serverInfo) = 0; 67 }; 68 69 70 #endif // NET_FS_SERVER_MANAGER_H 71