|
SatCat5
|
Callback object that prints incoming messages.
Given an eth::ChatProto object, this object receives ChatProto messages and prints them to the console. It can also send chat messages, either using the send_message method (for text) or the io::Writeable API (for binary data). This class is used inside "test/log_viewer" and other example applications.
Definition at line 26 of file chat_printer.h.
#include <chat_printer.h>
Public Member Functions | |
| ChatPrinter (satcat5::eth::ChatProto *chat, bool loopback=true) | |
| Attach to the designated ChatProto service. More... | |
| void | send_message (const std::string &msg) |
| Send a message string to all other chat clients. | |
| void | write_u8 (u8 data) |
| One of many functions for writing integer/floating point values, see details. More... | |
| virtual void | write_bytes (unsigned nbytes, const void *src) |
| Write 0 or more bytes from a buffer. More... | |
| void | write_str (const char *str) |
| Write the contents of a null-terminated string. More... | |
| virtual void | write_abort () |
| If possible, abort the current partially-written packet. More... | |
| template<class T > | |
| void | write_obj (const T &obj) |
Templated wrapper for any object with the following method: void write_to(satcat5::io::Writeable* wr) const; | |
Protected Member Functions | |
| virtual void | write_overflow () |
| Optional error handling for write overflow. More... | |
Protected Attributes | |
| satcat5::net::Type | m_filter |
| Incoming packet filter. | |
| friend | LimitedWrite |
| friend | WriteableBroadcast |
| friend | WriteableRedirect |
Private Member Functions | |
| void | print_message (const satcat5::eth::MacAddr &from, const std::string &msg) |
| Pretty formatting for incoming or outgoing messages. | |
| void | frame_rcvd (satcat5::io::LimitedRead &rd) override |
| Handle incoming data from eth::ChatProto. | |
| unsigned | get_write_space () const override |
| Writeable endpoint: Accumulate characters from input stream. More... | |
| void | write_next (u8 ch) |
| Writeable endpoint: Accumulate characters from input stream. More... | |
| bool | write_finalize () override |
| Writeable endpoint: Accumulate characters from input stream. More... | |
Private Attributes | |
| satcat5::eth::ChatProto *const | m_chat |
| std::string | m_line |
| bool | m_loopback |
| satcat5::net::Protocol * | m_next |
| Linked list of Protocols. | |
| ChatPrinter::ChatPrinter | ( | satcat5::eth::ChatProto * | chat, |
| bool | loopback = true |
||
| ) |
Attach to the designated ChatProto service.
| chat | Chat protocol object (required). |
| loopback | If enabled, print messages from self. |
Definition at line 17 of file chat_printer.cc.
|
overrideprivatevirtual |
Writeable endpoint: Accumulate characters from input stream.
End-of-packet sends accumulated message to the chat client.
Implements satcat5::io::Writeable.
Definition at line 66 of file chat_printer.cc.
|
virtualinherited |
If possible, abort the current partially-written packet.
Child objects of io::Writeable SHOULD override this method if it is practical to prevent in-progress data from being relayed downstream.
Reimplemented in satcat5::port::Mailmap, satcat5::io::PacketBuffer, satcat5::io::MultiWriter, satcat5::io::WriteableRedirect, satcat5::io::ArrayWrite, satcat5::io::CounterInline, satcat5::io::ChecksumRxCommon, satcat5::io::ChecksumTxCommon, satcat5::io::WriteableBroadcast, satcat5::eth::SwitchPort, satcat5::io::HdlcEncoder::ByteStuff, and satcat5::io::FileWriter.
Definition at line 186 of file io_writeable.cc.
|
virtualinherited |
Write 0 or more bytes from a buffer.
Child objects of io::Writeable MAY override write_bytes as needed for performance.
Reimplemented in satcat5::port::MailmapAligned, satcat5::port::Mailmap, satcat5::io::PacketBuffer, satcat5::io::MultiWriter, satcat5::io::MultiPacket::Overwriter, satcat5::io::NullWrite, satcat5::io::WriteableRedirect, satcat5::io::LimitedWrite, satcat5::io::CounterInline, satcat5::io::WriteableBroadcast, and satcat5::io::FileWriter.
Definition at line 170 of file io_writeable.cc.
|
overrideprivatevirtual |
Writeable endpoint: Accumulate characters from input stream.
End-of-packet sends accumulated message to the chat client.
Reimplemented from satcat5::io::Writeable.
Definition at line 55 of file chat_printer.cc.
|
privatevirtual |
Writeable endpoint: Accumulate characters from input stream.
End-of-packet sends accumulated message to the chat client.
Implements satcat5::io::Writeable.
Definition at line 72 of file chat_printer.cc.
|
protectedvirtualinherited |
Optional error handling for write overflow.
Child objects of io::Writeable MAY override this method for error handling.
Reimplemented in satcat5::port::Mailmap, satcat5::io::PacketBuffer, satcat5::io::MultiWriter, satcat5::io::WriteableRedirect, satcat5::io::ArrayWrite, satcat5::io::ChecksumTxCommon, satcat5::io::WriteableBroadcast, satcat5::io::SlipDecoder, satcat5::io::SlipEncoder, satcat5::io::HdlcDecoder, satcat5::io::CobsDecoder, and satcat5::io::CobsEncoder.
Definition at line 187 of file io_writeable.cc.
|
inherited |
Write the contents of a null-terminated string.
Note: Null-termination is not copied to the output.
Definition at line 180 of file io_writeable.cc.
|
inherited |
One of many functions for writing 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 20 of file io_writeable.cc.