Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.6KB

  1. //
  2. // detail/winrt_resolve_op.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_DETAIL_WINRT_RESOLVE_OP_HPP
  11. #define ASIO_DETAIL_WINRT_RESOLVE_OP_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_WINDOWS_RUNTIME)
  17. #include "asio/detail/bind_handler.hpp"
  18. #include "asio/detail/fenced_block.hpp"
  19. #include "asio/detail/handler_alloc_helpers.hpp"
  20. #include "asio/detail/handler_invoke_helpers.hpp"
  21. #include "asio/detail/memory.hpp"
  22. #include "asio/detail/winrt_async_op.hpp"
  23. #include "asio/ip/basic_resolver_results.hpp"
  24. #include "asio/error.hpp"
  25. #include "asio/detail/push_options.hpp"
  26. namespace asio {
  27. namespace detail {
  28. template <typename Protocol, typename Handler, typename IoExecutor>
  29. class winrt_resolve_op :
  30. public winrt_async_op<
  31. Windows::Foundation::Collections::IVectorView<
  32. Windows::Networking::EndpointPair^>^>
  33. {
  34. public:
  35. ASIO_DEFINE_HANDLER_PTR(winrt_resolve_op);
  36. typedef typename Protocol::endpoint endpoint_type;
  37. typedef asio::ip::basic_resolver_query<Protocol> query_type;
  38. typedef asio::ip::basic_resolver_results<Protocol> results_type;
  39. winrt_resolve_op(const query_type& query,
  40. Handler& handler, const IoExecutor& io_ex)
  41. : winrt_async_op<
  42. Windows::Foundation::Collections::IVectorView<
  43. Windows::Networking::EndpointPair^>^>(
  44. &winrt_resolve_op::do_complete),
  45. query_(query),
  46. handler_(ASIO_MOVE_CAST(Handler)(handler)),
  47. io_executor_(io_ex)
  48. {
  49. handler_work<Handler, IoExecutor>::start(handler_, io_executor_);
  50. }
  51. static void do_complete(void* owner, operation* base,
  52. const asio::error_code&, std::size_t)
  53. {
  54. // Take ownership of the operation object.
  55. winrt_resolve_op* o(static_cast<winrt_resolve_op*>(base));
  56. ptr p = { asio::detail::addressof(o->handler_), o, o };
  57. handler_work<Handler, IoExecutor> w(o->handler_, o->io_executor_);
  58. ASIO_HANDLER_COMPLETION((*o));
  59. results_type results = results_type();
  60. if (!o->ec_)
  61. {
  62. try
  63. {
  64. results = results_type::create(o->result_, o->query_.hints(),
  65. o->query_.host_name(), o->query_.service_name());
  66. }
  67. catch (Platform::Exception^ e)
  68. {
  69. o->ec_ = asio::error_code(e->HResult,
  70. asio::system_category());
  71. }
  72. }
  73. // Make a copy of the handler so that the memory can be deallocated before
  74. // the upcall is made. Even if we're not about to make an upcall, a
  75. // sub-object of the handler may be the true owner of the memory associated
  76. // with the handler. Consequently, a local copy of the handler is required
  77. // to ensure that any owning sub-object remains valid until after we have
  78. // deallocated the memory here.
  79. detail::binder2<Handler, asio::error_code, results_type>
  80. handler(o->handler_, o->ec_, results);
  81. p.h = asio::detail::addressof(handler.handler_);
  82. p.reset();
  83. // Make the upcall if required.
  84. if (owner)
  85. {
  86. fenced_block b(fenced_block::half);
  87. ASIO_HANDLER_INVOCATION_BEGIN((handler.arg1_, "..."));
  88. w.complete(handler, handler.handler_);
  89. ASIO_HANDLER_INVOCATION_END;
  90. }
  91. }
  92. private:
  93. query_type query_;
  94. Handler handler_;
  95. IoExecutor io_executor_;
  96. };
  97. } // namespace detail
  98. } // namespace asio
  99. #include "asio/detail/pop_options.hpp"
  100. #endif // defined(ASIO_WINDOWS_RUNTIME)
  101. #endif // ASIO_DETAIL_WINRT_RESOLVE_OP_HPP