1 // NetFSServer.h 2 3 #ifndef NET_FS_SERVER_H 4 #define NET_FS_SERVER_H 5 6 #include <Application.h> 7 #include <List.h> 8 9 #include "ClientConnection.h" 10 #include "ConnectionListenerFactory.h" 11 #include "Locker.h" 12 13 class BPath; 14 15 class Connection; 16 class ConnectionListener; 17 class SecurityContext; 18 class ServerInfo; 19 20 class NetFSServer : public BApplication, private ClientConnectionListener { 21 public: 22 NetFSServer(bool useBroadcasting); 23 ~NetFSServer(); 24 25 status_t Init(); 26 virtual thread_id Run(); 27 28 virtual void MessageReceived(BMessage* message); 29 30 VolumeManager* GetVolumeManager() const; 31 SecurityContext* GetSecurityContext() const; 32 33 private: 34 class ConnectionInitializer; 35 friend class ConnectionInitializer; 36 class ServerInfoSender; 37 38 status_t _AddClientConnection( 39 ClientConnection* connection); 40 41 virtual void ClientConnectionClosed( 42 ClientConnection* connection, 43 bool broken); 44 45 status_t _LoadSecurityContext( 46 SecurityContext** securityContext); 47 status_t _InitSettings(); 48 status_t _LoadSettings(); 49 status_t _SaveSettings(); 50 status_t _GetSettingsDirPath(BPath* path, 51 bool create = false); 52 status_t _GetSettingsFilePath(BPath* path, 53 bool createDir = false); 54 55 status_t _InitServerInfoConnectionListener(); 56 void _ExitServerInfoConnectionListener(); 57 58 static int32 _ConnectionListenerEntry(void* data); 59 int32 _ConnectionListener(); 60 61 static int32 _ConnectionDeleterEntry(void* data); 62 int32 _ConnectionDeleter(); 63 64 static int32 _BroadcasterEntry(void* data); 65 int32 _Broadcaster(); 66 67 static int32 _ServerInfoConnectionListenerEntry(void* data); 68 int32 _ServerInfoConnectionListener(); 69 status_t _GetServerInfo(ServerInfo& serverInfo); 70 71 void _ServerInfoUpdated(); 72 73 void _SendReply(BMessage* message, BMessage* reply, 74 status_t error = B_OK); 75 void _SendReply(BMessage* message, 76 status_t error = B_OK); 77 78 private: 79 SecurityContext* fSecurityContext; 80 ConnectionListenerFactory fConnectionListenerFactory; 81 ConnectionListener* fConnectionListener; 82 Locker fLock; 83 BList fClientConnections; 84 VolumeManager* fVolumeManager; 85 BList fClosedConnections; 86 sem_id fClosedConnectionsSemaphore; 87 thread_id fConnectionListenerThread; 88 thread_id fConnectionDeleter; 89 thread_id fBroadcaster; 90 int32 fBroadcastingSocket; 91 sem_id fBroadcasterSemaphore; 92 thread_id fServerInfoConnectionListener; 93 int32 fServerInfoConnectionListenerSocket; 94 int32 fServerInfoUpdated; 95 bool fUseBroadcasting; 96 volatile bool fTerminating; 97 }; 98 99 #endif // NET_FS_SERVER_H 100