annotate DEPENDENCIES/generic/include/boost/asio/waitable_timer_service.hpp @ 133:4acb5d8d80b6 tip

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