1 // 2 // serial_port_base.hpp 3 // ~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com) 7 // 8 // Distributed under the Boost Software License, Version 1.0. (See accompanying 9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 10 // 11 12 #ifndef ASIO_SERIAL_PORT_BASE_HPP 13 #define ASIO_SERIAL_PORT_BASE_HPP 14 15 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 # pragma once 17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 19 #include "asio/detail/config.hpp" 20 21 #if defined(ASIO_HAS_SERIAL_PORT) \ 22 || defined(GENERATING_DOCUMENTATION) 23 24 #if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__) 25 # include <termios.h> 26 #endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__) 27 28 #include "asio/detail/socket_types.hpp" 29 #include "asio/error_code.hpp" 30 31 #if defined(GENERATING_DOCUMENTATION) 32 # define ASIO_OPTION_STORAGE implementation_defined 33 #elif defined(ASIO_WINDOWS) || defined(__CYGWIN__) 34 # define ASIO_OPTION_STORAGE DCB 35 #else 36 # define ASIO_OPTION_STORAGE termios 37 #endif 38 39 #include "asio/detail/push_options.hpp" 40 41 namespace asio { 42 43 /// The serial_port_base class is used as a base for the basic_serial_port class 44 /// template so that we have a common place to define the serial port options. 45 class serial_port_base 46 { 47 public: 48 /// Serial port option to permit changing the baud rate. 49 /** 50 * Implements changing the baud rate for a given serial port. 51 */ 52 class baud_rate 53 { 54 public: 55 explicit baud_rate(unsigned int rate = 0); 56 unsigned int value() const; 57 ASIO_DECL asio::error_code store( 58 ASIO_OPTION_STORAGE& storage, 59 asio::error_code& ec) const; 60 ASIO_DECL asio::error_code load( 61 const ASIO_OPTION_STORAGE& storage, 62 asio::error_code& ec); 63 private: 64 unsigned int value_; 65 }; 66 67 /// Serial port option to permit changing the flow control. 68 /** 69 * Implements changing the flow control for a given serial port. 70 */ 71 class flow_control 72 { 73 public: 74 enum type { none, software, hardware }; 75 ASIO_DECL explicit flow_control(type t = none); 76 type value() const; 77 ASIO_DECL asio::error_code store( 78 ASIO_OPTION_STORAGE& storage, 79 asio::error_code& ec) const; 80 ASIO_DECL asio::error_code load( 81 const ASIO_OPTION_STORAGE& storage, 82 asio::error_code& ec); 83 private: 84 type value_; 85 }; 86 87 /// Serial port option to permit changing the parity. 88 /** 89 * Implements changing the parity for a given serial port. 90 */ 91 class parity 92 { 93 public: 94 enum type { none, odd, even }; 95 ASIO_DECL explicit parity(type t = none); 96 type value() const; 97 ASIO_DECL asio::error_code store( 98 ASIO_OPTION_STORAGE& storage, 99 asio::error_code& ec) const; 100 ASIO_DECL asio::error_code load( 101 const ASIO_OPTION_STORAGE& storage, 102 asio::error_code& ec); 103 private: 104 type value_; 105 }; 106 107 /// Serial port option to permit changing the number of stop bits. 108 /** 109 * Implements changing the number of stop bits for a given serial port. 110 */ 111 class stop_bits 112 { 113 public: 114 enum type { one, onepointfive, two }; 115 ASIO_DECL explicit stop_bits(type t = one); 116 type value() const; 117 ASIO_DECL asio::error_code store( 118 ASIO_OPTION_STORAGE& storage, 119 asio::error_code& ec) const; 120 ASIO_DECL asio::error_code load( 121 const ASIO_OPTION_STORAGE& storage, 122 asio::error_code& ec); 123 private: 124 type value_; 125 }; 126 127 /// Serial port option to permit changing the character size. 128 /** 129 * Implements changing the character size for a given serial port. 130 */ 131 class character_size 132 { 133 public: 134 ASIO_DECL explicit character_size(unsigned int t = 8); 135 unsigned int value() const; 136 ASIO_DECL asio::error_code store( 137 ASIO_OPTION_STORAGE& storage, 138 asio::error_code& ec) const; 139 ASIO_DECL asio::error_code load( 140 const ASIO_OPTION_STORAGE& storage, 141 asio::error_code& ec); 142 private: 143 unsigned int value_; 144 }; 145 146 protected: 147 /// Protected destructor to prevent deletion through this type. ~serial_port_base()148 ~serial_port_base() 149 { 150 } 151 }; 152 153 } // namespace asio 154 155 #include "asio/detail/pop_options.hpp" 156 157 #undef ASIO_OPTION_STORAGE 158 159 #include "asio/impl/serial_port_base.hpp" 160 #if defined(ASIO_HEADER_ONLY) 161 # include "asio/impl/serial_port_base.ipp" 162 #endif // defined(ASIO_HEADER_ONLY) 163 164 #endif // defined(ASIO_HAS_SERIAL_PORT) 165 // || defined(GENERATING_DOCUMENTATION) 166 167 #endif // ASIO_SERIAL_PORT_BASE_HPP 168