Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / serial_port_service.hpp @ 2486

History | View | Annotate | Download (7.6 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// serial_port_service.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_SERIAL_PORT_SERVICE_HPP
12 2486 sjacqu01
#define BOOST_ASIO_SERIAL_PORT_SERVICE_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
20 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_SERIAL_PORT) \
21 2486 sjacqu01
  || defined(GENERATING_DOCUMENTATION)
22 2486 sjacqu01
23 2486 sjacqu01
#include <cstddef>
24 2486 sjacqu01
#include <string>
25 2486 sjacqu01
#include <boost/asio/async_result.hpp>
26 2486 sjacqu01
#include <boost/asio/detail/reactive_serial_port_service.hpp>
27 2486 sjacqu01
#include <boost/asio/detail/win_iocp_serial_port_service.hpp>
28 2486 sjacqu01
#include <boost/asio/error.hpp>
29 2486 sjacqu01
#include <boost/asio/io_service.hpp>
30 2486 sjacqu01
#include <boost/asio/serial_port_base.hpp>
31 2486 sjacqu01
32 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
33 2486 sjacqu01
34 2486 sjacqu01
namespace boost {
35 2486 sjacqu01
namespace asio {
36 2486 sjacqu01
37 2486 sjacqu01
/// Default service implementation for a serial port.
38 2486 sjacqu01
class serial_port_service
39 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
40 2486 sjacqu01
  : public boost::asio::io_service::service
41 2486 sjacqu01
#else
42 2486 sjacqu01
  : public boost::asio::detail::service_base<serial_port_service>
43 2486 sjacqu01
#endif
44 2486 sjacqu01
{
45 2486 sjacqu01
public:
46 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
47 2486 sjacqu01
  /// The unique service identifier.
48 2486 sjacqu01
  static boost::asio::io_service::id id;
49 2486 sjacqu01
#endif
50 2486 sjacqu01
51 2486 sjacqu01
private:
52 2486 sjacqu01
  // The type of the platform-specific implementation.
53 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_IOCP)
54 2486 sjacqu01
  typedef detail::win_iocp_serial_port_service service_impl_type;
55 2486 sjacqu01
#else
56 2486 sjacqu01
  typedef detail::reactive_serial_port_service service_impl_type;
57 2486 sjacqu01
#endif
58 2486 sjacqu01
59 2486 sjacqu01
public:
60 2486 sjacqu01
  /// The type of a serial port implementation.
61 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
62 2486 sjacqu01
  typedef implementation_defined implementation_type;
63 2486 sjacqu01
#else
64 2486 sjacqu01
  typedef service_impl_type::implementation_type implementation_type;
65 2486 sjacqu01
#endif
66 2486 sjacqu01
67 2486 sjacqu01
  /// (Deprecated: Use native_handle_type.) The native handle type.
68 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
69 2486 sjacqu01
  typedef implementation_defined native_type;
70 2486 sjacqu01
#else
71 2486 sjacqu01
  typedef service_impl_type::native_handle_type native_type;
72 2486 sjacqu01
#endif
73 2486 sjacqu01
74 2486 sjacqu01
  /// The native handle type.
75 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
76 2486 sjacqu01
  typedef implementation_defined native_handle_type;
77 2486 sjacqu01
#else
78 2486 sjacqu01
  typedef service_impl_type::native_handle_type native_handle_type;
79 2486 sjacqu01
#endif
80 2486 sjacqu01
81 2486 sjacqu01
  /// Construct a new serial port service for the specified io_service.
82 2486 sjacqu01
  explicit serial_port_service(boost::asio::io_service& io_service)
83 2486 sjacqu01
    : boost::asio::detail::service_base<serial_port_service>(io_service),
84 2486 sjacqu01
      service_impl_(io_service)
85 2486 sjacqu01
  {
86 2486 sjacqu01
  }
87 2486 sjacqu01
88 2486 sjacqu01
  /// Construct a new serial port implementation.
89 2486 sjacqu01
  void construct(implementation_type& impl)
90 2486 sjacqu01
  {
91 2486 sjacqu01
    service_impl_.construct(impl);
92 2486 sjacqu01
  }
93 2486 sjacqu01
94 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
95 2486 sjacqu01
  /// Move-construct a new serial port implementation.
96 2486 sjacqu01
  void move_construct(implementation_type& impl,
97 2486 sjacqu01
      implementation_type& other_impl)
98 2486 sjacqu01
  {
99 2486 sjacqu01
    service_impl_.move_construct(impl, other_impl);
100 2486 sjacqu01
  }
101 2486 sjacqu01
102 2486 sjacqu01
  /// Move-assign from another serial port implementation.
103 2486 sjacqu01
  void move_assign(implementation_type& impl,
104 2486 sjacqu01
      serial_port_service& other_service,
105 2486 sjacqu01
      implementation_type& other_impl)
106 2486 sjacqu01
  {
107 2486 sjacqu01
    service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
108 2486 sjacqu01
  }
109 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
110 2486 sjacqu01
111 2486 sjacqu01
  /// Destroy a serial port implementation.
112 2486 sjacqu01
  void destroy(implementation_type& impl)
113 2486 sjacqu01
  {
114 2486 sjacqu01
    service_impl_.destroy(impl);
115 2486 sjacqu01
  }
116 2486 sjacqu01
117 2486 sjacqu01
  /// Open a serial port.
118 2486 sjacqu01
  boost::system::error_code open(implementation_type& impl,
119 2486 sjacqu01
      const std::string& device, boost::system::error_code& ec)
120 2486 sjacqu01
  {
121 2486 sjacqu01
    return service_impl_.open(impl, device, ec);
122 2486 sjacqu01
  }
123 2486 sjacqu01
124 2486 sjacqu01
  /// Assign an existing native handle to a serial port.
125 2486 sjacqu01
  boost::system::error_code assign(implementation_type& impl,
126 2486 sjacqu01
      const native_handle_type& handle, boost::system::error_code& ec)
127 2486 sjacqu01
  {
128 2486 sjacqu01
    return service_impl_.assign(impl, handle, ec);
129 2486 sjacqu01
  }
130 2486 sjacqu01
131 2486 sjacqu01
  /// Determine whether the handle is open.
132 2486 sjacqu01
  bool is_open(const implementation_type& impl) const
133 2486 sjacqu01
  {
134 2486 sjacqu01
    return service_impl_.is_open(impl);
135 2486 sjacqu01
  }
136 2486 sjacqu01
137 2486 sjacqu01
  /// Close a serial port implementation.
138 2486 sjacqu01
  boost::system::error_code close(implementation_type& impl,
139 2486 sjacqu01
      boost::system::error_code& ec)
140 2486 sjacqu01
  {
141 2486 sjacqu01
    return service_impl_.close(impl, ec);
142 2486 sjacqu01
  }
143 2486 sjacqu01
144 2486 sjacqu01
  /// (Deprecated: Use native_handle().) Get the native handle implementation.
145 2486 sjacqu01
  native_type native(implementation_type& impl)
146 2486 sjacqu01
  {
147 2486 sjacqu01
    return service_impl_.native_handle(impl);
148 2486 sjacqu01
  }
149 2486 sjacqu01
150 2486 sjacqu01
  /// Get the native handle implementation.
151 2486 sjacqu01
  native_handle_type native_handle(implementation_type& impl)
152 2486 sjacqu01
  {
153 2486 sjacqu01
    return service_impl_.native_handle(impl);
154 2486 sjacqu01
  }
155 2486 sjacqu01
156 2486 sjacqu01
  /// Cancel all asynchronous operations associated with the handle.
157 2486 sjacqu01
  boost::system::error_code cancel(implementation_type& impl,
158 2486 sjacqu01
      boost::system::error_code& ec)
159 2486 sjacqu01
  {
160 2486 sjacqu01
    return service_impl_.cancel(impl, ec);
161 2486 sjacqu01
  }
162 2486 sjacqu01
163 2486 sjacqu01
  /// Set a serial port option.
164 2486 sjacqu01
  template <typename SettableSerialPortOption>
165 2486 sjacqu01
  boost::system::error_code set_option(implementation_type& impl,
166 2486 sjacqu01
      const SettableSerialPortOption& option, boost::system::error_code& ec)
167 2486 sjacqu01
  {
168 2486 sjacqu01
    return service_impl_.set_option(impl, option, ec);
169 2486 sjacqu01
  }
170 2486 sjacqu01
171 2486 sjacqu01
  /// Get a serial port option.
172 2486 sjacqu01
  template <typename GettableSerialPortOption>
173 2486 sjacqu01
  boost::system::error_code get_option(const implementation_type& impl,
174 2486 sjacqu01
      GettableSerialPortOption& option, boost::system::error_code& ec) const
175 2486 sjacqu01
  {
176 2486 sjacqu01
    return service_impl_.get_option(impl, option, ec);
177 2486 sjacqu01
  }
178 2486 sjacqu01
179 2486 sjacqu01
  /// Send a break sequence to the serial port.
180 2486 sjacqu01
  boost::system::error_code send_break(implementation_type& impl,
181 2486 sjacqu01
      boost::system::error_code& ec)
182 2486 sjacqu01
  {
183 2486 sjacqu01
    return service_impl_.send_break(impl, ec);
184 2486 sjacqu01
  }
185 2486 sjacqu01
186 2486 sjacqu01
  /// Write the given data to the stream.
187 2486 sjacqu01
  template <typename ConstBufferSequence>
188 2486 sjacqu01
  std::size_t write_some(implementation_type& impl,
189 2486 sjacqu01
      const ConstBufferSequence& buffers, boost::system::error_code& ec)
190 2486 sjacqu01
  {
191 2486 sjacqu01
    return service_impl_.write_some(impl, buffers, ec);
192 2486 sjacqu01
  }
193 2486 sjacqu01
194 2486 sjacqu01
  /// Start an asynchronous write.
195 2486 sjacqu01
  template <typename ConstBufferSequence, typename WriteHandler>
196 2486 sjacqu01
  BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
197 2486 sjacqu01
      void (boost::system::error_code, std::size_t))
198 2486 sjacqu01
  async_write_some(implementation_type& impl,
199 2486 sjacqu01
      const ConstBufferSequence& buffers,
200 2486 sjacqu01
      BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
201 2486 sjacqu01
  {
202 2486 sjacqu01
    detail::async_result_init<
203 2486 sjacqu01
      WriteHandler, void (boost::system::error_code, std::size_t)> init(
204 2486 sjacqu01
        BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
205 2486 sjacqu01
206 2486 sjacqu01
    service_impl_.async_write_some(impl, buffers, init.handler);
207 2486 sjacqu01
208 2486 sjacqu01
    return init.result.get();
209 2486 sjacqu01
  }
210 2486 sjacqu01
211 2486 sjacqu01
  /// Read some data from the stream.
212 2486 sjacqu01
  template <typename MutableBufferSequence>
213 2486 sjacqu01
  std::size_t read_some(implementation_type& impl,
214 2486 sjacqu01
      const MutableBufferSequence& buffers, boost::system::error_code& ec)
215 2486 sjacqu01
  {
216 2486 sjacqu01
    return service_impl_.read_some(impl, buffers, ec);
217 2486 sjacqu01
  }
218 2486 sjacqu01
219 2486 sjacqu01
  /// Start an asynchronous read.
220 2486 sjacqu01
  template <typename MutableBufferSequence, typename ReadHandler>
221 2486 sjacqu01
  BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
222 2486 sjacqu01
      void (boost::system::error_code, std::size_t))
223 2486 sjacqu01
  async_read_some(implementation_type& impl,
224 2486 sjacqu01
      const MutableBufferSequence& buffers,
225 2486 sjacqu01
      BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
226 2486 sjacqu01
  {
227 2486 sjacqu01
    detail::async_result_init<
228 2486 sjacqu01
      ReadHandler, void (boost::system::error_code, std::size_t)> init(
229 2486 sjacqu01
        BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
230 2486 sjacqu01
231 2486 sjacqu01
    service_impl_.async_read_some(impl, buffers, init.handler);
232 2486 sjacqu01
233 2486 sjacqu01
    return init.result.get();
234 2486 sjacqu01
  }
235 2486 sjacqu01
236 2486 sjacqu01
private:
237 2486 sjacqu01
  // Destroy all user-defined handler objects owned by the service.
238 2486 sjacqu01
  void shutdown_service()
239 2486 sjacqu01
  {
240 2486 sjacqu01
    service_impl_.shutdown_service();
241 2486 sjacqu01
  }
242 2486 sjacqu01
243 2486 sjacqu01
  // The platform-specific implementation.
244 2486 sjacqu01
  service_impl_type service_impl_;
245 2486 sjacqu01
};
246 2486 sjacqu01
247 2486 sjacqu01
} // namespace asio
248 2486 sjacqu01
} // namespace boost
249 2486 sjacqu01
250 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
251 2486 sjacqu01
252 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
253 2486 sjacqu01
       //   || defined(GENERATING_DOCUMENTATION)
254 2486 sjacqu01
255 2486 sjacqu01
#endif // BOOST_ASIO_SERIAL_PORT_SERVICE_HPP