Line data Source code
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 353651 : TimerImpl(boost::asio::io_context &io_service) 16 353651 : : timer_(io_service) { 17 353650 : } 18 : 19 4585813 : void expires_from_now(uint64_t ms, boost::system::error_code &ec) { 20 : #if __cplusplus >= 201103L 21 4585813 : timer_.expires_from_now(std::chrono::milliseconds(ms), ec); 22 : #else 23 : timer_.expires_from_now(boost::chrono::milliseconds(ms), ec); 24 : #endif 25 4586297 : } 26 : 27 730 : TimerType::duration expires_from_now() { 28 730 : return timer_.expires_from_now(); 29 : } 30 : 31 : template <typename WaitHandler> 32 4661086 : void async_wait(WaitHandler handler) { timer_.async_wait(handler); } 33 : void cancel(boost::system::error_code &ec) { timer_.cancel(ec); } 34 : 35 : private: 36 : TimerType timer_; 37 : }; 38 : 39 : #endif // BASE_TIMER_IMPL_H__