Initial commit
[remote/remote-mci.git] / diku_mcs / HostListener.h
blob82b726310da69c03a674c0f8ca5c7522d3a677ea
1 #ifndef _HOSTLISTENER_H_
2 #define _HOSTLISTENER_H_
4 #include "macros.h"
5 #include "tcputil.h"
6 #include "database.h"
7 #include "FileDescriptor.h"
8 #include "Host.h"
10 namespace remote { namespace diku_mcs {
12 /** This class listen for new host connections and creates
13 * host objects for the host connections that are accepted **/
14 class HostListener : public FileDescriptor
16 public:
17 /** Constructor sets up the host listener
18 * \param port Port on which to accept new host connections
19 **/
20 HostListener(unsigned int port);
21 /** Destructor **/
22 virtual ~HostListener();
23 private:
24 /** Create a new host if it is listed in the database.
25 * \param p_fd File descriptor for the new host connection
26 * \param client Address of the new host
27 * \returns TRUE if the host object was created, FALSE otherwise
28 **/
29 bool createHostByConnection(int p_fd, sockaddr_in& client);
30 /** Destroy all current host objects and delete references to them. **/
31 void deleteAllHosts();
32 /** Handle an event on the file descriptor.
33 * \param events Event descriptor.
34 * **/
35 void handleEvent(short events);
36 /** TODO: document me **/
37 struct sockaddr_in server;
38 /** Map of all currently connected hosts. **/
39 hostmapbykey_t hosts;
44 #endif