SatCat5
io_buffer.h
Go to the documentation of this file.
1 // Copyright 2021-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
11 
12 #pragma once
13 
14 #include <satcat5/io_core.h>
15 #include <satcat5/pkt_buffer.h>
16 #include <satcat5/timeref.h>
17 
18 namespace satcat5 {
19  namespace io {
26  //
38  class BufferedIO
41  , protected satcat5::io::EventListener
42  {
43  protected:
48  BufferedIO(
49  u8* txbuff, unsigned txbytes, unsigned txpkt,
50  u8* rxbuff, unsigned rxbytes, unsigned rxpkt);
51  ~BufferedIO() {}
52 
53  // Child MUST implement the following inherited methods:
54  // void data_rcvd(satcat5::io::Readable* src) override;
55 
58 
61  };
62 
66  class BufferedCopy final
68  {
69  public:
80  satcat5::io::CopyMode mode = CopyMode::PACKET);
81  ~BufferedCopy() SATCAT5_OPTIONAL_DTOR;
82 
86  { return m_dst; }
88  { return m_src; }
90 
91  protected:
92  void data_rcvd(satcat5::io::Readable* src) override;
93  void data_unlink(satcat5::io::Readable* src) override;
94 
95  satcat5::io::Readable* m_src;
96  satcat5::io::Writeable* const m_dst;
97  satcat5::io::CopyMode m_mode;
98  };
99 
124  class BufferedStream final
126  {
127  public:
133  unsigned max_chunk = 512,
134  unsigned min_txnow = UINT_MAX);
135  ~BufferedStream() SATCAT5_OPTIONAL_DTOR;
136 
139  inline void set_timeout(unsigned msec)
140  { m_timeout_msec = msec; }
141 
142  protected:
143  // Required event handlers.
144  void data_rcvd(satcat5::io::Readable* src) override;
145  void data_unlink(satcat5::io::Readable* src) override;
146 
147  // Member variables.
148  satcat5::io::Readable* m_src;
149  satcat5::net::Address* const m_dst;
150  const unsigned m_max_chunk;
151  const unsigned m_min_txnow;
152  unsigned m_timeout_msec;
153  satcat5::util::TimeVal m_tref;
154  };
155 
161  class BufferedPackets final
163  {
164  public:
169  satcat5::net::Address* dst);
170  ~BufferedPackets() SATCAT5_OPTIONAL_DTOR;
171 
172  protected:
173  // Required event handlers.
174  void data_rcvd(satcat5::io::Readable* src) override;
175  void data_unlink(satcat5::io::Readable* src) override;
176 
177  // Member variables.
178  satcat5::io::Readable* m_src;
179  satcat5::net::Address* const m_dst;
180  };
181 
187  {
188  public:
191  u8* txbuff, unsigned txbytes, unsigned txpkt);
192 
193  protected:
196  };
197  }
198 }
BufferedCopy copies from any Readable source to any Writeable sink.
Definition: io_buffer.h:68
BufferedCopy(satcat5::io::Readable *src, satcat5::io::Writeable *dst, satcat5::io::CopyMode mode=CopyMode::PACKET)
Create an object that copies data from src to dst.
Definition: io_buffer.cc:28
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
Definition: io_buffer.cc:49
satcat5::io::Readable * src()
Other accessors.
Definition: io_buffer.h:87
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
Definition: io_buffer.cc:45
satcat5::io::Writeable * dst()
Other accessors.
Definition: io_buffer.h:85
Extensible transmit and receive buffer.
Definition: io_buffer.h:42
BufferedIO(u8 *txbuff, unsigned txbytes, unsigned txpkt, u8 *rxbuff, unsigned rxbytes, unsigned rxpkt)
Child provides Tx and Rx working buffers.
Definition: io_buffer.cc:16
satcat5::io::PacketBuffer m_tx
Transmit data (user writes, child reads)
Definition: io_buffer.h:57
satcat5::io::PacketBuffer m_rx
Receive data (user reads, child writes)
Definition: io_buffer.h:60
Copy packets from a Readable source to a network address.
Definition: io_buffer.h:163
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
Definition: io_buffer.cc:116
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
Definition: io_buffer.cc:125
BufferedPackets(satcat5::io::Readable *src, satcat5::net::Address *dst)
Set source, destination, APID, and chunk-size.
Definition: io_buffer.cc:101
Copy bytes from a Readable source to a network address.
Definition: io_buffer.h:126
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
Definition: io_buffer.cc:99
BufferedStream(satcat5::io::Readable *src, satcat5::net::Address *dst, unsigned max_chunk=512, unsigned min_txnow=UINT_MAX)
Set source, destination, APID, and chunk-size.
Definition: io_buffer.cc:51
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
Definition: io_buffer.cc:72
void set_timeout(unsigned msec)
Set packetization timeout, in milliseconds.
Definition: io_buffer.h:139
BufferedWriter adds an inline buffer to any Writeable interface.
Definition: io_buffer.h:187
Event-handler interface for newly received data.
Definition: io_readable.h:43
The PacketBuffer class is a wrapper for a circular buffer, with optional logic to support retention o...
Definition: pkt_buffer.h:66
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Wrapper class for forwarding reads to another object.
Definition: io_readable.h:299
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Wrapper class for forwarding writes to another object.
Definition: io_writeable.h:218
Defines a generic API for sending data to a specific destination, such as a MAC address,...
Definition: net_address.h:30
I/O interface core definitions.
CopyMode
Specify read and write behavior for Readable::copy_and_finalize().
Definition: io_readable.h:23
Timestamp for measuring elapsed time.
Definition: timeref.h:48
TimeRef and TimeVal define the API for monotonic timers.