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.

basic_object_handle.hpp 5.9KB

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