SatCat5
io_broadcast.h
Go to the documentation of this file.
1 // Copyright 2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
17 
18 #pragma once
19 
20 #include <satcat5/io_writeable.h>
21 #include <satcat5/types.h>
22 
23 namespace satcat5 {
24  namespace io {
36  public:
38  unsigned get_write_space() const override;
39 
41  void write_abort() override;
42 
44  void write_bytes(unsigned nbytes, const void* src) override;
45 
48  bool write_finalize() override;
49 
51  Writeable*& operator[](unsigned idx)
52  { return m_dsts[idx]; }
53 
55  void port_set(unsigned idx, Writeable* dst)
56  { if (idx < m_size) { m_dsts[idx] = dst; } }
57 
59  inline unsigned len() const
60  { return m_size; }
61 
62  protected:
65  constexpr WriteableBroadcast(unsigned n_dsts,
67  : m_size(n_dsts), m_dsts(dsts) {}
68  ~WriteableBroadcast() {}
69  void write_next(u8 data) override;
70  void write_overflow() override;
71 
72  // Member variables.
73  const unsigned m_size;
75  };
76 
83  public:
85  unsigned get_write_space() const override;
86 
89  bool write_finalize() override;
90 
91  protected:
92  constexpr WriteableBroadcastAny(unsigned n_dsts,
94  : WriteableBroadcast(n_dsts, dsts) {}
95  };
96 
98  template <unsigned SIZE>
101  public:
103  : WriteableBroadcast(SIZE, m_dst_array), m_dst_array{0} {}
104  private:
105  satcat5::io::Writeable* m_dst_array[SIZE];
106  };
107 
109  template <unsigned SIZE>
112  public:
114  : WriteableBroadcastAny(SIZE, m_dst_array), m_dst_array{0} {}
115  private:
116  satcat5::io::Writeable* m_dst_array[SIZE];
117  };
118  }
119 }
Version of io::WriteableBroadcast that considers a write successful if ANY of the downstream Writeabl...
Definition: io_broadcast.h:82
bool write_finalize() override
Finalize the in-progress write for all downstream Writeables.
Definition: io_broadcast.cc:75
unsigned get_write_space() const override
Get the max available write space of any downstream Writeable.
Definition: io_broadcast.cc:66
Statically-allocated version of io::WriteableBroadcastAny.
Definition: io_broadcast.h:111
Forwards incoming writes to multiple downstream Writeables.
Definition: io_broadcast.h:35
void port_set(unsigned idx, Writeable *dst)
Designate the Nth downstream Writeable object.
Definition: io_broadcast.h:55
void write_bytes(unsigned nbytes, const void *src) override
Write a byte sequence to all downstream Writeables.
Definition: io_broadcast.cc:32
satcat5::io::Writeable **const m_dsts
Array of Writeables.
Definition: io_broadcast.h:74
const unsigned m_size
Size of m_dsts.
Definition: io_broadcast.h:73
void write_abort() override
Abort writes for all downstream Writeables.
Definition: io_broadcast.cc:25
bool write_finalize() override
Finalize the in-progress write for all downstream Writeables.
Definition: io_broadcast.cc:43
void write_overflow() override
Optional error handling for write overflow.
Definition: io_broadcast.cc:59
constexpr WriteableBroadcast(unsigned n_dsts, satcat5::io::Writeable **dsts)
Constructor takes a pointer to an array of io::Writeable pointers along with the length of the given ...
Definition: io_broadcast.h:65
unsigned len() const
Length of the output array.
Definition: io_broadcast.h:59
unsigned get_write_space() const override
Get the min available write space of downstream Writeables.
Definition: io_broadcast.cc:16
Writeable *& operator[](unsigned idx)
Access or assign the Nth downstream Writeable object.
Definition: io_broadcast.h:51
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
Definition: io_broadcast.cc:52
Statically-allocated version of io::WriteableBroadcast.
Definition: io_broadcast.h:100
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
"Writeable" I/O interface core definitions
Basic type aliases and prototypes used throughout SatCat5.