1 #ifndef SCD_OUT_CONNECTOR_H
2 #define SCD_OUT_CONNECTOR_H
8 #include "scd_socket.h"
9 #include "scd_sock_poller.h"
10 #include "scd_simulator.h"
11 #include "scd_command_writer.h"
14 const time_t SCD_CON_TIMEOUT = 2;
15 const time_t SCD_CON_RETRY = 1;
18 /* forward declaration */
23 * Initiates an outgoing connection and sends the register command
24 * to the other side. If an attempt to connect failes it is
25 * retried after some time. To drive this, process() has to be called
28 class scd_out_connector : public scd_sock_ev_handler_if
33 * \param sim the simulator
34 * \param type what should be connected (SCD_CM_NETSIM or SCD_CM_CHANNEL)
35 * \param name the name of the ressource to connect (i.e. channel name
38 scd_out_connector(scd_simulator& sim, uint16_t type,
39 const std::string& name);
41 virtual ~scd_out_connector();
44 * Sets the host to connect to and starts the first connection attempt.
46 * \param host the IP or hostname to connect to
47 * \param port the port to connect to
49 void connect_to(const std::string& host, uint16_t port);
52 * Indicates if this out_connector is still trying to connect or
53 * sending the command.
54 * * \return true if this out_connector is still working
59 * Indicates if the command has been sent successfully and the registered
60 * connection can be collected.
61 * \return true if a connection is registered
63 bool has_connection();
66 * Returns the established and registered connection.
68 scd_socket* get_connection();
72 * Checks if a time outs have occured. A connection attempt that is running
73 * for more than SCD_CON_TIMEOUT seconds is terminated and failed
74 * connection attempts are retried after SCD_CON_RETRY seconds.
79 * Stops to try to connect or terminates an already established
85 * Returns the name of the ressource to connect.
87 const std::string& get_name() const;
89 /* scd_sock_ev_handler_if */
90 void handle_sock_ev(sock_ev events);
91 const scd_socket& get_sock();
100 bool _has_connection;
102 scd_command_writer* _writer;
105 struct timeval _last_con;
107 void _conn_attempt();