1 #ifndef H_CANOPEN_TIMER 2 #define H_CANOPEN_TIMER 7 #include <boost/asio.hpp> 8 #include <boost/thread/thread.hpp> 9 #include <boost/asio/high_resolution_timer.hpp> 21 static_cast<size_t(boost::asio::io_service::*)(void)>(&boost::asio::io_service::
run), &
io))
26 boost::mutex::scoped_lock lock(
mutex);
29 template<
typename T>
void start(
const TimerFunc &del,
const T &dur,
bool start_now =
true){
30 boost::mutex::scoped_lock lock(
mutex);
32 period = boost::chrono::duration_cast<boost::chrono::high_resolution_clock::duration>(dur);
39 boost::mutex::scoped_lock lock(
mutex);
43 const boost::chrono::high_resolution_clock::duration &
getPeriod(){
44 boost::mutex::scoped_lock lock(
mutex);
53 boost::asio::io_service
io;
54 boost::asio::io_service::work
work;
55 boost::asio::basic_waitable_timer<boost::chrono::high_resolution_clock>
timer;
56 boost::chrono::high_resolution_clock::duration
period;
61 void handler(
const boost::system::error_code& ec){
63 boost::mutex::scoped_lock lock(mutex);
65 timer.expires_at(timer.expires_at() +
period);
66 timer.async_wait(std::bind(&
Timer::handler,
this, std::placeholders::_1));
void run(class_loader::ClassLoader *loader)
boost::asio::io_service io
void handler(const boost::system::error_code &ec)
const boost::chrono::high_resolution_clock::duration & getPeriod()
boost::asio::basic_waitable_timer< boost::chrono::high_resolution_clock > timer
std::function< bool(void)> TimerFunc
void start(const TimerFunc &del, const T &dur, bool start_now=true)
boost::chrono::high_resolution_clock::duration period
boost::asio::io_service::work work