OpenSDN source code
timer_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef BASE_TIMER_IMPL_H_
7 #define BASE_TIMER_IMPL_H__
8 
9 #include <boost/asio/steady_timer.hpp>
10 #include <boost/chrono.hpp>
11 
12 class TimerImpl {
13 public:
14  typedef boost::asio::steady_timer TimerType;
15 
16  TimerImpl(boost::asio::io_context &io_service)
17  : timer_(io_service) {
18  }
19 
20  void expires_from_now(uint64_t ms, boost::system::error_code &ec) {
21 #if __cplusplus >= 201103L
22  timer_.expires_from_now(std::chrono::milliseconds(ms), ec);
23 #else
24  timer_.expires_from_now(boost::chrono::milliseconds(ms), ec);
25 #endif
26  }
27 
28  TimerType::duration expires_from_now() {
29  return timer_.expires_from_now();
30  }
31 
32  template <typename WaitHandler>
33  void async_wait(WaitHandler handler) { timer_.async_wait(handler); }
34  void cancel(boost::system::error_code &ec) { timer_.cancel(ec); }
35 
36 private:
38 };
39 
40 #endif // BASE_TIMER_IMPL_H__
TimerImpl(boost::asio::io_context &io_service)
Definition: timer_impl.h:16
void expires_from_now(uint64_t ms, boost::system::error_code &ec)
Definition: timer_impl.h:20
TimerType::duration expires_from_now()
Definition: timer_impl.h:28
void cancel(boost::system::error_code &ec)
Definition: timer_impl.h:34
void async_wait(WaitHandler handler)
Definition: timer_impl.h:33
TimerType timer_
Definition: timer_impl.h:37
boost::asio::steady_timer TimerType
Definition: timer_impl.h:14