Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rosbag2_cpp: sequential reader specifies no order #1162

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string>
#include <unordered_set>
#include <vector>
#include <optional>

#include "rosbag2_cpp/bag_events.hpp"
#include "rosbag2_cpp/converter.hpp"
Expand Down Expand Up @@ -208,7 +209,7 @@ class ROSBAG2_CPP_PUBLIC SequentialReader
std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory_{};

bag_events::EventCallbackManager callback_manager_;
rosbag2_storage::ReadOrder read_order_{};
std::optional<rosbag2_storage::ReadOrder> read_order_;
};

} // namespace readers
Expand Down
12 changes: 8 additions & 4 deletions rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ void SequentialReader::open(
if (!storage_) {
throw std::runtime_error{"No storage could be initialized from the inputs."};
}
storage_->set_read_order(read_order_);
if (read_order_ != std::nullopt) {
storage_->set_read_order(*read_order_);
}
metadata_ = storage_->get_metadata();
if (metadata_.relative_file_paths.empty()) {
ROSBAG2_CPP_LOG_WARN("No file paths were found in metadata.");
Expand Down Expand Up @@ -144,11 +146,11 @@ bool SequentialReader::has_next()
// to read from there. Otherwise, check if there's another message.
bool current_storage_has_next = storage_->has_next();
if (!current_storage_has_next) {
if (!read_order_.reverse && has_next_file()) {
if ((read_order_ == std::nullopt || !read_order_->reverse) && has_next_file()) {
load_next_file();
return has_next();
}
if (read_order_.reverse && has_prev_file()) {
if (read_order_->reverse && has_prev_file()) {
load_prev_file();
return has_next();
}
Expand Down Expand Up @@ -255,7 +257,9 @@ void SequentialReader::load_current_file()
throw std::runtime_error{"No storage could be initialized. Abort"};
}
// set filters
storage_->set_read_order(read_order_);
if (read_order_ != std::nullopt) {
storage_->set_read_order(*read_order_);
}
storage_->seek(seek_time_);
set_filter(topics_filter_);
}
Expand Down