Skip to content

Commit

Permalink
Fix master build and small renamings (ros2#67)
Browse files Browse the repository at this point in the history
* ros2GH-143 Fix master build after merge of PR 66

- Detail: avoid | in regexp as this is not portable.

* ros2GH-143 Rename cpp_type_support to rmw_type_support

* ros2GH-143 rename ros2_message_t to introspection_message_t
  • Loading branch information
anhosi authored and Karsten1987 committed Nov 29, 2018
1 parent 5c1045d commit f5f9b5a
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 81 deletions.
4 changes: 2 additions & 2 deletions rosbag2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ add_library(${PROJECT_NAME} SHARED
src/rosbag2/serialization_format_converter_factory.cpp
src/rosbag2/typesupport_helpers.cpp
src/rosbag2/writer.cpp
src/rosbag2/types/ros2_message.cpp)
src/rosbag2/types/introspection_message.cpp)

ament_target_dependencies(${PROJECT_NAME}
ament_index_cpp
Expand Down Expand Up @@ -125,7 +125,7 @@ if(BUILD_TESTING)
ament_add_gmock(test_ros2_message
test/rosbag2/types/test_ros2_message.cpp
src/rosbag2/typesupport_helpers.cpp
src/rosbag2/types/ros2_message.cpp)
src/rosbag2/types/introspection_message.cpp)
if(TARGET test_ros2_message)
target_compile_definitions(test_ros2_message PRIVATE "ROSBAG2_BUILDING_DLL")
if(NOT DISABLE_SANITIZERS)
Expand Down
2 changes: 1 addition & 1 deletion rosbag2/include/rosbag2/converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace rosbag2
// Only used internally.
struct ConverterTypeSupport
{
const rosidl_message_type_support_t * cpp_type_support;
const rosidl_message_type_support_t * rmw_type_support;
const rosidl_message_type_support_t * introspection_type_support;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <memory>
#include <string>

#include "rosbag2/types/ros2_message.hpp"
#include "rosbag2/types/introspection_message.hpp"
#include "rosbag2/types.hpp"
#include "rcutils/types.h"
#include "rosbag2_storage/serialized_bag_message.hpp"
Expand All @@ -35,10 +35,10 @@ class SerializationFormatConverterInterface
virtual void deserialize(
std::shared_ptr<const rosbag2::SerializedBagMessage> serialized_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2_ros2_message_t> ros_message) = 0;
std::shared_ptr<rosbag2_introspection_message_t> ros_message) = 0;

virtual void serialize(
std::shared_ptr<const rosbag2_ros2_message_t> ros_message,
std::shared_ptr<const rosbag2_introspection_message_t> ros_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2::SerializedBagMessage> serialized_message) = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ROSBAG2__TYPES__ROS2_MESSAGE_HPP_
#define ROSBAG2__TYPES__ROS2_MESSAGE_HPP_
#ifndef ROSBAG2__TYPES__INTROSPECTION_MESSAGE_HPP_
#define ROSBAG2__TYPES__INTROSPECTION_MESSAGE_HPP_

#include <memory>

Expand All @@ -23,7 +23,7 @@
#include "rcutils/allocator.h"
#include "rosbag2/visibility_control.hpp"

typedef struct rosbag2_ros2_message_t
typedef struct rosbag2_introspection_message_t
{
void * message;
char * topic_name;
Expand All @@ -35,12 +35,13 @@ namespace rosbag2
{

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

ROSBAG2_PUBLIC
void ros2_message_set_topic_name(rosbag2_ros2_message_t * msg, const char * topic_name);
void introspection_message_set_topic_name(
rosbag2_introspection_message_t * msg, const char * topic_name);

ROSBAG2_PUBLIC
void allocate_internal_types(
Expand All @@ -59,8 +60,8 @@ void allocate_vector(
void * data, const rosidl_typesupport_introspection_cpp::MessageMember & member);

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

ROSBAG2_PUBLIC
Expand All @@ -81,4 +82,4 @@ void cleanup_vector(

} // namespace rosbag2

#endif // ROSBAG2__TYPES__ROS2_MESSAGE_HPP_
#endif // ROSBAG2__TYPES__INTROSPECTION_MESSAGE_HPP_
8 changes: 4 additions & 4 deletions rosbag2/src/rosbag2/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ Converter::~Converter()
std::shared_ptr<SerializedBagMessage> Converter::convert(
std::shared_ptr<const rosbag2::SerializedBagMessage> message)
{
auto ts = topics_and_types_.at(message->topic_name).cpp_type_support;
auto ts = topics_and_types_.at(message->topic_name).rmw_type_support;
auto introspection_ts = topics_and_types_.at(message->topic_name).introspection_type_support;
auto allocator = rcutils_get_default_allocator();
std::shared_ptr<rosbag2_ros2_message_t> allocated_ros_message =
allocate_ros2_message(introspection_ts, &allocator);
std::shared_ptr<rosbag2_introspection_message_t> allocated_ros_message =
allocate_introspection_message(introspection_ts, &allocator);

input_converter_->deserialize(message, ts, allocated_ros_message);
auto output_message = std::make_shared<rosbag2::SerializedBagMessage>();
Expand All @@ -80,7 +80,7 @@ std::shared_ptr<SerializedBagMessage> Converter::convert(
void Converter::add_topic(const std::string & topic, const std::string & type)
{
ConverterTypeSupport type_support;
type_support.cpp_type_support = get_typesupport(type, "rosidl_typesupport_cpp");
type_support.rmw_type_support = get_typesupport(type, "rosidl_typesupport_cpp");
type_support.introspection_type_support =
get_typesupport(type, "rosidl_typesupport_introspection_cpp");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "rosbag2/types/ros2_message.hpp"
#include "rosbag2/types/introspection_message.hpp"

#include <memory>
#include <string>
Expand All @@ -26,27 +26,28 @@
namespace rosbag2
{

std::shared_ptr<rosbag2_ros2_message_t>
allocate_ros2_message(
std::shared_ptr<rosbag2_introspection_message_t>
allocate_introspection_message(
const rosidl_message_type_support_t * introspection_ts, const rcutils_allocator_t * allocator)
{
auto intro_ts_members = static_cast<const rosidl_typesupport_introspection_cpp::MessageMembers *>(
introspection_ts->data);
auto raw_ros2_message = new rosbag2_ros2_message_t();
auto raw_ros2_message = new rosbag2_introspection_message_t();
raw_ros2_message->allocator = *allocator;
raw_ros2_message->topic_name = nullptr;
raw_ros2_message->message = raw_ros2_message->allocator.zero_allocate(
1, intro_ts_members->size_of_, raw_ros2_message->allocator.state);
// TODO(Martin-Idel-SI): Use custom allocator to make sure all memory is obtained that way
allocate_internal_types(raw_ros2_message->message, intro_ts_members);

auto deleter = [intro_ts_members](rosbag2_ros2_message_t * msg) {
deallocate_ros2_message(msg, intro_ts_members);
auto deleter = [intro_ts_members](rosbag2_introspection_message_t * msg) {
deallocate_introspection_message(msg, intro_ts_members);
};
return std::shared_ptr<rosbag2_ros2_message_t>(raw_ros2_message, deleter);
return std::shared_ptr<rosbag2_introspection_message_t>(raw_ros2_message, deleter);
}

void ros2_message_set_topic_name(rosbag2_ros2_message_t * msg, const char * topic_name)
void introspection_message_set_topic_name(
rosbag2_introspection_message_t * msg, const char * topic_name)
{
if (msg->topic_name) {
msg->allocator.deallocate(msg->topic_name, msg->allocator.state);
Expand All @@ -55,8 +56,8 @@ void ros2_message_set_topic_name(rosbag2_ros2_message_t * msg, const char * topi
msg->topic_name = rcutils_strdup(topic_name, msg->allocator);
}

void deallocate_ros2_message(
rosbag2_ros2_message_t * msg,
void deallocate_introspection_message(
rosbag2_introspection_message_t * msg,
const rosidl_typesupport_introspection_cpp::MessageMembers * members)
{
deallocate_internal_types(msg->message, members);
Expand Down
4 changes: 2 additions & 2 deletions rosbag2/test/rosbag2/converter_test_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
void ConverterTestPlugin::deserialize(
const std::shared_ptr<const rosbag2::SerializedBagMessage> serialized_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2_ros2_message_t> ros_message)
std::shared_ptr<rosbag2_introspection_message_t> ros_message)
{
(void) ros_message;
(void) serialized_message;
(void) type_support;
}

void ConverterTestPlugin::serialize(
const std::shared_ptr<const rosbag2_ros2_message_t> ros_message,
const std::shared_ptr<const rosbag2_introspection_message_t> ros_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2::SerializedBagMessage> serialized_message)
{
Expand Down
4 changes: 2 additions & 2 deletions rosbag2/test/rosbag2/converter_test_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class ConverterTestPlugin : public rosbag2::SerializationFormatConverterInterfac
void deserialize(
std::shared_ptr<const rosbag2::SerializedBagMessage> serialized_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2_ros2_message_t> ros_message) override;
std::shared_ptr<rosbag2_introspection_message_t> ros_message) override;

void serialize(
std::shared_ptr<const rosbag2_ros2_message_t> ros_message,
std::shared_ptr<const rosbag2_introspection_message_t> ros_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2::SerializedBagMessage> serialized_message) override;
};
Expand Down
2 changes: 1 addition & 1 deletion rosbag2/test/rosbag2/mock_converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MockConverter : public rosbag2::SerializationFormatConverterInterface

MOCK_METHOD3(serialize,
void(
std::shared_ptr<const rosbag2_ros2_message_t>,
std::shared_ptr<const rosbag2_introspection_message_t>,
const rosidl_message_type_support_t *,
std::shared_ptr<rosbag2::SerializedBagMessage>));
};
Expand Down
10 changes: 5 additions & 5 deletions rosbag2/test/rosbag2/types/test_ros2_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <vector>

#include "rosbag2/typesupport_helpers.hpp"
#include "rosbag2/types/ros2_message.hpp"
#include "rosbag2/types/introspection_message.hpp"
#include "test_msgs/msg/bounded_array_nested.hpp"
#include "test_msgs/msg/bounded_array_primitives_nested.hpp"
#include "test_msgs/msg/bounded_array_primitives.hpp"
Expand Down Expand Up @@ -52,7 +52,7 @@ class Ros2MessageTest : public Test
auto introspection_ts =
rosbag2::get_typesupport(message_type, "rosidl_typesupport_introspection_cpp");

return rosbag2::allocate_ros2_message(introspection_ts, &allocator_);
return rosbag2::allocate_introspection_message(introspection_ts, &allocator_);
}

rcutils_allocator_t allocator_;
Expand Down Expand Up @@ -208,16 +208,16 @@ TEST_F(Ros2MessageTest, allocate_ros2_message_allocates_nested_bounded_array_nes
TEST_F(Ros2MessageTest, allocate_ros2_message_cleans_up_topic_name_on_shutdown) {
auto message = get_allocated_message("test_msgs/BoundedArrayNested");

rosbag2::ros2_message_set_topic_name(message.get(), "Topic name");
rosbag2::introspection_message_set_topic_name(message.get(), "Topic name");

EXPECT_THAT(message->topic_name, StrEq("Topic name"));
}

TEST_F(Ros2MessageTest, duplicate_set_topic_does_not_leak) {
auto message = get_allocated_message("test_msgs/BoundedArrayNested");

rosbag2::ros2_message_set_topic_name(message.get(), "Topic name");
rosbag2::ros2_message_set_topic_name(message.get(), "Topic name");
rosbag2::introspection_message_set_topic_name(message.get(), "Topic name");
rosbag2::introspection_message_set_topic_name(message.get(), "Topic name");

EXPECT_THAT(message->topic_name, StrEq("Topic name"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "Poco/SharedLibrary.h"

#include "rcutils/strdup.h"
#include "rosbag2/types/introspection_message.hpp"
#include "rosidl_generator_cpp/message_type_support_decl.hpp"

#include "../logging.hpp"

Expand Down Expand Up @@ -96,28 +98,29 @@ CdrConverter::CdrConverter()
void CdrConverter::deserialize(
const std::shared_ptr<const rosbag2::SerializedBagMessage> serialized_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2_ros2_message_t> ros_message)
std::shared_ptr<rosbag2_introspection_message_t> introspection_message)
{
rosbag2::ros2_message_set_topic_name(ros_message.get(), serialized_message->topic_name.c_str());
ros_message->time_stamp = serialized_message->time_stamp;
rosbag2::introspection_message_set_topic_name(
introspection_message.get(), serialized_message->topic_name.c_str());
introspection_message->time_stamp = serialized_message->time_stamp;

auto ret =
deserialize_fcn_(serialized_message->serialized_data.get(), type_support, ros_message->message);
auto ret = deserialize_fcn_(
serialized_message->serialized_data.get(), type_support, introspection_message->message);
if (ret != RMW_RET_OK) {
ROSBAG2_CONVERTER_DEFAULT_PLUGINS_LOG_ERROR("Failed to deserialize message.");
}
}

void CdrConverter::serialize(
const std::shared_ptr<const rosbag2_ros2_message_t> ros_message,
const std::shared_ptr<const rosbag2_introspection_message_t> introspection_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2::SerializedBagMessage> serialized_message)
{
serialized_message->topic_name = std::string(ros_message->topic_name);
serialized_message->time_stamp = ros_message->time_stamp;
serialized_message->topic_name = std::string(introspection_message->topic_name);
serialized_message->time_stamp = introspection_message->time_stamp;

auto ret = serialize_fcn_(
ros_message->message, type_support, serialized_message->serialized_data.get());
introspection_message->message, type_support, serialized_message->serialized_data.get());
if (ret != RMW_RET_OK) {
ROSBAG2_CONVERTER_DEFAULT_PLUGINS_LOG_ERROR("Failed to serialize message.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

#include "rmw/types.h"

#include "rosidl_generator_cpp/message_type_support_decl.hpp"
#include "rosbag2/serialization_format_converter_interface.hpp"
#include "rosbag2/types/introspection_message.hpp"

namespace rosbag2_converter_default_plugins
{
Expand All @@ -33,10 +35,10 @@ class CdrConverter : public rosbag2::SerializationFormatConverterInterface
void deserialize(
std::shared_ptr<const rosbag2::SerializedBagMessage> serialized_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2_ros2_message_t> ros_message) override;
std::shared_ptr<rosbag2_introspection_message_t> introspection_message) override;

void serialize(
std::shared_ptr<const rosbag2_ros2_message_t> ros_message,
std::shared_ptr<const rosbag2_introspection_message_t> introspection_message,
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2::SerializedBagMessage> serialized_message) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "rcutils/strdup.h"
#include "rosbag2/serialization_format_converter_interface.hpp"
#include "rosbag2/typesupport_helpers.hpp"
#include "rosbag2/types/introspection_message.hpp"
#include "rosbag2_test_common/memory_management.hpp"
#include "test_msgs/message_fixtures.hpp"

Expand All @@ -40,16 +41,16 @@ class CdrConverterTestFixture : public Test
allocator_ = rcutils_get_default_allocator();
}

std::shared_ptr<rosbag2_ros2_message_t> make_shared_ros_message(
std::shared_ptr<rosbag2_introspection_message_t> make_shared_ros_message(
const std::string & topic_name = "")
{
auto ros_message = std::make_shared<rosbag2_ros2_message_t>();
auto ros_message = std::make_shared<rosbag2_introspection_message_t>();
ros_message->time_stamp = 0;
ros_message->message = nullptr;
ros_message->allocator = allocator_;

if (!topic_name.empty()) {
rosbag2::ros2_message_set_topic_name(ros_message.get(), topic_name.c_str());
rosbag2::introspection_message_set_topic_name(ros_message.get(), topic_name.c_str());
}

return ros_message;
Expand Down
15 changes: 8 additions & 7 deletions rosbag2_tests/test/rosbag2_tests/test_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "rcutils/strdup.h"
#include "rosbag2/serialization_format_converter_factory.hpp"
#include "rosbag2/typesupport_helpers.hpp"
#include "rosbag2/types/ros2_message.hpp"
#include "rosbag2/types/introspection_message.hpp"
#include "rosbag2_test_common/memory_management.hpp"
#include "test_msgs/message_fixtures.hpp"

Expand All @@ -42,17 +42,18 @@ class ConverterTestFixture : public Test
rosbag2::get_typesupport("test_msgs/DynamicArrayNested", "rosidl_typesupport_cpp");
}

std::shared_ptr<rosbag2_ros2_message_t> allocate_empty_dynamic_array_message()
std::shared_ptr<rosbag2_introspection_message_t> allocate_empty_dynamic_array_message()
{
auto introspection_type_support = rosbag2::get_typesupport(
"test_msgs/DynamicArrayNested", "rosidl_typesupport_introspection_cpp");
auto ros_message = rosbag2::allocate_ros2_message(introspection_type_support, &allocator_);
ros_message->time_stamp = 1;
rosbag2::ros2_message_set_topic_name(ros_message.get(), topic_name_.c_str());
return ros_message;
auto introspection_message =
rosbag2::allocate_introspection_message(introspection_type_support, &allocator_);
introspection_message->time_stamp = 1;
rosbag2::introspection_message_set_topic_name(introspection_message.get(), topic_name_.c_str());
return introspection_message;
}

void fill_dynamic_array_message(std::shared_ptr<rosbag2_ros2_message_t> message)
void fill_dynamic_array_message(std::shared_ptr<rosbag2_introspection_message_t> message)
{
auto correctly_typed_ros_message =
reinterpret_cast<test_msgs::msg::DynamicArrayNested *>(message->message);
Expand Down
Loading

0 comments on commit f5f9b5a

Please sign in to comment.