dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_init_listener.h
1 #ifndef SCD_INIT_LISTENER_H
2 #define SCD_INIT_LISTENER_H
3
4 #include <list>
5
6 #include "scd_sock_poller.h"
7 #include "scd_socket.h"
8 #include "scd_simulator.h"
9 #include "scd_in_connector.h"
10
11 /**
12  * Accepts incomming connection during initialization and instanciates
13  * a connector that handles the new connection.
14  */
15 class scd_init_listener : public scd_sock_ev_handler_if
16 {
17 public:
18     /**
19      * Constructor. Binds the listener to the specified TCP port on all
20      * available network interfaces.
21      * \param sim the simulator
22      * \param port TCP port to bind to
23      */
24     scd_init_listener(scd_simulator &sim, uint16_t port);
25
26     /**
27      * Constructor. Binds the listener to the specified TCP port
28      * only on the specified network interface.
29      * \param sim the simulator
30      * \param host IP or domain name of the interface to bind to
31      * \param port TCP port to bind to
32      */
33     scd_init_listener(scd_simulator &sim, 
34             const std::string &host, uint16_t port);
35
36     /**
37      * Deconstructor.
38      */
39     virtual ~scd_init_listener();
40
41     /**
42      * Creates the listening socket.
43      * \exception scd_exception if unexpected errors occure
44      */
45     void listen();
46
47     /**
48      * Closes the listening socket.
49      */
50     void close();
51
52     /**
53      * Removes connectors that finished their job. If the optional argument
54      * hard is true all connectors are destroyed independend if they
55      * have finished or not.
56      * \param hard if true all connectors will be destroyed
57      */
58     void cleanup(bool hard = false);
59
60     /* scd_sock_ev_handler_if */
61     void handle_sock_ev(sock_ev events);
62     const scd_socket& get_sock();
63
64 private:
65     scd_simulator &_sim;
66     std::string _host;
67     uint16_t _port;
68     scd_socket _socket;
69     std::list<scd_in_connector*>_connectors;
70     bool _handler;
71 };
72
73 #endif