Serial-TCP/IPbridge  1.0
serial_config.h
Go to the documentation of this file.
1 
12 #ifndef SERIAL_CONFIG_H
13 #define SERIAL_CONFIG_H
14 
15 #include <string>
16 #include <unistd.h>
17 #include <termios.h>
18 
19 #include "base_exception.h"
20 #include "config.h"
21 
30 class SerialConfig: public Config {
31  public:
33  typedef std::map<std::string, std::string> RawConfigValues;
34 
36  enum Parity {
42  };
43 
45  enum StopBits {
49  };
50 
52  enum FlowControl {
56  };
57 
58  public:
72  static SerialConfig fromRawConfigValues(RawConfigValues rawConfigValues);
73 
79  ~SerialConfig();
80 
88  SerialConfig(const SerialConfig &other);
89 
99  SerialConfig & operator=(const SerialConfig &other);
100 
108  bool operator==(const SerialConfig &other) const;
109 
117  bool operator!=(const SerialConfig &other) const;
118 
126  void swap(SerialConfig &other);
127 
129  std::string getDevice() const { return _device; }
130 
132  speed_t getSpeed() const { return _speed; }
133 
135  tcflag_t getDataBits() const { return _dataBits; }
136 
138  Parity getParity() const { return _parity; }
139 
141  StopBits getStopBits() const { return _stopBits; }
142 
145 
146  private:
152  SerialConfig();
153 
161  SerialConfig(Config::RawConfigValues rawConfigValues);
162 
163  // All parsig functions have the same behaviour - they parses the
164  // selected value and returns it. They throw InvalidValueError if the
165  // value is invalid.
166  static std::string parseDevice(const std::string &rawDevice);
167  static speed_t parseSpeed(const std::string &rawSpeed);
168  static tcflag_t parseDataBits(const std::string &rawDataBits);
169  static Parity parseParity(const std::string &rawParity);
170  static StopBits parseStopBits(const std::string &rawStopBits);
171  static FlowControl parseFlowControl(const std::string &rawFlowControl);
172 
173  private:
175  std::string _device;
177  speed_t _speed;
179  tcflag_t _dataBits;
186 
188  static const std::string DEFAULT_DEVICE;
190  static const speed_t DEFAULT_SPEED;
192  static const tcflag_t DEFAULT_DATA_BITS;
194  static const Parity DEFAULT_PARITY;
199 };
200 
201 #endif // #ifndef SERIAL_CONFIG_H
202 
203 // End of file serial_config.h
Definition: serial_config.h:46
bool operator==(const SerialConfig &other) const
Equality comparison.
std::map< std::string, std::string > RawConfigValues
Raw configuration option -> values mapping.
Definition: config.h:40
Definition: serial_config.h:38
static std::string parseDevice(const std::string &rawDevice)
SerialConfig & operator=(const SerialConfig &other)
Assignment operator.
static const Parity DEFAULT_PARITY
Default parity bit generation type.
Definition: serial_config.h:194
speed_t _speed
Serial port speed (in baudes).
Definition: serial_config.h:177
Parity
Parity bit generation types.
Definition: serial_config.h:36
Configuration for a TCP/IP server.
Definition: serial_config.h:30
speed_t getSpeed() const
Returns the serial port speed.
Definition: serial_config.h:132
std::string getDevice() const
Returns the serial port device.
Definition: serial_config.h:129
Config class - declarations.
Definition: serial_config.h:53
static const StopBits DEFAULT_STOP_BITS
Default number of stop bits.
Definition: serial_config.h:196
Definition: serial_config.h:54
FlowControl _flowControl
Flow control type.
Definition: serial_config.h:185
static speed_t parseSpeed(const std::string &rawSpeed)
static FlowControl parseFlowControl(const std::string &rawFlowControl)
BaseException class - declarations.
Base class for all configuration classes.
Definition: config.h:28
Definition: serial_config.h:55
std::string _device
Serial port device.
Definition: serial_config.h:175
Definition: serial_config.h:39
Definition: serial_config.h:37
StopBits getStopBits() const
Returns the number of stop bits.
Definition: serial_config.h:141
StopBits
Number of stop bits.
Definition: serial_config.h:45
static const speed_t DEFAULT_SPEED
Default speed.
Definition: serial_config.h:190
tcflag_t getDataBits() const
Returns the number of data bits.
Definition: serial_config.h:135
Definition: serial_config.h:40
static tcflag_t parseDataBits(const std::string &rawDataBits)
static Parity parseParity(const std::string &rawParity)
Definition: serial_config.h:48
std::map< std::string, std::string > RawConfigValues
Raw configuration option -> values mapping.
Definition: serial_config.h:33
Parity getParity() const
Returns the parity bit generation type.
Definition: serial_config.h:138
tcflag_t _dataBits
Number of data bits.
Definition: serial_config.h:179
Definition: serial_config.h:47
static const tcflag_t DEFAULT_DATA_BITS
Default number of data bits.
Definition: serial_config.h:192
static const FlowControl DEFAULT_FLOW_CONTROL
Default flow control.
Definition: serial_config.h:198
static SerialConfig fromRawConfigValues(RawConfigValues rawConfigValues)
Creates a SerialConfig object from raw configuration values.
Parity _parity
Parity bit generation type.
Definition: serial_config.h:181
static StopBits parseStopBits(const std::string &rawStopBits)
~SerialConfig()
Destructor.
Definition: serial_config.h:41
FlowControl
Flow control types.
Definition: serial_config.h:52
StopBits _stopBits
Number of stop bits.
Definition: serial_config.h:183
void swap(SerialConfig &other)
Swap the contents of this object with the other object.
bool operator!=(const SerialConfig &other) const
Non-equality comparison.
FlowControl getFlowControl() const
Returns the flow control type.
Definition: serial_config.h:144
static const std::string DEFAULT_DEVICE
Default interface.
Definition: serial_config.h:188
SerialConfig()
Default constructor.