blob: 6572ca47d96b146a6a3d47fc6f513a0552bfc552 [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/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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
29#include <boost/asio.hpp>
30#include "time.hpp"
31
32namespace boost {
33namespace asio {
34
Alexander Afanasyev85b17b82014-11-10 16:22:05 -080035template<>
36struct time_traits<ndn::time::steady_clock>
Alexander Afanasyevf6468892014-01-29 01:04:14 -080037{
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070038 typedef ndn::time::steady_clock::TimePoint time_type;
Alexander Afanasyev85b17b82014-11-10 16:22:05 -080039 typedef ndn::time::steady_clock::Duration duration_type;
Alexander Afanasyevf6468892014-01-29 01:04:14 -080040
41 static time_type
42 now()
43 {
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070044 return ndn::time::steady_clock::now();
Alexander Afanasyevf6468892014-01-29 01:04:14 -080045 }
46
47 static time_type
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070048 add(const time_type& time, const duration_type& duration)
Alexander Afanasyevf6468892014-01-29 01:04:14 -080049 {
50 return time + duration;
51 }
52
53 static duration_type
54 subtract(const time_type& timeLhs, const time_type& timeRhs)
55 {
56 return timeLhs - timeRhs;
57 }
58
59 static bool
60 less_than(const time_type& timeLhs, const time_type& timeRhs)
61 {
62 return timeLhs < timeRhs;
63 }
64
65 static boost::posix_time::time_duration
66 to_posix_duration(const duration_type& duration)
67 {
Alexander Afanasyev85b17b82014-11-10 16:22:05 -080068 return ndn::time::steady_clock::to_posix_duration(duration);
Alexander Afanasyevf6468892014-01-29 01:04:14 -080069 }
70};
71
Alexander Afanasyevf6468892014-01-29 01:04:14 -080072} // namespace asio
73} // namespace boost
74
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070075namespace ndn {
76
Alexander Afanasyev85b17b82014-11-10 16:22:05 -080077typedef boost::asio::basic_deadline_timer<time::steady_clock> monotonic_deadline_timer;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070078
79} // namespace ndn
80
Alexander Afanasyevf6468892014-01-29 01:04:14 -080081#endif // NDN_UTIL_MONOTONIC_DEADLINE_TIMER_HPP