Pigweed
 
Loading...
Searching...
No Matches
pw::hdlc::Router Class Referencefinal

#include <router.h>

Public Member Functions

 Router (pw::channel::ByteReaderWriter &io_channel, ByteSpan decode_buffer)
 
 Router (const Router &)=delete
 
Routeroperator= (const Router &)=delete
 
 Router (Router &&)=delete
 
Routeroperator= (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.
 

Detailed Description

A router that multiplexes multiple datagram-oriented Channel s over a single byte-oriented Channel using HDLC framing.

Constructor & Destructor Documentation

◆ Router()

pw::hdlc::Router::Router ( pw::channel::ByteReaderWriter io_channel,
ByteSpan  decode_buffer 
)
inline

Constructs a Router

Parameters
[in]io_channelThe channel on which to send and receive encoded HDLC packets.
[in]decode_bufferThe 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.

Member Function Documentation

◆ AddChannel()

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.

Parameters
[in]receive_addressIncoming HDLC messages received on the external io_channel with an address matching receive_address will be decoded and written to channel.
[in]send_addressData read from channel will be written to io_channel with the HDLC address send_address.
Returns
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.
* 
*  

◆ Pend()

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.

◆ RemoveChannel()

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.

Returns
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.
* 
*  

The documentation for this class was generated from the following file: