Chris@16
|
1 //
|
Chris@16
|
2 // windows/basic_object_handle.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 // Copyright (c) 2011 Boris Schaeling (boris@highscore.de)
|
Chris@16
|
7 //
|
Chris@16
|
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10 //
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP
|
Chris@16
|
13 #define BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
16 # pragma once
|
Chris@16
|
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #if defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE) \
|
Chris@16
|
22 || defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
23
|
Chris@16
|
24 #include <boost/asio/detail/throw_error.hpp>
|
Chris@16
|
25 #include <boost/asio/error.hpp>
|
Chris@16
|
26 #include <boost/asio/windows/basic_handle.hpp>
|
Chris@16
|
27 #include <boost/asio/windows/object_handle_service.hpp>
|
Chris@16
|
28
|
Chris@16
|
29 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
30
|
Chris@16
|
31 namespace boost {
|
Chris@16
|
32 namespace asio {
|
Chris@16
|
33 namespace windows {
|
Chris@16
|
34
|
Chris@16
|
35 /// Provides object-oriented handle functionality.
|
Chris@16
|
36 /**
|
Chris@16
|
37 * The windows::basic_object_handle class template provides asynchronous and
|
Chris@16
|
38 * blocking object-oriented handle functionality.
|
Chris@16
|
39 *
|
Chris@16
|
40 * @par Thread Safety
|
Chris@16
|
41 * @e Distinct @e objects: Safe.@n
|
Chris@16
|
42 * @e Shared @e objects: Unsafe.
|
Chris@16
|
43 */
|
Chris@16
|
44 template <typename ObjectHandleService = object_handle_service>
|
Chris@16
|
45 class basic_object_handle
|
Chris@16
|
46 : public basic_handle<ObjectHandleService>
|
Chris@16
|
47 {
|
Chris@16
|
48 public:
|
Chris@16
|
49 /// The native representation of a handle.
|
Chris@16
|
50 typedef typename ObjectHandleService::native_handle_type native_handle_type;
|
Chris@16
|
51
|
Chris@16
|
52 /// Construct a basic_object_handle without opening it.
|
Chris@16
|
53 /**
|
Chris@16
|
54 * This constructor creates an object handle without opening it.
|
Chris@16
|
55 *
|
Chris@16
|
56 * @param io_service The io_service object that the object handle will use to
|
Chris@16
|
57 * dispatch handlers for any asynchronous operations performed on the handle.
|
Chris@16
|
58 */
|
Chris@16
|
59 explicit basic_object_handle(boost::asio::io_service& io_service)
|
Chris@16
|
60 : basic_handle<ObjectHandleService>(io_service)
|
Chris@16
|
61 {
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 /// Construct a basic_object_handle on an existing native handle.
|
Chris@16
|
65 /**
|
Chris@16
|
66 * This constructor creates an object handle object to hold an existing native
|
Chris@16
|
67 * handle.
|
Chris@16
|
68 *
|
Chris@16
|
69 * @param io_service The io_service object that the object handle will use to
|
Chris@16
|
70 * dispatch handlers for any asynchronous operations performed on the handle.
|
Chris@16
|
71 *
|
Chris@16
|
72 * @param native_handle The new underlying handle implementation.
|
Chris@16
|
73 *
|
Chris@16
|
74 * @throws boost::system::system_error Thrown on failure.
|
Chris@16
|
75 */
|
Chris@16
|
76 basic_object_handle(boost::asio::io_service& io_service,
|
Chris@16
|
77 const native_handle_type& native_handle)
|
Chris@16
|
78 : basic_handle<ObjectHandleService>(io_service, native_handle)
|
Chris@16
|
79 {
|
Chris@16
|
80 }
|
Chris@16
|
81
|
Chris@16
|
82 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
83 /// Move-construct a basic_object_handle from another.
|
Chris@16
|
84 /**
|
Chris@16
|
85 * This constructor moves an object handle from one object to another.
|
Chris@16
|
86 *
|
Chris@16
|
87 * @param other The other basic_object_handle object from which the move will
|
Chris@16
|
88 * occur.
|
Chris@16
|
89 *
|
Chris@16
|
90 * @note Following the move, the moved-from object is in the same state as if
|
Chris@16
|
91 * constructed using the @c basic_object_handle(io_service&) constructor.
|
Chris@16
|
92 */
|
Chris@16
|
93 basic_object_handle(basic_object_handle&& other)
|
Chris@16
|
94 : basic_handle<ObjectHandleService>(
|
Chris@16
|
95 BOOST_ASIO_MOVE_CAST(basic_object_handle)(other))
|
Chris@16
|
96 {
|
Chris@16
|
97 }
|
Chris@16
|
98
|
Chris@16
|
99 /// Move-assign a basic_object_handle from another.
|
Chris@16
|
100 /**
|
Chris@16
|
101 * This assignment operator moves an object handle from one object to another.
|
Chris@16
|
102 *
|
Chris@16
|
103 * @param other The other basic_object_handle object from which the move will
|
Chris@16
|
104 * occur.
|
Chris@16
|
105 *
|
Chris@16
|
106 * @note Following the move, the moved-from object is in the same state as if
|
Chris@16
|
107 * constructed using the @c basic_object_handle(io_service&) constructor.
|
Chris@16
|
108 */
|
Chris@16
|
109 basic_object_handle& operator=(basic_object_handle&& other)
|
Chris@16
|
110 {
|
Chris@16
|
111 basic_handle<ObjectHandleService>::operator=(
|
Chris@16
|
112 BOOST_ASIO_MOVE_CAST(basic_object_handle)(other));
|
Chris@16
|
113 return *this;
|
Chris@16
|
114 }
|
Chris@16
|
115 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
116
|
Chris@16
|
117 /// Perform a blocking wait on the object handle.
|
Chris@16
|
118 /**
|
Chris@16
|
119 * This function is used to wait for the object handle to be set to the
|
Chris@16
|
120 * signalled state. This function blocks and does not return until the object
|
Chris@16
|
121 * handle has been set to the signalled state.
|
Chris@16
|
122 *
|
Chris@16
|
123 * @throws boost::system::system_error Thrown on failure.
|
Chris@16
|
124 */
|
Chris@16
|
125 void wait()
|
Chris@16
|
126 {
|
Chris@16
|
127 boost::system::error_code ec;
|
Chris@16
|
128 this->get_service().wait(this->get_implementation(), ec);
|
Chris@16
|
129 boost::asio::detail::throw_error(ec, "wait");
|
Chris@16
|
130 }
|
Chris@16
|
131
|
Chris@16
|
132 /// Perform a blocking wait on the object handle.
|
Chris@16
|
133 /**
|
Chris@16
|
134 * This function is used to wait for the object handle to be set to the
|
Chris@16
|
135 * signalled state. This function blocks and does not return until the object
|
Chris@16
|
136 * handle has been set to the signalled state.
|
Chris@16
|
137 *
|
Chris@16
|
138 * @param ec Set to indicate what error occurred, if any.
|
Chris@16
|
139 */
|
Chris@16
|
140 void wait(boost::system::error_code& ec)
|
Chris@16
|
141 {
|
Chris@16
|
142 this->get_service().wait(this->get_implementation(), ec);
|
Chris@16
|
143 }
|
Chris@16
|
144
|
Chris@16
|
145 /// Start an asynchronous wait on the object handle.
|
Chris@16
|
146 /**
|
Chris@16
|
147 * This function is be used to initiate an asynchronous wait against the
|
Chris@16
|
148 * object handle. It always returns immediately.
|
Chris@16
|
149 *
|
Chris@16
|
150 * @param handler The handler to be called when the object handle is set to
|
Chris@16
|
151 * the signalled state. Copies will be made of the handler as required. The
|
Chris@16
|
152 * function signature of the handler must be:
|
Chris@16
|
153 * @code void handler(
|
Chris@16
|
154 * const boost::system::error_code& error // Result of operation.
|
Chris@16
|
155 * ); @endcode
|
Chris@16
|
156 * Regardless of whether the asynchronous operation completes immediately or
|
Chris@16
|
157 * not, the handler will not be invoked from within this function. Invocation
|
Chris@16
|
158 * of the handler will be performed in a manner equivalent to using
|
Chris@16
|
159 * boost::asio::io_service::post().
|
Chris@16
|
160 */
|
Chris@16
|
161 template <typename WaitHandler>
|
Chris@16
|
162 BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
|
Chris@16
|
163 void (boost::system::error_code))
|
Chris@16
|
164 async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
|
Chris@16
|
165 {
|
Chris@16
|
166 return this->get_service().async_wait(this->get_implementation(),
|
Chris@16
|
167 BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
|
Chris@16
|
168 }
|
Chris@16
|
169 };
|
Chris@16
|
170
|
Chris@16
|
171 } // namespace windows
|
Chris@16
|
172 } // namespace asio
|
Chris@16
|
173 } // namespace boost
|
Chris@16
|
174
|
Chris@16
|
175 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
176
|
Chris@16
|
177 #endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
|
Chris@16
|
178 // || defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
179
|
Chris@16
|
180 #endif // BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP
|