2 // windows/object_handle_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 // Copyright (c) 2011 Boris Schaeling (boris@highscore.de)
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)
12 #ifndef BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
13 #define BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/config.hpp>
21 #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \
22 || defined(GENERATING_DOCUMENTATION)
24 #include <boost/asio/async_result.hpp>
25 #include <boost/asio/detail/win_object_handle_service.hpp>
26 #include <boost/asio/error.hpp>
27 #include <boost/asio/io_service.hpp>
29 #include <boost/asio/detail/push_options.hpp>
35 /// Default service implementation for an object handle.
36 class object_handle_service
37 #if defined(GENERATING_DOCUMENTATION)
38 : public boost::asio::io_service::service
40 : public boost::asio::detail::service_base<object_handle_service>
44 #if defined(GENERATING_DOCUMENTATION)
45 /// The unique service identifier.
46 static boost::asio::io_service::id id;
50 // The type of the platform-specific implementation.
51 typedef detail::win_object_handle_service service_impl_type;
54 /// The type of an object handle implementation.
55 #if defined(GENERATING_DOCUMENTATION)
56 typedef implementation_defined implementation_type;
58 typedef service_impl_type::implementation_type implementation_type;
61 /// The native handle type.
62 #if defined(GENERATING_DOCUMENTATION)
63 typedef implementation_defined native_handle_type;
65 typedef service_impl_type::native_handle_type native_handle_type;
68 /// Construct a new object handle service for the specified io_service.
69 explicit object_handle_service(boost::asio::io_service& io_service)
70 : boost::asio::detail::service_base<object_handle_service>(io_service),
71 service_impl_(io_service)
75 /// Construct a new object handle implementation.
76 void construct(implementation_type& impl)
78 service_impl_.construct(impl);
81 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
82 /// Move-construct a new object handle implementation.
83 void move_construct(implementation_type& impl,
84 implementation_type& other_impl)
86 service_impl_.move_construct(impl, other_impl);
89 /// Move-assign from another object handle implementation.
90 void move_assign(implementation_type& impl,
91 object_handle_service& other_service,
92 implementation_type& other_impl)
94 service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
96 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
98 /// Destroy an object handle implementation.
99 void destroy(implementation_type& impl)
101 service_impl_.destroy(impl);
104 /// Assign an existing native handle to an object handle.
105 boost::system::error_code assign(implementation_type& impl,
106 const native_handle_type& handle, boost::system::error_code& ec)
108 return service_impl_.assign(impl, handle, ec);
111 /// Determine whether the handle is open.
112 bool is_open(const implementation_type& impl) const
114 return service_impl_.is_open(impl);
117 /// Close an object handle implementation.
118 boost::system::error_code close(implementation_type& impl,
119 boost::system::error_code& ec)
121 return service_impl_.close(impl, ec);
124 /// Get the native handle implementation.
125 native_handle_type native_handle(implementation_type& impl)
127 return service_impl_.native_handle(impl);
130 /// Cancel all asynchronous operations associated with the handle.
131 boost::system::error_code cancel(implementation_type& impl,
132 boost::system::error_code& ec)
134 return service_impl_.cancel(impl, ec);
137 // Wait for a signaled state.
138 void wait(implementation_type& impl, boost::system::error_code& ec)
140 service_impl_.wait(impl, ec);
143 /// Start an asynchronous wait.
144 template <typename WaitHandler>
145 BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
146 void (boost::system::error_code))
147 async_wait(implementation_type& impl,
148 BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
150 boost::asio::detail::async_result_init<
151 WaitHandler, void (boost::system::error_code)> init(
152 BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
154 service_impl_.async_wait(impl, init.handler);
156 return init.result.get();
160 // Destroy all user-defined handler objects owned by the service.
161 void shutdown_service()
163 service_impl_.shutdown_service();
166 // The platform-specific implementation.
167 service_impl_type service_impl_;
170 } // namespace windows
174 #include <boost/asio/detail/pop_options.hpp>
176 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
177 // || defined(GENERATING_DOCUMENTATION)
179 #endif // BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP