$search
00001 // 00002 // deadline_timer_service.hpp 00003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) 00006 // 00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 00011 #ifndef ASIO_DEADLINE_TIMER_SERVICE_HPP 00012 #define ASIO_DEADLINE_TIMER_SERVICE_HPP 00013 00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 00015 # pragma once 00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 00017 00018 #include "asio/detail/push_options.hpp" 00019 00020 #include "asio/detail/push_options.hpp" 00021 #include <cstddef> 00022 #include <boost/config.hpp> 00023 #include "asio/detail/pop_options.hpp" 00024 00025 #include "asio/io_service.hpp" 00026 #include "asio/time_traits.hpp" 00027 #include "asio/detail/deadline_timer_service.hpp" 00028 #include "asio/detail/epoll_reactor.hpp" 00029 #include "asio/detail/kqueue_reactor.hpp" 00030 #include "asio/detail/select_reactor.hpp" 00031 #include "asio/detail/service_base.hpp" 00032 #include "asio/detail/win_iocp_io_service.hpp" 00033 00034 namespace asio { 00035 00037 template <typename TimeType, 00038 typename TimeTraits = asio::time_traits<TimeType> > 00039 class deadline_timer_service 00040 #if defined(GENERATING_DOCUMENTATION) 00041 : public asio::io_service::service 00042 #else 00043 : public asio::detail::service_base< 00044 deadline_timer_service<TimeType, TimeTraits> > 00045 #endif 00046 { 00047 public: 00048 #if defined(GENERATING_DOCUMENTATION) 00049 00050 static asio::io_service::id id; 00051 #endif 00052 00054 typedef TimeTraits traits_type; 00055 00057 typedef typename traits_type::time_type time_type; 00058 00060 typedef typename traits_type::duration_type duration_type; 00061 00062 private: 00063 // The type of the platform-specific implementation. 00064 #if defined(ASIO_HAS_IOCP) 00065 typedef detail::deadline_timer_service< 00066 traits_type, detail::win_iocp_io_service> service_impl_type; 00067 #elif defined(ASIO_HAS_EPOLL) 00068 typedef detail::deadline_timer_service< 00069 traits_type, detail::epoll_reactor<false> > service_impl_type; 00070 #elif defined(ASIO_HAS_KQUEUE) 00071 typedef detail::deadline_timer_service< 00072 traits_type, detail::kqueue_reactor<false> > service_impl_type; 00073 #elif defined(ASIO_HAS_DEV_POLL) 00074 typedef detail::deadline_timer_service< 00075 traits_type, detail::dev_poll_reactor<false> > service_impl_type; 00076 #else 00077 typedef detail::deadline_timer_service< 00078 traits_type, detail::select_reactor<false> > service_impl_type; 00079 #endif 00080 00081 public: 00083 #if defined(GENERATING_DOCUMENTATION) 00084 typedef implementation_defined implementation_type; 00085 #else 00086 typedef typename service_impl_type::implementation_type implementation_type; 00087 #endif 00088 00090 explicit deadline_timer_service(asio::io_service& io_service) 00091 : asio::detail::service_base< 00092 deadline_timer_service<TimeType, TimeTraits> >(io_service), 00093 service_impl_(asio::use_service<service_impl_type>(io_service)) 00094 { 00095 } 00096 00098 void shutdown_service() 00099 { 00100 } 00101 00103 void construct(implementation_type& impl) 00104 { 00105 service_impl_.construct(impl); 00106 } 00107 00109 void destroy(implementation_type& impl) 00110 { 00111 service_impl_.destroy(impl); 00112 } 00113 00115 std::size_t cancel(implementation_type& impl, asio::error_code& ec) 00116 { 00117 return service_impl_.cancel(impl, ec); 00118 } 00119 00121 time_type expires_at(const implementation_type& impl) const 00122 { 00123 return service_impl_.expires_at(impl); 00124 } 00125 00127 std::size_t expires_at(implementation_type& impl, 00128 const time_type& expiry_time, asio::error_code& ec) 00129 { 00130 return service_impl_.expires_at(impl, expiry_time, ec); 00131 } 00132 00134 duration_type expires_from_now(const implementation_type& impl) const 00135 { 00136 return service_impl_.expires_from_now(impl); 00137 } 00138 00140 std::size_t expires_from_now(implementation_type& impl, 00141 const duration_type& expiry_time, asio::error_code& ec) 00142 { 00143 return service_impl_.expires_from_now(impl, expiry_time, ec); 00144 } 00145 00146 // Perform a blocking wait on the timer. 00147 void wait(implementation_type& impl, asio::error_code& ec) 00148 { 00149 service_impl_.wait(impl, ec); 00150 } 00151 00152 // Start an asynchronous wait on the timer. 00153 template <typename WaitHandler> 00154 void async_wait(implementation_type& impl, WaitHandler handler) 00155 { 00156 service_impl_.async_wait(impl, handler); 00157 } 00158 00159 private: 00160 // The service that provides the platform-specific implementation. 00161 service_impl_type& service_impl_; 00162 }; 00163 00164 } // namespace asio 00165 00166 #include "asio/detail/pop_options.hpp" 00167 00168 #endif // ASIO_DEADLINE_TIMER_SERVICE_HPP