|
SatCat5
|
A variant of MultiReader with a simple first-in, first-out queue.
Definition at line 336 of file multi_buffer.h.
#include <multi_buffer.h>
Public Member Functions | |
| MultiReaderSimple (satcat5::io::MultiBuffer *src) | |
| Create this port and link it to the source buffer. | |
| bool | can_accept () const |
| Can this object accept new packets? Required for testing. | |
| virtual bool | accept (satcat5::io::MultiPacket *packet) |
| Accept a packet from the source buffer? Default accepts all packets unless this port is disabled or full. More... | |
| void | flush () |
| Discard all queued packets. | |
| bool | get_port_enable () const |
| Is this port currently enabled? More... | |
| void | set_port_enable (bool enable) |
| Enable or disable this port. More... | |
| void | set_timeout (unsigned timeout_msec) |
| Update the watchdog timeout. More... | |
| void | read_finalize () override |
| Consume any remaining bytes in this frame, if applicable. More... | |
| satcat5::io::MultiPacket * | get_packet () const |
| Get a pointer to the current packet, if active. | |
| void | read_reset (const satcat5::io::MultiPacket *pkt) |
| Reset read state for the designated packet. | |
| unsigned | get_read_ready () const override |
| How many bytes can be read without blocking? More... | |
| bool | read_bytes (unsigned nbytes, void *dst) override |
| Read 0 or more bytes into a buffer. More... | |
| bool | read_consume (unsigned nbytes) override |
| Read and discard 0 or more bytes. More... | |
| virtual void | set_callback (satcat5::io::EventListener *callback) |
| Update registered callback for data_rcvd() events. More... | |
| u8 | read_u8 () |
| One of many functions for reading integer/floating point values, see details. More... | |
| unsigned | read_str (unsigned dst_size, char *dst) |
| Safely read a null-terminated input string. More... | |
| template<class T > | |
| bool | read_obj (T &t) |
Templated wrapper for any object with the following method: bool read_from(satcat5::io::Readable* rd); | |
| unsigned | copy_to (satcat5::io::Writeable *dst) |
| Copy data to a Writeable object, without finalizing. More... | |
| bool | copy_and_finalize (satcat5::io::Writeable *dst, satcat5::io::CopyMode mode=CopyMode::PACKET) |
| Copy data to a Writeable object, then finalize. More... | |
| void | request_poll () |
| Call this method to request polling at a later time. More... | |
| void | request_cancel () |
| Call this method to cancel a previous request_poll(). | |
| void | timer_once (unsigned msec) |
| Configure a one-time notification after X milliseconds. | |
| void | timer_every (unsigned msec) |
| Configure a repeating notification every X milliseconds. | |
| void | timer_stop () |
| Stop all future notifications. | |
| unsigned | timer_interval () const |
| Accessor for recurring timer interval, if one is set. | |
| unsigned | timer_remaining () const |
| Accessor for time to next event, if one is set. | |
Static Public Member Functions | |
| static unsigned | count_ondemand () |
| Count queued objects of this type (i.e., non-idle). | |
| static unsigned | count_timer () |
| Count all objects of this type, including idle timers. | |
Protected Member Functions | |
| void | pkt_init (satcat5::io::MultiPacket *packet) |
| Helper function for starting a new packet, or NULL to stop. | |
| void | pkt_free (satcat5::io::MultiPacket *packet) |
| Decrement reference count, free when it reaches zero. | |
| void | timer_event () override |
| Timeouts help prevent resource-hogging. | |
| u8 | read_next () override |
| Read the next byte from the underlying buffer or device. More... | |
| void | read_notify () |
Attempt notification by calling m_callback->data_rcvd(). More... | |
| virtual void | read_underflow () |
| Optional error handling for read underflow. More... | |
| bool | pkt_push (satcat5::io::MultiPacket *pkt) override |
| Implement the push() and pop() methods. | |
| satcat5::io::MultiPacket * | pkt_pop () override |
| Implement the push() and pop() methods. | |
Protected Attributes | |
| satcat5::io::MultiBuffer *const | m_src |
| Pointer to the source buffer. | |
| satcat5::io::MultiReader * | m_next |
| bool | m_port_enable |
| Internal state. | |
| unsigned | m_read_timeout |
| Internal state. | |
Private Member Functions | |
| void | poll_demand () |
| Event handler for on-demand polling. | |
| void | query (unsigned elapsed_msec) |
Private Attributes | |
| satcat5::io::EventListener * | m_callback |
| Pointer to the callback object, or NULL. More... | |
| bool | m_idle |
| unsigned | m_trem |
| unsigned | m_tnext |
| unsigned | m_queue_rdidx |
| Queue based on a circular buffer. More... | |
| unsigned | m_queue_count |
| Queue based on a circular buffer. More... | |
| satcat5::io::MultiPacket * | m_queue [SATCAT5_MBUFF_RXPKT] |
| Queue based on a circular buffer. More... | |
| unsigned | m_read_pos |
| Current read state. | |
| unsigned | m_read_rem |
| Current read state. | |
| const satcat5::io::MultiPacket * | m_read_pkt |
| Current read state. | |
| satcat5::io::MultiChunk * | m_read_chunk |
| Current read state. | |
|
virtualinherited |
Accept a packet from the source buffer? Default accepts all packets unless this port is disabled or full.
Child classes MAY override this method to adjust this policy, apply filters, or to implement an additional pre-buffer. Child classes that accept(...) a packet MUST eventually call either pkt_push(...) or pkt_free(...) to avoid memory leaks.
Note: This method SHOULD only be called from MultiBuffer or its children. This method is public only for to allow flexibility in mutual "friend" inheritance rules.
Definition at line 274 of file multi_buffer.cc.
|
inherited |
Copy data to a Writeable object, then finalize.
As copy_to(), but also calls read_finalize() and/or write_finalize() depending on the input/output mode.
In packet mode (the default), call both read_finalize() and write_finalize() if the operation copies all available data. Use this mode whenever the input is packetized.
In byte-stream mode, call write_finalize() if the operation copies any data, but never call read_finalize(). Use this mode for inputs that do not delimit packet boundaries.
| dst | The destination object. |
| mode | Select packet mode or stream mode. |
Definition at line 234 of file io_readable.cc.
|
inherited |
Copy data to a Writeable object, without finalizing.
Copy the contents of this Readable to a Writeable object, stopping at end-of-input, end-of-frame, or the capacity of the destination buffer (whichever comes first). This method does not call read_finalize or write_finalize(). To automatically make finalize calls,
Definition at line 214 of file io_readable.cc.
|
inlineinherited |
Is this port currently enabled?
Definition at line 278 of file multi_buffer.h.
|
overridevirtualinherited |
How many bytes can be read without blocking?
Child objects of io::Readable MUST override this method.
Implements satcat5::io::Readable.
Definition at line 63 of file multi_buffer.cc.
|
overridevirtualinherited |
Read 0 or more bytes into a buffer.
Child objects of io::Readable MAY override this method for improved performance.
Reimplemented from satcat5::io::Readable.
Definition at line 68 of file multi_buffer.cc.
|
overridevirtualinherited |
Read and discard 0 or more bytes.
Child objects of io::Readable MAY override this method for improved performance.
Reimplemented from satcat5::io::Readable.
Definition at line 88 of file multi_buffer.cc.
|
overridevirtualinherited |
Consume any remaining bytes in this frame, if applicable.
Child objects of io::Readable SHOULD override this method if they support framing.
Reimplemented from satcat5::io::MultiPacket::Reader.
Definition at line 290 of file multi_buffer.cc.
|
overrideprotectedvirtualinherited |
Read the next byte from the underlying buffer or device.
Child objects of io::Readable MUST override this method.
Implements satcat5::io::Readable.
Definition at line 96 of file multi_buffer.cc.
|
protectedinherited |
Attempt notification by calling m_callback->data_rcvd().
Child objects of io::Readable MAY call this to override default notifications.
Definition at line 254 of file io_readable.cc.
|
inherited |
Safely read a null-terminated input string.
The input is always consumed up to the end-of-input or the first zero byte, whichever comes first.
Definition at line 179 of file io_readable.cc.
|
inherited |
One of many functions for reading integer/floating point values, see details.
Several functions are provided for reading and writing scalar types to/from io::Readable and io::Writeable instances. Since there are many of these that are frequently inherited, they are hidden from documentation. These functions follow a shared template:
read_ or write_ prefix.u for unsigned, s for signed, f for floating-point.l suffix if little-endian, no suffix if big-endian.Example: write_s48l is "Write 48 bits (6 bytes) to this
io::Writeable as a signed value in little-endian order".
Definition at line 44 of file io_readable.cc.
|
protectedvirtualinherited |
Optional error handling for read underflow.
Child objects of io::Readable MAY override this method.
Reimplemented in satcat5::port::Mailmap, and satcat5::io::ReadableRedirect.
Definition at line 271 of file io_readable.cc.
|
inherited |
Call this method to request polling at a later time.
Safe to stack requests, but only one call to poll().
Definition at line 208 of file polling.cc.
|
virtualinherited |
Update registered callback for data_rcvd() events.
Child objects of io::Readable SHOULD usually leave this method as-is.
Reimplemented in satcat5::io::ReadableRedirect, satcat5::io::Override, satcat5::io::MuxPort, and satcat5::test::EthernetInterface.
Definition at line 39 of file io_readable.cc.
|
inlineinherited |
Enable or disable this port.
Disabled ports reject all incoming packets.
Definition at line 283 of file multi_buffer.h.
|
inlineinherited |
Update the watchdog timeout.
The watchdog is reset each time a byte is read; if data is available, but nothing is is read, then the Reader discards everything in the queue.
Definition at line 290 of file multi_buffer.h.
|
privateinherited |
Pointer to the callback object, or NULL.
This can only be modified through the set_callback(...) method.
Definition at line 199 of file io_readable.h.
|
private |
Queue based on a circular buffer.
This has O(1) push and O(1) pop.
Definition at line 359 of file multi_buffer.h.
|
private |
Queue based on a circular buffer.
This has O(1) push and O(1) pop.
Definition at line 358 of file multi_buffer.h.
|
private |
Queue based on a circular buffer.
This has O(1) push and O(1) pop.
Definition at line 357 of file multi_buffer.h.