1//
2// windows/object_handle_service.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2015 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
12#ifndef BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
13#define BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
14
15#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16# pragma once
17#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
19#include <boost/asio/detail/config.hpp>
20
21#if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \
22 || defined(GENERATING_DOCUMENTATION)
23
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>
28
29#include <boost/asio/detail/push_options.hpp>
30
31namespace boost {
32namespace asio {
33namespace windows {
34
35/// Default service implementation for an object handle.
36class object_handle_service
37#if defined(GENERATING_DOCUMENTATION)
38 : public boost::asio::io_service::service
39#else
40 : public boost::asio::detail::service_base<object_handle_service>
41#endif
42{
43public:
44#if defined(GENERATING_DOCUMENTATION)
45 /// The unique service identifier.
46 static boost::asio::io_service::id id;
47#endif
48
49private:
50 // The type of the platform-specific implementation.
51 typedef detail::win_object_handle_service service_impl_type;
52
53public:
54 /// The type of an object handle implementation.
55#if defined(GENERATING_DOCUMENTATION)
56 typedef implementation_defined implementation_type;
57#else
58 typedef service_impl_type::implementation_type implementation_type;
59#endif
60
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
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)
72 {
73 }
74
75 /// Construct a new object handle implementation.
76 void construct(implementation_type& impl)
77 {
78 service_impl_.construct(impl);
79 }
80
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)
85 {
86 service_impl_.move_construct(impl, other_impl);
87 }
88
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)
93 {
94 service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
95 }
96#endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
97
98 /// Destroy an object handle implementation.
99 void destroy(implementation_type& impl)
100 {
101 service_impl_.destroy(impl);
102 }
103
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)
107 {
108 return service_impl_.assign(impl, handle, ec);
109 }
110
111 /// Determine whether the handle is open.
112 bool is_open(const implementation_type& impl) const
113 {
114 return service_impl_.is_open(impl);
115 }
116
117 /// Close an object handle implementation.
118 boost::system::error_code close(implementation_type& impl,
119 boost::system::error_code& ec)
120 {
121 return service_impl_.close(impl, ec);
122 }
123
124 /// Get the native handle implementation.
125 native_handle_type native_handle(implementation_type& impl)
126 {
127 return service_impl_.native_handle(impl);
128 }
129
130 /// Cancel all asynchronous operations associated with the handle.
131 boost::system::error_code cancel(implementation_type& impl,
132 boost::system::error_code& ec)
133 {
134 return service_impl_.cancel(impl, ec);
135 }
136
137 // Wait for a signaled state.
138 void wait(implementation_type& impl, boost::system::error_code& ec)
139 {
140 service_impl_.wait(impl, ec);
141 }
142
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)
149 {
150 boost::asio::detail::async_result_init<
151 WaitHandler, void (boost::system::error_code)> init(
152 BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
153
154 service_impl_.async_wait(impl, init.handler);
155
156 return init.result.get();
157 }
158
159private:
160 // Destroy all user-defined handler objects owned by the service.
161 void shutdown_service()
162 {
163 service_impl_.shutdown_service();
164 }
165
166 // The platform-specific implementation.
167 service_impl_type service_impl_;
168};
169
170} // namespace windows
171} // namespace asio
172} // namespace boost
173
174#include <boost/asio/detail/pop_options.hpp>
175
176#endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
177 // || defined(GENERATING_DOCUMENTATION)
178
179#endif // BOOST_ASIO_WINDOWS_OBJECT_HANDLE_SERVICE_HPP
180

source code of boost/boost/asio/windows/object_handle_service.hpp