Skip to content

Commit

Permalink
open overload for simple uri string
Browse files Browse the repository at this point in the history
Signed-off-by: Karsten Knese <[email protected]>
  • Loading branch information
Karsten1987 committed Jul 10, 2020
1 parent c3c50da commit c9bdbdd
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
16 changes: 16 additions & 0 deletions rosbag2_cpp/include/rosbag2_cpp/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ class ROSBAG2_CPP_PUBLIC Reader final

~Reader();

/**
* Opens an existing bagfile and prepare it for reading messages.
* The bagfile must exist.
* This must be called before any other function is used.
*
* \note This will open URI with the default storage options
* * using sqlite3 storage backend
* * using no converter options, storing messages with the incoming serialization format
* \sa rmw_get_serialization_format.
* For specifications, please see \sa open, which let's you specify
* more storage and converter options.
*
* \param storage_uri URI of the storage to open.
**/
void open(const std::string & uri);

/**
* Throws if file could not be opened.
* This must be called before any other function is used.
Expand Down
15 changes: 15 additions & 0 deletions rosbag2_cpp/include/rosbag2_cpp/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ class ROSBAG2_CPP_PUBLIC Writer final

~Writer();

/**
* 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.
*
* \note This will open URI with the default storage options
* * using sqlite3 storage backend
* * using no converter options, storing messages with the incoming serialization format
* \sa rmw_get_serialization_format.
* For specifications, please see \sa open, which let's you specify
* more storage and converter options.
*
* \param storage_uri URI of the storage to open.
**/
void open(const std::string & uri);

/**
* 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.
Expand Down
2 changes: 2 additions & 0 deletions rosbag2_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<depend>rosidl_typesupport_introspection_cpp</depend>
<depend>shared_queues_vendor</depend>

<exec_depend>rosbag2_storage_default_plugins</exec_depend>

<test_depend>ament_cmake_gmock</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
13 changes: 13 additions & 0 deletions rosbag2_cpp/src/rosbag2_cpp/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "rosbag2_cpp/reader.hpp"

#include <memory>
#include <string>
#include <utility>
#include <vector>

Expand All @@ -34,6 +35,18 @@ Reader::~Reader()
reader_impl_->reset();
}

void Reader::open(const std::string & uri)
{
rosbag2_cpp::StorageOptions storage_options;
storage_options.uri = uri;
storage_options.storage_id = "sqlite3";
storage_options.max_bagfile_size = 0; // default
storage_options.max_cache_size = 0; // default

rosbag2_cpp::ConverterOptions converter_options{};
return open(storage_options, converter_options);
}

void Reader::open(
const StorageOptions & storage_options,
const ConverterOptions & converter_options)
Expand Down
12 changes: 12 additions & 0 deletions rosbag2_cpp/src/rosbag2_cpp/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ Writer::~Writer()
writer_impl_.reset();
}

void Writer::open(const std::string & uri)
{
rosbag2_cpp::StorageOptions storage_options;
storage_options.uri = uri;
storage_options.storage_id = "sqlite3";
storage_options.max_bagfile_size = 0; // default
storage_options.max_cache_size = 0; // default

rosbag2_cpp::ConverterOptions converter_options{};
return open(storage_options, converter_options);
}

void Writer::open(
const StorageOptions & storage_options, const ConverterOptions & converter_options)
{
Expand Down
10 changes: 2 additions & 8 deletions rosbag2_tests/test/rosbag2_tests/test_rosbag2_cpp_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,9 @@ TEST(TestRosbag2CPPAPI, minimal_writer_example)
// See https://github.com/ros2/rosbag2/issues/448
rcpputils::fs::create_directories(rosbag_directory);

rosbag2_cpp::StorageOptions storage_options;
storage_options.uri = rosbag_directory.string();
storage_options.storage_id = "sqlite3";
storage_options.max_bagfile_size = 0; // default
storage_options.max_cache_size = 0; // default

{
rosbag2_cpp::Writer writer;
writer.open(storage_options);
writer.open(rosbag_directory.string());

auto bag_message = std::make_shared<rosbag2_storage::SerializedBagMessage>();
auto ret = rcutils_system_time_now(&bag_message->time_stamp);
Expand All @@ -78,7 +72,7 @@ TEST(TestRosbag2CPPAPI, minimal_writer_example)

{
rosbag2_cpp::Reader reader;
reader.open(storage_options);
reader.open(rosbag_directory.string());
while (reader.has_next()) {
auto bag_message = reader.read_next();

Expand Down

0 comments on commit c9bdbdd

Please sign in to comment.