Serial-TCP/IPbridge  1.0
tcpip_config.h
Go to the documentation of this file.
1 
12 #ifndef TCPIP_CONFIG_H
13 #define TCPIP_CONFIG_H
14 
15 #include <string>
16 #include <vector>
17 #include <tr1/cstdint>
18 
19 #include "base_exception.h"
20 #include "config.h"
21 
30 class TCPIPConfig: public Config {
31  public:
33  typedef std::vector<std::string> Interfaces;
34 
36  typedef std::tr1::uint16_t Port;
37 
39  typedef time_t Timeout;
40 
41  public:
55  static TCPIPConfig fromRawConfigValues(RawConfigValues rawConfigValues);
56 
62  ~TCPIPConfig();
63 
71  TCPIPConfig(const TCPIPConfig &other);
72 
82  TCPIPConfig & operator=(const TCPIPConfig &other);
83 
91  bool operator==(const TCPIPConfig &other) const;
92 
100  bool operator!=(const TCPIPConfig &other) const;
101 
109  void swap(TCPIPConfig &other);
110 
120 
122  Port getPort() const { return _port; }
123 
125  time_t getTimeout() const { return _timeout; }
126 
127  public:
130  static const std::string ANY_INTERFACE;
131 
132  private:
138  TCPIPConfig();
139 
147  TCPIPConfig(Config::RawConfigValues rawConfigValues);
148 
149  // All parsig functions have the same behaviour - they parses the
150  // selected value and returns it. They throw InvalidValueError if the
151  // value is invalid.
152  static Interfaces parseInterfaces(const std::string &rawInterfaces);
153  static Port parsePort(const std::string &rawPort);
154  static Timeout parseTimeout(const std::string &rawTimeout);
155 
156  private:
163 
165  static const Port DEFAULT_PORT;
167  static const Timeout DEFAULT_TIMEOUT;
168 };
169 
170 #endif // #ifndef TCPIP_CONFIG_H
171 
172 // End of file tcpip_config.h
bool operator!=(const TCPIPConfig &other) const
Non-equality comparison.
std::map< std::string, std::string > RawConfigValues
Raw configuration option -> values mapping.
Definition: config.h:40
bool operator==(const TCPIPConfig &other) const
Equality comparison.
static Interfaces parseInterfaces(const std::string &rawInterfaces)
static const Port DEFAULT_PORT
Default port number.
Definition: tcpip_config.h:165
static const Timeout DEFAULT_TIMEOUT
Default connection timeout (in seconds).
Definition: tcpip_config.h:167
Timeout _timeout
Connection timeout (in seconds).
Definition: tcpip_config.h:162
Config class - declarations.
BaseException class - declarations.
Base class for all configuration classes.
Definition: config.h:28
std::tr1::uint16_t Port
Port number type.
Definition: tcpip_config.h:36
Interfaces _interfaces
Interfaces on which the TCP/IP server should listen.
Definition: tcpip_config.h:158
std::vector< std::string > Interfaces
List of network iterfaces.
Definition: tcpip_config.h:33
time_t Timeout
Timeout type.
Definition: tcpip_config.h:39
Port _port
Port number on which the TCP/IP server should listen.
Definition: tcpip_config.h:160
Interfaces getInterfaces() const
Returns the list of interfaces on which the TCP/IP server should listen.
Definition: tcpip_config.h:119
Port getPort() const
Returns the port number on which the TCP/IP server should listen.
Definition: tcpip_config.h:122
TCPIPConfig & operator=(const TCPIPConfig &other)
Assignment operator.
Configuration for a TCP/IP server.
Definition: tcpip_config.h:30
void swap(TCPIPConfig &other)
Swap the contents of this object with the other object.
static Port parsePort(const std::string &rawPort)
time_t getTimeout() const
Returns the connection timout (in seconds).
Definition: tcpip_config.h:125
static Timeout parseTimeout(const std::string &rawTimeout)
~TCPIPConfig()
Destructor.
TCPIPConfig()
Default constructor.
static const std::string ANY_INTERFACE
Definition: tcpip_config.h:130
static TCPIPConfig fromRawConfigValues(RawConfigValues rawConfigValues)
Creates a TCPIPConfig object from raw configuration values.