Class SequentialWriter
Defined in File sequential_writer.hpp
Inheritance Relationships
Base Type
public rosbag2_cpp::writer_interfaces::BaseWriterInterface
(Class BaseWriterInterface)
Class Documentation
-
class SequentialWriter : public rosbag2_cpp::writer_interfaces::BaseWriterInterface
The Writer allows writing messages to a new bag. For every topic, information about its type needs to be added before writing the first message.
Public Functions
-
~SequentialWriter() override
-
virtual void open(const rosbag2_storage::StorageOptions &storage_options, const ConverterOptions &converter_options) override
Opens a new bagfile and prepare it for writing messages. The bagfile must not exist. This must be called before any other function is used.
- Parameters:
storage_options – Options to configure the storage
converter_options – options to define in which format incoming messages are stored
-
virtual void close() override
-
virtual void create_topic(const rosbag2_storage::TopicMetadata &topic_with_type) override
Create a new topic in the underlying storage. Needs to be called for every topic used within a message which is passed to write(…).
- Parameters:
topic_with_type – name and type identifier of topic to be created
- Throws:
runtime_error – if the Writer is not open.
-
virtual void remove_topic(const rosbag2_storage::TopicMetadata &topic_with_type) override
Remove a new topic in the underlying storage. If creation of subscription fails remove the topic from the db (more of cleanup)
- Parameters:
topic_with_type – name and type identifier of topic to be created
- Throws:
runtime_error – if the Writer is not open.
Write a message to a bagfile. The topic needs to have been created before writing is possible.
- Parameters:
message – to be written to the bagfile
- Throws:
runtime_error – if the Writer is not open.
-
virtual bool take_snapshot() override
Take a snapshot by triggering a circular buffer flip, writing data to disk. *
- Returns:
true if snapshot is successful
-
virtual void add_event_callbacks(const bag_events::WriterEventCallbacks &callbacks) override
Add callbacks for events that may occur during bag writing.
- Parameters:
callbacks – the structure containing the callback to add for each event.
Protected Functions
-
std::string split_bagfile_local(bool execute_callbacks = true)
-
void execute_bag_split_callbacks(const std::string &closed_file, const std::string &opened_file)
-
void switch_to_next_storage()
-
std::string format_storage_uri(const std::string &base_folder, uint64_t storage_count)
-
virtual void split_bagfile()
-
bool should_split_bagfile(const std::chrono::time_point<std::chrono::high_resolution_clock> ¤t_time) const
-
virtual void init_metadata()
-
void finalize_metadata()
Protected Attributes
-
std::string base_folder_
-
std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory_
-
std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory_
-
std::shared_ptr<rosbag2_storage::storage_interfaces::ReadWriteInterface> storage_
-
std::unique_ptr<rosbag2_storage::MetadataIo> metadata_io_
-
bool use_cache_ = {false}
-
std::shared_ptr<rosbag2_cpp::cache::MessageCacheInterface> message_cache_
-
std::unique_ptr<rosbag2_cpp::cache::CacheConsumer> cache_consumer_
-
rosbag2_storage::StorageOptions storage_options_
-
std::unordered_map<std::string, rosbag2_storage::TopicInformation> topics_names_to_info_
-
std::mutex topics_info_mutex_
-
rosbag2_storage::BagMetadata metadata_
-
~SequentialWriter() override