Fray Engine
Loading...
Searching...
No Matches
fray::console::EntryList Class Reference

The Console entries the Engine owns and the Renderer shows, keyed by UID. The UID is the one stamped on the message the entry describes, so the Engine, the disk log and the Renderer all refer to the same thing. Every change bumps the entry's revision, which lets the Renderer ignore anything older than what it has. The list is bounded; the oldest entries are forgotten first. Safe to use from any thread. More...

#include <console_list.hpp>

Classes

struct  Confirmation
 What confirm() changed. More...

Public Member Functions

 EntryList (std::size_t capacity=5000)
 Creates an empty list.
ConsoleEntry add (ConsoleEntry entry)
 Adds an entry, or returns the one already held under the same UID.
std::optional< Confirmation > confirm (ConsoleEntry fallback, ProcessKind sender=PROCESS_KIND_UNSPECIFIED, std::uint32_t senderId=0)
 Records that a command was received. A direct entry becomes received. A multicast entry becomes received only after all distinct recipients confirm it. If the UID is unknown, the fallback is received for direct messages and pending for multicast.
std::size_t size () const
 Number of entries currently held.

Private Member Functions

void remember (const ConsoleEntry &entry)
 Stores an entry and forgets the oldest ones beyond capacity. The caller holds the lock.

Private Attributes

std::mutex _mutex
 Guards the entries and their order.
std::size_t _capacity
 Most entries kept.
std::unordered_map< std::string, ConsoleEntry > _entries
 Entries by UID.
std::unordered_map< std::string, std::set< std::pair< ProcessKind, std::uint32_t > > > _receipts
std::deque< std::string > _order
 UIDs oldest first, used to forget the oldest entry.

Detailed Description

The Console entries the Engine owns and the Renderer shows, keyed by UID. The UID is the one stamped on the message the entry describes, so the Engine, the disk log and the Renderer all refer to the same thing. Every change bumps the entry's revision, which lets the Renderer ignore anything older than what it has. The list is bounded; the oldest entries are forgotten first. Safe to use from any thread.

Definition at line 29 of file console_list.hpp.

Constructor & Destructor Documentation

◆ EntryList()

fray::console::EntryList::EntryList ( std::size_t capacity = 5000)
inlineexplicit

Creates an empty list.

Parameters
capacityMost entries kept before the oldest is forgotten; at least one.

Definition at line 36 of file console_list.hpp.

Member Function Documentation

◆ add()

ConsoleEntry fray::console::EntryList::add ( ConsoleEntry entry)
inline

Adds an entry, or returns the one already held under the same UID.

Parameters
entryEntry to add, in whatever status it already has; its revision is set to 1.
Returns
The entry as held, which is the existing one when the UID was already known.

Definition at line 45 of file console_list.hpp.

◆ confirm()

std::optional< Confirmation > fray::console::EntryList::confirm ( ConsoleEntry fallback,
ProcessKind sender = PROCESS_KIND_UNSPECIFIED,
std::uint32_t senderId = 0 )
inline

Records that a command was received. A direct entry becomes received. A multicast entry becomes received only after all distinct recipients confirm it. If the UID is unknown, the fallback is received for direct messages and pending for multicast.

Parameters
fallbackEntry describing the command, used only when its UID is unknown.
senderProcess kind that issued the receipt.
senderIdInstance ID that issued the receipt.
Returns
What changed, or nullopt if the entry was already received.

Definition at line 76 of file console_list.hpp.

◆ remember()

void fray::console::EntryList::remember ( const ConsoleEntry & entry)
inlineprivate

Stores an entry and forgets the oldest ones beyond capacity. The caller holds the lock.

Parameters
entryEntry to store.

Definition at line 131 of file console_list.hpp.

◆ size()

std::size_t fray::console::EntryList::size ( ) const
inline

Number of entries currently held.

Definition at line 120 of file console_list.hpp.

Member Data Documentation

◆ _capacity

std::size_t fray::console::EntryList::_capacity
private

Most entries kept.

Definition at line 147 of file console_list.hpp.

◆ _entries

std::unordered_map<std::string, ConsoleEntry> fray::console::EntryList::_entries
private

Entries by UID.

Definition at line 149 of file console_list.hpp.

◆ _mutex

std::mutex fray::console::EntryList::_mutex
mutableprivate

Guards the entries and their order.

Definition at line 145 of file console_list.hpp.

◆ _order

std::deque<std::string> fray::console::EntryList::_order
private

UIDs oldest first, used to forget the oldest entry.

Definition at line 153 of file console_list.hpp.

◆ _receipts

std::unordered_map<std::string, std::set<std::pair<ProcessKind, std::uint32_t> > > fray::console::EntryList::_receipts
private

Distinct multicast recipients whose receipts have been observed.

Definition at line 151 of file console_list.hpp.


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