File indexing completed on 2025-01-18 09:28:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_ASIO_DETAIL_WIN_IOCP_SERIAL_PORT_SERVICE_HPP
0013 #define BOOST_ASIO_DETAIL_WIN_IOCP_SERIAL_PORT_SERVICE_HPP
0014
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 # pragma once
0017 #endif
0018
0019 #include <boost/asio/detail/config.hpp>
0020
0021 #if defined(BOOST_ASIO_HAS_IOCP) && defined(BOOST_ASIO_HAS_SERIAL_PORT)
0022
0023 #include <string>
0024 #include <boost/asio/error.hpp>
0025 #include <boost/asio/execution_context.hpp>
0026 #include <boost/asio/detail/win_iocp_handle_service.hpp>
0027
0028 #include <boost/asio/detail/push_options.hpp>
0029
0030 namespace boost {
0031 namespace asio {
0032 namespace detail {
0033
0034
0035 class win_iocp_serial_port_service :
0036 public execution_context_service_base<win_iocp_serial_port_service>
0037 {
0038 public:
0039
0040 typedef win_iocp_handle_service::native_handle_type native_handle_type;
0041
0042
0043 typedef win_iocp_handle_service::implementation_type implementation_type;
0044
0045
0046 BOOST_ASIO_DECL win_iocp_serial_port_service(execution_context& context);
0047
0048
0049 BOOST_ASIO_DECL void shutdown();
0050
0051
0052 void construct(implementation_type& impl)
0053 {
0054 handle_service_.construct(impl);
0055 }
0056
0057
0058 void move_construct(implementation_type& impl,
0059 implementation_type& other_impl)
0060 {
0061 handle_service_.move_construct(impl, other_impl);
0062 }
0063
0064
0065 void move_assign(implementation_type& impl,
0066 win_iocp_serial_port_service& other_service,
0067 implementation_type& other_impl)
0068 {
0069 handle_service_.move_assign(impl,
0070 other_service.handle_service_, other_impl);
0071 }
0072
0073
0074 void destroy(implementation_type& impl)
0075 {
0076 handle_service_.destroy(impl);
0077 }
0078
0079
0080 BOOST_ASIO_DECL boost::system::error_code open(implementation_type& impl,
0081 const std::string& device, boost::system::error_code& ec);
0082
0083
0084 boost::system::error_code assign(implementation_type& impl,
0085 const native_handle_type& handle, boost::system::error_code& ec)
0086 {
0087 return handle_service_.assign(impl, handle, ec);
0088 }
0089
0090
0091 bool is_open(const implementation_type& impl) const
0092 {
0093 return handle_service_.is_open(impl);
0094 }
0095
0096
0097 boost::system::error_code close(implementation_type& impl,
0098 boost::system::error_code& ec)
0099 {
0100 return handle_service_.close(impl, ec);
0101 }
0102
0103
0104 native_handle_type native_handle(implementation_type& impl)
0105 {
0106 return handle_service_.native_handle(impl);
0107 }
0108
0109
0110 boost::system::error_code cancel(implementation_type& impl,
0111 boost::system::error_code& ec)
0112 {
0113 return handle_service_.cancel(impl, ec);
0114 }
0115
0116
0117 template <typename SettableSerialPortOption>
0118 boost::system::error_code set_option(implementation_type& impl,
0119 const SettableSerialPortOption& option, boost::system::error_code& ec)
0120 {
0121 return do_set_option(impl,
0122 &win_iocp_serial_port_service::store_option<SettableSerialPortOption>,
0123 &option, ec);
0124 }
0125
0126
0127 template <typename GettableSerialPortOption>
0128 boost::system::error_code get_option(const implementation_type& impl,
0129 GettableSerialPortOption& option, boost::system::error_code& ec) const
0130 {
0131 return do_get_option(impl,
0132 &win_iocp_serial_port_service::load_option<GettableSerialPortOption>,
0133 &option, ec);
0134 }
0135
0136
0137 boost::system::error_code send_break(implementation_type&,
0138 boost::system::error_code& ec)
0139 {
0140 ec = boost::asio::error::operation_not_supported;
0141 BOOST_ASIO_ERROR_LOCATION(ec);
0142 return ec;
0143 }
0144
0145
0146 template <typename ConstBufferSequence>
0147 size_t write_some(implementation_type& impl,
0148 const ConstBufferSequence& buffers, boost::system::error_code& ec)
0149 {
0150 return handle_service_.write_some(impl, buffers, ec);
0151 }
0152
0153
0154
0155 template <typename ConstBufferSequence, typename Handler, typename IoExecutor>
0156 void async_write_some(implementation_type& impl,
0157 const ConstBufferSequence& buffers,
0158 Handler& handler, const IoExecutor& io_ex)
0159 {
0160 handle_service_.async_write_some(impl, buffers, handler, io_ex);
0161 }
0162
0163
0164 template <typename MutableBufferSequence>
0165 size_t read_some(implementation_type& impl,
0166 const MutableBufferSequence& buffers, boost::system::error_code& ec)
0167 {
0168 return handle_service_.read_some(impl, buffers, ec);
0169 }
0170
0171
0172
0173 template <typename MutableBufferSequence,
0174 typename Handler, typename IoExecutor>
0175 void async_read_some(implementation_type& impl,
0176 const MutableBufferSequence& buffers,
0177 Handler& handler, const IoExecutor& io_ex)
0178 {
0179 handle_service_.async_read_some(impl, buffers, handler, io_ex);
0180 }
0181
0182 private:
0183
0184 typedef boost::system::error_code (*store_function_type)(
0185 const void*, ::DCB&, boost::system::error_code&);
0186
0187
0188 template <typename SettableSerialPortOption>
0189 static boost::system::error_code store_option(const void* option,
0190 ::DCB& storage, boost::system::error_code& ec)
0191 {
0192 static_cast<const SettableSerialPortOption*>(option)->store(storage, ec);
0193 return ec;
0194 }
0195
0196
0197 BOOST_ASIO_DECL boost::system::error_code do_set_option(
0198 implementation_type& impl, store_function_type store,
0199 const void* option, boost::system::error_code& ec);
0200
0201
0202 typedef boost::system::error_code (*load_function_type)(
0203 void*, const ::DCB&, boost::system::error_code&);
0204
0205
0206 template <typename GettableSerialPortOption>
0207 static boost::system::error_code load_option(void* option,
0208 const ::DCB& storage, boost::system::error_code& ec)
0209 {
0210 static_cast<GettableSerialPortOption*>(option)->load(storage, ec);
0211 return ec;
0212 }
0213
0214
0215 BOOST_ASIO_DECL boost::system::error_code do_get_option(
0216 const implementation_type& impl, load_function_type load,
0217 void* option, boost::system::error_code& ec) const;
0218
0219
0220 win_iocp_handle_service handle_service_;
0221 };
0222
0223 }
0224 }
0225 }
0226
0227 #include <boost/asio/detail/pop_options.hpp>
0228
0229 #if defined(BOOST_ASIO_HEADER_ONLY)
0230 # include <boost/asio/detail/impl/win_iocp_serial_port_service.ipp>
0231 #endif
0232
0233 #endif
0234
0235 #endif