timer_queue_ptime.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // detail/timer_queue_ptime.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 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_DETAIL_TIMER_QUEUE_PTIME_HPP
  11. #define BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/time_traits.hpp>
  16. #include <boost/asio/detail/timer_queue.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  19. namespace boost {
  20. namespace asio {
  21. namespace detail {
  22. struct forwarding_posix_time_traits : time_traits<boost::posix_time::ptime> {};
  23. // Template specialisation for the commonly used instantation.
  24. template <>
  25. class timer_queue<time_traits<boost::posix_time::ptime> >
  26. : public timer_queue_base
  27. {
  28. public:
  29. // The time type.
  30. typedef boost::posix_time::ptime time_type;
  31. // The duration type.
  32. typedef boost::posix_time::time_duration duration_type;
  33. // Per-timer data.
  34. typedef timer_queue<forwarding_posix_time_traits>::per_timer_data
  35. per_timer_data;
  36. // Constructor.
  37. BOOST_ASIO_DECL timer_queue();
  38. // Destructor.
  39. BOOST_ASIO_DECL virtual ~timer_queue();
  40. // Add a new timer to the queue. Returns true if this is the timer that is
  41. // earliest in the queue, in which case the reactor's event demultiplexing
  42. // function call may need to be interrupted and restarted.
  43. BOOST_ASIO_DECL bool enqueue_timer(const time_type& time,
  44. per_timer_data& timer, wait_op* op);
  45. // Whether there are no timers in the queue.
  46. BOOST_ASIO_DECL virtual bool empty() const;
  47. // Get the time for the timer that is earliest in the queue.
  48. BOOST_ASIO_DECL virtual long wait_duration_msec(long max_duration) const;
  49. // Get the time for the timer that is earliest in the queue.
  50. BOOST_ASIO_DECL virtual long wait_duration_usec(long max_duration) const;
  51. // Dequeue all timers not later than the current time.
  52. BOOST_ASIO_DECL virtual void get_ready_timers(op_queue<operation>& ops);
  53. // Dequeue all timers.
  54. BOOST_ASIO_DECL virtual void get_all_timers(op_queue<operation>& ops);
  55. // Cancel and dequeue operations for the given timer.
  56. BOOST_ASIO_DECL std::size_t cancel_timer(
  57. per_timer_data& timer, op_queue<operation>& ops,
  58. std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
  59. private:
  60. timer_queue<forwarding_posix_time_traits> impl_;
  61. };
  62. } // namespace detail
  63. } // namespace asio
  64. } // namespace boost
  65. #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
  66. #include <boost/asio/detail/pop_options.hpp>
  67. #if defined(BOOST_ASIO_HEADER_ONLY)
  68. # include <boost/asio/detail/impl/timer_queue_ptime.ipp>
  69. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  70. #endif // BOOST_ASIO_DETAIL_TIMER_QUEUE_PTIME_HPP