blob: 543cd7aa59e49980207ba626ac0647921551efe2 [file] [log] [blame]
Alexander Afanasyev920af2f2014-01-25 22:56:11 -08001/* -*- 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
16namespace boost {
17namespace asio {
18
19template <>
20struct time_traits<ndn::time::monotonic_clock>
21{
22 typedef ndn::time::Point time_type;
23 typedef ndn::time::Duration duration_type;
24
25 static time_type
26 now()
27 {
28 return ndn::time::now();
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
56typedef basic_deadline_timer<ndn::time::monotonic_clock> monotonic_deadline_timer;
57
58} // namespace asio
59} // namespace boost
60
61#endif // NFD_CORE_MONOTONIC_DEADLINE_TIMER_HPP