/Src/Dependencies/Boost/boost/asio/deadline_timer_service.hpp

http://hadesmem.googlecode.com/ · C++ Header · 156 lines · 100 code · 27 blank · 29 comment · 1 complexity · 60f44a627cb4f2860cc74a613e7561d7 MD5 · raw file

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