Class CircularMessageCache
Defined in File circular_message_cache.hpp
Inheritance Relationships
Base Type
public rosbag2_cpp::cache::MessageCacheInterface(Class MessageCacheInterface)
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_buffersmanually. This is useful for 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. The buffer can be limited by both size (max_buffer_size) and time duration (max_buffer_duration). If both are non-zero, both bounds are enforced.Public Functions
-
explicit CircularMessageCache(size_t max_buffer_size, uint32_t max_buffer_duration = 0)
Parametrized constructor.
- Parameters:
max_buffer_size – Maximum buffer size in bytes. If 0, only limited by duration.
max_buffer_duration – Maximum buffer duration in seconds. If 0, only limited by size. At least one parameter must be non-zero.
-
~CircularMessageCache() override
Puts msg into circular buffer, replacing the oldest msg when buffer is full
- Returns:
True if message was successfully pushed, otherwise false. NOTE: Unless message is null or too large for the buffer, this will always return true since the circular buffer by design drops old messages when the 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_buffershas 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.
-
explicit CircularMessageCache(size_t max_buffer_size, uint32_t max_buffer_duration = 0)