~ubuntu-branches/ubuntu/trusty/miro/trusty

« back to all changes in this revision

Viewing changes to portable/libtorrent/include/libtorrent/asio/deadline_timer_service.hpp

  • Committer: Daniel Hahler
  • Date: 2010-04-13 18:51:35 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: ubuntu-launchpad@thequod.de-20100413185135-xi24v1diqg8w406x
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// deadline_timer_service.hpp
3
 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
4
 
//
5
 
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6
 
//
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)
9
 
//
10
 
 
11
 
#ifndef ASIO_DEADLINE_TIMER_SERVICE_HPP
12
 
#define ASIO_DEADLINE_TIMER_SERVICE_HPP
13
 
 
14
 
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15
 
# pragma once
16
 
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
 
 
18
 
#include "asio/detail/push_options.hpp"
19
 
 
20
 
#include "asio/detail/push_options.hpp"
21
 
#include <cstddef>
22
 
#include <boost/config.hpp>
23
 
#include "asio/detail/pop_options.hpp"
24
 
 
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"
33
 
 
34
 
namespace asio {
35
 
 
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
42
 
#else
43
 
  : public asio::detail::service_base<
44
 
      deadline_timer_service<TimeType, TimeTraits> >
45
 
#endif
46
 
{
47
 
public:
48
 
#if defined(GENERATING_DOCUMENTATION)
49
 
  /// The unique service identifier.
50
 
  static asio::io_service::id id;
51
 
#endif
52
 
 
53
 
  /// The time traits type.
54
 
  typedef TimeTraits traits_type;
55
 
 
56
 
  /// The time type.
57
 
  typedef typename traits_type::time_type time_type;
58
 
 
59
 
  /// The duration type.
60
 
  typedef typename traits_type::duration_type duration_type;
61
 
 
62
 
private:
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;
76
 
#else
77
 
  typedef detail::deadline_timer_service<
78
 
    traits_type, detail::select_reactor<false> > service_impl_type;
79
 
#endif
80
 
 
81
 
public:
82
 
  /// The implementation type of the deadline timer.
83
 
#if defined(GENERATING_DOCUMENTATION)
84
 
  typedef implementation_defined implementation_type;
85
 
#else
86
 
  typedef typename service_impl_type::implementation_type implementation_type;
87
 
#endif
88
 
 
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))
94
 
  {
95
 
  }
96
 
 
97
 
  /// Destroy all user-defined handler objects owned by the service.
98
 
  void shutdown_service()
99
 
  {
100
 
  }
101
 
 
102
 
  /// Construct a new timer implementation.
103
 
  void construct(implementation_type& impl)
104
 
  {
105
 
    service_impl_.construct(impl);
106
 
  }
107
 
 
108
 
  /// Destroy a timer implementation.
109
 
  void destroy(implementation_type& impl)
110
 
  {
111
 
    service_impl_.destroy(impl);
112
 
  }
113
 
 
114
 
  /// Cancel any asynchronous wait operations associated with the timer.
115
 
  std::size_t cancel(implementation_type& impl, asio::error_code& ec)
116
 
  {
117
 
    return service_impl_.cancel(impl, ec);
118
 
  }
119
 
 
120
 
  /// Get the expiry time for the timer as an absolute time.
121
 
  time_type expires_at(const implementation_type& impl) const
122
 
  {
123
 
    return service_impl_.expires_at(impl);
124
 
  }
125
 
 
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)
129
 
  {
130
 
    return service_impl_.expires_at(impl, expiry_time, ec);
131
 
  }
132
 
 
133
 
  /// Get the expiry time for the timer relative to now.
134
 
  duration_type expires_from_now(const implementation_type& impl) const
135
 
  {
136
 
    return service_impl_.expires_from_now(impl);
137
 
  }
138
 
 
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)
142
 
  {
143
 
    return service_impl_.expires_from_now(impl, expiry_time, ec);
144
 
  }
145
 
 
146
 
  // Perform a blocking wait on the timer.
147
 
  void wait(implementation_type& impl, asio::error_code& ec)
148
 
  {
149
 
    service_impl_.wait(impl, ec);
150
 
  }
151
 
 
152
 
  // Start an asynchronous wait on the timer.
153
 
  template <typename WaitHandler>
154
 
  void async_wait(implementation_type& impl, WaitHandler handler)
155
 
  {
156
 
    service_impl_.async_wait(impl, handler);
157
 
  }
158
 
 
159
 
private:
160
 
  // The service that provides the platform-specific implementation.
161
 
  service_impl_type& service_impl_;
162
 
};
163
 
 
164
 
} // namespace asio
165
 
 
166
 
#include "asio/detail/pop_options.hpp"
167
 
 
168
 
#endif // ASIO_DEADLINE_TIMER_SERVICE_HPP