SatCat5
satcat5::util::ChatPrinter Class Referencefinal

Detailed Description

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>

Inheritance diagram for satcat5::util::ChatPrinter:
[legend]
Collaboration diagram for satcat5::util::ChatPrinter:
[legend]

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::Protocolm_next
 Linked list of Protocols.
 

Constructor & Destructor Documentation

◆ ChatPrinter()

ChatPrinter::ChatPrinter ( satcat5::eth::ChatProto chat,
bool  loopback = true 
)

Attach to the designated ChatProto service.

Parameters
chatChat protocol object (required).
loopbackIf enabled, print messages from self.

Definition at line 17 of file chat_printer.cc.

Member Function Documentation

◆ get_write_space()

unsigned ChatPrinter::get_write_space ( ) const
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.

◆ write_abort()

void Writeable::write_abort ( )
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.

◆ write_bytes()

void Writeable::write_bytes ( unsigned  nbytes,
const void *  src 
)
virtualinherited

◆ write_finalize()

bool ChatPrinter::write_finalize ( )
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.

◆ write_next()

void ChatPrinter::write_next ( u8  ch)
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.

◆ write_overflow()

void Writeable::write_overflow ( )
protectedvirtualinherited

◆ write_str()

void Writeable::write_str ( const char *  str)
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.

◆ write_u8()

void Writeable::write_u8 ( u8  data)
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.
  • Data-type width in bits.
    • Available widths for ints: 8/16/24/32/48/64.
    • Available widths for floats: 32/64.
  • 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.


The documentation for this class was generated from the following files: