PageRenderTime 20ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/asio/impl/io_service.ipp

http://pythonocc.googlecode.com/
C++ Header | 226 lines | 173 code | 41 blank | 12 comment | 4 complexity | cf8586cf03e6fe703e992c7a71bba568 MD5 | raw file
  1//
  2// io_service.ipp
  3// ~~~~~~~~~~~~~~
  4//
  5// Copyright (c) 2003-2010 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 BOOST_ASIO_IO_SERVICE_IPP
 12#define BOOST_ASIO_IO_SERVICE_IPP
 13
 14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
 15# pragma once
 16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
 17
 18#include <boost/asio/detail/push_options.hpp>
 19
 20#include <boost/asio/detail/push_options.hpp>
 21#include <boost/limits.hpp>
 22#include <boost/asio/detail/pop_options.hpp>
 23
 24#include <boost/asio/detail/service_registry.hpp>
 25#include <boost/asio/detail/throw_error.hpp>
 26
 27#if defined(BOOST_ASIO_HAS_IOCP)
 28# include <boost/asio/detail/win_iocp_io_service.hpp>
 29#else
 30# include <boost/asio/detail/task_io_service.hpp>
 31# include <boost/asio/detail/reactor.hpp>
 32#endif
 33
 34namespace boost {
 35namespace asio {
 36
 37inline io_service::io_service()
 38  : service_registry_(new boost::asio::detail::service_registry(*this)),
 39    impl_(service_registry_->use_service<impl_type>())
 40{
 41  impl_.init((std::numeric_limits<std::size_t>::max)());
 42}
 43
 44inline io_service::io_service(std::size_t concurrency_hint)
 45  : service_registry_(new boost::asio::detail::service_registry(*this)),
 46    impl_(service_registry_->use_service<impl_type>())
 47{
 48  impl_.init(concurrency_hint);
 49}
 50
 51inline io_service::~io_service()
 52{
 53  delete service_registry_;
 54}
 55
 56inline std::size_t io_service::run()
 57{
 58  boost::system::error_code ec;
 59  std::size_t s = impl_.run(ec);
 60  boost::asio::detail::throw_error(ec);
 61  return s;
 62}
 63
 64inline std::size_t io_service::run(boost::system::error_code& ec)
 65{
 66  return impl_.run(ec);
 67}
 68
 69inline std::size_t io_service::run_one()
 70{
 71  boost::system::error_code ec;
 72  std::size_t s = impl_.run_one(ec);
 73  boost::asio::detail::throw_error(ec);
 74  return s;
 75}
 76
 77inline std::size_t io_service::run_one(boost::system::error_code& ec)
 78{
 79  return impl_.run_one(ec);
 80}
 81
 82inline std::size_t io_service::poll()
 83{
 84  boost::system::error_code ec;
 85  std::size_t s = impl_.poll(ec);
 86  boost::asio::detail::throw_error(ec);
 87  return s;
 88}
 89
 90inline std::size_t io_service::poll(boost::system::error_code& ec)
 91{
 92  return impl_.poll(ec);
 93}
 94
 95inline std::size_t io_service::poll_one()
 96{
 97  boost::system::error_code ec;
 98  std::size_t s = impl_.poll_one(ec);
 99  boost::asio::detail::throw_error(ec);
100  return s;
101}
102
103inline std::size_t io_service::poll_one(boost::system::error_code& ec)
104{
105  return impl_.poll_one(ec);
106}
107
108inline void io_service::stop()
109{
110  impl_.stop();
111}
112
113inline void io_service::reset()
114{
115  impl_.reset();
116}
117
118template <typename Handler>
119inline void io_service::dispatch(Handler handler)
120{
121  impl_.dispatch(handler);
122}
123
124template <typename Handler>
125inline void io_service::post(Handler handler)
126{
127  impl_.post(handler);
128}
129
130template <typename Handler>
131#if defined(GENERATING_DOCUMENTATION)
132unspecified
133#else
134inline detail::wrapped_handler<io_service&, Handler>
135#endif
136io_service::wrap(Handler handler)
137{
138  return detail::wrapped_handler<io_service&, Handler>(*this, handler);
139}
140
141inline io_service::work::work(boost::asio::io_service& io_service)
142  : io_service_(io_service)
143{
144  io_service_.impl_.work_started();
145}
146
147inline io_service::work::work(const work& other)
148  : io_service_(other.io_service_)
149{
150  io_service_.impl_.work_started();
151}
152
153inline io_service::work::~work()
154{
155  io_service_.impl_.work_finished();
156}
157
158inline boost::asio::io_service& io_service::work::io_service()
159{
160  return io_service_;
161}
162
163inline boost::asio::io_service& io_service::work::get_io_service()
164{
165  return io_service_;
166}
167
168inline io_service::service::service(boost::asio::io_service& owner)
169  : owner_(owner),
170    next_(0)
171{
172}
173
174inline io_service::service::~service()
175{
176}
177
178inline boost::asio::io_service& io_service::service::io_service()
179{
180  return owner_;
181}
182
183inline boost::asio::io_service& io_service::service::get_io_service()
184{
185  return owner_;
186}
187
188template <typename Service>
189inline Service& use_service(io_service& ios)
190{
191  // Check that Service meets the necessary type requirements.
192  (void)static_cast<io_service::service*>(static_cast<Service*>(0));
193  (void)static_cast<const io_service::id*>(&Service::id);
194
195  return ios.service_registry_->template use_service<Service>();
196}
197
198template <typename Service>
199void add_service(io_service& ios, Service* svc)
200{
201  // Check that Service meets the necessary type requirements.
202  (void)static_cast<io_service::service*>(static_cast<Service*>(0));
203  (void)static_cast<const io_service::id*>(&Service::id);
204
205  if (&ios != &svc->io_service())
206    boost::throw_exception(invalid_service_owner());
207  if (!ios.service_registry_->template add_service<Service>(svc))
208    boost::throw_exception(service_already_exists());
209}
210
211template <typename Service>
212bool has_service(io_service& ios)
213{
214  // Check that Service meets the necessary type requirements.
215  (void)static_cast<io_service::service*>(static_cast<Service*>(0));
216  (void)static_cast<const io_service::id*>(&Service::id);
217
218  return ios.service_registry_->template has_service<Service>();
219}
220
221} // namespace asio
222} // namespace boost
223
224#include <boost/asio/detail/pop_options.hpp>
225
226#endif // BOOST_ASIO_IO_SERVICE_IPP