CommRaT 2.0.0
C++20 Real-Time Messaging Framework
Loading...
Searching...
No Matches
commrat::HistoricalMailbox< UserRegistry, HistorySize > Class Template Reference

Mailbox with timestamped history for getData synchronization. More...

#include <commrat/mailbox/historical_mailbox.hpp>

Public Types

using Registry = UserRegistry
 
using MailboxType = RegistryMailbox< UserRegistry >
 
using HistoryBufferTuple = decltype(make_history_tuple_type(std::make_index_sequence< Registry::num_types >{}))
 

Public Member Functions

 HistoricalMailbox (const MailboxConfig &config, Milliseconds default_tolerance=Milliseconds(50))
 Constructor with mailbox config and default tolerance.
 
auto start () -> MailboxResult< void >
 Start the mailbox (pass-through to underlying mailbox)
 
void stop ()
 Stop the mailbox (pass-through to underlying mailbox)
 
template<typename T >
auto receive () -> MailboxResult< TimsMessage< T > >
 Receive a message and automatically store in history.
 
template<typename T >
std::optional< TimsMessage< T > > getData (uint64_t timestamp, Milliseconds tolerance=Milliseconds(-1), InterpolationMode mode=InterpolationMode::NEAREST) const
 
template<typename T >
std::pair< uint64_t, uint64_t > getTimestampRange () const
 Get timestamp range currently buffered for type T.
 
template<typename T >
void clearHistory ()
 Clear history for type T.
 
void clearAllHistory ()
 Clear all history buffers.
 
template<typename T >
auto send (T &message, uint32_t dest_mailbox) -> MailboxResult< void >
 Send a message (pass-through to underlying mailbox)
 
uint32_t get_mailbox_id () const
 Get mailbox ID.
 
bool is_initialized () const
 Check if mailbox is initialized.
 

Static Public Member Functions

template<std::size_t... Is>
static auto make_history_tuple_type (std::index_sequence< Is... >)
 

Detailed Description

template<typename UserRegistry, std::size_t HistorySize = 100>
class commrat::HistoricalMailbox< UserRegistry, HistorySize >

Mailbox with timestamped history for getData synchronization.

Wraps RegistryMailbox and maintains a TimestampedRingBuffer for each registered message type. Received messages are automatically stored in history, enabling getData() queries for multi-input synchronization.

Template Parameters
UserRegistryMessage registry (MessageRegistry<...>)
HistorySizeMaximum messages to buffer per type (default: 100)

Thread Safety:

Usage Pattern:

// Primary input (blocking - drives execution rate)
auto imu = imu_mailbox.receive<IMUData>();
// Secondary inputs (non-blocking - fetch at primary timestamp)
auto gps = gps_history.getData<GPSData>(imu.timestamp);
auto lidar = lidar_history.getData<LidarData>(imu.timestamp);
if (gps && lidar) {
process(imu, *gps, *lidar); // All time-aligned!
}

Architecture:

  • One TimestampedRingBuffer per message type in registry
  • Automatic deserialization on receive → store in history
  • getData() queries appropriate buffer based on type
  • FIFO overflow: oldest messages discarded when buffer full

Definition at line 63 of file historical_mailbox.hpp.

Member Typedef Documentation

◆ HistoryBufferTuple

template<typename UserRegistry , std::size_t HistorySize = 100>
using commrat::HistoricalMailbox< UserRegistry, HistorySize >::HistoryBufferTuple = decltype(make_history_tuple_type( std::make_index_sequence<Registry::num_types>{} ))

◆ MailboxType

template<typename UserRegistry , std::size_t HistorySize = 100>
using commrat::HistoricalMailbox< UserRegistry, HistorySize >::MailboxType = RegistryMailbox<UserRegistry>

◆ Registry

template<typename UserRegistry , std::size_t HistorySize = 100>
using commrat::HistoricalMailbox< UserRegistry, HistorySize >::Registry = UserRegistry

Constructor & Destructor Documentation

◆ HistoricalMailbox()

template<typename UserRegistry , std::size_t HistorySize = 100>
commrat::HistoricalMailbox< UserRegistry, HistorySize >::HistoricalMailbox ( const MailboxConfig config,
Milliseconds  default_tolerance = Milliseconds(50) 
)
inlineexplicit

Constructor with mailbox config and default tolerance.

Parameters
configMailbox configuration
default_toleranceDefault tolerance for getData (milliseconds)

Definition at line 89 of file historical_mailbox.hpp.

Member Function Documentation

◆ clearAllHistory()

template<typename UserRegistry , std::size_t HistorySize = 100>
void commrat::HistoricalMailbox< UserRegistry, HistorySize >::clearAllHistory ( )
inline

◆ clearHistory()

template<typename UserRegistry , std::size_t HistorySize = 100>
template<typename T >
void commrat::HistoricalMailbox< UserRegistry, HistorySize >::clearHistory ( )
inline

◆ get_mailbox_id()

template<typename UserRegistry , std::size_t HistorySize = 100>
uint32_t commrat::HistoricalMailbox< UserRegistry, HistorySize >::get_mailbox_id ( ) const
inline

◆ getData()

template<typename UserRegistry , std::size_t HistorySize = 100>
template<typename T >
std::optional< TimsMessage< T > > commrat::HistoricalMailbox< UserRegistry, HistorySize >::getData ( uint64_t  timestamp,
Milliseconds  tolerance = Milliseconds(-1),
InterpolationMode  mode = InterpolationMode::NEAREST 
) const
inline

◆ getTimestampRange()

template<typename UserRegistry , std::size_t HistorySize = 100>
template<typename T >
std::pair< uint64_t, uint64_t > commrat::HistoricalMailbox< UserRegistry, HistorySize >::getTimestampRange ( ) const
inline

Get timestamp range currently buffered for type T.

Returns
{oldest_timestamp, newest_timestamp} or {0, 0} if empty
Examples
/home/runner/work/CommRaT/CommRaT/include/commrat/mailbox/historical_mailbox.hpp.

Definition at line 196 of file historical_mailbox.hpp.

◆ is_initialized()

template<typename UserRegistry , std::size_t HistorySize = 100>
bool commrat::HistoricalMailbox< UserRegistry, HistorySize >::is_initialized ( ) const
inline

Check if mailbox is initialized.

Examples
/home/runner/work/CommRaT/CommRaT/include/commrat/mailbox/historical_mailbox.hpp.

Definition at line 239 of file historical_mailbox.hpp.

◆ make_history_tuple_type()

template<typename UserRegistry , std::size_t HistorySize = 100>
template<std::size_t... Is>
static auto commrat::HistoricalMailbox< UserRegistry, HistorySize >::make_history_tuple_type ( std::index_sequence< Is... >  )
inlinestatic

◆ receive()

template<typename UserRegistry , std::size_t HistorySize = 100>
template<typename T >
auto commrat::HistoricalMailbox< UserRegistry, HistorySize >::receive ( ) -> MailboxResult<TimsMessage<T>>
inline

Receive a message and automatically store in history.

Receives next message of type T, stores it in history, and returns it. This is the PRIMARY input API - blocks until message arrives.

Template Parameters
TPayload type (must be registered in UserRegistry)
Returns
Received message or error
Note
Thread-safe: Exclusive write access to history buffer
Automatically stores in history for future getData() queries
Examples
/home/runner/work/CommRaT/CommRaT/include/commrat/mailbox/historical_mailbox.hpp.

Definition at line 138 of file historical_mailbox.hpp.

◆ send()

template<typename UserRegistry , std::size_t HistorySize = 100>
template<typename T >
auto commrat::HistoricalMailbox< UserRegistry, HistorySize >::send ( T &  message,
uint32_t  dest_mailbox 
) -> MailboxResult<void>
inline

◆ start()

template<typename UserRegistry , std::size_t HistorySize = 100>
auto commrat::HistoricalMailbox< UserRegistry, HistorySize >::start ( ) -> MailboxResult<void>
inline

Start the mailbox (pass-through to underlying mailbox)

Returns
Success or error from underlying mailbox initialization
Examples
/home/runner/work/CommRaT/CommRaT/include/commrat/mailbox/historical_mailbox.hpp.

Definition at line 101 of file historical_mailbox.hpp.

References commrat::RegistryMailbox< Registry >::mailbox_id(), and commrat::RegistryMailbox< Registry >::start().

◆ stop()

template<typename UserRegistry , std::size_t HistorySize = 100>
void commrat::HistoricalMailbox< UserRegistry, HistorySize >::stop ( )
inline

Stop the mailbox (pass-through to underlying mailbox)

Examples
/home/runner/work/CommRaT/CommRaT/include/commrat/mailbox/historical_mailbox.hpp.

Definition at line 117 of file historical_mailbox.hpp.

References commrat::RegistryMailbox< Registry >::stop().


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