object_handle_service.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // windows/object_handle_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. // Copyright (c) 2011 Boris Schaeling (boris@highscore.de)
  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. #ifndef BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
  12. #define BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include <boost/asio/detail/config.hpp>
  17. #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \
  18. || defined(GENERATING_DOCUMENTATION)
  19. #include <boost/asio/async_result.hpp>
  20. #include <boost/asio/detail/win_object_handle_service.hpp>
  21. #include <boost/asio/error.hpp>
  22. #include <boost/asio/io_service.hpp>
  23. #include <boost/asio/detail/push_options.hpp>
  24. namespace boost {
  25. namespace asio {
  26. namespace windows {
  27. /// Default service implementation for an object handle.
  28. class object_handle_service
  29. #if defined(GENERATING_DOCUMENTATION)
  30. : public boost::asio::io_service::service
  31. #else
  32. : public boost::asio::detail::service_base<object_handle_service>
  33. #endif
  34. {
  35. public:
  36. #if defined(GENERATING_DOCUMENTATION)
  37. /// The unique service identifier.
  38. static boost::asio::io_service::id id;
  39. #endif
  40. private:
  41. // The type of the platform-specific implementation.
  42. typedef detail::win_object_handle_service service_impl_type;
  43. public:
  44. /// The type of an object handle implementation.
  45. #if defined(GENERATING_DOCUMENTATION)
  46. typedef implementation_defined implementation_type;
  47. #else
  48. typedef service_impl_type::implementation_type implementation_type;
  49. #endif
  50. /// The native handle type.
  51. #if defined(GENERATING_DOCUMENTATION)
  52. typedef implementation_defined native_handle_type;
  53. #else
  54. typedef service_impl_type::native_handle_type native_handle_type;
  55. #endif
  56. /// Construct a new object handle service for the specified io_service.
  57. explicit object_handle_service(boost::asio::io_service& io_service)
  58. : boost::asio::detail::service_base<object_handle_service>(io_service),
  59. service_impl_(io_service)
  60. {
  61. }
  62. /// Construct a new object handle implementation.
  63. void construct(implementation_type& impl)
  64. {
  65. service_impl_.construct(impl);
  66. }
  67. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  68. /// Move-construct a new object handle implementation.
  69. void move_construct(implementation_type& impl,
  70. implementation_type& other_impl)
  71. {
  72. service_impl_.move_construct(impl, other_impl);
  73. }
  74. /// Move-assign from another object handle implementation.
  75. void move_assign(implementation_type& impl,
  76. object_handle_service& other_service,
  77. implementation_type& other_impl)
  78. {
  79. service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
  80. }
  81. #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  82. /// Destroy an object handle implementation.
  83. void destroy(implementation_type& impl)
  84. {
  85. service_impl_.destroy(impl);
  86. }
  87. /// Assign an existing native handle to an object handle.
  88. boost::system::error_code assign(implementation_type& impl,
  89. const native_handle_type& handle, boost::system::error_code& ec)
  90. {
  91. return service_impl_.assign(impl, handle, ec);
  92. }
  93. /// Determine whether the handle is open.
  94. bool is_open(const implementation_type& impl) const
  95. {
  96. return service_impl_.is_open(impl);
  97. }
  98. /// Close an object handle implementation.
  99. boost::system::error_code close(implementation_type& impl,
  100. boost::system::error_code& ec)
  101. {
  102. return service_impl_.close(impl, ec);
  103. }
  104. /// Get the native handle implementation.
  105. native_handle_type native_handle(implementation_type& impl)
  106. {
  107. return service_impl_.native_handle(impl);
  108. }
  109. /// Cancel all asynchronous operations associated with the handle.
  110. boost::system::error_code cancel(implementation_type& impl,
  111. boost::system::error_code& ec)
  112. {
  113. return service_impl_.cancel(impl, ec);
  114. }
  115. // Wait for a signaled state.
  116. void wait(implementation_type& impl, boost::system::error_code& ec)
  117. {
  118. service_impl_.wait(impl, ec);
  119. }
  120. /// Start an asynchronous wait.
  121. template <typename WaitHandler>
  122. BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
  123. void (boost::system::error_code))
  124. async_wait(implementation_type& impl,
  125. BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
  126. {
  127. boost::asio::detail::async_result_init<
  128. WaitHandler, void (boost::system::error_code)> init(
  129. BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
  130. service_impl_.async_wait(impl, init.handler);
  131. return init.result.get();
  132. }
  133. private:
  134. // Destroy all user-defined handler objects owned by the service.
  135. void shutdown_service()
  136. {
  137. service_impl_.shutdown_service();
  138. }
  139. // The platform-specific implementation.
  140. service_impl_type service_impl_;
  141. };
  142. } // namespace windows
  143. } // namespace asio
  144. } // namespace boost
  145. #include <boost/asio/detail/pop_options.hpp>
  146. #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
  147. // || defined(GENERATING_DOCUMENTATION)
  148. #endif // BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP