dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_init_listener.h
diff --git a/dol/src/dol/visitor/hdsd/scd/scd_init_listener.h b/dol/src/dol/visitor/hdsd/scd/scd_init_listener.h
new file mode 100644 (file)
index 0000000..5ae7b5a
--- /dev/null
@@ -0,0 +1,73 @@
+#ifndef SCD_INIT_LISTENER_H
+#define SCD_INIT_LISTENER_H
+
+#include <list>
+
+#include "scd_sock_poller.h"
+#include "scd_socket.h"
+#include "scd_simulator.h"
+#include "scd_in_connector.h"
+
+/**
+ * Accepts incomming connection during initialization and instanciates
+ * a connector that handles the new connection.
+ */
+class scd_init_listener : public scd_sock_ev_handler_if
+{
+public:
+    /**
+     * Constructor. Binds the listener to the specified TCP port on all
+     * available network interfaces.
+     * \param sim the simulator
+     * \param port TCP port to bind to
+     */
+    scd_init_listener(scd_simulator &sim, uint16_t port);
+
+    /**
+     * Constructor. Binds the listener to the specified TCP port
+     * only on the specified network interface.
+     * \param sim the simulator
+     * \param host IP or domain name of the interface to bind to
+     * \param port TCP port to bind to
+     */
+    scd_init_listener(scd_simulator &sim, 
+            const std::string &host, uint16_t port);
+
+    /**
+     * Deconstructor.
+     */
+    virtual ~scd_init_listener();
+
+    /**
+     * Creates the listening socket.
+     * \exception scd_exception if unexpected errors occure
+     */
+    void listen();
+
+    /**
+     * Closes the listening socket.
+     */
+    void close();
+
+    /**
+     * Removes connectors that finished their job. If the optional argument
+     * hard is true all connectors are destroyed independend if they
+     * have finished or not.
+     * \param hard if true all connectors will be destroyed
+     */
+    void cleanup(bool hard = false);
+
+    /* scd_sock_ev_handler_if */
+    void handle_sock_ev(sock_ev events);
+    const scd_socket& get_sock();
+
+private:
+    scd_simulator &_sim;
+    std::string _host;
+    uint16_t _port;
+    scd_socket _socket;
+    std::list<scd_in_connector*>_connectors;
+    bool _handler;
+};
+
+#endif