blob: c158fe4df7216632fd5fa45309e264ac93d4e99a [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 <>
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080020struct time_traits<nfd::time::monotonic_clock>
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080021{
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080022 typedef nfd::time::Point time_type;
23 typedef nfd::time::Duration duration_type;
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080024
25 static time_type
26 now()
27 {
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080028 return nfd::time::now();
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080029 }
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 Afanasyev18bbf812014-01-29 01:40:23 -080056typedef basic_deadline_timer<nfd::time::monotonic_clock> monotonic_deadline_timer;
Alexander Afanasyev920af2f2014-01-25 22:56:11 -080057
58} // namespace asio
59} // namespace boost
60
61#endif // NFD_CORE_MONOTONIC_DEADLINE_TIMER_HPP