Class ReadersManager

Class Documentation

class ReadersManager

This class manages multiple rosbag2_cpp::Reader instances, allowing for chronological reading of messages across all readers.

It maintains a cache of the next message from each reader and provides methods to retrieve the next message in chronological order, seek to a specific timestamp across all readers, and apply filters to all readers. It also provides access to the earliest and latest timestamps across all readers.

Public Types

using reader_storage_options_pair_t = std::pair<std::unique_ptr<rosbag2_cpp::Reader>, rosbag2_storage::StorageOptions>

Public Functions

explicit ReadersManager(std::vector<reader_storage_options_pair_t> &&reader_with_options)

Constructor which initializes the ReadersManager with multiple readers and their associated storage options.

Note

The readers will be opened during construction and cache will be populated with the first message from each reader (if available).

Parameters:

reader_with_options – Vector of pairs of unique pointer to the rosbag2_cpp::Reader class (which will be moved to the internal instance of the ReadersManager class during construction) and storage options (which will be applied to the rosbag2_cpp::reader when opening it).

ReadersManager() = delete

Deleted default constructor and copy/move operations.

ReadersManager(const ReadersManager&) = delete
ReadersManager &operator=(const ReadersManager&) = delete
ReadersManager(ReadersManager&&) = delete
ReadersManager &operator=(ReadersManager&&) = delete
virtual ~ReadersManager()

Destructor which cleans up resources used by the ReadersManager.

Note

The readers will be closed during destruction.

std::vector<rosbag2_storage::StorageOptions> get_all_storage_options() const

Getter for the currently stored storage options.

Returns:

Copy of the currently stored storage options

bool has_next() const

Check if there are present some messages to take.

Indicates that all readers have been exhausted. i.e. there are no more messages to take from readers.

Returns:

true if there are more messages to take, false otherwise.

std::shared_ptr<rosbag2_storage::SerializedBagMessage> get_next_message_in_chronological_order()

Get the next message with the earliest recv_timestamp. Updates the cache by reading from readers as necessary.

void seek(const rcutils_time_point_value_t &timestamp)

Seek all readers to the provided timestamp.

seek(t) will cause subsequent reads from readers to return messages that satisfy timestamp >= time t.

Parameters:

timestamp – The timestamp to seek to.

rcutils_time_point_value_t get_earliest_timestamp() const

Getter method for the earliest time among all readers.

Returns:

Returns timestamp of the first message in nanoseconds.

rcutils_time_point_value_t get_latest_timestamp() const

Getter method for te latest time among all readers.

Returns:

Returns timestamp of the last message in nanoseconds.

void set_filter(const rosbag2_storage::StorageFilter &storage_filter)

Apply a filter to all readers.

Parameters:

storage_filter – The filter to apply.

std::vector<rosbag2_storage::TopicMetadata> get_all_topics_and_types() const

Getter for all topics and types in all readers.

Returns:

vector of topics with topic name and type as std::string

void add_event_callbacks(rosbag2_cpp::bag_events::ReaderEventCallbacks &callbacks)

Add event callbacks to all readers.

Parameters:

callbacks – The callbacks to add.