00001 // 00002 // strand.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_STRAND_HPP 00012 #define ASIO_STRAND_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/io_service.hpp" 00021 #include "asio/detail/strand_service.hpp" 00022 #include "asio/detail/wrapped_handler.hpp" 00023 00024 namespace asio { 00025 00027 00039 class io_service::strand 00040 { 00041 public: 00043 00049 explicit strand(asio::io_service& io_service) 00050 : service_(asio::use_service< 00051 asio::detail::strand_service>(io_service)) 00052 { 00053 service_.construct(impl_); 00054 } 00055 00057 00063 ~strand() 00064 { 00065 service_.destroy(impl_); 00066 } 00067 00070 00077 asio::io_service& io_service() 00078 { 00079 return service_.get_io_service(); 00080 } 00081 00083 00090 asio::io_service& get_io_service() 00091 { 00092 return service_.get_io_service(); 00093 } 00094 00096 00114 template <typename Handler> 00115 void dispatch(Handler handler) 00116 { 00117 service_.dispatch(impl_, handler); 00118 } 00119 00122 00136 template <typename Handler> 00137 void post(Handler handler) 00138 { 00139 service_.post(impl_, handler); 00140 } 00141 00144 00163 template <typename Handler> 00164 #if defined(GENERATING_DOCUMENTATION) 00165 unspecified 00166 #else 00167 detail::wrapped_handler<strand, Handler> 00168 #endif 00169 wrap(Handler handler) 00170 { 00171 return detail::wrapped_handler<io_service::strand, Handler>(*this, handler); 00172 } 00173 00174 private: 00175 asio::detail::strand_service& service_; 00176 asio::detail::strand_service::implementation_type impl_; 00177 }; 00178 00180 typedef asio::io_service::strand strand; 00181 00182 } // namespace asio 00183 00184 #include "asio/detail/pop_options.hpp" 00185 00186 #endif // ASIO_STRAND_HPP