// // deadline_timer_service.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2005 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_DEADLINE_TIMER_SERVICE_HPP #define BOOST_ASIO_DEADLINE_TIMER_SERVICE_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include #include // Must come before posix_time. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace asio { /// Default service implementation for a timer. template , typename Allocator = std::allocator > class deadline_timer_service : private noncopyable { public: /// The demuxer type. typedef basic_demuxer > demuxer_type; /// The time traits type. typedef Time_Traits traits_type; /// The time type. typedef typename traits_type::time_type time_type; /// The duration type. typedef typename traits_type::duration_type duration_type; private: // The type of the platform-specific implementation. #if defined(BOOST_ASIO_HAS_IOCP_DEMUXER) typedef detail::reactive_deadline_timer_service > service_impl_type; #elif defined(BOOST_ASIO_HAS_EPOLL_REACTOR) typedef detail::reactive_deadline_timer_service > service_impl_type; #elif defined(BOOST_ASIO_HAS_KQUEUE_REACTOR) typedef detail::reactive_deadline_timer_service > service_impl_type; #else typedef detail::reactive_deadline_timer_service > service_impl_type; #endif public: /// The native type of the deadline timer. #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined impl_type; #else typedef typename service_impl_type::impl_type impl_type; #endif /// Construct a new timer service for the specified demuxer. explicit deadline_timer_service(demuxer_type& demuxer) : service_impl_(demuxer.get_service(service_factory())) { } /// Get the demuxer associated with the service. demuxer_type& demuxer() { return service_impl_.demuxer(); } /// Return a null timer implementation. impl_type null() const { return service_impl_.null(); } /// Create a new timer implementation. void create(impl_type& impl) { service_impl_.create(impl); } /// Destroy a timer implementation. void destroy(impl_type& impl) { service_impl_.destroy(impl); } /// Get the expiry time for the timer as an absolute time. time_type expires_at(const impl_type& impl) const { return service_impl_.expires_at(impl); } /// Set the expiry time for the timer as an absolute time. void expires_at(impl_type& impl, const time_type& expiry_time) { service_impl_.expires_at(impl, expiry_time); } /// Get the expiry time for the timer relative to now. duration_type expires_from_now(const impl_type& impl) const { return service_impl_.expires_from_now(impl); } /// Set the expiry time for the timer relative to now. void expires_from_now(impl_type& impl, const duration_type& expiry_time) { service_impl_.expires_from_now(impl, expiry_time); } /// Cancel any asynchronous wait operations associated with the timer. std::size_t cancel(impl_type& impl) { return service_impl_.cancel(impl); } // Perform a blocking wait on the timer. void wait(impl_type& impl) { service_impl_.wait(impl); } // Start an asynchronous wait on the timer. template void async_wait(impl_type& impl, Handler handler) { service_impl_.async_wait(impl, handler); } private: // The service that provides the platform-specific implementation. service_impl_type& service_impl_; }; } // namespace asio } // namespace boost #include #endif // BOOST_ASIO_DEADLINE_TIMER_SERVICE_HPP