00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_BASIC_DEADLINE_TIMER_HPP
00012 #define ASIO_BASIC_DEADLINE_TIMER_HPP
00013
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017
00018 #include "asio/detail/push_options.hpp"
00019
00020 #include "asio/detail/push_options.hpp"
00021 #include <cstddef>
00022 #include <boost/config.hpp>
00023 #include "asio/detail/pop_options.hpp"
00024
00025 #include "asio/basic_io_object.hpp"
00026 #include "asio/deadline_timer_service.hpp"
00027 #include "asio/error.hpp"
00028 #include "asio/detail/throw_error.hpp"
00029
00030 namespace asio {
00031
00033
00079 template <typename Time,
00080 typename TimeTraits = asio::time_traits<Time>,
00081 typename TimerService = deadline_timer_service<Time, TimeTraits> >
00082 class basic_deadline_timer
00083 : public basic_io_object<TimerService>
00084 {
00085 public:
00087 typedef TimeTraits traits_type;
00088
00090 typedef typename traits_type::time_type time_type;
00091
00093 typedef typename traits_type::duration_type duration_type;
00094
00096
00104 explicit basic_deadline_timer(asio::io_service& io_service)
00105 : basic_io_object<TimerService>(io_service)
00106 {
00107 }
00108
00110
00119 basic_deadline_timer(asio::io_service& io_service,
00120 const time_type& expiry_time)
00121 : basic_io_object<TimerService>(io_service)
00122 {
00123 asio::error_code ec;
00124 this->service.expires_at(this->implementation, expiry_time, ec);
00125 asio::detail::throw_error(ec);
00126 }
00127
00129
00138 basic_deadline_timer(asio::io_service& io_service,
00139 const duration_type& expiry_time)
00140 : basic_io_object<TimerService>(io_service)
00141 {
00142 asio::error_code ec;
00143 this->service.expires_from_now(this->implementation, expiry_time, ec);
00144 asio::detail::throw_error(ec);
00145 }
00146
00148
00159 std::size_t cancel()
00160 {
00161 asio::error_code ec;
00162 std::size_t s = this->service.cancel(this->implementation, ec);
00163 asio::detail::throw_error(ec);
00164 return s;
00165 }
00166
00168
00179 std::size_t cancel(asio::error_code& ec)
00180 {
00181 return this->service.cancel(this->implementation, ec);
00182 }
00183
00185
00189 time_type expires_at() const
00190 {
00191 return this->service.expires_at(this->implementation);
00192 }
00193
00195
00209 std::size_t expires_at(const time_type& expiry_time)
00210 {
00211 asio::error_code ec;
00212 std::size_t s = this->service.expires_at(
00213 this->implementation, expiry_time, ec);
00214 asio::detail::throw_error(ec);
00215 return s;
00216 }
00217
00219
00233 std::size_t expires_at(const time_type& expiry_time,
00234 asio::error_code& ec)
00235 {
00236 return this->service.expires_at(this->implementation, expiry_time, ec);
00237 }
00238
00240
00244 duration_type expires_from_now() const
00245 {
00246 return this->service.expires_from_now(this->implementation);
00247 }
00248
00250
00264 std::size_t expires_from_now(const duration_type& expiry_time)
00265 {
00266 asio::error_code ec;
00267 std::size_t s = this->service.expires_from_now(
00268 this->implementation, expiry_time, ec);
00269 asio::detail::throw_error(ec);
00270 return s;
00271 }
00272
00274
00288 std::size_t expires_from_now(const duration_type& expiry_time,
00289 asio::error_code& ec)
00290 {
00291 return this->service.expires_from_now(
00292 this->implementation, expiry_time, ec);
00293 }
00294
00296
00302 void wait()
00303 {
00304 asio::error_code ec;
00305 this->service.wait(this->implementation, ec);
00306 asio::detail::throw_error(ec);
00307 }
00308
00310
00316 void wait(asio::error_code& ec)
00317 {
00318 this->service.wait(this->implementation, ec);
00319 }
00320
00322
00345 template <typename WaitHandler>
00346 void async_wait(WaitHandler handler)
00347 {
00348 this->service.async_wait(this->implementation, handler);
00349 }
00350 };
00351
00395 }
00396
00397 #include "asio/detail/pop_options.hpp"
00398
00399 #endif // ASIO_BASIC_DEADLINE_TIMER_HPP