2
// deadline_timer_service.hpp
3
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11
#ifndef ASIO_DEADLINE_TIMER_SERVICE_HPP
12
#define ASIO_DEADLINE_TIMER_SERVICE_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/push_options.hpp"
22
#include <boost/config.hpp>
23
#include "asio/detail/pop_options.hpp"
25
#include "asio/io_service.hpp"
26
#include "asio/time_traits.hpp"
27
#include "asio/detail/deadline_timer_service.hpp"
28
#include "asio/detail/epoll_reactor.hpp"
29
#include "asio/detail/kqueue_reactor.hpp"
30
#include "asio/detail/select_reactor.hpp"
31
#include "asio/detail/service_base.hpp"
32
#include "asio/detail/win_iocp_io_service.hpp"
36
/// Default service implementation for a timer.
37
template <typename TimeType,
38
typename TimeTraits = asio::time_traits<TimeType> >
39
class deadline_timer_service
40
#if defined(GENERATING_DOCUMENTATION)
41
: public asio::io_service::service
43
: public asio::detail::service_base<
44
deadline_timer_service<TimeType, TimeTraits> >
48
#if defined(GENERATING_DOCUMENTATION)
49
/// The unique service identifier.
50
static asio::io_service::id id;
53
/// The time traits type.
54
typedef TimeTraits traits_type;
57
typedef typename traits_type::time_type time_type;
59
/// The duration type.
60
typedef typename traits_type::duration_type duration_type;
63
// The type of the platform-specific implementation.
64
#if defined(ASIO_HAS_IOCP)
65
typedef detail::deadline_timer_service<
66
traits_type, detail::win_iocp_io_service> service_impl_type;
67
#elif defined(ASIO_HAS_EPOLL)
68
typedef detail::deadline_timer_service<
69
traits_type, detail::epoll_reactor<false> > service_impl_type;
70
#elif defined(ASIO_HAS_KQUEUE)
71
typedef detail::deadline_timer_service<
72
traits_type, detail::kqueue_reactor<false> > service_impl_type;
73
#elif defined(ASIO_HAS_DEV_POLL)
74
typedef detail::deadline_timer_service<
75
traits_type, detail::dev_poll_reactor<false> > service_impl_type;
77
typedef detail::deadline_timer_service<
78
traits_type, detail::select_reactor<false> > service_impl_type;
82
/// The implementation type of the deadline timer.
83
#if defined(GENERATING_DOCUMENTATION)
84
typedef implementation_defined implementation_type;
86
typedef typename service_impl_type::implementation_type implementation_type;
89
/// Construct a new timer service for the specified io_service.
90
explicit deadline_timer_service(asio::io_service& io_service)
91
: asio::detail::service_base<
92
deadline_timer_service<TimeType, TimeTraits> >(io_service),
93
service_impl_(asio::use_service<service_impl_type>(io_service))
97
/// Destroy all user-defined handler objects owned by the service.
98
void shutdown_service()
102
/// Construct a new timer implementation.
103
void construct(implementation_type& impl)
105
service_impl_.construct(impl);
108
/// Destroy a timer implementation.
109
void destroy(implementation_type& impl)
111
service_impl_.destroy(impl);
114
/// Cancel any asynchronous wait operations associated with the timer.
115
std::size_t cancel(implementation_type& impl, asio::error_code& ec)
117
return service_impl_.cancel(impl, ec);
120
/// Get the expiry time for the timer as an absolute time.
121
time_type expires_at(const implementation_type& impl) const
123
return service_impl_.expires_at(impl);
126
/// Set the expiry time for the timer as an absolute time.
127
std::size_t expires_at(implementation_type& impl,
128
const time_type& expiry_time, asio::error_code& ec)
130
return service_impl_.expires_at(impl, expiry_time, ec);
133
/// Get the expiry time for the timer relative to now.
134
duration_type expires_from_now(const implementation_type& impl) const
136
return service_impl_.expires_from_now(impl);
139
/// Set the expiry time for the timer relative to now.
140
std::size_t expires_from_now(implementation_type& impl,
141
const duration_type& expiry_time, asio::error_code& ec)
143
return service_impl_.expires_from_now(impl, expiry_time, ec);
146
// Perform a blocking wait on the timer.
147
void wait(implementation_type& impl, asio::error_code& ec)
149
service_impl_.wait(impl, ec);
152
// Start an asynchronous wait on the timer.
153
template <typename WaitHandler>
154
void async_wait(implementation_type& impl, WaitHandler handler)
156
service_impl_.async_wait(impl, handler);
160
// The service that provides the platform-specific implementation.
161
service_impl_type& service_impl_;
166
#include "asio/detail/pop_options.hpp"
168
#endif // ASIO_DEADLINE_TIMER_SERVICE_HPP