19 #if defined(__GNUC__) || defined(__clang__)
20 #pragma GCC diagnostic ignored "-Wsign-conversion"
21 #pragma GCC diagnostic ignored "-Wconversion"
24 #include <boost/asio/executor_work_guard.hpp>
25 #include <boost/asio/io_context.hpp>
39 std::shared_ptr<interface::Channel>
channel;
61 explicit Impl(std::shared_ptr<interface::Channel> ch) :
channel(std::move(ch)) {}
74 return p.get_future();
88 boost::asio::executor_work_guard<boost::asio::io_context::executor_type> guard(ioc->get_executor());
160 : impl_(std::make_unique<
Impl>(cfg, ioc)) {}
161 Udp::Udp(std::shared_ptr<interface::Channel> ch) : impl_(std::make_unique<
Impl>(ch)) {
162 impl_->setup_internal_handlers();
167 Udp&
Udp::operator=(
Udp&&) noexcept = default;
169 std::future<
bool>
Udp::start() {
return impl_->
start(); }
181 impl_->data_handler = std::move(h);
185 impl_->connect_handler = std::move(h);
189 impl_->disconnect_handler = std::move(h);
193 impl_->error_handler = std::move(h);
198 impl_->auto_manage = m;
199 if (impl_->auto_manage && !impl_->started)
start();
static std::shared_ptr< interface::Channel > create(const ChannelOptions &options, std::shared_ptr< boost::asio::io_context > external_ioc=nullptr)
A C++17 compatible span-like class for safe array access.
constexpr size_type size() const noexcept
constexpr pointer data() const noexcept
Common interface for 1:1 point-to-point communication (e.g., TcpClient, Serial, Udp)
std::function< void(const ErrorContext &)> ErrorHandler
std::function< void(const MessageContext &)> MessageHandler
std::function< void(const ConnectionContext &)> ConnectionHandler
void set_manage_external_context(bool manage)
ChannelInterface & on_disconnect(ConnectionHandler handler) override
ChannelInterface & auto_manage(bool manage=true) override
std::future< bool > start() override
void send_line(std::string_view line) override
void send(std::string_view data) override
bool is_connected() const override
Udp(const config::UdpConfig &cfg)
ChannelInterface & on_error(ErrorHandler handler) override
ChannelInterface & on_data(MessageHandler handler) override
ChannelInterface & on_connect(ConnectionHandler handler) override
std::string uint8_to_string(const uint8_t *data, size_t size)
Safely convert uint8_t* to const char* for string operations.
std::pair< const uint8_t *, size_t > string_to_bytes(std::string_view str)
Safely obtain a view of std::string as byte array without allocation.
wrapper::ConnectionContext ConnectionContext
wrapper::ErrorContext ErrorContext
wrapper::MessageContext MessageContext
bool use_external_context
std::shared_ptr< boost::asio::io_context > external_ioc
ErrorHandler error_handler
void setup_internal_handlers()
std::shared_ptr< interface::Channel > channel
bool start_promise_fulfilled_
std::thread external_thread
ConnectionHandler connect_handler
bool manage_external_context
Impl(const config::UdpConfig &config)
Impl(const config::UdpConfig &config, std::shared_ptr< boost::asio::io_context > ioc)
ConnectionHandler disconnect_handler
std::promise< bool > start_promise_
std::future< bool > start()
Impl(std::shared_ptr< interface::Channel > ch)
MessageHandler data_handler