/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. #ifndef BOOST_ASIO_SERIAL_PORT_SERVICE_HPP
  11. #define BOOST_ASIO_SERIAL_PORT_SERVICE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if defined(BOOST_ASIO_HAS_SERIAL_PORT) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include <cstddef>
  19. #include <string>
  20. #include <boost/asio/detail/reactive_serial_port_service.hpp>
  21. #include <boost/asio/detail/win_iocp_serial_port_service.hpp>
  22. #include <boost/asio/error.hpp>
  23. #include <boost/asio/io_service.hpp>
  24. #include <boost/asio/serial_port_base.hpp>
  25. #include <boost/asio/detail/push_options.hpp>
  26. namespace boost {
  27. namespace asio {
  28. /// Default service implementation for a serial port.
  29. class serial_port_service
  30. #if defined(GENERATING_DOCUMENTATION)
  31. : public boost::asio::io_service::service
  32. #else
  33. : public boost::asio::detail::service_base<serial_port_service>
  34. #endif
  35. {
  36. public:
  37. #if defined(GENERATING_DOCUMENTATION)
  38. /// The unique service identifier.
  39. static boost::asio::io_service::id id;
  40. #endif
  41. private:
  42. // The type of the platform-specific implementation.
  43. #if defined(BOOST_ASIO_HAS_IOCP)
  44. typedef detail::win_iocp_serial_port_service service_impl_type;
  45. #else
  46. typedef detail::reactive_serial_port_service service_impl_type;
  47. #endif
  48. public:
  49. /// The type of a serial port implementation.
  50. #if defined(GENERATING_DOCUMENTATION)
  51. typedef implementation_defined implementation_type;
  52. #else
  53. typedef service_impl_type::implementation_type implementation_type;
  54. #endif
  55. /// (Deprecated: Use native_handle_type.) The native handle type.
  56. #if defined(GENERATING_DOCUMENTATION)
  57. typedef implementation_defined native_type;
  58. #else
  59. typedef service_impl_type::native_handle_type native_type;
  60. #endif
  61. /// The native handle type.
  62. #if defined(GENERATING_DOCUMENTATION)
  63. typedef implementation_defined native_handle_type;
  64. #else
  65. typedef service_impl_type::native_handle_type native_handle_type;
  66. #endif
  67. /// Construct a new serial port service for the specified io_service.
  68. explicit serial_port_service(boost::asio::io_service& io_service)
  69. : boost::asio::detail::service_base<serial_port_service>(io_service),
  70. service_impl_(io_service)
  71. {
  72. }
  73. /// Construct a new serial port implementation.
  74. void construct(implementation_type& impl)
  75. {
  76. service_impl_.construct(impl);
  77. }
  78. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  79. /// Move-construct a new serial port implementation.
  80. void move_construct(implementation_type& impl,
  81. implementation_type& other_impl)
  82. {
  83. service_impl_.move_construct(impl, other_impl);
  84. }
  85. /// Move-assign from another serial port implementation.
  86. void move_assign(implementation_type& impl,
  87. serial_port_service& other_service,
  88. implementation_type& other_impl)
  89. {
  90. service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
  91. }
  92. #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  93. /// Destroy a serial port implementation.
  94. void destroy(implementation_type& impl)
  95. {
  96. service_impl_.destroy(impl);
  97. }
  98. /// Open a serial port.
  99. boost::system::error_code open(implementation_type& impl,
  100. const std::string& device, boost::system::error_code& ec)
  101. {
  102. return service_impl_.open(impl, device, ec);
  103. }
  104. /// Assign an existing native handle to a serial port.
  105. boost::system::error_code assign(implementation_type& impl,
  106. const native_handle_type& handle, boost::system::error_code& ec)
  107. {
  108. return service_impl_.assign(impl, handle, ec);
  109. }
  110. /// Determine whether the handle is open.
  111. bool is_open(const implementation_type& impl) const
  112. {
  113. return service_impl_.is_open(impl);
  114. }
  115. /// Close a serial port implementation.
  116. boost::system::error_code close(implementation_type& impl,
  117. boost::system::error_code& ec)
  118. {
  119. return service_impl_.close(impl, ec);
  120. }
  121. /// (Deprecated: Use native_handle().) Get the native handle implementation.
  122. native_type native(implementation_type& impl)
  123. {
  124. return service_impl_.native_handle(impl);
  125. }
  126. /// Get the native handle implementation.
  127. native_handle_type native_handle(implementation_type& impl)
  128. {
  129. return service_impl_.native_handle(impl);
  130. }
  131. /// Cancel all asynchronous operations associated with the handle.
  132. boost::system::error_code cancel(implementation_type& impl,
  133. boost::system::error_code& ec)
  134. {
  135. return service_impl_.cancel(impl, ec);
  136. }
  137. /// Set a serial port option.
  138. template <typename SettableSerialPortOption>
  139. boost::system::error_code set_option(implementation_type& impl,
  140. const SettableSerialPortOption& option, boost::system::error_code& ec)
  141. {
  142. return service_impl_.set_option(impl, option, ec);
  143. }
  144. /// Get a serial port option.
  145. template <typename GettableSerialPortOption>
  146. boost::system::error_code get_option(const implementation_type& impl,
  147. GettableSerialPortOption& option, boost::system::error_code& ec) const
  148. {
  149. return service_impl_.get_option(impl, option, ec);
  150. }
  151. /// Send a break sequence to the serial port.
  152. boost::system::error_code send_break(implementation_type& impl,
  153. boost::system::error_code& ec)
  154. {
  155. return service_impl_.send_break(impl, ec);
  156. }
  157. /// Write the given data to the stream.
  158. template <typename ConstBufferSequence>
  159. std::size_t write_some(implementation_type& impl,
  160. const ConstBufferSequence& buffers, boost::system::error_code& ec)
  161. {
  162. return service_impl_.write_some(impl, buffers, ec);
  163. }
  164. /// Start an asynchronous write.
  165. template <typename ConstBufferSequence, typename WriteHandler>
  166. void async_write_some(implementation_type& impl,
  167. const ConstBufferSequence& buffers,
  168. BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  169. {
  170. service_impl_.async_write_some(impl, buffers,
  171. BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
  172. }
  173. /// Read some data from the stream.
  174. template <typename MutableBufferSequence>
  175. std::size_t read_some(implementation_type& impl,
  176. const MutableBufferSequence& buffers, boost::system::error_code& ec)
  177. {
  178. return service_impl_.read_some(impl, buffers, ec);
  179. }
  180. /// Start an asynchronous read.
  181. template <typename MutableBufferSequence, typename ReadHandler>
  182. void async_read_some(implementation_type& impl,
  183. const MutableBufferSequence& buffers,
  184. BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
  185. {
  186. service_impl_.async_read_some(impl, buffers,
  187. BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
  188. }
  189. private:
  190. // Destroy all user-defined handler objects owned by the service.
  191. void shutdown_service()
  192. {
  193. service_impl_.shutdown_service();
  194. }
  195. // The platform-specific implementation.
  196. service_impl_type service_impl_;
  197. };
  198. } // namespace asio
  199. } // namespace boost
  200. #include <boost/asio/detail/pop_options.hpp>
  201. #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
  202. // || defined(GENERATING_DOCUMENTATION)
  203. #endif // BOOST_ASIO_SERIAL_PORT_SERVICE_HPP