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

Readable and Writable storage #18

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1427d7f
Fix build and uncrustify
botteroa-si Aug 2, 2018
ef2f8db
Add readable and writable storage interfaces
botteroa-si Aug 2, 2018
a924d48
Delete first storage interface proposal and adapt storage factory to …
botteroa-si Aug 2, 2018
099d89c
Modify test to work with new storage interfaces
botteroa-si Aug 2, 2018
95e6307
Prevent pluginlib from using boost
Martin-Idel-SI Aug 6, 2018
f757f39
Introduce better logging using rcutils in rosbag_storage
botteroa-si Aug 8, 2018
2a8b1fb
Add visibility control for Windows in rosbag_storage
botteroa-si Aug 7, 2018
7fd2593
Rename visibility_control.h to visibility_control.hpp
botteroa-si Aug 7, 2018
be92a5d
Fix package.xml in rosbag2_storage
botteroa-si Aug 8, 2018
9e70eb5
Cleanup CMakeLists in rosbag2_storage
Martin-Idel-SI Aug 7, 2018
695d5dd
Adapt read() and write() methods signature
botteroa-si Aug 2, 2018
800cb4a
Use void * instead of char * in rosbag_storage
botteroa-si Aug 8, 2018
cd129c4
Add storage facade for plugins which are both readable and writable
Martin-Idel-SI Aug 8, 2018
88977b1
Extract bag_info struct to own file
Martin-Idel-SI Aug 8, 2018
d9e33e3
Change storage interface to have read/write access
Martin-Idel-SI Aug 9, 2018
8410c7e
Add visibility to template specializations
Martin-Idel-SI Aug 10, 2018
4b806f4
Remove no longer necessary File install from CMakeLists.txt
botteroa-si Aug 10, 2018
e3e8fe9
Refactor storage_factory_impl.hpp
botteroa-si Aug 10, 2018
6f89010
Minor refactoring
botteroa-si Aug 10, 2018
bc1044e
Fix Windows warning
botteroa-si Aug 10, 2018
8eede3b
Add COLCON_IGNORE files to irrelevant projects
botteroa-si Aug 10, 2018
ef63977
Simpler class hierarchy without WritableStorage
Martin-Idel-SI Aug 13, 2018
568e1d9
Use exceptions instead of bool returns everywhere in interface
Martin-Idel-SI Aug 13, 2018
262f598
Change rosbag2_storage interface
Martin-Idel-SI Aug 13, 2018
177600f
Adapt sqlite3 plugin to new interface and extract rosbag2 part to own…
botteroa-si Aug 2, 2018
6564ac5
Update plugin_description.xml and write() method
botteroa-si Aug 8, 2018
d3f6f3f
Remove Sqlite dependencies from rosbag2 tests
botteroa-si Aug 7, 2018
7fb8bb8
Add tests to rosbag2_storage_default_plugins
botteroa-si Aug 7, 2018
9491cc3
Adapt interface and introduce better logging
botteroa-si Aug 8, 2018
81fb249
Adapt copyright and use copyright linter
Martin-Idel-SI Aug 9, 2018
a861461
Add plugin development documentation
Martin-Idel-SI Aug 6, 2018
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
Prev Previous commit
Next Next commit
Adapt interface and introduce better logging
  • Loading branch information
botteroa-si authored and Martin-Idel-SI committed Aug 13, 2018
commit 9491cc3675df5a7171596bae5a3d3477422c5913
22 changes: 15 additions & 7 deletions rosbag2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ endif()

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rcutils REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosbag2_storage REQUIRED)


add_library(librosbag
include/rosbag2/rosbag2.hpp
src/rosbag2/rosbag2.cpp)

ament_target_dependencies(librosbag rclcpp std_msgs rosbag2_storage)
target_link_libraries(librosbag)
ament_target_dependencies(librosbag rclcpp rcutils std_msgs rosbag2_storage)
target_include_directories(librosbag
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -38,7 +36,15 @@ target_link_libraries(${PROJECT_NAME}_record librosbag)

add_executable(${PROJECT_NAME}_play src/rosbag2/demo_play.cpp)
target_link_libraries(${PROJECT_NAME}_play librosbag)
# TODO(anhosi): Add install for library and headers (GH-5)

install(
DIRECTORY include/
DESTINATION include)

install(
TARGETS librosbag
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)

if(BUILD_TESTING)
# TODO(Martin-Idel-SI): Add copyright linter or use ament_lint_auto() once available
Expand All @@ -54,14 +60,16 @@ if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_gmock REQUIRED)

ament_add_gmock(rosbag2_write_integration_test test/rosbag2/rosbag2_write_integration_test.cpp
ament_add_gmock(rosbag2_write_integration_test
test/rosbag2/rosbag2_write_integration_test.cpp
test/rosbag2/rosbag2_test_fixture.hpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(TARGET rosbag2_write_integration_test)
target_link_libraries(rosbag2_write_integration_test librosbag)
endif()

ament_add_gmock(rosbag2_read_integration_test test/rosbag2/rosbag2_read_integration_test.cpp
ament_add_gmock(rosbag2_read_integration_test
test/rosbag2/rosbag2_read_integration_test.cpp
test/rosbag2/rosbag2_test_fixture.hpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(TARGET rosbag2_read_integration_test)
Expand Down
3 changes: 3 additions & 0 deletions rosbag2/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>rosbag2_storage</build_depend>
<build_depend>rcutils</build_depend>

<exec_depend>rosbag2_storage</exec_depend>
<exec_depend>rcutils</exec_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
25 changes: 12 additions & 13 deletions rosbag2/src/rosbag2/rosbag2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,54 @@
#include <string>

#include "rclcpp/rclcpp.hpp"
#include "rcutils/logging_macros.h"
#include "std_msgs/msg/string.hpp"

#include "rosbag2_storage/storage_factory.hpp"

namespace rosbag2
{

const char * ROS_PACKAGE_NAME = "rosbag2";

void Rosbag2::record(
const std::string & file_name,
const std::string & topic_name,
std::function<void(void)> after_write_action)
{
rosbag2_storage::StorageFactory factory;
std::unique_ptr<rosbag2_storage::WritableStorage> storage =
factory.get_for_writing("sqlite3", file_name);
auto storage =
factory.get_read_write_storage("sqlite3", file_name);
storage->create_topic();

if (storage) {
auto node = std::make_shared<rclcpp::Node>("rosbag_node");
auto subscription = node->create_subscription<std_msgs::msg::String>(
topic_name,
[&storage, after_write_action](std_msgs::msg::String::ConstSharedPtr msg) {
std::string message = msg->data;
void * data = &message;
storage->write(data, strlen(msg->data.c_str()));
storage->write(msg->data);
if (after_write_action) {
after_write_action();
}
});

// TODO(anhosi): use proper logging from rcutils
std::cout << "Waiting for messages..." << std::endl;
RCUTILS_LOG_INFO_NAMED(ROS_PACKAGE_NAME, "Waiting for messages...");
rclcpp::spin(node);
}
}

void Rosbag2::play(const std::string & file_name, const std::string & topic_name)
{
rosbag2_storage::StorageFactory factory;
std::unique_ptr<rosbag2_storage::ReadableStorage> storage =
factory.get_for_reading("sqlite3", file_name);
auto storage = factory.get_read_only_storage("sqlite3", file_name);

if (storage) {
char buffer[1000];
size_t size = 0;
auto node = std::make_shared<rclcpp::Node>("rosbag_publisher_node");
auto publisher = node->create_publisher<std_msgs::msg::String>(topic_name);
while (storage->read_next(buffer, size)) {
while (storage->has_next()) {
std::string message = storage->read_next();
auto string_msg = std_msgs::msg::String();
string_msg.data = buffer;
string_msg.data = message;
// without the sleep_for() many messages are lost.
std::this_thread::sleep_for(std::chrono::milliseconds(500));
publisher->publish(string_msg);
Expand Down
18 changes: 9 additions & 9 deletions rosbag2/test/rosbag2/rosbag2_test_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,13 @@ class Rosbag2TestFixture : public Test
{
std::vector<std::string> table_msgs;
rosbag2_storage::StorageFactory factory;
std::unique_ptr<rosbag2_storage::ReadableStorage> storage =
factory.get_for_reading("sqlite3", db_name);
auto storage =
factory.get_read_only_storage("sqlite3", db_name);

if (storage) {
char buffer[1000];
size_t size = 0;
while (storage->read_next(buffer, size)) {
table_msgs.emplace_back(buffer);
while (storage->has_next()) {
std::string message = storage->read_next();
table_msgs.emplace_back(message);
}
}
return table_msgs;
Expand All @@ -109,12 +108,13 @@ class Rosbag2TestFixture : public Test
void write_messages(const std::string & db_name, std::vector<std::string> messages)
{
rosbag2_storage::StorageFactory factory;
std::unique_ptr<rosbag2_storage::WritableStorage> storage =
factory.get_for_writing("sqlite3", db_name);
auto storage =
factory.get_read_write_storage("sqlite3", db_name);
storage->create_topic();

if (storage) {
for (auto msg : messages) {
storage->write(&msg, 0);
storage->write(msg);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rosbag2/test/rosbag2/rosbag2_write_integration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ TEST_F(RosBag2IntegrationTestFixture, published_messages_are_recorded)

auto recorded_messages = get_messages(database_name_);

ASSERT_THAT(recorded_messages, SizeIs(1));
ASSERT_THAT(recorded_messages, Not(IsEmpty()));
ASSERT_THAT(recorded_messages[0], Eq(message_to_publish));
}
36 changes: 29 additions & 7 deletions rosbag2_storage_default_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

find_package(ament_cmake REQUIRED)
find_package(sqlite3_vendor REQUIRED)
find_package(rosbag2_storage REQUIRED)
find_package(pluginlib REQUIRED)

find_package(rcutils REQUIRED)
find_package(rosbag2_storage REQUIRED)
find_package(sqlite3_vendor REQUIRED)
find_package(SQLite3 REQUIRED) # provided by sqlite3_vendor

add_library(${PROJECT_NAME} SHARED
Expand All @@ -28,8 +28,14 @@ add_library(${PROJECT_NAME} SHARED
src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.hpp
src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp)

ament_target_dependencies(${PROJECT_NAME} rclcpp std_msgs SQLite3 rosbag2_storage pluginlib)
target_link_libraries(${PROJECT_NAME})
ament_target_dependencies(${PROJECT_NAME}
rosbag2_storage
rclcpp
rcutils
std_msgs
SQLite3
pluginlib)

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down Expand Up @@ -60,16 +66,32 @@ if(BUILD_TESTING)

ament_add_gmock(sqlite_storage_test
test/rosbag2_storage_default_plugins/sqlite/sqlite_storage_test.cpp
src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp
src/rosbag2_storage_default_plugins/sqlite/sqlite_wrapper.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(TARGET sqlite_storage_test)
target_link_libraries(sqlite_storage_test ${PROJECT_NAME})
ament_target_dependencies(sqlite_storage_test
rosbag2_storage
rclcpp
rcutils
std_msgs
SQLite3
pluginlib)
endif()

ament_add_gmock(sqlite_storage_integration_test
test/rosbag2_storage_default_plugins/sqlite/sqlite_storage_integration_test.cpp
src/rosbag2_storage_default_plugins/sqlite/sqlite_storage.cpp
src/rosbag2_storage_default_plugins/sqlite/sqlite_wrapper.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(TARGET sqlite_storage_integration_test)
target_link_libraries(sqlite_storage_integration_test ${PROJECT_NAME})
ament_target_dependencies(sqlite_storage_integration_test
rosbag2_storage
rclcpp
rcutils
std_msgs
SQLite3
pluginlib)
endif()
endif()

Expand Down
3 changes: 2 additions & 1 deletion rosbag2_storage_default_plugins/package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>rosbag2_storage_default_plugins</name>
<version>0.0.0</version>
Expand All @@ -12,11 +11,13 @@
<build_depend>sqlite3_vendor</build_depend>
<build_depend>rclcpp</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>rcutils</build_depend>
<build_depend>rosbag2_storage</build_depend>

<exec_depend>sqlite3_vendor</exec_depend>
<exec_depend>rosbag2_storage</exec_depend>
<exec_depend>rclcpp</exec_depend>
<exec_depend>rcutils</exec_depend>
<exec_depend>std_msgs</exec_depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
10 changes: 1 addition & 9 deletions rosbag2_storage_default_plugins/plugin_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
<class
name="sqlite3"
type="rosbag2_storage_plugins::SqliteStorage"
base_class_type="rosbag2_storage::WritableStorage"
base_class_type="rosbag2_storage::ReadWriteStorage"
>
<description>Plugin to write to SQLite3 databases</description>
</class>

<class
name="sqlite3"
type="rosbag2_storage_plugins::SqliteStorage"
base_class_type="rosbag2_storage::ReadableStorage"
>
<description>Plugin to read from SQLite3 databases</description>
</class>
</library>
Loading