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

Use converters when playing back files #56

Merged
merged 29 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e30b5ce
GH-112 Open storage for reading handing in rmw_identifier
Martin-Idel-SI Oct 24, 2018
2e9f6c9
GH-113 Cleanup: better naming
anhosi Oct 25, 2018
d017279
GH-113 Introduce interface for StorageFactory to allow mocks in tests
anhosi Oct 25, 2018
d7c7572
GH-113 Add test for SequentialReader for using converters
anhosi Oct 25, 2018
f086bb5
GH-113 Implement skeleton convert function
anhosi Oct 25, 2018
4aa25ce
GH-113 Implement allocate_ros2_message
anhosi Oct 26, 2018
b2b97e5
GH-113 Fix DynamicArrayNested deallocation
anhosi Oct 26, 2018
43833e6
GH-113 Add test for BoundedArrayNested deallocation
anhosi Oct 26, 2018
565beb2
GH-113 Refactoring of deallocation code
anhosi Oct 26, 2018
da808af
GH-113 Fix string initialization in all types
Martin-Idel-SI Oct 29, 2018
faac84a
GH-113 Fix vector<bool> initialization
Martin-Idel-SI Oct 29, 2018
87f94dc
GH-113 Add test for deallocation of topic name + Refactoring
Martin-Idel-SI Oct 29, 2018
9565c6c
GH-113 Minor refactoring of converter
Martin-Idel-SI Oct 29, 2018
92c69e8
GH-113 Make sure to throw an error if converters do not exist
Martin-Idel-SI Oct 29, 2018
0b5ab69
GH-113 Delete superfluous imports
Martin-Idel-SI Oct 29, 2018
8ad6af7
GH-113 Small fix for deleting vectors
Martin-Idel-SI Oct 29, 2018
eb1d1d2
GH-113 Fix build after rebase
botteroa-si Nov 9, 2018
13f2e70
GH-30 Minor refactoring
botteroa-si Nov 13, 2018
74602cd
GH-30 Give an allocator as parameter to allocate_ros2_message()
botteroa-si Nov 13, 2018
647d6f0
GH-111 Add missing test dependencies for CDR converter test
botteroa-si Nov 14, 2018
9071440
GH-128 Extend message allocation test to also cover big strings
anhosi Nov 15, 2018
9e1cb19
GH-128 Add tests for nested arrays
anhosi Nov 15, 2018
e5d1460
GH-128 always initialize vectors with a placement new
anhosi Nov 15, 2018
0253dfc
pass by ref
Karsten1987 Nov 21, 2018
8317066
use new getter functions
Karsten1987 Nov 21, 2018
740e820
consistent function naming
Karsten1987 Nov 21, 2018
bdfe850
uncrustify
Karsten1987 Nov 21, 2018
aec25aa
GH-30 Fix windows build
anhosi Nov 21, 2018
6b58674
use visibility macros on all functions
Karsten1987 Nov 23, 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
25 changes: 22 additions & 3 deletions rosbag2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ find_package(Poco COMPONENTS Foundation)
find_package(rcutils REQUIRED)
find_package(rosbag2_storage REQUIRED)
find_package(rosidl_generator_cpp REQUIRED)
find_package(rosidl_typesupport_cpp REQUIRED)
find_package(rosidl_typesupport_introspection_cpp REQUIRED)

add_library(${PROJECT_NAME} SHARED
src/rosbag2/converter.cpp
src/rosbag2/info.cpp
src/rosbag2/sequential_reader.cpp
src/rosbag2/serialization_format_converter_factory.cpp
src/rosbag2/typesupport_helpers.cpp
src/rosbag2/writer.cpp)
src/rosbag2/writer.cpp
src/rosbag2/types/ros2_message.cpp)

ament_target_dependencies(${PROJECT_NAME}
ament_index_cpp
Expand All @@ -38,6 +42,8 @@ ament_target_dependencies(${PROJECT_NAME}
rcutils
rosbag2_storage
rosidl_generator_cpp
rosidl_typesupport_introspection_cpp
rosidl_typesupport_cpp
)

target_include_directories(${PROJECT_NAME}
Expand Down Expand Up @@ -65,11 +71,12 @@ install(

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(rosbag2_storage)
ament_export_dependencies(rosbag2_storage rosidl_typesupport_introspection_cpp)

if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
find_package(ament_lint_auto REQUIRED)
find_package(test_msgs REQUIRED)
ament_lint_auto_find_test_dependencies()

add_library(
Expand Down Expand Up @@ -100,12 +107,24 @@ if(BUILD_TESTING)

ament_add_gmock(test_info
test/rosbag2/test_info.cpp
test/rosbag2/mock_metadata_io.hpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(TARGET test_info)
target_link_libraries(test_info rosbag2)
ament_target_dependencies(test_info rosbag2_test_common)
endif()

ament_add_gmock(test_sequential_reader
test/rosbag2/test_sequential_reader.cpp)
if(TARGET test_sequential_reader)
target_link_libraries(test_sequential_reader rosbag2)
endif()

ament_add_gmock(test_ros2_message
test/rosbag2/types/test_ros2_message.cpp)
if(TARGET test_ros2_message)
target_link_libraries(test_ros2_message rosbag2)
ament_target_dependencies(test_ros2_message test_msgs)
endif()
endif()

ament_package()
72 changes: 72 additions & 0 deletions rosbag2/include/rosbag2/converter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2018, Bosch Software Innovations GmbH.
//
// 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__CONVERTER_HPP_
#define ROSBAG2__CONVERTER_HPP_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "rosbag2/serialization_format_converter_factory.hpp"
#include "rosbag2/serialization_format_converter_factory_interface.hpp"
#include "rosbag2/serialization_format_converter_interface.hpp"
#include "rosbag2/types.hpp"
#include "rosbag2/visibility_control.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
{
class ROSBAG2_PUBLIC Converter
{
public:
explicit
Converter(
const std::string & input_format,
const std::string & output_format,
const std::vector<TopicWithType> & topics_and_types,
std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory =
std::make_shared<SerializationFormatConverterFactory>());

~Converter();

/**
* Converts the given SerializedBagMessage into the output format of the converter. The
* serialization format of the input message must be identical to the input format of the
* converter.
*
* \param message Message to convert
* \returns Converted message
*/
std::shared_ptr<SerializedBagMessage>
convert(std::shared_ptr<const SerializedBagMessage> message);

private:
std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory_;
std::unique_ptr<SerializationFormatConverterInterface> input_converter_;
std::unique_ptr<SerializationFormatConverterInterface> output_converter_;
std::map<std::string, std::string> topics_and_types_;
};

} // namespace rosbag2

#endif // ROSBAG2__CONVERTER_HPP_
22 changes: 20 additions & 2 deletions rosbag2/include/rosbag2/sequential_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#include <vector>

#include "rosbag2_storage/storage_factory.hpp"
#include "rosbag2_storage/storage_factory_interface.hpp"
#include "rosbag2_storage/storage_interfaces/read_only_interface.hpp"
#include "rosbag2/converter.hpp"
#include "rosbag2/serialization_format_converter_factory.hpp"
#include "rosbag2/serialization_format_converter_factory_interface.hpp"
#include "rosbag2/storage_options.hpp"
#include "rosbag2/types.hpp"
#include "rosbag2/visibility_control.hpp"
Expand All @@ -42,16 +46,27 @@ namespace rosbag2
class ROSBAG2_PUBLIC SequentialReader
{
public:
explicit
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>());
virtual ~SequentialReader();

/**
* Open a rosbag for reading messages sequentially (time-ordered). Throws if file could not be
* opened. This must be called before any other function is used. The rosbag is
* automatically closed on destruction.
*
* If the rmw_serialization_format is not the same as the format of the underlying storage, a
* converter will be used to automatically convert the functions. Throws if the converter
* plugin does not exist
*
* \param options Options to configure the storage
* \param rmw_serialization_format Messages will be serialized in this format
*/
virtual void open(const StorageOptions & options);
virtual void open(const StorageOptions & options, const std::string & rmw_serialization_format);

/**
* Ask whether the underlying bagfile contains at least one more message.
Expand All @@ -63,6 +78,7 @@ class ROSBAG2_PUBLIC SequentialReader

/**
* Read next message from storage. Will throw if no more messages are available.
* The message will be serialized in the format given to `open`.
*
* Expected usage:
* if (writer.has_next()) message = writer.read_next();
Expand All @@ -81,8 +97,10 @@ class ROSBAG2_PUBLIC SequentialReader
virtual std::vector<TopicWithType> get_all_topics_and_types();

private:
rosbag2_storage::StorageFactory factory_;
std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory_;
std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory_;
std::shared_ptr<rosbag2_storage::storage_interfaces::ReadOnlyInterface> storage_;
std::unique_ptr<Converter> converter_;
};

} // namespace rosbag2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ROSBAG2_PUBLIC SerializationFormatConverterFactory

~SerializationFormatConverterFactory() override;

std::shared_ptr<SerializationFormatConverterInterface>
std::unique_ptr<SerializationFormatConverterInterface>
load_converter(const std::string & format) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ROSBAG2_PUBLIC SerializationFormatConverterFactoryInterface
public:
virtual ~SerializationFormatConverterFactoryInterface() = default;

virtual std::shared_ptr<SerializationFormatConverterInterface>
virtual std::unique_ptr<SerializationFormatConverterInterface>
load_converter(const std::string & format) = 0;
};

Expand Down
52 changes: 52 additions & 0 deletions rosbag2/include/rosbag2/types/ros2_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
#ifndef ROSBAG2__TYPES__ROS2_MESSAGE_HPP_
#define ROSBAG2__TYPES__ROS2_MESSAGE_HPP_

#include <memory>

#include "rosidl_typesupport_introspection_cpp/message_introspection.hpp"
#include "rosidl_typesupport_cpp/message_type_support.hpp"
#include "rcutils/time.h"
#include "rcutils/allocator.h"
#include "rosbag2/visibility_control.hpp"

typedef struct rosbag2_ros2_message_t
{
Expand All @@ -26,4 +31,51 @@ typedef struct rosbag2_ros2_message_t
rcutils_allocator_t allocator;
} rosbag2_ros2_message_t;

namespace rosbag2
{

ROSBAG2_PUBLIC
std::shared_ptr<rosbag2_ros2_message_t>
allocate_ros2_message(
const rosidl_message_type_support_t * introspection_ts, const rcutils_allocator_t * allocator);

ROSBAG2_PUBLIC
void allocate_internal_types(
void * msg, const rosidl_typesupport_introspection_cpp::MessageMembers * members);

ROSBAG2_PUBLIC
void allocate_element(
void * data, const rosidl_typesupport_introspection_cpp::MessageMember & member);

ROSBAG2_PUBLIC
void allocate_array(
void * data, const rosidl_typesupport_introspection_cpp::MessageMember & member);

ROSBAG2_PUBLIC
void allocate_vector(
void * data, const rosidl_typesupport_introspection_cpp::MessageMember & member);

ROSBAG2_PUBLIC
void deallocate_ros2_message(
rosbag2_ros2_message_t * msg,
const rosidl_typesupport_introspection_cpp::MessageMembers * members);

ROSBAG2_PUBLIC
void deallocate_internal_types(
void * msg, const rosidl_typesupport_introspection_cpp::MessageMembers * members);

ROSBAG2_PUBLIC
void cleanup_element(
void * data, const rosidl_typesupport_introspection_cpp::MessageMember & member);

ROSBAG2_PUBLIC
void cleanup_array(
void * data, const rosidl_typesupport_introspection_cpp::MessageMember & member);

ROSBAG2_PUBLIC
void cleanup_vector(
void * data, const rosidl_typesupport_introspection_cpp::MessageMember & member);

} // namespace rosbag2

#endif // ROSBAG2__TYPES__ROS2_MESSAGE_HPP_
3 changes: 2 additions & 1 deletion rosbag2/include/rosbag2/typesupport_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace rosbag2
{

ROSBAG2_PUBLIC
const rosidl_message_type_support_t * get_typesupport(const std::string & type);
const rosidl_message_type_support_t *
get_typesupport(const std::string & type, const std::string & typesupport_identifier);

ROSBAG2_PUBLIC
const std::pair<std::string, std::string> extract_type_and_package(const std::string & full_type);
Expand Down
7 changes: 6 additions & 1 deletion rosbag2/include/rosbag2/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string>

#include "rosbag2_storage/storage_factory.hpp"
#include "rosbag2_storage/storage_factory_interface.hpp"
#include "rosbag2_storage/storage_interfaces/read_write_interface.hpp"
#include "rosbag2/storage_options.hpp"
#include "rosbag2/types.hpp"
Expand All @@ -42,6 +43,10 @@ namespace rosbag2
class ROSBAG2_PUBLIC Writer
{
public:
explicit
Writer(
std::unique_ptr<rosbag2_storage::StorageFactoryInterface> factory =
std::make_unique<rosbag2_storage::StorageFactory>());
virtual ~Writer();

/**
Expand Down Expand Up @@ -71,7 +76,7 @@ class ROSBAG2_PUBLIC Writer

private:
std::string uri_;
rosbag2_storage::StorageFactory factory_;
std::unique_ptr<rosbag2_storage::StorageFactoryInterface> factory_;
std::shared_ptr<rosbag2_storage::storage_interfaces::ReadWriteInterface> storage_;
};

Expand Down
2 changes: 2 additions & 0 deletions rosbag2/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<depend>rcutils</depend>
<depend>rosbag2_storage</depend>
<depend>rosidl_generator_cpp</depend>
<depend>rosidl_typesupport_cpp</depend>
<depend>rosidl_typesupport_introspection_cpp</depend>
<depend>shared_queues_vendor</depend>

<test_depend>ament_cmake_gmock</test_depend>
Expand Down
Loading