5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_IMPL_IO_SERVICE_HPP
12 #define BOOST_ASIO_IMPL_IO_SERVICE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/handler_type_requirements.hpp>
19 #include <boost/asio/detail/service_registry.hpp>
21 #include <boost/asio/detail/push_options.hpp>
26 template <typename Service>
27 inline Service& use_service(io_service& ios)
29 // Check that Service meets the necessary type requirements.
30 (void)static_cast<io_service::service*>(static_cast<Service*>(0));
31 (void)static_cast<const io_service::id*>(&Service::id);
33 return ios.service_registry_->template use_service<Service>();
37 inline detail::io_service_impl& use_service<detail::io_service_impl>(
43 template <typename Service>
44 inline void add_service(io_service& ios, Service* svc)
46 // Check that Service meets the necessary type requirements.
47 (void)static_cast<io_service::service*>(static_cast<Service*>(0));
48 (void)static_cast<const io_service::id*>(&Service::id);
50 ios.service_registry_->template add_service<Service>(svc);
53 template <typename Service>
54 inline bool has_service(io_service& ios)
56 // Check that Service meets the necessary type requirements.
57 (void)static_cast<io_service::service*>(static_cast<Service*>(0));
58 (void)static_cast<const io_service::id*>(&Service::id);
60 return ios.service_registry_->template has_service<Service>();
66 #include <boost/asio/detail/pop_options.hpp>
68 #if defined(BOOST_ASIO_HAS_IOCP)
69 # include <boost/asio/detail/win_iocp_io_service.hpp>
71 # include <boost/asio/detail/task_io_service.hpp>
74 #include <boost/asio/detail/push_options.hpp>
79 template <typename CompletionHandler>
80 inline BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
81 io_service::dispatch(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler)
83 // If you get an error on the following line it means that your handler does
84 // not meet the documented type requirements for a CompletionHandler.
85 BOOST_ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check;
87 detail::async_result_init<
88 CompletionHandler, void ()> init(
89 BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler));
91 impl_.dispatch(init.handler);
93 return init.result.get();
96 template <typename CompletionHandler>
97 inline BOOST_ASIO_INITFN_RESULT_TYPE(CompletionHandler, void ())
98 io_service::post(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler)
100 // If you get an error on the following line it means that your handler does
101 // not meet the documented type requirements for a CompletionHandler.
102 BOOST_ASIO_COMPLETION_HANDLER_CHECK(CompletionHandler, handler) type_check;
104 detail::async_result_init<
105 CompletionHandler, void ()> init(
106 BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler));
108 impl_.post(init.handler);
110 return init.result.get();
113 template <typename Handler>
114 #if defined(GENERATING_DOCUMENTATION)
117 inline detail::wrapped_handler<io_service&, Handler>
119 io_service::wrap(Handler handler)
121 return detail::wrapped_handler<io_service&, Handler>(*this, handler);
124 inline io_service::work::work(boost::asio::io_service& io_service)
125 : io_service_impl_(io_service.impl_)
127 io_service_impl_.work_started();
130 inline io_service::work::work(const work& other)
131 : io_service_impl_(other.io_service_impl_)
133 io_service_impl_.work_started();
136 inline io_service::work::~work()
138 io_service_impl_.work_finished();
141 inline boost::asio::io_service& io_service::work::get_io_service()
143 return io_service_impl_.get_io_service();
146 inline boost::asio::io_service& io_service::service::get_io_service()
154 #include <boost/asio/detail/pop_options.hpp>
156 #endif // BOOST_ASIO_IMPL_IO_SERVICE_HPP