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