AsyncOkPoll.h
Go to the documentation of this file.
00001 
00034 #include <boost/bind.hpp>
00035 #include <boost/asio.hpp>
00036 #include <boost/function.hpp>
00037 
00038 
00039 class AsyncOkPoll {
00040 public:
00041   AsyncOkPoll(boost::asio::io_service& io_service,
00042                     boost::posix_time::time_duration interval,
00043                     boost::function<bool()> ok_fn)
00044       : io_service_(io_service), interval_(interval), fn_(ok_fn),
00045         timer_(io_service) {
00046     if (!fn_) {
00047       return;
00048     }
00049     set();
00050   }
00051 
00052 private:
00053   void set() {
00054     timer_.expires_from_now(interval_);
00055     timer_.async_wait(boost::bind(&AsyncOkPoll::handler, this,
00056           boost::asio::placeholders::error));
00057   }
00058 
00059   void handler(const boost::system::error_code& error) {
00060     if (!error) {
00061       if (!fn_()) {
00062         io_service_.stop();
00063       } else {
00064         set();
00065       }
00066     }
00067   }
00068 
00069   boost::posix_time::time_duration interval_;
00070   boost::asio::deadline_timer timer_;
00071   boost::asio::io_service& io_service_;
00072   boost::function<bool()> fn_;
00073 };
00074 
00075 


rosserial_server
Author(s): Mike Purvis
autogenerated on Fri Aug 28 2015 12:44:56