blob: 3cfb05f8450b2665a7af51dc44bbbdb54a36d4f9 [file] [log] [blame]
Alexander Afanasyevf6468892014-01-29 01:04:14 -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 NDN_UTIL_MONOTONIC_DEADLINE_TIMER_HPP
12#define NDN_UTIL_MONOTONIC_DEADLINE_TIMER_HPP
13
14#include <boost/asio.hpp>
15#include "time.hpp"
16
17namespace boost {
18namespace asio {
19
20template <>
21struct time_traits<ndn::time::monotonic_clock>
22{
23 typedef ndn::time::Point time_type;
24 typedef ndn::time::Duration duration_type;
25
26 static time_type
27 now()
28 {
29 return ndn::time::now();
30 }
31
32 static time_type
33 add(const time_type& time, const duration_type& duration)
34 {
35 return time + duration;
36 }
37
38 static duration_type
39 subtract(const time_type& timeLhs, const time_type& timeRhs)
40 {
41 return timeLhs - timeRhs;
42 }
43
44 static bool
45 less_than(const time_type& timeLhs, const time_type& timeRhs)
46 {
47 return timeLhs < timeRhs;
48 }
49
50 static boost::posix_time::time_duration
51 to_posix_duration(const duration_type& duration)
52 {
53 return boost::posix_time::microseconds(duration/1000);
54 }
55};
56
57typedef basic_deadline_timer<ndn::time::monotonic_clock> monotonic_deadline_timer;
58
59} // namespace asio
60} // namespace boost
61
62#endif // NDN_UTIL_MONOTONIC_DEADLINE_TIMER_HPP