Realistic 3D camera system
3D camera system components
waitable_timer_service.hpp
Go to the documentation of this file.
1 //
2 // waitable_timer_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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_WAITABLE_TIMER_SERVICE_HPP
12 #define ASIO_WAITABLE_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/config.hpp"
19 #include <cstddef>
20 #include "asio/async_result.hpp"
23 #include "asio/io_service.hpp"
24 #include "asio/wait_traits.hpp"
25 
27 
28 namespace asio {
29 
31 template <typename Clock,
32  typename WaitTraits = asio::wait_traits<Clock> >
34 #if defined(GENERATING_DOCUMENTATION)
36 #else
38  waitable_timer_service<Clock, WaitTraits> >
39 #endif
40 {
41 public:
42 #if defined(GENERATING_DOCUMENTATION)
43  static asio::io_service::id id;
45 #endif
46 
48  typedef Clock clock_type;
49 
51  typedef typename clock_type::duration duration;
52 
54  typedef typename clock_type::time_point time_point;
55 
57  typedef WaitTraits traits_type;
58 
59 private:
60  // The type of the platform-specific implementation.
63 
64 public:
66 #if defined(GENERATING_DOCUMENTATION)
67  typedef implementation_defined implementation_type;
68 #else
69  typedef typename service_impl_type::implementation_type implementation_type;
70 #endif
71 
74  : asio::detail::service_base<
75  waitable_timer_service<Clock, WaitTraits> >(io_service),
76  service_impl_(io_service)
77  {
78  }
79 
81  void construct(implementation_type& impl)
82  {
83  service_impl_.construct(impl);
84  }
85 
87  void destroy(implementation_type& impl)
88  {
89  service_impl_.destroy(impl);
90  }
91 
93  std::size_t cancel(implementation_type& impl, asio::error_code& ec)
94  {
95  return service_impl_.cancel(impl, ec);
96  }
97 
99  std::size_t cancel_one(implementation_type& impl,
100  asio::error_code& ec)
101  {
102  return service_impl_.cancel_one(impl, ec);
103  }
104 
106  time_point expires_at(const implementation_type& impl) const
107  {
108  return service_impl_.expires_at(impl);
109  }
110 
112  std::size_t expires_at(implementation_type& impl,
113  const time_point& expiry_time, asio::error_code& ec)
114  {
115  return service_impl_.expires_at(impl, expiry_time, ec);
116  }
117 
119  duration expires_from_now(const implementation_type& impl) const
120  {
121  return service_impl_.expires_from_now(impl);
122  }
123 
125  std::size_t expires_from_now(implementation_type& impl,
126  const duration& expiry_time, asio::error_code& ec)
127  {
128  return service_impl_.expires_from_now(impl, expiry_time, ec);
129  }
130 
131  // Perform a blocking wait on the timer.
132  void wait(implementation_type& impl, asio::error_code& ec)
133  {
134  service_impl_.wait(impl, ec);
135  }
136 
137  // Start an asynchronous wait on the timer.
138  template <typename WaitHandler>
139  ASIO_INITFN_RESULT_TYPE(WaitHandler,
140  void (asio::error_code))
141  async_wait(implementation_type& impl,
142  ASIO_MOVE_ARG(WaitHandler) handler)
143  {
145  WaitHandler, void (asio::error_code)> init(
146  ASIO_MOVE_CAST(WaitHandler)(handler));
147 
148  service_impl_.async_wait(impl, init.handler);
149 
150  return init.result.get();
151  }
152 
153 private:
154  // Destroy all user-defined handler objects owned by the service.
155  void shutdown_service()
156  {
157  service_impl_.shutdown_service();
158  }
159 
160  // The platform-specific implementation.
161  service_impl_type service_impl_;
162 };
163 
164 } // namespace asio
165 
167 
168 #endif // ASIO_WAITABLE_TIMER_SERVICE_HPP
void wait(implementation_type &impl, asio::error_code &ec)
clock_type::time_point time_point
The time point type of the clock.
Class used to uniquely identify a service.
Definition: io_service.hpp:665
Provides core I/O functionality.
Definition: io_service.hpp:184
std::size_t cancel_one(implementation_type &impl, asio::error_code &ec)
Cancels one asynchronous wait operation associated with the timer.
WaitTraits traits_type
The wait traits type.
asio::basic_streambuf< Allocator > MatchCondition enable_if< is_match_condition< MatchCondition >::value >::type *detail::async_result_init< ReadHandler, void(asio::error_code, std::size_t)> init(ASIO_MOVE_CAST(ReadHandler)(handler))
std::size_t cancel(implementation_type &impl, asio::error_code &ec)
Cancel any asynchronous wait operations associated with the timer.
std::size_t cancel_one(implementation_type &impl, asio::error_code &ec)
void wait(implementation_type &impl, asio::error_code &ec)
duration_type expires_from_now(const implementation_type &impl) const
std::size_t expires_at(implementation_type &impl, const time_point &expiry_time, asio::error_code &ec)
Set the expiry time for the timer as an absolute time.
void async_wait(implementation_type &impl, Handler &handler)
time_type expires_at(const implementation_type &impl) const
Wait traits suitable for use with the basic_waitable_timer class template.
Definition: wait_traits.hpp:24
duration expires_from_now(const implementation_type &impl) const
Get the expiry time for the timer relative to now.
void destroy(implementation_type &impl)
Destroy a timer implementation.
waitable_timer_service(asio::io_service &io_service)
Construct a new timer service for the specified io_service.
Class to represent an error code value.
Definition: error_code.hpp:80
ASIO_INITFN_RESULT_TYPE(WaitHandler, void(asio::error_code)) async_wait(implementation_type &impl
clock_type::duration duration
The duration type of the clock.
void construct(implementation_type &impl)
Construct a new timer implementation.
static asio::detail::service_id< waitable_timer_service< Clock, WaitTraits > > id
Definition: io_service.hpp:748
std::size_t expires_from_now(implementation_type &impl, const duration &expiry_time, asio::error_code &ec)
Set the expiry time for the timer relative to now.
void destroy(implementation_type &impl)
void construct(implementation_type &impl)
handler_type< Handler, Signature >::type handler
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
async_result< typename handler_type< Handler, Signature >::type > result
Default service implementation for a timer.
Base class for all io_service services.
Definition: io_service.hpp:674
std::size_t cancel(implementation_type &impl, asio::error_code &ec)
service_impl_type::implementation_type implementation_type
The implementation type of the waitable timer.
time_point expires_at(const implementation_type &impl) const
Get the expiry time for the timer as an absolute time.