Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * This code is based on https://svn.boost.org/trac/boost/attachment/ticket/3504/MonotonicDeadlineTimer.h |
| 9 | */ |
| 10 | |
| 11 | #ifndef NFD_CORE_MONOTONIC_DEADLINE_TIMER_HPP |
| 12 | #define NFD_CORE_MONOTONIC_DEADLINE_TIMER_HPP |
| 13 | |
| 14 | #include "time.hpp" |
| 15 | |
| 16 | namespace boost { |
| 17 | namespace asio { |
| 18 | |
| 19 | template <> |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 20 | struct time_traits<nfd::time::monotonic_clock> |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 21 | { |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 22 | typedef nfd::time::Point time_type; |
| 23 | typedef nfd::time::Duration duration_type; |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 24 | |
| 25 | static time_type |
| 26 | now() |
| 27 | { |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 28 | return nfd::time::now(); |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static time_type |
| 32 | add(const time_type& time, const duration_type& duration) |
| 33 | { |
| 34 | return time + duration; |
| 35 | } |
| 36 | |
| 37 | static duration_type |
| 38 | subtract(const time_type& timeLhs, const time_type& timeRhs) |
| 39 | { |
| 40 | return timeLhs - timeRhs; |
| 41 | } |
| 42 | |
| 43 | static bool |
| 44 | less_than(const time_type& timeLhs, const time_type& timeRhs) |
| 45 | { |
| 46 | return timeLhs < timeRhs; |
| 47 | } |
| 48 | |
| 49 | static boost::posix_time::time_duration |
| 50 | to_posix_duration(const duration_type& duration) |
| 51 | { |
| 52 | return boost::posix_time::microseconds(duration/1000); |
| 53 | } |
| 54 | }; |
| 55 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 56 | typedef basic_deadline_timer<nfd::time::monotonic_clock> monotonic_deadline_timer; |
Alexander Afanasyev | 920af2f | 2014-01-25 22:56:11 -0800 | [diff] [blame] | 57 | |
| 58 | } // namespace asio |
| 59 | } // namespace boost |
| 60 | |
| 61 | #endif // NFD_CORE_MONOTONIC_DEADLINE_TIMER_HPP |