From bf71f78b154dd284b60fc7634131bc81763e6d4d Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 27 Feb 2020 14:31:46 -0500 Subject: [PATCH 01/12] add filter for selecting topics to read Signed-off-by: Mabel Zhang --- .../rosbag2_cpp/readers/sequential_reader.hpp | 3 ++ .../rosbag2_cpp/readers/sequential_reader.cpp | 6 ++++ rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp | 2 ++ .../read_only_interface.hpp | 3 ++ .../read_write_interface.hpp | 3 ++ .../test/rosbag2_storage/test_plugin.cpp | 6 ++++ .../test/rosbag2_storage/test_plugin.hpp | 2 ++ .../rosbag2_storage/test_read_only_plugin.cpp | 6 ++++ .../rosbag2_storage/test_read_only_plugin.hpp | 3 ++ .../sqlite/sqlite_storage.hpp | 4 +++ .../sqlite/sqlite_storage.cpp | 33 ++++++++++++++++--- .../sqlite/test_sqlite_storage.cpp | 29 ++++++++++++++++ 12 files changed, 96 insertions(+), 4 deletions(-) diff --git a/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp b/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp index f6586a97b2..7af3199f38 100644 --- a/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp +++ b/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp @@ -28,6 +28,7 @@ #include "rosbag2_storage/metadata_io.hpp" #include "rosbag2_storage/storage_factory.hpp" #include "rosbag2_storage/storage_factory_interface.hpp" +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/storage_interfaces/read_only_interface.hpp" // This is necessary because of using stl types here. It is completely safe, because @@ -68,6 +69,8 @@ class ROSBAG2_CPP_PUBLIC SequentialReader std::vector get_all_topics_and_types() override; + void set_filter(const rosbag2_storage::StorageFilter & storage_filter); + /** * Ask whether there is another database file to read from the list of relative * file paths. diff --git a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp index 24b030f635..1e19f6d3d5 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp @@ -130,6 +130,12 @@ std::vector SequentialReader::get_all_topics_and throw std::runtime_error("Bag is not open. Call open() before reading."); } +void SequentialReader::set_filter( + const rosbag2_storage::StorageFilter & storage_filter) +{ + storage_->set_filter(storage_filter); +} + bool SequentialReader::has_next_file() const { return current_file_iterator_ + 1 != file_paths_.end(); diff --git a/rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp b/rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp index a2c790c4ef..e5bb571e9a 100644 --- a/rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp +++ b/rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp @@ -23,6 +23,7 @@ #include "rosbag2_storage/bag_metadata.hpp" #include "rosbag2_storage/serialized_bag_message.hpp" +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/storage_interfaces/read_write_interface.hpp" #include "rosbag2_storage/topic_metadata.hpp" @@ -37,6 +38,7 @@ class MockStorage : public rosbag2_storage::storage_interfaces::ReadWriteInterfa MOCK_METHOD1(write, void(std::shared_ptr)); MOCK_METHOD0(get_all_topics_and_types, std::vector()); MOCK_METHOD0(get_metadata, rosbag2_storage::BagMetadata()); + MOCK_METHOD1(set_filter, void(const rosbag2_storage::StorageFilter &)); MOCK_CONST_METHOD0(get_bagfile_size, uint64_t()); MOCK_CONST_METHOD0(get_relative_file_path, std::string()); MOCK_CONST_METHOD0(get_storage_identifier, std::string()); diff --git a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_only_interface.hpp b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_only_interface.hpp index c638515a07..e1c12d5bc4 100644 --- a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_only_interface.hpp +++ b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_only_interface.hpp @@ -17,6 +17,7 @@ #include +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/storage_interfaces/base_info_interface.hpp" #include "rosbag2_storage/storage_interfaces/base_io_interface.hpp" #include "rosbag2_storage/storage_interfaces/base_read_interface.hpp" @@ -38,6 +39,8 @@ class ROSBAG2_STORAGE_PUBLIC ReadOnlyInterface uint64_t get_bagfile_size() const override = 0; std::string get_storage_identifier() const override = 0; + + virtual void set_filter(const StorageFilter & storage_filter) = 0; }; } // namespace storage_interfaces diff --git a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp index 57f65c69ed..85c926014f 100644 --- a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp +++ b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp @@ -17,6 +17,7 @@ #include +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/storage_interfaces/read_only_interface.hpp" #include "rosbag2_storage/storage_interfaces/base_write_interface.hpp" #include "rosbag2_storage/visibility_control.hpp" @@ -39,6 +40,8 @@ class ROSBAG2_STORAGE_PUBLIC ReadWriteInterface std::string get_storage_identifier() const override = 0; virtual uint64_t get_minimum_split_file_size() const = 0; + + void set_filter(const StorageFilter & storage_filter) override = 0; }; } // namespace storage_interfaces diff --git a/rosbag2_storage/test/rosbag2_storage/test_plugin.cpp b/rosbag2_storage/test/rosbag2_storage/test_plugin.cpp index 006b5369d4..7dd0bc57cb 100644 --- a/rosbag2_storage/test/rosbag2_storage/test_plugin.cpp +++ b/rosbag2_storage/test/rosbag2_storage/test_plugin.cpp @@ -104,4 +104,10 @@ uint64_t TestPlugin::get_minimum_split_file_size() const return test_constants::MIN_SPLIT_FILE_SIZE; } +void TestPlugin::set_filter( + const rosbag2_storage::StorageFilter & /*storage_filter*/) +{ + std::cout << "\nsetting storage filter\n"; +} + PLUGINLIB_EXPORT_CLASS(TestPlugin, rosbag2_storage::storage_interfaces::ReadWriteInterface) diff --git a/rosbag2_storage/test/rosbag2_storage/test_plugin.hpp b/rosbag2_storage/test/rosbag2_storage/test_plugin.hpp index c250cc3f98..08a6e40f3e 100644 --- a/rosbag2_storage/test/rosbag2_storage/test_plugin.hpp +++ b/rosbag2_storage/test/rosbag2_storage/test_plugin.hpp @@ -52,6 +52,8 @@ class TestPlugin : public rosbag2_storage::storage_interfaces::ReadWriteInterfac std::string get_storage_identifier() const override; uint64_t get_minimum_split_file_size() const override; + + void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override; }; #endif // ROSBAG2_STORAGE__TEST_PLUGIN_HPP_ diff --git a/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.cpp b/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.cpp index 9345be50ec..3bb00371f9 100644 --- a/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.cpp +++ b/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.cpp @@ -79,4 +79,10 @@ std::string TestReadOnlyPlugin::get_storage_identifier() const return test_constants::READ_ONLY_PLUGIN_IDENTIFIER; } +void TestReadOnlyPlugin::set_filter( + const rosbag2_storage::StorageFilter & /*storage_filter*/) +{ + std::cout << "\nsetting storage filter\n"; +} + PLUGINLIB_EXPORT_CLASS(TestReadOnlyPlugin, rosbag2_storage::storage_interfaces::ReadOnlyInterface) diff --git a/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.hpp b/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.hpp index 6dbed3a37e..cdd24a36bd 100644 --- a/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.hpp +++ b/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.hpp @@ -19,6 +19,7 @@ #include #include +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/storage_interfaces/read_only_interface.hpp" class TestReadOnlyPlugin : public rosbag2_storage::storage_interfaces::ReadOnlyInterface @@ -41,6 +42,8 @@ class TestReadOnlyPlugin : public rosbag2_storage::storage_interfaces::ReadOnlyI uint64_t get_bagfile_size() const override; std::string get_storage_identifier() const override; + + void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override; }; #endif // ROSBAG2_STORAGE__TEST_READ_ONLY_PLUGIN_HPP_ diff --git a/rosbag2_storage_default_plugins/include/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp b/rosbag2_storage_default_plugins/include/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp index 256e6f1b53..8903697e82 100644 --- a/rosbag2_storage_default_plugins/include/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp +++ b/rosbag2_storage_default_plugins/include/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp @@ -23,6 +23,7 @@ #include "rcutils/types.h" #include "rosbag2_storage/storage_interfaces/read_write_interface.hpp" #include "rosbag2_storage/serialized_bag_message.hpp" +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/topic_metadata.hpp" #include "rosbag2_storage_default_plugins/sqlite/sqlite_wrapper.hpp" #include "rosbag2_storage_default_plugins/visibility_control.hpp" @@ -72,6 +73,8 @@ class ROSBAG2_STORAGE_DEFAULT_PLUGINS_PUBLIC SqliteStorage uint64_t get_minimum_split_file_size() const override; + void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override; + private: void initialize(); void prepare_for_writing(); @@ -90,6 +93,7 @@ class ROSBAG2_STORAGE_DEFAULT_PLUGINS_PUBLIC SqliteStorage std::unordered_map topics_; std::vector all_topics_and_types_; std::string relative_path_; + rosbag2_storage::StorageFilter storage_filter_ {}; }; } // namespace rosbag2_storage_plugins diff --git a/rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp b/rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp index 0a33fe23b3..4e9ddc46fc 100644 --- a/rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp +++ b/rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp @@ -103,6 +103,8 @@ void SqliteStorage::open( ROSBAG2_STORAGE_DEFAULT_PLUGINS_LOG_INFO_STREAM( "Opened database '" << relative_path_ << "' for " << to_string(io_flag) << "."); + + storage_filter_.topics.clear(); } void SqliteStorage::write(std::shared_ptr message) @@ -211,10 +213,27 @@ void SqliteStorage::prepare_for_writing() void SqliteStorage::prepare_for_reading() { - read_statement_ = database_->prepare_statement( - "SELECT data, timestamp, topics.name " - "FROM messages JOIN topics ON messages.topic_id = topics.id " - "ORDER BY messages.timestamp;"); + if (!storage_filter_.topics.empty()) { + // Construct string for selected topics + std::string topic_list{""}; + for (auto & topic : storage_filter_.topics) { + topic_list += "'" + topic + "'"; + if (&topic != &storage_filter_.topics.back()) { + topic_list += ","; + } + } + + read_statement_ = database_->prepare_statement( + "SELECT data, timestamp, topics.name " + "FROM messages JOIN topics ON messages.topic_id = topics.id " + "WHERE topics.name IN (" + topic_list + ")" + "ORDER BY messages.timestamp;"); + } else { + read_statement_ = database_->prepare_statement( + "SELECT data, timestamp, topics.name " + "FROM messages JOIN topics ON messages.topic_id = topics.id " + "ORDER BY messages.timestamp;"); + } message_result_ = read_statement_->execute_query< std::shared_ptr, rcutils_time_point_value_t, std::string>(); current_message_row_ = message_result_.begin(); @@ -292,6 +311,12 @@ rosbag2_storage::BagMetadata SqliteStorage::get_metadata() return metadata; } +void SqliteStorage::set_filter( + const rosbag2_storage::StorageFilter & storage_filter) +{ + storage_filter_ = storage_filter; +} + } // namespace rosbag2_storage_plugins #include "pluginlib/class_list_macros.hpp" // NOLINT diff --git a/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp b/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp index e989f5d862..65133f014a 100644 --- a/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp +++ b/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp @@ -14,6 +14,8 @@ #include +#include + #include #include #include @@ -111,6 +113,33 @@ TEST_F(StorageTestFixture, get_next_returns_messages_in_timestamp_order) { EXPECT_FALSE(readable_storage->has_next()); } +TEST_F(StorageTestFixture, read_next_returns_filtered_messages) { + std::vector> + string_messages = + {std::make_tuple("topic1 message", 1, "topic1", "", ""), + std::make_tuple("topic2 message", 2, "topic2", "", ""), + std::make_tuple("topic3 message", 3, "topic3", "", "")}; + + write_messages_to_sqlite(string_messages); + std::unique_ptr readable_storage = + std::make_unique(); + + auto db_filename = (rcpputils::fs::path(temporary_dir_path_) / "rosbag.db3").string(); + readable_storage->open(db_filename); + + rosbag2_storage::StorageFilter storage_filter; + storage_filter.topics.push_back("topic2"); + storage_filter.topics.push_back("topic3"); + readable_storage->set_filter(storage_filter); + + EXPECT_TRUE(readable_storage->has_next()); + auto first_message = readable_storage->read_next(); + EXPECT_THAT(first_message->topic_name, Eq("topic2")); + EXPECT_TRUE(readable_storage->has_next()); + auto second_message = readable_storage->read_next(); + EXPECT_THAT(second_message->topic_name, Eq("topic3")); +} + TEST_F(StorageTestFixture, get_all_topics_and_types_returns_the_correct_vector) { std::unique_ptr writable_storage = std::make_unique(); From fa96e5cf08068985c14d29428af17f4f00a9b7f3 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Thu, 27 Feb 2020 14:39:42 -0500 Subject: [PATCH 02/12] add StorageFilter Signed-off-by: Mabel Zhang --- .../rosbag2_storage/storage_filter.hpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 rosbag2_storage/include/rosbag2_storage/storage_filter.hpp diff --git a/rosbag2_storage/include/rosbag2_storage/storage_filter.hpp b/rosbag2_storage/include/rosbag2_storage/storage_filter.hpp new file mode 100644 index 0000000000..c2a3f1f72e --- /dev/null +++ b/rosbag2_storage/include/rosbag2_storage/storage_filter.hpp @@ -0,0 +1,31 @@ +// Copyright 2020 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ROSBAG2_STORAGE__STORAGE_FILTER_HPP_ +#define ROSBAG2_STORAGE__STORAGE_FILTER_HPP_ + +#include +#include + +namespace rosbag2_storage +{ + +struct StorageFilter +{ + std::vector topics; +}; + +} // namespace rosbag2_storage + +#endif // ROSBAG2_STORAGE__STORAGE_FILTER_HPP_ From 7d16787af4a52006d351c4fa0d26daac7ab6e1a8 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Fri, 6 Mar 2020 16:30:13 -0500 Subject: [PATCH 03/12] add safety check for storage pointer; add reset_filter Signed-off-by: Mabel Zhang --- .../rosbag2_cpp/readers/sequential_reader.hpp | 2 ++ .../src/rosbag2_cpp/readers/sequential_reader.cpp | 14 +++++++++++++- rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp | 1 + .../storage_interfaces/read_only_interface.hpp | 2 ++ .../storage_interfaces/read_write_interface.hpp | 2 ++ .../test/rosbag2_storage/test_plugin.cpp | 5 +++++ .../test/rosbag2_storage/test_plugin.hpp | 2 ++ .../test/rosbag2_storage/test_read_only_plugin.cpp | 5 +++++ .../test/rosbag2_storage/test_read_only_plugin.hpp | 2 ++ .../sqlite/sqlite_storage.hpp | 2 ++ .../sqlite/sqlite_storage.cpp | 7 +++++-- 11 files changed, 41 insertions(+), 3 deletions(-) diff --git a/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp b/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp index 7af3199f38..1b7862b8fe 100644 --- a/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp +++ b/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp @@ -71,6 +71,8 @@ class ROSBAG2_CPP_PUBLIC SequentialReader void set_filter(const rosbag2_storage::StorageFilter & storage_filter); + void reset_filter(); + /** * Ask whether there is another database file to read from the list of relative * file paths. diff --git a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp index 1e19f6d3d5..658383d90e 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp @@ -133,7 +133,19 @@ std::vector SequentialReader::get_all_topics_and void SequentialReader::set_filter( const rosbag2_storage::StorageFilter & storage_filter) { - storage_->set_filter(storage_filter); + if (storage_) { + storage_->set_filter(storage_filter); + return; + } + throw std::runtime_error("Bag is not open. Call open() before setting " + "filter."); +} + +void SequentialReader::reset_filter() +{ + if (storage_) { + storage_->reset_filter(); + } } bool SequentialReader::has_next_file() const diff --git a/rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp b/rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp index e5bb571e9a..75cc7ef166 100644 --- a/rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp +++ b/rosbag2_cpp/test/rosbag2_cpp/mock_storage.hpp @@ -38,6 +38,7 @@ class MockStorage : public rosbag2_storage::storage_interfaces::ReadWriteInterfa MOCK_METHOD1(write, void(std::shared_ptr)); MOCK_METHOD0(get_all_topics_and_types, std::vector()); MOCK_METHOD0(get_metadata, rosbag2_storage::BagMetadata()); + MOCK_METHOD0(reset_filter, void()); MOCK_METHOD1(set_filter, void(const rosbag2_storage::StorageFilter &)); MOCK_CONST_METHOD0(get_bagfile_size, uint64_t()); MOCK_CONST_METHOD0(get_relative_file_path, std::string()); diff --git a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_only_interface.hpp b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_only_interface.hpp index e1c12d5bc4..bec12d8eb9 100644 --- a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_only_interface.hpp +++ b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_only_interface.hpp @@ -41,6 +41,8 @@ class ROSBAG2_STORAGE_PUBLIC ReadOnlyInterface std::string get_storage_identifier() const override = 0; virtual void set_filter(const StorageFilter & storage_filter) = 0; + + virtual void reset_filter() = 0; }; } // namespace storage_interfaces diff --git a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp index 85c926014f..3e25443511 100644 --- a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp +++ b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp @@ -42,6 +42,8 @@ class ROSBAG2_STORAGE_PUBLIC ReadWriteInterface virtual uint64_t get_minimum_split_file_size() const = 0; void set_filter(const StorageFilter & storage_filter) override = 0; + + void reset_filter() = 0; }; } // namespace storage_interfaces diff --git a/rosbag2_storage/test/rosbag2_storage/test_plugin.cpp b/rosbag2_storage/test/rosbag2_storage/test_plugin.cpp index 7dd0bc57cb..62522a4fee 100644 --- a/rosbag2_storage/test/rosbag2_storage/test_plugin.cpp +++ b/rosbag2_storage/test/rosbag2_storage/test_plugin.cpp @@ -110,4 +110,9 @@ void TestPlugin::set_filter( std::cout << "\nsetting storage filter\n"; } +void TestPlugin::reset_filter() +{ + std::cout << "\nresetting storage filter\n"; +} + PLUGINLIB_EXPORT_CLASS(TestPlugin, rosbag2_storage::storage_interfaces::ReadWriteInterface) diff --git a/rosbag2_storage/test/rosbag2_storage/test_plugin.hpp b/rosbag2_storage/test/rosbag2_storage/test_plugin.hpp index 08a6e40f3e..3fe7564366 100644 --- a/rosbag2_storage/test/rosbag2_storage/test_plugin.hpp +++ b/rosbag2_storage/test/rosbag2_storage/test_plugin.hpp @@ -54,6 +54,8 @@ class TestPlugin : public rosbag2_storage::storage_interfaces::ReadWriteInterfac uint64_t get_minimum_split_file_size() const override; void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override; + + void reset_filter() override; }; #endif // ROSBAG2_STORAGE__TEST_PLUGIN_HPP_ diff --git a/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.cpp b/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.cpp index 3bb00371f9..8aa847f357 100644 --- a/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.cpp +++ b/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.cpp @@ -85,4 +85,9 @@ void TestReadOnlyPlugin::set_filter( std::cout << "\nsetting storage filter\n"; } +void TestReadOnlyPlugin::reset_filter() +{ + std::cout << "\nresetting storage filter\n"; +} + PLUGINLIB_EXPORT_CLASS(TestReadOnlyPlugin, rosbag2_storage::storage_interfaces::ReadOnlyInterface) diff --git a/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.hpp b/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.hpp index cdd24a36bd..0fdaca694a 100644 --- a/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.hpp +++ b/rosbag2_storage/test/rosbag2_storage/test_read_only_plugin.hpp @@ -44,6 +44,8 @@ class TestReadOnlyPlugin : public rosbag2_storage::storage_interfaces::ReadOnlyI std::string get_storage_identifier() const override; void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override; + + void reset_filter() override; }; #endif // ROSBAG2_STORAGE__TEST_READ_ONLY_PLUGIN_HPP_ diff --git a/rosbag2_storage_default_plugins/include/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp b/rosbag2_storage_default_plugins/include/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp index 8903697e82..bc0fe7df9a 100644 --- a/rosbag2_storage_default_plugins/include/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp +++ b/rosbag2_storage_default_plugins/include/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp @@ -75,6 +75,8 @@ class ROSBAG2_STORAGE_DEFAULT_PLUGINS_PUBLIC SqliteStorage void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override; + void reset_filter() override; + private: void initialize(); void prepare_for_writing(); diff --git a/rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp b/rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp index 4e9ddc46fc..bf2f48915c 100644 --- a/rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp +++ b/rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp @@ -103,8 +103,6 @@ void SqliteStorage::open( ROSBAG2_STORAGE_DEFAULT_PLUGINS_LOG_INFO_STREAM( "Opened database '" << relative_path_ << "' for " << to_string(io_flag) << "."); - - storage_filter_.topics.clear(); } void SqliteStorage::write(std::shared_ptr message) @@ -317,6 +315,11 @@ void SqliteStorage::set_filter( storage_filter_ = storage_filter; } +void SqliteStorage::reset_filter() +{ + storage_filter_ = rosbag2_storage::StorageFilter(); +} + } // namespace rosbag2_storage_plugins #include "pluginlib/class_list_macros.hpp" // NOLINT From 80e06be6c610633051991851b04cf8553ec40b1a Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 24 Mar 2020 02:16:34 -0400 Subject: [PATCH 04/12] add set_filter and reset_filter to Reader Signed-off-by: Mabel Zhang --- .../sequential_compression_reader.hpp | 5 +++ .../sequential_compression_reader.cpp | 18 ++++++++++ rosbag2_cpp/include/rosbag2_cpp/reader.hpp | 14 ++++++++ .../base_reader_interface.hpp | 5 +++ rosbag2_cpp/src/rosbag2_cpp/reader.cpp | 10 ++++++ .../rosbag2_cpp/readers/sequential_reader.cpp | 2 +- .../mock_sequential_reader.hpp | 35 ++++++++++++++++++- 7 files changed, 87 insertions(+), 2 deletions(-) diff --git a/rosbag2_compression/include/rosbag2_compression/sequential_compression_reader.hpp b/rosbag2_compression/include/rosbag2_compression/sequential_compression_reader.hpp index acc30cc9a6..e0d275675e 100644 --- a/rosbag2_compression/include/rosbag2_compression/sequential_compression_reader.hpp +++ b/rosbag2_compression/include/rosbag2_compression/sequential_compression_reader.hpp @@ -30,6 +30,7 @@ #include "rosbag2_storage/metadata_io.hpp" #include "rosbag2_storage/storage_factory.hpp" #include "rosbag2_storage/storage_factory_interface.hpp" +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/storage_interfaces/read_only_interface.hpp" #include "compression_factory.hpp" @@ -73,6 +74,10 @@ class ROSBAG2_COMPRESSION_PUBLIC SequentialCompressionReader std::vector get_all_topics_and_types() override; + void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override; + + void reset_filter() override; + /** * Ask whether there is another database file to read from the list of relative * file paths. diff --git a/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp b/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp index 5d5761affd..39329ac668 100644 --- a/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp +++ b/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp @@ -142,6 +142,24 @@ std::vector SequentialCompressionReader::get_all throw std::runtime_error{"Bag is not open. Call open() before reading."}; } +void SequentialCompressionReader::set_filter( + const rosbag2_storage::StorageFilter & storage_filter) +{ + if (storage_) { + storage_->set_filter(storage_filter); + return; + } + throw std::runtime_error("Bag is not open. Call open() before setting " + "filter."); +} + +void SequentialCompressionReader::reset_filter() +{ + if (storage_) { + storage_->reset_filter(); + } +} + bool SequentialCompressionReader::has_next_file() const { // Handle case where bagfile is not split diff --git a/rosbag2_cpp/include/rosbag2_cpp/reader.hpp b/rosbag2_cpp/include/rosbag2_cpp/reader.hpp index adbf530e7d..7a9da056be 100644 --- a/rosbag2_cpp/include/rosbag2_cpp/reader.hpp +++ b/rosbag2_cpp/include/rosbag2_cpp/reader.hpp @@ -25,6 +25,7 @@ #include "rosbag2_cpp/visibility_control.hpp" #include "rosbag2_storage/serialized_bag_message.hpp" +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/topic_metadata.hpp" // This is necessary because of using stl types here. It is completely safe, because @@ -95,6 +96,19 @@ class ROSBAG2_CPP_PUBLIC Reader final */ std::vector get_all_topics_and_types(); + /** + * Set filters to adhere to during reading. + * + * \param storage_filter Filter to apply to reading + * \throws runtime_error if the Reader is not open. + */ + void set_filter(const rosbag2_storage::StorageFilter & storage_filter); + + /** + * Reset all filters for reading. + */ + void reset_filter(); + reader_interfaces::BaseReaderInterface & get_implementation_handle() const { return *reader_impl_; diff --git a/rosbag2_cpp/include/rosbag2_cpp/reader_interfaces/base_reader_interface.hpp b/rosbag2_cpp/include/rosbag2_cpp/reader_interfaces/base_reader_interface.hpp index 112d1343cd..e514dc7e13 100644 --- a/rosbag2_cpp/include/rosbag2_cpp/reader_interfaces/base_reader_interface.hpp +++ b/rosbag2_cpp/include/rosbag2_cpp/reader_interfaces/base_reader_interface.hpp @@ -23,6 +23,7 @@ #include "rosbag2_cpp/visibility_control.hpp" #include "rosbag2_storage/serialized_bag_message.hpp" +#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/topic_metadata.hpp" namespace rosbag2_cpp @@ -45,6 +46,10 @@ class ROSBAG2_CPP_PUBLIC BaseReaderInterface virtual std::shared_ptr read_next() = 0; virtual std::vector get_all_topics_and_types() = 0; + + virtual void set_filter(const rosbag2_storage::StorageFilter & storage_filter) = 0; + + virtual void reset_filter() = 0; }; } // namespace reader_interfaces diff --git a/rosbag2_cpp/src/rosbag2_cpp/reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/reader.cpp index 218efaa859..cdbc07a33d 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/reader.cpp @@ -56,4 +56,14 @@ std::vector Reader::get_all_topics_and_types() return reader_impl_->get_all_topics_and_types(); } +void Reader::set_filter(const rosbag2_storage::StorageFilter & storage_filter) +{ + reader_impl_->set_filter(storage_filter); +} + +void Reader::reset_filter() +{ + reader_impl_->reset_filter(); +} + } // namespace rosbag2_cpp diff --git a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp index 658383d90e..a959671079 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp @@ -138,7 +138,7 @@ void SequentialReader::set_filter( return; } throw std::runtime_error("Bag is not open. Call open() before setting " - "filter."); + "filter."); } void SequentialReader::reset_filter() diff --git a/rosbag2_transport/test/rosbag2_transport/mock_sequential_reader.hpp b/rosbag2_transport/test/rosbag2_transport/mock_sequential_reader.hpp index 36e6784456..635af76992 100644 --- a/rosbag2_transport/test/rosbag2_transport/mock_sequential_reader.hpp +++ b/rosbag2_transport/test/rosbag2_transport/mock_sequential_reader.hpp @@ -37,12 +37,34 @@ class MockSequentialReader : public rosbag2_cpp::reader_interfaces::BaseReaderIn bool has_next() override { - return num_read_ < messages_.size(); + //return num_read_ < messages_.size(); + + while (num_read_ < messages_.size()) { + for (const auto & filter_topic : filter_.topics) { + if (!messages_[num_read_ + 1]->topic_name.compare(filter_topic)) { + return true; + } + } + num_read_++; + } + return false; } std::shared_ptr read_next() override { return messages_[num_read_++]; + + /* + while (num_read_ < messages_.size()) { + for (const auto & filter_topic : filter_.topics) { + if (!messages_[num_read_ + 1]->topic_name.compare(filter_topic)) { + return messages_[num_read_++]; + } + } + num_read_++; + } + return nullptr; + */ } std::vector get_all_topics_and_types() override @@ -50,6 +72,16 @@ class MockSequentialReader : public rosbag2_cpp::reader_interfaces::BaseReaderIn return topics_; } + void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override + { + filter_ = storage_filter; + } + + void reset_filter() override + { + filter_ = rosbag2_storage::StorageFilter(); + } + void prepare( std::vector> messages, std::vector topics) @@ -62,6 +94,7 @@ class MockSequentialReader : public rosbag2_cpp::reader_interfaces::BaseReaderIn std::vector> messages_; std::vector topics_; size_t num_read_; + rosbag2_storage::StorageFilter filter_; }; #endif // ROSBAG2_TRANSPORT__MOCK_SEQUENTIAL_READER_HPP_ From 5e09b58d2a4bb8ff6880812edde5644d468fe8c3 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Mon, 30 Mar 2020 23:57:40 -0400 Subject: [PATCH 05/12] test sequential reader with mock storage Signed-off-by: Mabel Zhang --- .../rosbag2_cpp/readers/sequential_reader.cpp | 7 ++++++- .../rosbag2_cpp/test_sequential_reader.cpp | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp index a959671079..ff91044b21 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp @@ -45,7 +45,9 @@ SequentialReader::~SequentialReader() void SequentialReader::reset() { - storage_.reset(); + if (storage_) { + storage_.reset(); + } } void SequentialReader::open( @@ -145,7 +147,10 @@ void SequentialReader::reset_filter() { if (storage_) { storage_->reset_filter(); + return; } + throw std::runtime_error("Bag is not open. Call open() before resetting " + "filter."); } bool SequentialReader::has_next_file() const diff --git a/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp b/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp index 44d7dd1c8a..77b8dc6be4 100644 --- a/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp +++ b/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp @@ -116,3 +116,24 @@ TEST_F( reader_->open(rosbag2_cpp::StorageOptions(), {"", storage_serialization_format}); reader_->read_next(); } + +TEST_F(SequentialReaderTest, set_filter_calls_storage) { + // Prior to opening the file, setting filter should throw exception + rosbag2_storage::StorageFilter storage_filter; + storage_filter.topics.push_back("topic"); + EXPECT_ANY_THROW(reader_->set_filter(storage_filter)); + EXPECT_ANY_THROW(reader_->reset_filter()); + + EXPECT_CALL(*storage_, set_filter(_)).Times(2); + reader_->open(rosbag2_cpp::StorageOptions(), {"", storage_serialization_format_}); + reader_->set_filter(storage_filter); + reader_->read_next(); + storage_filter.topics.clear(); + storage_filter.topics.push_back("topic2"); + reader_->set_filter(storage_filter); + reader_->read_next(); + + EXPECT_CALL(*storage_, reset_filter()).Times(1); + reader_->reset_filter(); + reader_->read_next(); +} From 59d4cb1b2d6511a255a51fae0369ad7696419fa8 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 31 Mar 2020 00:56:10 -0400 Subject: [PATCH 06/12] style Signed-off-by: Mabel Zhang --- .../sqlite/test_sqlite_storage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp b/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp index 65133f014a..da61437c66 100644 --- a/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp +++ b/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp @@ -14,8 +14,6 @@ #include -#include - #include #include #include @@ -26,6 +24,8 @@ #include "rcutils/snprintf.h" +#include "rosbag2_storage/storage_filter.hpp" + #include "storage_test_fixture.hpp" using namespace ::testing; // NOLINT From 071612b90c56592e2469a2124c6f36e5289b0610 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 31 Mar 2020 16:45:06 -0400 Subject: [PATCH 07/12] fix transport mock_sequential_reader Signed-off-by: Mabel Zhang --- .../rosbag2_transport/mock_sequential_reader.hpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/rosbag2_transport/test/rosbag2_transport/mock_sequential_reader.hpp b/rosbag2_transport/test/rosbag2_transport/mock_sequential_reader.hpp index 635af76992..c83bb0dc3e 100644 --- a/rosbag2_transport/test/rosbag2_transport/mock_sequential_reader.hpp +++ b/rosbag2_transport/test/rosbag2_transport/mock_sequential_reader.hpp @@ -37,7 +37,9 @@ class MockSequentialReader : public rosbag2_cpp::reader_interfaces::BaseReaderIn bool has_next() override { - //return num_read_ < messages_.size(); + if (filter_.topics.empty()) { + return num_read_ < messages_.size(); + } while (num_read_ < messages_.size()) { for (const auto & filter_topic : filter_.topics) { @@ -53,18 +55,6 @@ class MockSequentialReader : public rosbag2_cpp::reader_interfaces::BaseReaderIn std::shared_ptr read_next() override { return messages_[num_read_++]; - - /* - while (num_read_ < messages_.size()) { - for (const auto & filter_topic : filter_.topics) { - if (!messages_[num_read_ + 1]->topic_name.compare(filter_topic)) { - return messages_[num_read_++]; - } - } - num_read_++; - } - return nullptr; - */ } std::vector get_all_topics_and_types() override From f29c609e936647ff2b2e999b10a2cd20477a9485 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Tue, 31 Mar 2020 18:29:53 -0400 Subject: [PATCH 08/12] remove storage filter from Reader Signed-off-by: Mabel Zhang --- rosbag2_cpp/include/rosbag2_cpp/reader.hpp | 14 -------------- rosbag2_cpp/src/rosbag2_cpp/reader.cpp | 10 ---------- .../test/rosbag2_cpp/test_sequential_reader.cpp | 10 +++++----- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/rosbag2_cpp/include/rosbag2_cpp/reader.hpp b/rosbag2_cpp/include/rosbag2_cpp/reader.hpp index 7a9da056be..adbf530e7d 100644 --- a/rosbag2_cpp/include/rosbag2_cpp/reader.hpp +++ b/rosbag2_cpp/include/rosbag2_cpp/reader.hpp @@ -25,7 +25,6 @@ #include "rosbag2_cpp/visibility_control.hpp" #include "rosbag2_storage/serialized_bag_message.hpp" -#include "rosbag2_storage/storage_filter.hpp" #include "rosbag2_storage/topic_metadata.hpp" // This is necessary because of using stl types here. It is completely safe, because @@ -96,19 +95,6 @@ class ROSBAG2_CPP_PUBLIC Reader final */ std::vector get_all_topics_and_types(); - /** - * Set filters to adhere to during reading. - * - * \param storage_filter Filter to apply to reading - * \throws runtime_error if the Reader is not open. - */ - void set_filter(const rosbag2_storage::StorageFilter & storage_filter); - - /** - * Reset all filters for reading. - */ - void reset_filter(); - reader_interfaces::BaseReaderInterface & get_implementation_handle() const { return *reader_impl_; diff --git a/rosbag2_cpp/src/rosbag2_cpp/reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/reader.cpp index cdbc07a33d..218efaa859 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/reader.cpp @@ -56,14 +56,4 @@ std::vector Reader::get_all_topics_and_types() return reader_impl_->get_all_topics_and_types(); } -void Reader::set_filter(const rosbag2_storage::StorageFilter & storage_filter) -{ - reader_impl_->set_filter(storage_filter); -} - -void Reader::reset_filter() -{ - reader_impl_->reset_filter(); -} - } // namespace rosbag2_cpp diff --git a/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp b/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp index 77b8dc6be4..34bc4f57e4 100644 --- a/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp +++ b/rosbag2_cpp/test/rosbag2_cpp/test_sequential_reader.cpp @@ -121,19 +121,19 @@ TEST_F(SequentialReaderTest, set_filter_calls_storage) { // Prior to opening the file, setting filter should throw exception rosbag2_storage::StorageFilter storage_filter; storage_filter.topics.push_back("topic"); - EXPECT_ANY_THROW(reader_->set_filter(storage_filter)); - EXPECT_ANY_THROW(reader_->reset_filter()); + EXPECT_ANY_THROW(reader_->get_implementation_handle().set_filter(storage_filter)); + EXPECT_ANY_THROW(reader_->get_implementation_handle().reset_filter()); EXPECT_CALL(*storage_, set_filter(_)).Times(2); reader_->open(rosbag2_cpp::StorageOptions(), {"", storage_serialization_format_}); - reader_->set_filter(storage_filter); + reader_->get_implementation_handle().set_filter(storage_filter); reader_->read_next(); storage_filter.topics.clear(); storage_filter.topics.push_back("topic2"); - reader_->set_filter(storage_filter); + reader_->get_implementation_handle().set_filter(storage_filter); reader_->read_next(); EXPECT_CALL(*storage_, reset_filter()).Times(1); - reader_->reset_filter(); + reader_->get_implementation_handle().reset_filter(); reader_->read_next(); } From b62736ab380d3bc5a33364ee441a6d52224ad694 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Wed, 1 Apr 2020 17:51:39 -0400 Subject: [PATCH 09/12] add tests Signed-off-by: Mabel Zhang --- .../sequential_compression_reader.cpp | 2 ++ .../rosbag2_storage/storage_filter.hpp | 3 +++ .../sqlite/test_sqlite_storage.cpp | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp b/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp index 39329ac668..6a644fd64b 100644 --- a/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp +++ b/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp @@ -158,6 +158,8 @@ void SequentialCompressionReader::reset_filter() if (storage_) { storage_->reset_filter(); } + throw std::runtime_error("Bag is not open. Call open() before resetting " + "filter."); } bool SequentialCompressionReader::has_next_file() const diff --git a/rosbag2_storage/include/rosbag2_storage/storage_filter.hpp b/rosbag2_storage/include/rosbag2_storage/storage_filter.hpp index c2a3f1f72e..1cfd00fc90 100644 --- a/rosbag2_storage/include/rosbag2_storage/storage_filter.hpp +++ b/rosbag2_storage/include/rosbag2_storage/storage_filter.hpp @@ -23,6 +23,9 @@ namespace rosbag2_storage struct StorageFilter { + // Topic names to whitelist when reading a bag. Only messages matching these + // specified topics will be returned. If list is empty, the filter is ignored + // and all messages are returned. std::vector topics; }; diff --git a/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp b/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp index d1c162cf1b..e3081e6d2a 100644 --- a/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp +++ b/rosbag2_storage_default_plugins/test/rosbag2_storage_default_plugins/sqlite/test_sqlite_storage.cpp @@ -138,6 +138,26 @@ TEST_F(StorageTestFixture, read_next_returns_filtered_messages) { EXPECT_TRUE(readable_storage->has_next()); auto second_message = readable_storage->read_next(); EXPECT_THAT(second_message->topic_name, Eq("topic3")); + EXPECT_FALSE(readable_storage->has_next()); + + // Test reset filter + std::unique_ptr readable_storage2 = + std::make_unique(); + + readable_storage2->open(db_filename); + readable_storage2->set_filter(storage_filter); + readable_storage2->reset_filter(); + + EXPECT_TRUE(readable_storage2->has_next()); + auto third_message = readable_storage2->read_next(); + EXPECT_THAT(third_message->topic_name, Eq("topic1")); + EXPECT_TRUE(readable_storage2->has_next()); + auto fourth_message = readable_storage2->read_next(); + EXPECT_THAT(fourth_message->topic_name, Eq("topic2")); + EXPECT_TRUE(readable_storage2->has_next()); + auto fifth_message = readable_storage2->read_next(); + EXPECT_THAT(fifth_message->topic_name, Eq("topic3")); + EXPECT_FALSE(readable_storage2->has_next()); } TEST_F(StorageTestFixture, get_all_topics_and_types_returns_the_correct_vector) { From f0b3f49b7acbe69959554f12c9d2e58af12cc4d2 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Wed, 1 Apr 2020 18:44:09 -0400 Subject: [PATCH 10/12] uncrustify Signed-off-by: Mabel Zhang --- .../rosbag2_compression/sequential_compression_reader.cpp | 8 ++++---- rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp b/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp index 6a644fd64b..aa288b49e6 100644 --- a/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp +++ b/rosbag2_compression/src/rosbag2_compression/sequential_compression_reader.cpp @@ -149,8 +149,8 @@ void SequentialCompressionReader::set_filter( storage_->set_filter(storage_filter); return; } - throw std::runtime_error("Bag is not open. Call open() before setting " - "filter."); + throw std::runtime_error( + "Bag is not open. Call open() before setting filter."); } void SequentialCompressionReader::reset_filter() @@ -158,8 +158,8 @@ void SequentialCompressionReader::reset_filter() if (storage_) { storage_->reset_filter(); } - throw std::runtime_error("Bag is not open. Call open() before resetting " - "filter."); + throw std::runtime_error( + "Bag is not open. Call open() before resetting filter."); } bool SequentialCompressionReader::has_next_file() const diff --git a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp index ff91044b21..999a138a58 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp @@ -139,8 +139,8 @@ void SequentialReader::set_filter( storage_->set_filter(storage_filter); return; } - throw std::runtime_error("Bag is not open. Call open() before setting " - "filter."); + throw std::runtime_error( + "Bag is not open. Call open() before setting filter."); } void SequentialReader::reset_filter() @@ -149,8 +149,8 @@ void SequentialReader::reset_filter() storage_->reset_filter(); return; } - throw std::runtime_error("Bag is not open. Call open() before resetting " - "filter."); + throw std::runtime_error( + "Bag is not open. Call open() before resetting filter."); } bool SequentialReader::has_next_file() const From 48ed8a794b5e22e9040cbf48525f735bc0f4cc33 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Wed, 1 Apr 2020 18:48:36 -0400 Subject: [PATCH 11/12] add override for OS X failure Signed-off-by: Mabel Zhang --- .../rosbag2_storage/storage_interfaces/read_write_interface.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp index 3e25443511..6b2f8257d5 100644 --- a/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp +++ b/rosbag2_storage/include/rosbag2_storage/storage_interfaces/read_write_interface.hpp @@ -43,7 +43,7 @@ class ROSBAG2_STORAGE_PUBLIC ReadWriteInterface void set_filter(const StorageFilter & storage_filter) override = 0; - void reset_filter() = 0; + void reset_filter() override = 0; }; } // namespace storage_interfaces From c0fbd0c1e3c2d4692df6013a3dee23adc0a302e5 Mon Sep 17 00:00:00 2001 From: Mabel Zhang Date: Wed, 1 Apr 2020 19:10:22 -0400 Subject: [PATCH 12/12] add override keywords for os x Signed-off-by: Mabel Zhang --- rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp b/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp index 1b7862b8fe..beb26023e4 100644 --- a/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp +++ b/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp @@ -69,9 +69,9 @@ class ROSBAG2_CPP_PUBLIC SequentialReader std::vector get_all_topics_and_types() override; - void set_filter(const rosbag2_storage::StorageFilter & storage_filter); + void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override; - void reset_filter(); + void reset_filter() override; /** * Ask whether there is another database file to read from the list of relative