9 #ifndef BOOST_ASIO_MOCKUP_SERIAL_PORT_SERVICE_HPP 10 #define BOOST_ASIO_MOCKUP_SERIAL_PORT_SERVICE_HPP 12 #include <boost/asio/detail/config.hpp> 14 #if defined(BOOST_ASIO_HAS_SERIAL_PORT) \ 15 || defined(GENERATING_DOCUMENTATION) 19 #include <boost/asio/async_result.hpp> 20 #include <pre/boost/asio/detail/mockup_serial_port_service.hpp> 21 #include <boost/asio/error.hpp> 22 #include <boost/asio/io_service.hpp> 23 #include <boost/asio/serial_port_base.hpp> 71 :
public boost::asio::detail::service_base<mockup_serial_port_service>
76 typedef detail::mockup_serial_port_service service_impl_type;
91 service_impl_(io_service)
98 service_impl_.construct(impl);
101 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 104 implementation_type& other_impl)
106 service_impl_.move_construct(impl, other_impl);
116 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 121 service_impl_.destroy(impl);
125 boost::system::error_code
open(implementation_type& impl,
126 const std::string& device, boost::system::error_code& ec)
128 return service_impl_.open(impl, device, ec);
132 boost::system::error_code
assign(implementation_type& impl,
133 const native_handle_type& handle, boost::system::error_code& ec)
135 return service_impl_.assign(impl, handle, ec);
139 bool is_open(
const implementation_type& impl)
const 141 return service_impl_.is_open(impl);
145 boost::system::error_code
close(implementation_type& impl,
146 boost::system::error_code& ec)
148 return service_impl_.close(impl, ec);
152 native_type
native(implementation_type& impl)
154 return service_impl_.native_handle(impl);
160 return service_impl_.native_handle(impl);
164 boost::system::error_code
cancel(implementation_type& impl,
165 boost::system::error_code& ec)
167 return service_impl_.cancel(impl, ec);
171 template <
typename SettableSerialPortOption>
172 boost::system::error_code
set_option(implementation_type& impl,
173 const SettableSerialPortOption& option, boost::system::error_code& ec)
175 return service_impl_.set_option(impl, option, ec);
179 template <
typename GettableSerialPortOption>
180 boost::system::error_code
get_option(
const implementation_type& impl,
181 GettableSerialPortOption& option, boost::system::error_code& ec)
const 183 return service_impl_.get_option(impl, option, ec);
187 boost::system::error_code
send_break(implementation_type& impl,
188 boost::system::error_code& ec)
190 return service_impl_.send_break(impl, ec);
194 template <
typename ConstBufferSequence>
196 const ConstBufferSequence& buffers, boost::system::error_code& ec)
198 return service_impl_.write_some(impl, buffers, ec);
202 template <
typename ConstBufferSequence,
typename WriteHandler>
204 void (boost::system::error_code, std::size_t))
205 async_write_some(implementation_type& impl,
206 const ConstBufferSequence& buffers,
207 BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
209 detail::async_result_init<
210 WriteHandler, void (boost::system::error_code, std::size_t)> init(
211 BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
213 service_impl_.async_write_some(impl, buffers, init.handler);
215 return init.result.get();
219 template <
typename MutableBufferSequence>
221 const MutableBufferSequence& buffers, boost::system::error_code& ec)
223 return service_impl_.read_some(impl, buffers, ec);
227 template <
typename MutableBufferSequence,
typename ReadHandler>
229 void (boost::system::error_code, std::size_t))
230 async_read_some(implementation_type& impl,
231 const MutableBufferSequence& buffers,
232 BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
234 detail::async_result_init<
235 ReadHandler, void (boost::system::error_code, std::size_t)> init(
236 BOOST_ASIO_MOVE_CAST(ReadHandler)(handler));
238 service_impl_.async_read_some(impl, buffers, init.handler);
240 return init.result.get();
245 void shutdown_service()
247 service_impl_.shutdown_service();
251 service_impl_type service_impl_;
259 #endif // defined(BOOST_ASIO_HAS_SERIAL_PORT) 262 #endif // BOOST_ASIO_SERIAL_PORT_SERVICE_HPP boost::system::error_code open(implementation_type &impl, const std::string &device, boost::system::error_code &ec)
Open a serial port.
Definition: mockup_serial_port_service.hpp:125
native_type native(implementation_type &impl)
(Deprecated: Use native_handle().) Get the native handle implementation.
Definition: mockup_serial_port_service.hpp:152
native_handle_type native_handle(implementation_type &impl)
Get the native handle implementation.
Definition: mockup_serial_port_service.hpp:158
bool is_open(const implementation_type &impl) const
Determine whether the handle is open.
Definition: mockup_serial_port_service.hpp:139
mockup_serial_port_service : A virtual serial port allowing to write cross platform unit tests of ser...
Definition: mockup_serial_port_service.hpp:70
service_impl_type::native_handle_type native_type
(Deprecated: Use native_handle_type.) The native handle type.
Definition: mockup_serial_port_service.hpp:83
void move_construct(implementation_type &impl, implementation_type &other_impl)
Move-construct a new serial port implementation.
Definition: mockup_serial_port_service.hpp:103
mockup_serial_port_service(boost::asio::io_service &io_service)
Construct a new serial port service for the specified io_service.
Definition: mockup_serial_port_service.hpp:89
service_impl_type::implementation_type implementation_type
The type of a serial port implementation.
Definition: mockup_serial_port_service.hpp:80
void construct(implementation_type &impl)
Construct a new serial port implementation.
Definition: mockup_serial_port_service.hpp:96
boost::system::error_code cancel(implementation_type &impl, boost::system::error_code &ec)
Cancel all asynchronous operations associated with the handle.
Definition: mockup_serial_port_service.hpp:164
std::size_t read_some(implementation_type &impl, const MutableBufferSequence &buffers, boost::system::error_code &ec)
Read some data from the stream.
Definition: mockup_serial_port_service.hpp:220
service_impl_type::native_handle_type native_handle_type
The native handle type.
Definition: mockup_serial_port_service.hpp:86
boost::system::error_code get_option(const implementation_type &impl, GettableSerialPortOption &option, boost::system::error_code &ec) const
Get a serial port option.
Definition: mockup_serial_port_service.hpp:180
boost::system::error_code set_option(implementation_type &impl, const SettableSerialPortOption &option, boost::system::error_code &ec)
Set a serial port option.
Definition: mockup_serial_port_service.hpp:172
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void(boost::system::error_code, std::size_t)) async_write_some(implementation_type &impl
Start an asynchronous write.
boost::system::error_code assign(implementation_type &impl, const native_handle_type &handle, boost::system::error_code &ec)
Assign an existing native handle to a serial port.
Definition: mockup_serial_port_service.hpp:132
boost::system::error_code send_break(implementation_type &impl, boost::system::error_code &ec)
Send a break sequence to the serial port.
Definition: mockup_serial_port_service.hpp:187
boost::system::error_code close(implementation_type &impl, boost::system::error_code &ec)
Close a serial port implementation.
Definition: mockup_serial_port_service.hpp:145
std::size_t write_some(implementation_type &impl, const ConstBufferSequence &buffers, boost::system::error_code &ec)
Write the given data to the stream.
Definition: mockup_serial_port_service.hpp:195
void destroy(implementation_type &impl)
Destroy a serial port implementation.
Definition: mockup_serial_port_service.hpp:119