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