File indexing completed on 2026-08-17 08:39:20
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_COBALT_IO_SERIAL_PORT_HPP
0009 #define BOOST_COBALT_IO_SERIAL_PORT_HPP
0010
0011 #include <boost/cobalt/io/detail/config.hpp>
0012 #include <boost/cobalt/op.hpp>
0013 #include <boost/cobalt/io/ops.hpp>
0014 #include <boost/cobalt/io/buffer.hpp>
0015 #include <boost/cobalt/io/stream.hpp>
0016
0017 #include <boost/asio/basic_serial_port.hpp>
0018 #include <boost/core/detail/string_view.hpp>
0019 #include <boost/system/result.hpp>
0020
0021 namespace boost::cobalt::io
0022 {
0023
0024
0025 struct BOOST_SYMBOL_VISIBLE serial_port final : stream
0026 {
0027 BOOST_COBALT_IO_DECL system::result<void> close();
0028 BOOST_COBALT_IO_DECL system::result<void> cancel();
0029 BOOST_COBALT_IO_DECL bool is_open() const;
0030
0031 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> send_break();
0032
0033 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> set_baud_rate(unsigned rate);
0034 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<unsigned> get_baud_rate();
0035
0036 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> set_character_size(unsigned rate);
0037 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<unsigned> get_character_size();
0038
0039 using flow_control = asio::serial_port_base::flow_control::type;
0040
0041 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> set_flow_control(flow_control rate);
0042 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<flow_control> get_flow_control();
0043
0044 using parity = asio::serial_port_base::parity::type;
0045
0046 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> set_parity(parity rate);
0047 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<parity> get_parity();
0048
0049 using native_handle_type = typename asio::basic_serial_port<executor>::native_handle_type;
0050 native_handle_type native_handle() {return serial_port_.native_handle();}
0051
0052 BOOST_COBALT_IO_DECL serial_port(const cobalt::executor & executor = this_thread::get_executor());
0053 BOOST_COBALT_IO_DECL serial_port(serial_port && lhs) = default;
0054 BOOST_COBALT_IO_DECL serial_port(std::string_view device, const cobalt::executor & executor = this_thread::get_executor());
0055 BOOST_COBALT_IO_DECL serial_port(native_handle_type native_handle, const cobalt::executor & executor = this_thread::get_executor());
0056
0057 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> assign(native_handle_type native_handle);
0058
0059 [[nodiscard]] BOOST_COBALT_IO_DECL system::result<void> open(std::string_view device);
0060
0061 [[nodiscard]] write_op write_some(const_buffer_sequence buffer)
0062 {
0063 return {buffer, this, initiate_write_some_};
0064 }
0065 [[nodiscard]] read_op read_some(mutable_buffer_sequence buffer)
0066 {
0067 return {buffer, this, initiate_read_some_};
0068 }
0069 private:
0070 BOOST_COBALT_IO_DECL static void initiate_read_some_(void *, mutable_buffer_sequence, boost::cobalt::completion_handler<system::error_code, std::size_t>);
0071 BOOST_COBALT_IO_DECL static void initiate_write_some_(void *, const_buffer_sequence, boost::cobalt::completion_handler<system::error_code, std::size_t>);
0072
0073 asio::basic_serial_port<executor> serial_port_;
0074 };
0075
0076
0077 }
0078
0079 #endif