#include <router.h>
Public Member Functions | |
Router (pw::channel::ByteReaderWriter &io_channel, ByteSpan decode_buffer) | |
Router (const Router &)=delete | |
Router & | operator= (const Router &)=delete |
Router (Router &&)=delete | |
Router & | operator= (Router &&)=delete |
Status | AddChannel (pw::channel::DatagramReaderWriter &channel, uint64_t receive_address, uint64_t send_address) |
Status | RemoveChannel (pw::channel::DatagramReaderWriter &channel, uint64_t receive_address, uint64_t send_address) |
pw::async2::Poll | Pend (pw::async2::Context &cx) |
pw::async2::Poll | PendClose (pw::async2::Context &cx) |
Closes all underlying channels, attempting to flush any data. | |
A router that multiplexes multiple datagram-oriented Channel
s over a single byte-oriented Channel
using HDLC framing.
|
inline |
Constructs a Router
[in] | io_channel | The channel on which to send and receive encoded HDLC packets. |
[in] | decode_buffer | The memory to use for storing partially-decoded HDLC frames. This buffer should be at least Decoder::RequiredBufferSizeForFrameSize(frame_size) bytes in order to ensure that HDLC frames of size frame_size can be successfully decoded. |
Status pw::hdlc::Router::AddChannel | ( | pw::channel::DatagramReaderWriter & | channel, |
uint64_t | receive_address, | ||
uint64_t | send_address | ||
) |
Registers a Channel
tied to the provided addresses.
All incoming HDLC messages received on io_channel
with HDLC address receive_address
will be decoded and routed to the provided channel
.
Data read from channel
will be HDLC-encoded and sent to io_channel
.
Note that a non-writeable channel will exert backpressure on the entire router, so channels should strive to consume or discard incoming data as quickly as possible in order to prevent starvation of other channels.
[in] | receive_address | Incoming HDLC messages received on the external io_channel with an address matching receive_address will be decoded and written to channel . |
[in] | send_address | Data read from channel will be written to io_channel with the HDLC address send_address . |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: ``Channel`` was successfully registered. * * ALREADY_EXISTS: A registration already exists for either * ``channel``, ``receive_address``, or ``send_address``. Channels may * not be registered with multiple addresses, nor may addresses be * used with multiple channels. * *
pw::async2::Poll pw::hdlc::Router::Pend | ( | pw::async2::Context & | cx | ) |
Progress the router as far as possible, waking the provided cx
when more progress can be made.
This will only return Ready
if io_channel
has been observed as closed, after which all messages have been flushed to the remaining channels and the channels have been closed.
Status pw::hdlc::Router::RemoveChannel | ( | pw::channel::DatagramReaderWriter & | channel, |
uint64_t | receive_address, | ||
uint64_t | send_address | ||
) |
Removes a previously registered Channel
tied to the provided addresses.
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The channel was successfully deregistered. * * NOT_FOUND: A registration of the channel for the provided * addresses was not found. * *