blob: c2b28cf3a7adf24ea869124db0d5dc9b9e7a94d4 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevf6468892014-01-29 01:04:14 -08002/**
Davide Pesavento537dc3a2016-02-18 19:35:26 +01003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyevf6468892014-01-29 01:04:14 -080020 */
21
22/**
23 * This code is based on https://svn.boost.org/trac/boost/attachment/ticket/3504/MonotonicDeadlineTimer.h
24 */
25
26#ifndef NDN_UTIL_MONOTONIC_DEADLINE_TIMER_HPP
27#define NDN_UTIL_MONOTONIC_DEADLINE_TIMER_HPP
28
Alexander Afanasyevf6468892014-01-29 01:04:14 -080029#include "time.hpp"
30
Davide Pesavento537dc3a2016-02-18 19:35:26 +010031#include <boost/asio/basic_deadline_timer.hpp>
32
Alexander Afanasyevf6468892014-01-29 01:04:14 -080033namespace boost {
34namespace asio {
35
Alexander Afanasyev85b17b82014-11-10 16:22:05 -080036template<>
37struct time_traits<ndn::time::steady_clock>
Alexander Afanasyevf6468892014-01-29 01:04:14 -080038{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070039 typedef ndn::time::steady_clock::TimePoint time_type;
Alexander Afanasyev85b17b82014-11-10 16:22:05 -080040 typedef ndn::time::steady_clock::Duration duration_type;
Alexander Afanasyevf6468892014-01-29 01:04:14 -080041
42 static time_type
43 now()
44 {
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070045 return ndn::time::steady_clock::now();
Alexander Afanasyevf6468892014-01-29 01:04:14 -080046 }
47
48 static time_type
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070049 add(const time_type& time, const duration_type& duration)
Alexander Afanasyevf6468892014-01-29 01:04:14 -080050 {
51 return time + duration;
52 }
53
54 static duration_type
55 subtract(const time_type& timeLhs, const time_type& timeRhs)
56 {
57 return timeLhs - timeRhs;
58 }
59
60 static bool
61 less_than(const time_type& timeLhs, const time_type& timeRhs)
62 {
63 return timeLhs < timeRhs;
64 }
65
66 static boost::posix_time::time_duration
67 to_posix_duration(const duration_type& duration)
68 {
Alexander Afanasyev85b17b82014-11-10 16:22:05 -080069 return ndn::time::steady_clock::to_posix_duration(duration);
Alexander Afanasyevf6468892014-01-29 01:04:14 -080070 }
71};
72
Alexander Afanasyevf6468892014-01-29 01:04:14 -080073} // namespace asio
74} // namespace boost
75
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070076namespace ndn {
77
Alexander Afanasyev85b17b82014-11-10 16:22:05 -080078typedef boost::asio::basic_deadline_timer<time::steady_clock> monotonic_deadline_timer;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070079
80} // namespace ndn
81
Alexander Afanasyevf6468892014-01-29 01:04:14 -080082#endif // NDN_UTIL_MONOTONIC_DEADLINE_TIMER_HPP