PageRenderTime 31ms CodeModel.GetById 2ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/asio/serial_port_service.hpp

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