int main(int argc, char* argv[]) { transformer = boost::shared_ptr<Transform>(new Transform()); threshold = boost::shared_ptr<Threshold>(new Threshold(transformer)); mask = boost::shared_ptr<Mask>(new Mask(threshold)); addDriver(transformer); addSignals(transformer); addSignals(threshold); addMasks(mask); timer = timer_ptr(new boost::asio::deadline_timer(get_io_service())); timer->expires_from_now(boost::posix_time::seconds(2)); // Wait for the timer to expire. timer->async_wait(on_timeout); get_scheduler().startup(); process::wait_for_shutdown(); return EXIT_SUCCESS; }
void on_timeout(const boost::system::error_code& error) { if (error != boost::asio::error::operation_aborted) { _LOG_STREAM << "wait period arrived." << error << endl; for(int i = 0; i < 4; i++) { } // skip 4 for(int j = 5; j < 9; j++) { mask->getSignalValue(boost::shared_ptr<GetSignalComplete>(new GetSignalComplete("sid:" + boost::lexical_cast<std::string>(j)))); } } timer->expires_from_now(boost::posix_time::seconds(2)); timer->async_wait(on_timeout); }
void AsyncProcessor::HandleTimer(timer_ptr timer, const boost::asio::deadline_timer::duration_type& duration, const boost::system::error_code& ec, const TimerJobFunc& func ) { //执行该任务 func(ec); //重新调度定时器 timer->expires_from_now(duration); timer->async_wait(boost::bind(&AsyncProcessor::HandleTimer, this, timer, duration, _1, func)); }