CppCMS
booster/aio/deadline_timer.h
00001 //
00002 //  Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
00003 //
00004 //  Distributed under the Boost Software License, Version 1.0. (See
00005 //  accompanying file LICENSE_1_0.txt or copy at
00006 //  http://www.boost.org/LICENSE_1_0.txt)
00007 //
00008 #ifndef BOOSTER_AIO_DEADLINE_TIMER_H
00009 #define BOOSTER_AIO_DEADLINE_TIMER_H
00010 
00011 #include <booster/config.h>
00012 #include <booster/posix_time.h>
00013 #include <booster/hold_ptr.h>
00014 #include <booster/callback.h>
00015 #include <booster/aio/types.h>
00016 #include <booster/noncopyable.h>
00017 
00018 namespace booster {
00019         namespace aio {
00020 
00024                 class BOOSTER_API deadline_timer : public noncopyable {
00025                 public:
00029                         deadline_timer();
00030 
00034                         deadline_timer(io_service &srv);
00035                         ~deadline_timer();
00036 
00040                         io_service &get_io_service();
00044                         void set_io_service(io_service &srv);
00048                         void reset_io_service();
00049 
00055                         void expires_from_now(ptime t);
00059                         ptime expires_from_now();
00060 
00066                         void expires_at(ptime t);
00070                         ptime expires_at();
00071 
00075                         void wait();
00081                         void async_wait(event_handler const &h);
00088                         void cancel();
00089                 private:
00090                         struct waiter;
00091                         friend struct waiter;
00092 
00093                         struct data;
00094                         hold_ptr<data> d;
00095 
00096                         io_service *srv_;
00097                         ptime deadline_;
00098                         int event_id_;
00099 
00100                 };
00101 
00102         } // aio
00103 } // booster
00104 
00105 
00106 
00107 #endif