SatCat5
io_override.h
1 // Copyright 2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Remote-control override of an I/O device.
6 
7 #pragma once
8 
9 #include <satcat5/io_readable.h>
10 #include <satcat5/io_writeable.h>
11 #include <satcat5/polling.h>
12 
13 namespace satcat5 {
14  namespace io {
54  class Override final
57  , protected satcat5::io::EventListener
58  , protected satcat5::poll::Timer
59  {
60  public:
65  Override(
68  satcat5::io::CopyMode mode = CopyMode::PACKET);
69  ~Override() SATCAT5_OPTIONAL_DTOR;
70 
72  void set_callback(satcat5::io::EventListener* callback) override
74 
76  inline bool is_remote() const
77  { return m_remote; }
78 
80  void set_override(bool remote);
81 
84 
87  void set_timeout(unsigned msec);
88 
89  protected:
90  // Event handlers.
91  void data_rcvd(satcat5::io::Readable* src) override;
92  void data_unlink(satcat5::io::Readable* src) override;
93  void timer_event() override;
94  void watchdog_reset();
95 
96  // Internal state
97  satcat5::io::Readable *m_dev_rd, *m_ovr_rd;
98  satcat5::io::Writeable *m_dev_wr, *m_ovr_wr;
99  const satcat5::io::CopyMode m_mode;
100  bool m_remote;
101  unsigned m_timeout;
102  };
103  }
104 }
Event-handler interface for newly received data.
Definition: io_readable.h:43
Remote-control override of an I/O device.
Definition: io_override.h:59
void set_remote(satcat5::io::Writeable *tx, satcat5::io::Readable *rx)
Attach the remote-control interface.
Definition: io_override.cc:45
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
Definition: io_override.cc:62
void timer_event() override
Child class MUST override this method.
Definition: io_override.cc:81
void set_callback(satcat5::io::EventListener *callback) override
Override set_callback() to set the internal variable only.
Definition: io_override.h:72
void set_override(bool remote)
Manually set local or remote mode.
Definition: io_override.cc:34
Override(satcat5::io::Writeable *dst, satcat5::io::Readable *src, satcat5::io::CopyMode mode=CopyMode::PACKET)
Attach to the underlying I/O device.
Definition: io_override.cc:13
bool is_remote() const
Is this block in local or remote mode?
Definition: io_override.h:76
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
Definition: io_override.cc:76
void set_timeout(unsigned msec)
Set timeout for automatic return to local mode.
Definition: io_override.cc:56
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
virtual void set_callback(satcat5::io::EventListener *callback)
Update registered callback for data_rcvd() events.
Definition: io_readable.cc:39
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
Timer objects are polled after a fixed delay or at a regular interval.
Definition: polling.h:213
"Readable" I/O interface core definitions
CopyMode
Specify read and write behavior for Readable::copy_and_finalize().
Definition: io_readable.h:23
"Writeable" I/O interface core definitions
Core event-processing loop for SatCat5 software.