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.

deadline_timer_service.hpp 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // deadline_timer_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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_DEADLINE_TIMER_SERVICE_HPP
  11. #define ASIO_DEADLINE_TIMER_SERVICE_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_HAS_BOOST_DATE_TIME) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include <cstddef>
  19. #include "asio/async_result.hpp"
  20. #include "asio/detail/deadline_timer_service.hpp"
  21. #include "asio/io_context.hpp"
  22. #include "asio/time_traits.hpp"
  23. #include "asio/detail/timer_queue_ptime.hpp"
  24. #include "asio/detail/push_options.hpp"
  25. namespace asio {
  26. /// Default service implementation for a timer.
  27. template <typename TimeType,
  28. typename TimeTraits = asio::time_traits<TimeType> >
  29. class deadline_timer_service
  30. #if defined(GENERATING_DOCUMENTATION)
  31. : public asio::io_context::service
  32. #else
  33. : public asio::detail::service_base<
  34. deadline_timer_service<TimeType, TimeTraits> >
  35. #endif
  36. {
  37. public:
  38. #if defined(GENERATING_DOCUMENTATION)
  39. /// The unique service identifier.
  40. static asio::io_context::id id;
  41. #endif
  42. /// The time traits type.
  43. typedef TimeTraits traits_type;
  44. /// The time type.
  45. typedef typename traits_type::time_type time_type;
  46. /// The duration type.
  47. typedef typename traits_type::duration_type duration_type;
  48. private:
  49. // The type of the platform-specific implementation.
  50. typedef detail::deadline_timer_service<traits_type> service_impl_type;
  51. public:
  52. /// The implementation type of the deadline timer.
  53. #if defined(GENERATING_DOCUMENTATION)
  54. typedef implementation_defined implementation_type;
  55. #else
  56. typedef typename service_impl_type::implementation_type implementation_type;
  57. #endif
  58. /// Construct a new timer service for the specified io_context.
  59. explicit deadline_timer_service(asio::io_context& io_context)
  60. : asio::detail::service_base<
  61. deadline_timer_service<TimeType, TimeTraits> >(io_context),
  62. service_impl_(io_context)
  63. {
  64. }
  65. /// Construct a new timer implementation.
  66. void construct(implementation_type& impl)
  67. {
  68. service_impl_.construct(impl);
  69. }
  70. /// Destroy a timer implementation.
  71. void destroy(implementation_type& impl)
  72. {
  73. service_impl_.destroy(impl);
  74. }
  75. /// Cancel any asynchronous wait operations associated with the timer.
  76. std::size_t cancel(implementation_type& impl, asio::error_code& ec)
  77. {
  78. return service_impl_.cancel(impl, ec);
  79. }
  80. /// Cancels one asynchronous wait operation associated with the timer.
  81. std::size_t cancel_one(implementation_type& impl,
  82. asio::error_code& ec)
  83. {
  84. return service_impl_.cancel_one(impl, ec);
  85. }
  86. /// Get the expiry time for the timer as an absolute time.
  87. time_type expires_at(const implementation_type& impl) const
  88. {
  89. return service_impl_.expiry(impl);
  90. }
  91. /// Set the expiry time for the timer as an absolute time.
  92. std::size_t expires_at(implementation_type& impl,
  93. const time_type& expiry_time, asio::error_code& ec)
  94. {
  95. return service_impl_.expires_at(impl, expiry_time, ec);
  96. }
  97. /// Get the expiry time for the timer relative to now.
  98. duration_type expires_from_now(const implementation_type& impl) const
  99. {
  100. return TimeTraits::subtract(service_impl_.expiry(impl), TimeTraits::now());
  101. }
  102. /// Set the expiry time for the timer relative to now.
  103. std::size_t expires_from_now(implementation_type& impl,
  104. const duration_type& expiry_time, asio::error_code& ec)
  105. {
  106. return service_impl_.expires_after(impl, expiry_time, ec);
  107. }
  108. // Perform a blocking wait on the timer.
  109. void wait(implementation_type& impl, asio::error_code& ec)
  110. {
  111. service_impl_.wait(impl, ec);
  112. }
  113. // Start an asynchronous wait on the timer.
  114. template <typename WaitHandler>
  115. ASIO_INITFN_RESULT_TYPE(WaitHandler,
  116. void (asio::error_code))
  117. async_wait(implementation_type& impl,
  118. ASIO_MOVE_ARG(WaitHandler) handler)
  119. {
  120. async_completion<WaitHandler,
  121. void (asio::error_code)> init(handler);
  122. service_impl_.async_wait(impl, init.handler);
  123. return init.result.get();
  124. }
  125. private:
  126. // Destroy all user-defined handler objects owned by the service.
  127. void shutdown()
  128. {
  129. service_impl_.shutdown();
  130. }
  131. // The platform-specific implementation.
  132. service_impl_type service_impl_;
  133. };
  134. } // namespace asio
  135. #include "asio/detail/pop_options.hpp"
  136. #endif // defined(ASIO_HAS_BOOST_DATE_TIME)
  137. // || defined(GENERATING_DOCUMENTATION)
  138. #endif // ASIO_DEADLINE_TIMER_SERVICE_HPP