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