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

[humble] rosbag2_storage: expose default storage ID as method (backport #1146) #1724

Merged
merged 2 commits into from
Jun 22, 2024
Merged
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
5 changes: 4 additions & 1 deletion ros2bag/ros2bag/verb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ros2bag.api import print_error
from ros2bag.verb import VerbExtension
from ros2cli.node import NODE_NAME_PREFIX
from rosbag2_py import get_default_storage_id
from rosbag2_py import get_registered_compressors
from rosbag2_py import get_registered_serializers
from rosbag2_py import get_registered_writers
Expand All @@ -35,7 +36,9 @@ class RecordVerb(VerbExtension):

def add_arguments(self, parser, cli_name): # noqa: D102
writer_choices = get_registered_writers()
default_writer = 'sqlite3' if 'sqlite3' in writer_choices else writer_choices[0]
default_storage_id = get_default_storage_id()
default_writer = default_storage_id if default_storage_id in writer_choices else \
next(iter(writer_choices))

compression_format_choices = get_registered_compressors()
serialization_choices = get_registered_serializers()
Expand Down
3 changes: 3 additions & 0 deletions rosbag2_cpp/src/rosbag2_cpp/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
#include "rosbag2_storage/serialized_bag_message.hpp"
#include "rosbag2_storage/storage_options.hpp"
#include "rosbag2_storage/topic_metadata.hpp"
#include "rosbag2_storage/default_storage_id.hpp"

#include "rmw/rmw.h"

namespace rosbag2_cpp
{


Writer::Writer(std::unique_ptr<rosbag2_cpp::writer_interfaces::BaseWriterInterface> writer_impl)
: writer_impl_(std::move(writer_impl))
{}
Expand All @@ -51,6 +53,7 @@ void Writer::open(const std::string & uri)
{
rosbag2_storage::StorageOptions storage_options;
storage_options.uri = uri;
storage_options.storage_id = rosbag2_storage::get_default_storage_id();

rosbag2_cpp::ConverterOptions converter_options{};
return open(storage_options, converter_options);
Expand Down
2 changes: 2 additions & 0 deletions rosbag2_py/rosbag2_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
get_registered_writers,
get_registered_compressors,
get_registered_serializers,
get_default_storage_id,
)
from rosbag2_py._info import (
Info,
Expand All @@ -55,6 +56,7 @@
__all__ = [
'bag_rewrite',
'ConverterOptions',
'get_default_storage_id',
'get_registered_readers',
'get_registered_writers',
'get_registered_compressors',
Expand Down
6 changes: 6 additions & 0 deletions rosbag2_py/src/rosbag2_py/_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rosbag2_cpp/writer.hpp"
#include "rosbag2_cpp/writers/sequential_writer.hpp"
#include "rosbag2_cpp/serialization_format_converter_factory.hpp"
#include "rosbag2_storage/default_storage_id.hpp"
#include "rosbag2_storage/ros_helper.hpp"
#include "rosbag2_storage/storage_filter.hpp"
#include "rosbag2_storage/storage_interfaces/read_write_interface.hpp"
Expand Down Expand Up @@ -141,4 +142,9 @@ PYBIND11_MODULE(_writer, m) {
"get_registered_serializers",
&rosbag2_py::get_registered_serializers,
"Returns list of serialization format plugins available for rosbag2 recording");

m.def(
"get_default_storage_id",
&rosbag2_storage::get_default_storage_id,
"Returns the default storage ID used when unspecified in StorageOptions");
}
1 change: 1 addition & 0 deletions rosbag2_storage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ find_package(yaml_cpp_vendor REQUIRED)
add_library(
${PROJECT_NAME}
SHARED
src/rosbag2_storage/default_storage_id.cpp
src/rosbag2_storage/metadata_io.cpp
src/rosbag2_storage/ros_helper.cpp
src/rosbag2_storage/storage_factory.cpp
Expand Down
29 changes: 29 additions & 0 deletions rosbag2_storage/include/rosbag2_storage/default_storage_id.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2022, Foxglove Technologies Inc. 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_STORAGE__DEFAULT_STORAGE_ID_HPP_
#define ROSBAG2_STORAGE__DEFAULT_STORAGE_ID_HPP_

#include <string>

#include "rosbag2_storage/visibility_control.hpp"

namespace rosbag2_storage
{

ROSBAG2_STORAGE_PUBLIC std::string get_default_storage_id();

} // namespace rosbag2_storage

#endif // ROSBAG2_STORAGE__DEFAULT_STORAGE_ID_HPP_
24 changes: 24 additions & 0 deletions rosbag2_storage/src/rosbag2_storage/default_storage_id.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2022, Foxglove Technologies Inc. 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.
#include "rosbag2_storage/default_storage_id.hpp"

namespace rosbag2_storage
{

std::string get_default_storage_id()
{
return "sqlite3";
}

} // namespace rosbag2_storage
Loading