Class CircularMessageCache

Inheritance Relationships

Base Type

Class Documentation

class CircularMessageCache : public rosbag2_cpp::cache::MessageCacheInterface

Provides a “deferred-consumption” implementation of the MessageCacheInterface. When a consumer asks for a buffer, it will not receive a new buffer until some control source calls swap_buffers manually. This is useful for a snapshot mode, where no data is written to disk until asked for, then the full circular buffer is dumped all at once, giving historical context.

Public Functions

explicit CircularMessageCache(size_t max_buffer_size)
~CircularMessageCache() override
virtual void push(std::shared_ptr<const rosbag2_storage::SerializedBagMessage> msg) override

Puts msg into circular buffer, replacing the oldest msg when buffer is full.

virtual std::shared_ptr< CacheBufferInterface > get_consumer_buffer () override RCPPUTILS_TSA_ACQUIRE(consumer_buffer_mutex_)

Get current buffer to consume. Locks consumer buffer until release_consumer_buffer is called. This may be repeatedly empty if swap_buffers has not been called.

virtual void release_consumer_buffer () override RCPPUTILS_TSA_RELEASE(consumer_buffer_mutex_)

Unlock access to the consumer buffer.

virtual void wait_for_data() override

Blocks current thread and going to wait on condition variable until notify_data_ready will be called.

virtual void swap_buffers() override

Swap the primary and secondary buffer before consumption. NOTE: If swap_buffers is called again before consuming via get_consumer_buffer, that data will be cleared for use by the producer.

virtual void begin_flushing() override

Signal wait_for_data to wake up and unblock consumer thread on exit or during bag split.

virtual void done_flushing() override

Notify that flushing is complete.

virtual void notify_data_ready() override

Snapshot API: notify cache consumer to wake-up for dumping buffer.