Serial-TCP/IPbridge  1.0
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
SerialConfig Class Reference

Configuration for a TCP/IP server. More...

#include <serial_config.h>

Inheritance diagram for SerialConfig:
Config

Public Types

enum  Parity {
  NONE_PARITY, EVEN_PARITY, ODD_PARITY, MARK_PARITY,
  SPACE_PARITY
}
 Parity bit generation types. More...
 
enum  StopBits { STOP_BITS_1, STOP_BITS_1_5, STOP_BITS_2 }
 Number of stop bits. More...
 
enum  FlowControl { NONE_FLOW_CONTROL, HARDWARE_FLOW_CONTROL, SOFTWARE_FLOW_CONTROL }
 Flow control types. More...
 
typedef std::map< std::string,
std::string > 
RawConfigValues
 Raw configuration option -> values mapping. More...
 
- Public Types inherited from Config
typedef std::map< std::string,
std::string > 
RawConfigValues
 Raw configuration option -> values mapping. More...
 
typedef size_t BufferSize
 Buffer size type. More...
 
typedef unsigned LengthField
 Length field type. More...
 
typedef std::tr1::uint32_t LengthFieldMessageLength
 Message length type when using length field. More...
 

Public Member Functions

 ~SerialConfig ()
 Destructor. More...
 
 SerialConfig (const SerialConfig &other)
 Copy constructor. More...
 
SerialConfigoperator= (const SerialConfig &other)
 Assignment operator. More...
 
bool operator== (const SerialConfig &other) const
 Equality comparison. More...
 
bool operator!= (const SerialConfig &other) const
 Non-equality comparison. More...
 
void swap (SerialConfig &other)
 Swap the contents of this object with the other object. More...
 
std::string getDevice () const
 Returns the serial port device. More...
 
speed_t getSpeed () const
 Returns the serial port speed. More...
 
tcflag_t getDataBits () const
 Returns the number of data bits. More...
 
Parity getParity () const
 Returns the parity bit generation type. More...
 
StopBits getStopBits () const
 Returns the number of stop bits. More...
 
FlowControl getFlowControl () const
 Returns the flow control type. More...
 
- Public Member Functions inherited from Config
 ~Config ()
 Destructor. More...
 
 Config (const Config &other)
 Copy constructor. More...
 
Configoperator= (const Config &other)
 Assignment operator. More...
 
bool operator== (const Config &other) const
 Equality comparison. More...
 
bool operator!= (const Config &other) const
 Non-equality comparison. More...
 
void swap (Config &other)
 Swap the contents of this object with the other object. More...
 
size_t getBufferSize () const
 Returns the buffer size (in bytes). More...
 
LengthField getLengthField () const
 Returns the size of a field containing the length of a message (in bytes). More...
 

Static Public Member Functions

static SerialConfig fromRawConfigValues (RawConfigValues rawConfigValues)
 Creates a SerialConfig object from raw configuration values. More...
 
- Static Public Member Functions inherited from Config
static Config fromRawConfigValues (RawConfigValues rawConfigValues)
 Creates a Config object from raw configuration values. More...
 
static LengthFieldMessageLength binaryFieldLengthToNumber (const std::string &binaryNumber)
 Transforms the selected binary string into a number. More...
 
static LengthFieldMessageLength computeMaximalMessageLength (unsigned lengthField)
 Returns the maximal message size that can be stored in lengthField bytes. More...
 
static std::string messageLengthToBinaryLengthField (LengthFieldMessageLength messageLength, unsigned lengthField)
 Transforms the selected message length into a binary length field string. More...
 

Private Member Functions

 SerialConfig ()
 Default constructor. More...
 
 SerialConfig (Config::RawConfigValues rawConfigValues)
 Constructor. More...
 

Static Private Member Functions

static std::string parseDevice (const std::string &rawDevice)
 
static speed_t parseSpeed (const std::string &rawSpeed)
 
static tcflag_t parseDataBits (const std::string &rawDataBits)
 
static Parity parseParity (const std::string &rawParity)
 
static StopBits parseStopBits (const std::string &rawStopBits)
 
static FlowControl parseFlowControl (const std::string &rawFlowControl)
 

Private Attributes

std::string _device
 Serial port device. More...
 
speed_t _speed
 Serial port speed (in baudes). More...
 
tcflag_t _dataBits
 Number of data bits. More...
 
Parity _parity
 Parity bit generation type. More...
 
StopBits _stopBits
 Number of stop bits. More...
 
FlowControl _flowControl
 Flow control type. More...
 

Static Private Attributes

static const std::string DEFAULT_DEVICE
 Default interface. More...
 
static const speed_t DEFAULT_SPEED
 Default speed. More...
 
static const tcflag_t DEFAULT_DATA_BITS
 Default number of data bits. More...
 
static const Parity DEFAULT_PARITY
 Default parity bit generation type. More...
 
static const StopBits DEFAULT_STOP_BITS
 Default number of stop bits. More...
 
static const FlowControl DEFAULT_FLOW_CONTROL
 Default flow control. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Config
 Config ()
 Default constructor. More...
 
 Config (RawConfigValues rawConfigValues)
 Constructor. More...
 
- Static Protected Member Functions inherited from Config
template<typename T >
static T parseNumber (const std::string &optionName, const std::string &rawValue, T minValue, T maxValue)
 Parses the selected number from the selected string. More...
 

Detailed Description

Configuration for a TCP/IP server.

This class provides a transformation of raw config values into verified and typed configuration values for a serial connection.

It provides value semantics (object copying and comparison is allowed).

Member Typedef Documentation

typedef std::map<std::string, std::string> SerialConfig::RawConfigValues

Raw configuration option -> values mapping.

Member Enumeration Documentation

Flow control types.

Enumerator
NONE_FLOW_CONTROL 
HARDWARE_FLOW_CONTROL 
SOFTWARE_FLOW_CONTROL 

Parity bit generation types.

Enumerator
NONE_PARITY 
EVEN_PARITY 
ODD_PARITY 
MARK_PARITY 
SPACE_PARITY 

Number of stop bits.

Enumerator
STOP_BITS_1 
STOP_BITS_1_5 
STOP_BITS_2 

Constructor & Destructor Documentation

SerialConfig::~SerialConfig ( )

Destructor.

Destroys a SerialConfig object.

SerialConfig::SerialConfig ( const SerialConfig other)

Copy constructor.

Parameters
otherObject that will be used as a model in the object creation.

Constructs a copy of the other object.

SerialConfig::SerialConfig ( )
private

Default constructor.

Constructs an empty SerialConfig object.

SerialConfig::SerialConfig ( Config::RawConfigValues  rawConfigValues)
private

Constructor.

Parameters
rawConfigValuesRaw configuration option -> values mappings.

Constructs a TCPIPConfig object from the selected values.

Member Function Documentation

static SerialConfig SerialConfig::fromRawConfigValues ( RawConfigValues  rawConfigValues)
static

Creates a SerialConfig object from raw configuration values.

Parameters
rawConfigValuesRaw configuration option -> values mappings.

If some passed value is invalid, InvalidValueError will be thrown.

Preconditions:

  • each option name and value must be without beginning and trailing white spaces

Meets the strong guarantee of exception safety.

tcflag_t SerialConfig::getDataBits ( ) const
inline

Returns the number of data bits.

References _dataBits.

std::string SerialConfig::getDevice ( ) const
inline

Returns the serial port device.

References _device.

FlowControl SerialConfig::getFlowControl ( ) const
inline

Returns the flow control type.

References _flowControl.

Parity SerialConfig::getParity ( ) const
inline

Returns the parity bit generation type.

References _parity.

speed_t SerialConfig::getSpeed ( ) const
inline

Returns the serial port speed.

References _speed.

StopBits SerialConfig::getStopBits ( ) const
inline

Returns the number of stop bits.

References _stopBits.

bool SerialConfig::operator!= ( const SerialConfig other) const

Non-equality comparison.

Parameters
otherObject that will be compared with this object.
Returns
True if this object is not equal to the other object.
SerialConfig& SerialConfig::operator= ( const SerialConfig other)

Assignment operator.

Parameters
otherObject that will be assigned to this object.
Returns
Reference to this object.

Guarantees the strong exception safety.

bool SerialConfig::operator== ( const SerialConfig other) const

Equality comparison.

Parameters
otherObject that will be compared with this object.
Returns
True if this object is equal to the other object.
static tcflag_t SerialConfig::parseDataBits ( const std::string &  rawDataBits)
staticprivate
static std::string SerialConfig::parseDevice ( const std::string &  rawDevice)
staticprivate
static FlowControl SerialConfig::parseFlowControl ( const std::string &  rawFlowControl)
staticprivate
static Parity SerialConfig::parseParity ( const std::string &  rawParity)
staticprivate
static speed_t SerialConfig::parseSpeed ( const std::string &  rawSpeed)
staticprivate
static StopBits SerialConfig::parseStopBits ( const std::string &  rawStopBits)
staticprivate
void SerialConfig::swap ( SerialConfig other)

Swap the contents of this object with the other object.

Parameters
otherObject that will be swapped with this object.

Guarantees nothrow exception safety.

Member Data Documentation

tcflag_t SerialConfig::_dataBits
private

Number of data bits.

Referenced by getDataBits().

std::string SerialConfig::_device
private

Serial port device.

Referenced by getDevice().

FlowControl SerialConfig::_flowControl
private

Flow control type.

Referenced by getFlowControl().

Parity SerialConfig::_parity
private

Parity bit generation type.

Referenced by getParity().

speed_t SerialConfig::_speed
private

Serial port speed (in baudes).

Referenced by getSpeed().

StopBits SerialConfig::_stopBits
private

Number of stop bits.

Referenced by getStopBits().

const tcflag_t SerialConfig::DEFAULT_DATA_BITS
staticprivate

Default number of data bits.

const std::string SerialConfig::DEFAULT_DEVICE
staticprivate

Default interface.

const FlowControl SerialConfig::DEFAULT_FLOW_CONTROL
staticprivate

Default flow control.

const Parity SerialConfig::DEFAULT_PARITY
staticprivate

Default parity bit generation type.

const speed_t SerialConfig::DEFAULT_SPEED
staticprivate

Default speed.

const StopBits SerialConfig::DEFAULT_STOP_BITS
staticprivate

Default number of stop bits.


The documentation for this class was generated from the following file: