1//
2// serial_port_base.hpp
3// ~~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2015 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 BOOST_ASIO_SERIAL_PORT_BASE_HPP
13#define BOOST_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 <boost/asio/detail/config.hpp>
20
21#if defined(BOOST_ASIO_HAS_SERIAL_PORT) \
22 || defined(GENERATING_DOCUMENTATION)
23
24#if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
25# include <termios.h>
26#endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
27
28#include <boost/asio/detail/socket_types.hpp>
29#include <boost/system/error_code.hpp>
30
31#if defined(GENERATING_DOCUMENTATION)
32# define BOOST_ASIO_OPTION_STORAGE implementation_defined
33#elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
34# define BOOST_ASIO_OPTION_STORAGE DCB
35#else
36# define BOOST_ASIO_OPTION_STORAGE termios
37#endif
38
39#include <boost/asio/detail/push_options.hpp>
40
41namespace boost {
42namespace asio {
43
44/// The serial_port_base class is used as a base for the basic_serial_port class
45/// template so that we have a common place to define the serial port options.
46class serial_port_base
47{
48public:
49 /// Serial port option to permit changing the baud rate.
50 /**
51 * Implements changing the baud rate for a given serial port.
52 */
53 class baud_rate
54 {
55 public:
56 explicit baud_rate(unsigned int rate = 0);
57 unsigned int value() const;
58 BOOST_ASIO_DECL boost::system::error_code store(
59 BOOST_ASIO_OPTION_STORAGE& storage,
60 boost::system::error_code& ec) const;
61 BOOST_ASIO_DECL boost::system::error_code load(
62 const BOOST_ASIO_OPTION_STORAGE& storage,
63 boost::system::error_code& ec);
64 private:
65 unsigned int value_;
66 };
67
68 /// Serial port option to permit changing the flow control.
69 /**
70 * Implements changing the flow control for a given serial port.
71 */
72 class flow_control
73 {
74 public:
75 enum type { none, software, hardware };
76 BOOST_ASIO_DECL explicit flow_control(type t = none);
77 type value() const;
78 BOOST_ASIO_DECL boost::system::error_code store(
79 BOOST_ASIO_OPTION_STORAGE& storage,
80 boost::system::error_code& ec) const;
81 BOOST_ASIO_DECL boost::system::error_code load(
82 const BOOST_ASIO_OPTION_STORAGE& storage,
83 boost::system::error_code& ec);
84 private:
85 type value_;
86 };
87
88 /// Serial port option to permit changing the parity.
89 /**
90 * Implements changing the parity for a given serial port.
91 */
92 class parity
93 {
94 public:
95 enum type { none, odd, even };
96 BOOST_ASIO_DECL explicit parity(type t = none);
97 type value() const;
98 BOOST_ASIO_DECL boost::system::error_code store(
99 BOOST_ASIO_OPTION_STORAGE& storage,
100 boost::system::error_code& ec) const;
101 BOOST_ASIO_DECL boost::system::error_code load(
102 const BOOST_ASIO_OPTION_STORAGE& storage,
103 boost::system::error_code& ec);
104 private:
105 type value_;
106 };
107
108 /// Serial port option to permit changing the number of stop bits.
109 /**
110 * Implements changing the number of stop bits for a given serial port.
111 */
112 class stop_bits
113 {
114 public:
115 enum type { one, onepointfive, two };
116 BOOST_ASIO_DECL explicit stop_bits(type t = one);
117 type value() const;
118 BOOST_ASIO_DECL boost::system::error_code store(
119 BOOST_ASIO_OPTION_STORAGE& storage,
120 boost::system::error_code& ec) const;
121 BOOST_ASIO_DECL boost::system::error_code load(
122 const BOOST_ASIO_OPTION_STORAGE& storage,
123 boost::system::error_code& ec);
124 private:
125 type value_;
126 };
127
128 /// Serial port option to permit changing the character size.
129 /**
130 * Implements changing the character size for a given serial port.
131 */
132 class character_size
133 {
134 public:
135 BOOST_ASIO_DECL explicit character_size(unsigned int t = 8);
136 unsigned int value() const;
137 BOOST_ASIO_DECL boost::system::error_code store(
138 BOOST_ASIO_OPTION_STORAGE& storage,
139 boost::system::error_code& ec) const;
140 BOOST_ASIO_DECL boost::system::error_code load(
141 const BOOST_ASIO_OPTION_STORAGE& storage,
142 boost::system::error_code& ec);
143 private:
144 unsigned int value_;
145 };
146
147protected:
148 /// Protected destructor to prevent deletion through this type.
149 ~serial_port_base()
150 {
151 }
152};
153
154} // namespace asio
155} // namespace boost
156
157#include <boost/asio/detail/pop_options.hpp>
158
159#undef BOOST_ASIO_OPTION_STORAGE
160
161#include <boost/asio/impl/serial_port_base.hpp>
162#if defined(BOOST_ASIO_HEADER_ONLY)
163# include <boost/asio/impl/serial_port_base.ipp>
164#endif // defined(BOOST_ASIO_HEADER_ONLY)
165
166#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
167 // || defined(GENERATING_DOCUMENTATION)
168
169#endif // BOOST_ASIO_SERIAL_PORT_BASE_HPP
170