2 // serial_port_base.hpp
3 // ~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
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)
12 #ifndef BOOST_ASIO_SERIAL_PORT_BASE_HPP
13 #define BOOST_ASIO_SERIAL_PORT_BASE_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/config.hpp>
21 #if defined(BOOST_ASIO_HAS_SERIAL_PORT) \
22 || defined(GENERATING_DOCUMENTATION)
24 #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
26 #endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
28 #include <boost/detail/workaround.hpp>
29 #include <boost/asio/detail/socket_types.hpp>
30 #include <boost/system/error_code.hpp>
32 #if defined(GENERATING_DOCUMENTATION)
33 # define BOOST_ASIO_OPTION_STORAGE implementation_defined
34 #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__)
35 # define BOOST_ASIO_OPTION_STORAGE DCB
37 # define BOOST_ASIO_OPTION_STORAGE termios
40 #include <boost/asio/detail/push_options.hpp>
45 /// The serial_port_base class is used as a base for the basic_serial_port class
46 /// template so that we have a common place to define the serial port options.
47 class serial_port_base
50 /// Serial port option to permit changing the baud rate.
52 * Implements changing the baud rate for a given serial port.
57 explicit baud_rate(unsigned int rate = 0);
58 unsigned int value() const;
59 BOOST_ASIO_DECL boost::system::error_code store(
60 BOOST_ASIO_OPTION_STORAGE& storage,
61 boost::system::error_code& ec) const;
62 BOOST_ASIO_DECL boost::system::error_code load(
63 const BOOST_ASIO_OPTION_STORAGE& storage,
64 boost::system::error_code& ec);
69 /// Serial port option to permit changing the flow control.
71 * Implements changing the flow control for a given serial port.
76 enum type { none, software, hardware };
77 BOOST_ASIO_DECL explicit flow_control(type t = none);
79 BOOST_ASIO_DECL boost::system::error_code store(
80 BOOST_ASIO_OPTION_STORAGE& storage,
81 boost::system::error_code& ec) const;
82 BOOST_ASIO_DECL boost::system::error_code load(
83 const BOOST_ASIO_OPTION_STORAGE& storage,
84 boost::system::error_code& ec);
89 /// Serial port option to permit changing the parity.
91 * Implements changing the parity for a given serial port.
96 enum type { none, odd, even };
97 BOOST_ASIO_DECL explicit parity(type t = none);
99 BOOST_ASIO_DECL boost::system::error_code store(
100 BOOST_ASIO_OPTION_STORAGE& storage,
101 boost::system::error_code& ec) const;
102 BOOST_ASIO_DECL boost::system::error_code load(
103 const BOOST_ASIO_OPTION_STORAGE& storage,
104 boost::system::error_code& ec);
109 /// Serial port option to permit changing the number of stop bits.
111 * Implements changing the number of stop bits for a given serial port.
116 enum type { one, onepointfive, two };
117 BOOST_ASIO_DECL explicit stop_bits(type t = one);
119 BOOST_ASIO_DECL boost::system::error_code store(
120 BOOST_ASIO_OPTION_STORAGE& storage,
121 boost::system::error_code& ec) const;
122 BOOST_ASIO_DECL boost::system::error_code load(
123 const BOOST_ASIO_OPTION_STORAGE& storage,
124 boost::system::error_code& ec);
129 /// Serial port option to permit changing the character size.
131 * Implements changing the character size for a given serial port.
136 BOOST_ASIO_DECL explicit character_size(unsigned int t = 8);
137 unsigned int value() const;
138 BOOST_ASIO_DECL boost::system::error_code store(
139 BOOST_ASIO_OPTION_STORAGE& storage,
140 boost::system::error_code& ec) const;
141 BOOST_ASIO_DECL boost::system::error_code load(
142 const BOOST_ASIO_OPTION_STORAGE& storage,
143 boost::system::error_code& ec);
149 /// Protected destructor to prevent deletion through this type.
154 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
156 // Workaround to enable the empty base optimisation with Borland C++.
164 #include <boost/asio/detail/pop_options.hpp>
166 #undef BOOST_ASIO_OPTION_STORAGE
168 #include <boost/asio/impl/serial_port_base.hpp>
169 #if defined(BOOST_ASIO_HEADER_ONLY)
170 # include <boost/asio/impl/serial_port_base.ipp>
171 #endif // defined(BOOST_ASIO_HEADER_ONLY)
173 #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
174 // || defined(GENERATING_DOCUMENTATION)
176 #endif // BOOST_ASIO_SERIAL_PORT_BASE_HPP