Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / waitable_timer_service.hpp @ 2486

History | View | Annotate | Download (4.8 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// waitable_timer_service.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_WAITABLE_TIMER_SERVICE_HPP
12 2486 sjacqu01
#define BOOST_ASIO_WAITABLE_TIMER_SERVICE_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <cstddef>
20 2486 sjacqu01
#include <boost/asio/async_result.hpp>
21 2486 sjacqu01
#include <boost/asio/detail/chrono_time_traits.hpp>
22 2486 sjacqu01
#include <boost/asio/detail/deadline_timer_service.hpp>
23 2486 sjacqu01
#include <boost/asio/io_service.hpp>
24 2486 sjacqu01
#include <boost/asio/wait_traits.hpp>
25 2486 sjacqu01
26 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
27 2486 sjacqu01
28 2486 sjacqu01
namespace boost {
29 2486 sjacqu01
namespace asio {
30 2486 sjacqu01
31 2486 sjacqu01
/// Default service implementation for a timer.
32 2486 sjacqu01
template <typename Clock,
33 2486 sjacqu01
    typename WaitTraits = boost::asio::wait_traits<Clock> >
34 2486 sjacqu01
class waitable_timer_service
35 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
36 2486 sjacqu01
  : public boost::asio::io_service::service
37 2486 sjacqu01
#else
38 2486 sjacqu01
  : public boost::asio::detail::service_base<
39 2486 sjacqu01
      waitable_timer_service<Clock, WaitTraits> >
40 2486 sjacqu01
#endif
41 2486 sjacqu01
{
42 2486 sjacqu01
public:
43 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
44 2486 sjacqu01
  /// The unique service identifier.
45 2486 sjacqu01
  static boost::asio::io_service::id id;
46 2486 sjacqu01
#endif
47 2486 sjacqu01
48 2486 sjacqu01
  /// The clock type.
49 2486 sjacqu01
  typedef Clock clock_type;
50 2486 sjacqu01
51 2486 sjacqu01
  /// The duration type of the clock.
52 2486 sjacqu01
  typedef typename clock_type::duration duration;
53 2486 sjacqu01
54 2486 sjacqu01
  /// The time point type of the clock.
55 2486 sjacqu01
  typedef typename clock_type::time_point time_point;
56 2486 sjacqu01
57 2486 sjacqu01
  /// The wait traits type.
58 2486 sjacqu01
  typedef WaitTraits traits_type;
59 2486 sjacqu01
60 2486 sjacqu01
private:
61 2486 sjacqu01
  // The type of the platform-specific implementation.
62 2486 sjacqu01
  typedef detail::deadline_timer_service<
63 2486 sjacqu01
    detail::chrono_time_traits<Clock, WaitTraits> > service_impl_type;
64 2486 sjacqu01
65 2486 sjacqu01
public:
66 2486 sjacqu01
  /// The implementation type of the waitable timer.
67 2486 sjacqu01
#if defined(GENERATING_DOCUMENTATION)
68 2486 sjacqu01
  typedef implementation_defined implementation_type;
69 2486 sjacqu01
#else
70 2486 sjacqu01
  typedef typename service_impl_type::implementation_type implementation_type;
71 2486 sjacqu01
#endif
72 2486 sjacqu01
73 2486 sjacqu01
  /// Construct a new timer service for the specified io_service.
74 2486 sjacqu01
  explicit waitable_timer_service(boost::asio::io_service& io_service)
75 2486 sjacqu01
    : boost::asio::detail::service_base<
76 2486 sjacqu01
        waitable_timer_service<Clock, WaitTraits> >(io_service),
77 2486 sjacqu01
      service_impl_(io_service)
78 2486 sjacqu01
  {
79 2486 sjacqu01
  }
80 2486 sjacqu01
81 2486 sjacqu01
  /// Construct a new timer implementation.
82 2486 sjacqu01
  void construct(implementation_type& impl)
83 2486 sjacqu01
  {
84 2486 sjacqu01
    service_impl_.construct(impl);
85 2486 sjacqu01
  }
86 2486 sjacqu01
87 2486 sjacqu01
  /// Destroy a timer implementation.
88 2486 sjacqu01
  void destroy(implementation_type& impl)
89 2486 sjacqu01
  {
90 2486 sjacqu01
    service_impl_.destroy(impl);
91 2486 sjacqu01
  }
92 2486 sjacqu01
93 2486 sjacqu01
  /// Cancel any asynchronous wait operations associated with the timer.
94 2486 sjacqu01
  std::size_t cancel(implementation_type& impl, boost::system::error_code& ec)
95 2486 sjacqu01
  {
96 2486 sjacqu01
    return service_impl_.cancel(impl, ec);
97 2486 sjacqu01
  }
98 2486 sjacqu01
99 2486 sjacqu01
  /// Cancels one asynchronous wait operation associated with the timer.
100 2486 sjacqu01
  std::size_t cancel_one(implementation_type& impl,
101 2486 sjacqu01
      boost::system::error_code& ec)
102 2486 sjacqu01
  {
103 2486 sjacqu01
    return service_impl_.cancel_one(impl, ec);
104 2486 sjacqu01
  }
105 2486 sjacqu01
106 2486 sjacqu01
  /// Get the expiry time for the timer as an absolute time.
107 2486 sjacqu01
  time_point expires_at(const implementation_type& impl) const
108 2486 sjacqu01
  {
109 2486 sjacqu01
    return service_impl_.expires_at(impl);
110 2486 sjacqu01
  }
111 2486 sjacqu01
112 2486 sjacqu01
  /// Set the expiry time for the timer as an absolute time.
113 2486 sjacqu01
  std::size_t expires_at(implementation_type& impl,
114 2486 sjacqu01
      const time_point& expiry_time, boost::system::error_code& ec)
115 2486 sjacqu01
  {
116 2486 sjacqu01
    return service_impl_.expires_at(impl, expiry_time, ec);
117 2486 sjacqu01
  }
118 2486 sjacqu01
119 2486 sjacqu01
  /// Get the expiry time for the timer relative to now.
120 2486 sjacqu01
  duration expires_from_now(const implementation_type& impl) const
121 2486 sjacqu01
  {
122 2486 sjacqu01
    return service_impl_.expires_from_now(impl);
123 2486 sjacqu01
  }
124 2486 sjacqu01
125 2486 sjacqu01
  /// Set the expiry time for the timer relative to now.
126 2486 sjacqu01
  std::size_t expires_from_now(implementation_type& impl,
127 2486 sjacqu01
      const duration& expiry_time, boost::system::error_code& ec)
128 2486 sjacqu01
  {
129 2486 sjacqu01
    return service_impl_.expires_from_now(impl, expiry_time, ec);
130 2486 sjacqu01
  }
131 2486 sjacqu01
132 2486 sjacqu01
  // Perform a blocking wait on the timer.
133 2486 sjacqu01
  void wait(implementation_type& impl, boost::system::error_code& ec)
134 2486 sjacqu01
  {
135 2486 sjacqu01
    service_impl_.wait(impl, ec);
136 2486 sjacqu01
  }
137 2486 sjacqu01
138 2486 sjacqu01
  // Start an asynchronous wait on the timer.
139 2486 sjacqu01
  template <typename WaitHandler>
140 2486 sjacqu01
  BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
141 2486 sjacqu01
      void (boost::system::error_code))
142 2486 sjacqu01
  async_wait(implementation_type& impl,
143 2486 sjacqu01
      BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
144 2486 sjacqu01
  {
145 2486 sjacqu01
    detail::async_result_init<
146 2486 sjacqu01
      WaitHandler, void (boost::system::error_code)> init(
147 2486 sjacqu01
        BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
148 2486 sjacqu01
149 2486 sjacqu01
    service_impl_.async_wait(impl, init.handler);
150 2486 sjacqu01
151 2486 sjacqu01
    return init.result.get();
152 2486 sjacqu01
  }
153 2486 sjacqu01
154 2486 sjacqu01
private:
155 2486 sjacqu01
  // Destroy all user-defined handler objects owned by the service.
156 2486 sjacqu01
  void shutdown_service()
157 2486 sjacqu01
  {
158 2486 sjacqu01
    service_impl_.shutdown_service();
159 2486 sjacqu01
  }
160 2486 sjacqu01
161 2486 sjacqu01
  // The platform-specific implementation.
162 2486 sjacqu01
  service_impl_type service_impl_;
163 2486 sjacqu01
};
164 2486 sjacqu01
165 2486 sjacqu01
} // namespace asio
166 2486 sjacqu01
} // namespace boost
167 2486 sjacqu01
168 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
169 2486 sjacqu01
170 2486 sjacqu01
#endif // BOOST_ASIO_WAITABLE_TIMER_SERVICE_HPP