Skip to content

Commit

Permalink
rosbag2_cpp: sequential reader specifies no order
Browse files Browse the repository at this point in the history
Signed-off-by: James Smith <james@foxglove.dev>
  • Loading branch information
james-rms committed Nov 17, 2022
1 parent 3c1e553 commit 246c9e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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

0 comments on commit 246c9e0

Please sign in to comment.