11 #ifndef ASIO_DETAIL_WINRT_ASYNC_MANAGER_HPP 12 #define ASIO_DETAIL_WINRT_ASYNC_MANAGER_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 20 #if defined(ASIO_WINDOWS_RUNTIME) 33 class winrt_async_manager
39 :
asio::detail::service_base<winrt_async_manager>(io_service),
46 ~winrt_async_manager()
51 void shutdown_service()
53 if (--outstanding_ops_ > 0)
56 std::future<void> f = promise_.get_future();
61 void sync(Windows::Foundation::IAsyncAction^ action,
64 using namespace Windows::Foundation;
65 using Windows::Foundation::AsyncStatus;
67 auto promise = std::make_shared<std::promise<asio::error_code>>();
68 auto future = promise->get_future();
70 action->Completed = ref
new AsyncActionCompletedHandler(
71 [promise](IAsyncAction^ action, AsyncStatus status)
75 case AsyncStatus::Canceled:
78 case AsyncStatus::Error:
79 case AsyncStatus::Completed:
82 action->ErrorCode.Value,
84 promise->set_value(ec);
92 template <
typename TResult>
93 TResult sync(Windows::Foundation::IAsyncOperation<TResult>^
operation,
96 using namespace Windows::Foundation;
97 using Windows::Foundation::AsyncStatus;
99 auto promise = std::make_shared<std::promise<asio::error_code>>();
100 auto future = promise->get_future();
102 operation->Completed = ref
new AsyncOperationCompletedHandler<TResult>(
103 [promise](IAsyncOperation<TResult>^
operation, AsyncStatus status)
107 case AsyncStatus::Canceled:
110 case AsyncStatus::Error:
111 case AsyncStatus::Completed:
114 operation->ErrorCode.Value,
116 promise->set_value(ec);
122 return operation->GetResults();
125 template <
typename TResult,
typename TProgress>
127 Windows::Foundation::IAsyncOperationWithProgress<
128 TResult, TProgress>^ operation,
131 using namespace Windows::Foundation;
132 using Windows::Foundation::AsyncStatus;
134 auto promise = std::make_shared<std::promise<asio::error_code>>();
135 auto future = promise->get_future();
138 = ref
new AsyncOperationWithProgressCompletedHandler<TResult, TProgress>(
139 [promise](IAsyncOperationWithProgress<TResult, TProgress>^
operation,
144 case AsyncStatus::Canceled:
147 case AsyncStatus::Started:
149 case AsyncStatus::Error:
150 case AsyncStatus::Completed:
153 operation->ErrorCode.Value,
155 promise->set_value(ec);
161 return operation->GetResults();
164 void async(Windows::Foundation::IAsyncAction^ action,
165 winrt_async_op<void>* handler)
167 using namespace Windows::Foundation;
168 using Windows::Foundation::AsyncStatus;
170 auto on_completed = ref
new AsyncActionCompletedHandler(
171 [
this, handler](IAsyncAction^ action, AsyncStatus status)
175 case AsyncStatus::Canceled:
178 case AsyncStatus::Started:
180 case AsyncStatus::Completed:
181 case AsyncStatus::Error:
184 action->ErrorCode.Value,
188 io_service_.post_deferred_completion(handler);
189 if (--outstanding_ops_ == 0)
190 promise_.set_value();
193 io_service_.work_started();
195 action->Completed = on_completed;
198 template <
typename TResult>
199 void async(Windows::Foundation::IAsyncOperation<TResult>^ operation,
200 winrt_async_op<TResult>* handler)
202 using namespace Windows::Foundation;
203 using Windows::Foundation::AsyncStatus;
205 auto on_completed = ref
new AsyncOperationCompletedHandler<TResult>(
206 [
this, handler](IAsyncOperation<TResult>^
operation, AsyncStatus status)
210 case AsyncStatus::Canceled:
213 case AsyncStatus::Started:
215 case AsyncStatus::Completed:
216 handler->result_ = operation->GetResults();
218 case AsyncStatus::Error:
221 operation->ErrorCode.Value,
225 io_service_.post_deferred_completion(handler);
226 if (--outstanding_ops_ == 0)
227 promise_.set_value();
230 io_service_.work_started();
232 operation->Completed = on_completed;
235 template <
typename TResult,
typename TProgress>
237 Windows::Foundation::IAsyncOperationWithProgress<
238 TResult, TProgress>^ operation,
239 winrt_async_op<TResult>* handler)
241 using namespace Windows::Foundation;
242 using Windows::Foundation::AsyncStatus;
245 = ref
new AsyncOperationWithProgressCompletedHandler<TResult, TProgress>(
246 [
this, handler](IAsyncOperationWithProgress<
247 TResult, TProgress>^
operation, AsyncStatus status)
251 case AsyncStatus::Canceled:
254 case AsyncStatus::Started:
256 case AsyncStatus::Completed:
257 handler->result_ = operation->GetResults();
259 case AsyncStatus::Error:
262 operation->ErrorCode.Value,
266 io_service_.post_deferred_completion(handler);
267 if (--outstanding_ops_ == 0)
268 promise_.set_value();
271 io_service_.work_started();
273 operation->Completed = on_completed;
284 std::promise<void> promise_;
292 #endif // defined(ASIO_WINDOWS_RUNTIME) 294 #endif // ASIO_DETAIL_WINRT_ASYNC_MANAGER_HPP
Provides core I/O functionality.
Service & use_service(io_service &ios)
class task_io_service io_service_impl
Class to represent an error code value.
task_io_service_operation operation
ASIO_DECL const error_category & system_category()
Returns the error category used for the system errors produced by asio.