Program Listing for File sequential_reader.hpp
↰ Return to documentation for file (/tmp/ws/src/rosbag2/rosbag2_cpp/include/rosbag2_cpp/readers/sequential_reader.hpp
)
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// 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_CPP__READERS__SEQUENTIAL_READER_HPP_
#define ROSBAG2_CPP__READERS__SEQUENTIAL_READER_HPP_
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>
#include "rosbag2_cpp/bag_events.hpp"
#include "rosbag2_cpp/converter.hpp"
#include "rosbag2_cpp/reader_interfaces/base_reader_interface.hpp"
#include "rosbag2_cpp/serialization_format_converter_factory.hpp"
#include "rosbag2_cpp/serialization_format_converter_factory_interface.hpp"
#include "rosbag2_cpp/visibility_control.hpp"
#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
// a) the member is not accessible from the outside
// b) there are no inline functions.
#ifdef _WIN32
# pragma warning(push)
# pragma warning(disable:4251)
#endif
namespace rosbag2_cpp
{
namespace readers
{
class ROSBAG2_CPP_PUBLIC SequentialReader
: public ::rosbag2_cpp::reader_interfaces::BaseReaderInterface
{
public:
SequentialReader(
std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory =
std::make_unique<rosbag2_storage::StorageFactory>(),
std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory =
std::make_shared<SerializationFormatConverterFactory>(),
std::unique_ptr<rosbag2_storage::MetadataIo> metadata_io =
std::make_unique<rosbag2_storage::MetadataIo>());
virtual ~SequentialReader();
void open(
const rosbag2_storage::StorageOptions & storage_options,
const ConverterOptions & converter_options) override;
void close() override;
bool has_next() override;
std::shared_ptr<rosbag2_storage::SerializedBagMessage> read_next() override;
const rosbag2_storage::BagMetadata & get_metadata() const override;
std::vector<rosbag2_storage::TopicMetadata> get_all_topics_and_types() const override;
void set_filter(const rosbag2_storage::StorageFilter & storage_filter) override;
void reset_filter() override;
void seek(const rcutils_time_point_value_t & timestamp) override;
virtual bool has_next_file() const;
virtual std::string get_current_file() const;
virtual std::string get_current_uri() const;
void add_event_callbacks(const bag_events::ReaderEventCallbacks & callbacks) override;
bool has_callback_for_event(const bag_events::BagEvent event) const;
protected:
virtual void load_current_file();
virtual void load_next_file();
virtual void check_topics_serialization_formats(
const std::vector<rosbag2_storage::TopicInformation> & topics);
virtual void check_converter_serialization_format(
const std::string & converter_serialization_format,
const std::string & storage_serialization_format);
virtual void fill_topics_metadata();
virtual void preprocess_current_file() {}
std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory_{};
std::shared_ptr<rosbag2_storage::storage_interfaces::ReadOnlyInterface> storage_{};
std::unique_ptr<Converter> converter_{};
std::unique_ptr<rosbag2_storage::MetadataIo> metadata_io_{};
rosbag2_storage::BagMetadata metadata_{};
rcutils_time_point_value_t seek_time_ = 0;
rosbag2_storage::StorageFilter topics_filter_{};
std::vector<rosbag2_storage::TopicMetadata> topics_metadata_{};
std::vector<std::string> file_paths_{}; // List of database files.
std::vector<std::string>::iterator current_file_iterator_{}; // Index of file to read from
std::unordered_set<std::string> preprocessed_file_paths_; // List of preprocessed paths
// Hang on to this because storage_options_ is mutated to point at individual files
std::string base_folder_;
private:
rosbag2_storage::StorageOptions storage_options_;
std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory_{};
bag_events::EventCallbackManager callback_manager_;
};
} // namespace readers
} // namespace rosbag2_cpp
#ifdef _WIN32
# pragma warning(pop)
#endif
#endif // ROSBAG2_CPP__READERS__SEQUENTIAL_READER_HPP_