PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/asio/deadline_timer_service.hpp

http://hadesmem.googlecode.com/
C++ Header | 156 lines | 100 code | 27 blank | 29 comment | 1 complexity | 60f44a627cb4f2860cc74a613e7561d7 MD5 | raw file
  1//
  2// deadline_timer_service.hpp
  3// ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4//
  5// Copyright (c) 2003-2011 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 BOOST_ASIO_DEADLINE_TIMER_SERVICE_HPP
 12#define BOOST_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 <boost/asio/detail/config.hpp>
 19#include <cstddef>
 20#include <boost/asio/detail/deadline_timer_service.hpp>
 21#include <boost/asio/io_service.hpp>
 22#include <boost/asio/time_traits.hpp>
 23
 24#include <boost/asio/detail/push_options.hpp>
 25
 26namespace boost {
 27namespace asio {
 28
 29/// Default service implementation for a timer.
 30template <typename TimeType,
 31    typename TimeTraits = boost::asio::time_traits<TimeType> >
 32class deadline_timer_service
 33#if defined(GENERATING_DOCUMENTATION)
 34  : public boost::asio::io_service::service
 35#else
 36  : public boost::asio::detail::service_base<
 37      deadline_timer_service<TimeType, TimeTraits> >
 38#endif
 39{
 40public:
 41#if defined(GENERATING_DOCUMENTATION)
 42  /// The unique service identifier.
 43  static boost::asio::io_service::id id;
 44#endif
 45
 46  /// The time traits type.
 47  typedef TimeTraits traits_type;
 48
 49  /// The time type.
 50  typedef typename traits_type::time_type time_type;
 51
 52  /// The duration type.
 53  typedef typename traits_type::duration_type duration_type;
 54
 55private:
 56  // The type of the platform-specific implementation.
 57  typedef detail::deadline_timer_service<traits_type> service_impl_type;
 58
 59public:
 60  /// The implementation type of the deadline timer.
 61#if defined(GENERATING_DOCUMENTATION)
 62  typedef implementation_defined implementation_type;
 63#else
 64  typedef typename service_impl_type::implementation_type implementation_type;
 65#endif
 66
 67  /// Construct a new timer service for the specified io_service.
 68  explicit deadline_timer_service(boost::asio::io_service& io_service)
 69    : boost::asio::detail::service_base<
 70        deadline_timer_service<TimeType, TimeTraits> >(io_service),
 71      service_impl_(io_service)
 72  {
 73  }
 74
 75  /// Construct a new timer implementation.
 76  void construct(implementation_type& impl)
 77  {
 78    service_impl_.construct(impl);
 79  }
 80
 81  /// Destroy a timer implementation.
 82  void destroy(implementation_type& impl)
 83  {
 84    service_impl_.destroy(impl);
 85  }
 86
 87  /// Cancel any asynchronous wait operations associated with the timer.
 88  std::size_t cancel(implementation_type& impl, boost::system::error_code& ec)
 89  {
 90    return service_impl_.cancel(impl, ec);
 91  }
 92
 93  /// Cancels one asynchronous wait operation associated with the timer.
 94  std::size_t cancel_one(implementation_type& impl,
 95      boost::system::error_code& ec)
 96  {
 97    return service_impl_.cancel_one(impl, ec);
 98  }
 99
100  /// Get the expiry time for the timer as an absolute time.
101  time_type expires_at(const implementation_type& impl) const
102  {
103    return service_impl_.expires_at(impl);
104  }
105
106  /// Set the expiry time for the timer as an absolute time.
107  std::size_t expires_at(implementation_type& impl,
108      const time_type& expiry_time, boost::system::error_code& ec)
109  {
110    return service_impl_.expires_at(impl, expiry_time, ec);
111  }
112
113  /// Get the expiry time for the timer relative to now.
114  duration_type expires_from_now(const implementation_type& impl) const
115  {
116    return service_impl_.expires_from_now(impl);
117  }
118
119  /// Set the expiry time for the timer relative to now.
120  std::size_t expires_from_now(implementation_type& impl,
121      const duration_type& expiry_time, boost::system::error_code& ec)
122  {
123    return service_impl_.expires_from_now(impl, expiry_time, ec);
124  }
125
126  // Perform a blocking wait on the timer.
127  void wait(implementation_type& impl, boost::system::error_code& ec)
128  {
129    service_impl_.wait(impl, ec);
130  }
131
132  // Start an asynchronous wait on the timer.
133  template <typename WaitHandler>
134  void async_wait(implementation_type& impl,
135      BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
136  {
137    service_impl_.async_wait(impl, BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
138  }
139
140private:
141  // Destroy all user-defined handler objects owned by the service.
142  void shutdown_service()
143  {
144    service_impl_.shutdown_service();
145  }
146
147  // The platform-specific implementation.
148  service_impl_type service_impl_;
149};
150
151} // namespace asio
152} // namespace boost
153
154#include <boost/asio/detail/pop_options.hpp>
155
156#endif // BOOST_ASIO_DEADLINE_TIMER_SERVICE_HPP