Skip to content

Commit

Permalink
Replace poco dependency by rcutils (#322)
Browse files Browse the repository at this point in the history
* Replaced poco with rcpputils

Signed-off-by: ahcorde <[email protected]>

* catch bad alloc exception

Signed-off-by: ahcorde <[email protected]>

* Fixed merge with master

Signed-off-by: ahcorde <[email protected]>

* Avoid catch bad_alloc in SharedLibrary - let it throw

Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde authored Apr 4, 2020
1 parent 59c90c8 commit 17b3d8e
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 69 deletions.
7 changes: 2 additions & 5 deletions rosbag2_converter_default_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ endif()

find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(poco_vendor REQUIRED)
find_package(Poco COMPONENTS Foundation)
find_package(pluginlib REQUIRED)
find_package(rcutils REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rmw REQUIRED)
find_package(rmw_fastrtps_cpp QUIET)
find_package(rosbag2_cpp REQUIRED)
Expand All @@ -38,8 +36,7 @@ if(rmw_fastrtps_cpp_FOUND)
ament_target_dependencies(${PROJECT_NAME}
ament_index_cpp
pluginlib
Poco
rcutils
rcpputils
rmw
rosbag2_cpp
rosidl_generator_cpp)
Expand Down
5 changes: 2 additions & 3 deletions rosbag2_converter_default_plugins/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@

<depend>ament_index_cpp</depend>
<depend>pluginlib</depend>
<depend>poco_vendor</depend>
<depend>rosidl_generator_cpp</depend>
<depend>rcutils</depend>
<depend>rcpputils</depend>
<depend>rmw</depend>
<depend>rmw_fastrtps_cpp</depend>
<depend>rosbag2_cpp</depend>

<test_depend>ament_cmake_gmock</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>rcutils</test_depend>
<test_depend>rcpputils</test_depend>
<test_depend>rmw_fastrtps_cpp</test_depend>
<test_depend>rosbag2_cpp</test_depend>
<test_depend>rosbag2_test_common</test_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#include "ament_index_cpp/get_resources.hpp"
#include "ament_index_cpp/get_package_prefix.hpp"

#include "Poco/SharedLibrary.h"

#include "rcpputils/shared_library.hpp"
#include "rcutils/strdup.h"

#include "rosbag2_cpp/types.hpp"
Expand Down Expand Up @@ -63,37 +62,36 @@ std::string get_package_library_path(const std::string & package_name)
CdrConverter::CdrConverter()
{
auto library_path = get_package_library_path("rmw_fastrtps_cpp");
std::shared_ptr<Poco::SharedLibrary> library;
try {
library = std::make_shared<Poco::SharedLibrary>(library_path);
} catch (Poco::LibraryLoadException &) {
library = std::make_shared<rcpputils::SharedLibrary>(library_path);
} catch (std::runtime_error &) {
throw std::runtime_error(
std::string("poco exception: library could not be found:") + library_path);
}

std::string serialize_symbol = "rmw_serialize";
std::string deserialize_symbol = "rmw_deserialize";

if (!library->hasSymbol(serialize_symbol)) {
throw std::runtime_error(
std::string("poco exception: symbol not found: ") + serialize_symbol);
if (!library->has_symbol(serialize_symbol.c_str())) {
throw std::runtime_error{std::string("rcutils exception: symbol not found: ") +
serialize_symbol};
}

if (!library->hasSymbol(deserialize_symbol)) {
throw std::runtime_error(
std::string("poco exception: symbol not found: ") + deserialize_symbol);
if (!library->has_symbol(deserialize_symbol.c_str())) {
throw std::runtime_error{
std::string("rcutils exception: symbol not found: ") + deserialize_symbol};
}

serialize_fcn_ = (decltype(serialize_fcn_))library->getSymbol(serialize_symbol);
serialize_fcn_ = (decltype(serialize_fcn_))library->get_symbol(serialize_symbol.c_str());
if (!serialize_fcn_) {
throw std::runtime_error(
std::string("poco exception: symbol of wrong type: ") + serialize_symbol);
throw std::runtime_error{
std::string("rcutils exception: symbol of wrong type: ") + serialize_symbol};
}

deserialize_fcn_ = (decltype(deserialize_fcn_))library->getSymbol(deserialize_symbol);
deserialize_fcn_ = (decltype(deserialize_fcn_))library->get_symbol(deserialize_symbol.c_str());
if (!deserialize_fcn_) {
throw std::runtime_error(
std::string("poco exception: symbol of wrong type: ") + deserialize_symbol);
throw std::runtime_error{
std::string("rcutils exception: symbol of wrong type: ") + deserialize_symbol};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "rosidl_generator_cpp/message_type_support_decl.hpp"

#include "rcpputils/shared_library.hpp"

#include "rosbag2_cpp/converter_interfaces/serialization_format_converter.hpp"
#include "rosbag2_cpp/types.hpp"

Expand All @@ -43,6 +45,9 @@ class CdrConverter : public rosbag2_cpp::converter_interfaces::SerializationForm
const rosidl_message_type_support_t * type_support,
std::shared_ptr<rosbag2_storage::SerializedBagMessage> serialized_message) override;

private:
std::shared_ptr<rcpputils::SharedLibrary> library;

protected:
rmw_ret_t (* serialize_fcn_)(
const void *,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <memory>
#include <string>

#include "rcpputils/shared_library.hpp"
#include "rcutils/strdup.h"

#include "rosbag2_cpp/converter_interfaces/serialization_format_converter.hpp"
Expand Down Expand Up @@ -77,8 +78,9 @@ TEST_F(CdrConverterTestFixture, deserialize_converts_cdr_into_ros_message_for_pr
auto ros_message = make_shared_ros_message();
test_msgs::msg::BasicTypes primitive_test_msg;
ros_message->message = &primitive_test_msg;
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/BasicTypes", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/BasicTypes", "rosidl_typesupport_cpp", library);

converter_->deserialize(serialized_message, type_support, ros_message);

Expand All @@ -96,8 +98,9 @@ TEST_F(CdrConverterTestFixture, serialize_converts_ros_message_into_cdr_for_prim

auto serialized_message = std::make_shared<rosbag2_storage::SerializedBagMessage>();
serialized_message->serialized_data = memory_management_->make_initialized_message();
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/BasicTypes", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/BasicTypes", "rosidl_typesupport_cpp", library);

converter_->serialize(ros_message, type_support, serialized_message);

Expand All @@ -119,8 +122,9 @@ TEST_F(CdrConverterTestFixture, deserialize_converts_cdr_into_ros_message_for_st
auto ros_message = make_shared_ros_message();
test_msgs::msg::Strings string_test_msg;
ros_message->message = &string_test_msg;
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/Strings", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/Strings", "rosidl_typesupport_cpp", library);

converter_->deserialize(serialized_message, type_support, ros_message);

Expand All @@ -138,8 +142,9 @@ TEST_F(CdrConverterTestFixture, serialize_converts_ros_message_into_cdr_for_stri

auto serialized_message = std::make_shared<rosbag2_storage::SerializedBagMessage>();
serialized_message->serialized_data = memory_management_->make_initialized_message();
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/Strings", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/Strings", "rosidl_typesupport_cpp", library);

converter_->serialize(ros_message, type_support, serialized_message);

Expand All @@ -161,8 +166,9 @@ TEST_F(CdrConverterTestFixture, deserialize_converts_cdr_into_ros_message_for_ws
auto ros_message = make_shared_ros_message();
test_msgs::msg::WStrings wstring_test_msg;
ros_message->message = &wstring_test_msg;
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/WStrings", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/WStrings", "rosidl_typesupport_cpp", library);

converter_->deserialize(serialized_message, type_support, ros_message);

Expand All @@ -180,8 +186,9 @@ TEST_F(CdrConverterTestFixture, serialize_converts_ros_message_into_cdr_for_wstr

auto serialized_message = std::make_shared<rosbag2_storage::SerializedBagMessage>();
serialized_message->serialized_data = memory_management_->make_initialized_message();
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/WStrings", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/WStrings", "rosidl_typesupport_cpp", library);

converter_->serialize(ros_message, type_support, serialized_message);

Expand All @@ -203,8 +210,9 @@ TEST_F(CdrConverterTestFixture, deserialize_converts_cdr_into_ros_message_for_st
auto ros_message = make_shared_ros_message();
test_msgs::msg::Arrays primitive_test_msg;
ros_message->message = &primitive_test_msg;
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/Arrays", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/Arrays", "rosidl_typesupport_cpp", library);

converter_->deserialize(serialized_message, type_support, ros_message);

Expand All @@ -222,8 +230,9 @@ TEST_F(CdrConverterTestFixture, serialize_converts_ros_message_into_cdr_for_stat

auto serialized_message = std::make_shared<rosbag2_storage::SerializedBagMessage>();
serialized_message->serialized_data = memory_management_->make_initialized_message();
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/Arrays", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/Arrays", "rosidl_typesupport_cpp", library);

converter_->serialize(ros_message, type_support, serialized_message);

Expand All @@ -245,8 +254,9 @@ TEST_F(CdrConverterTestFixture, deserialize_converts_cdr_into_ros_message_for_un
auto ros_message = make_shared_ros_message();
test_msgs::msg::UnboundedSequences dynamic_nested_message;
ros_message->message = &dynamic_nested_message;
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/UnboundedSequences", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/UnboundedSequences", "rosidl_typesupport_cpp", library);

converter_->deserialize(serialized_message, type_support, ros_message);

Expand All @@ -265,8 +275,9 @@ TEST_F(CdrConverterTestFixture, serialize_converts_ros_message_into_cdr_for_unbo

auto serialized_message = std::make_shared<rosbag2_storage::SerializedBagMessage>();
serialized_message->serialized_data = memory_management_->make_initialized_message();
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/UnboundedSequences", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/UnboundedSequences", "rosidl_typesupport_cpp", library);

converter_->serialize(ros_message, type_support, serialized_message);

Expand All @@ -288,8 +299,9 @@ TEST_F(CdrConverterTestFixture, deserialize_converts_cdr_into_ros_message_for_mu
auto ros_message = make_shared_ros_message();
test_msgs::msg::MultiNested multi_nested_message;
ros_message->message = &multi_nested_message;
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/MultiNested", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/MultiNested", "rosidl_typesupport_cpp", library);

converter_->deserialize(serialized_message, type_support, ros_message);

Expand All @@ -307,8 +319,9 @@ TEST_F(CdrConverterTestFixture, serialize_converts_ros_message_into_cdr_for_mult

auto serialized_message = std::make_shared<rosbag2_storage::SerializedBagMessage>();
serialized_message->serialized_data = memory_management_->make_initialized_message();
std::shared_ptr<rcpputils::SharedLibrary> library;
auto type_support =
rosbag2_cpp::get_typesupport("test_msgs/MultiNested", "rosidl_typesupport_cpp");
rosbag2_cpp::get_typesupport("test_msgs/MultiNested", "rosidl_typesupport_cpp", library);

converter_->serialize(ros_message, type_support, serialized_message);

Expand Down
6 changes: 1 addition & 5 deletions rosbag2_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(pluginlib REQUIRED)
find_package(poco_vendor)
find_package(Poco COMPONENTS Foundation)
find_package(rcpputils REQUIRED)
find_package(rcutils REQUIRED)
find_package(rosbag2_storage REQUIRED)
Expand All @@ -54,7 +52,6 @@ add_library(${PROJECT_NAME} SHARED
ament_target_dependencies(${PROJECT_NAME}
ament_index_cpp
pluginlib
Poco
rcpputils
rcutils
rosbag2_storage
Expand Down Expand Up @@ -160,8 +157,7 @@ if(BUILD_TESTING)
$<INSTALL_INTERFACE:include>)
ament_target_dependencies(test_ros2_message
ament_index_cpp
Poco
rcutils
rcpputils
rosbag2_storage
rosidl_generator_cpp
rosidl_typesupport_introspection_cpp
Expand Down
4 changes: 4 additions & 0 deletions rosbag2_cpp/include/rosbag2_cpp/converter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include "rosbag2_storage/serialized_bag_message.hpp"

#include "rcpputils/shared_library.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.
Expand Down Expand Up @@ -82,6 +84,8 @@ class ROSBAG2_CPP_PUBLIC Converter
std::unique_ptr<converter_interfaces::SerializationFormatDeserializer> input_converter_;
std::unique_ptr<converter_interfaces::SerializationFormatSerializer> output_converter_;
std::unordered_map<std::string, ConverterTypeSupport> topics_and_types_;
std::shared_ptr<rcpputils::SharedLibrary> library_rosidl_typesupport_cpp_;
std::shared_ptr<rcpputils::SharedLibrary> library_rosidl_typesupport_introspection_cpp_;
};

} // namespace rosbag2_cpp
Expand Down
7 changes: 6 additions & 1 deletion rosbag2_cpp/include/rosbag2_cpp/typesupport_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@
#include <string>
#include <tuple>
#include <utility>
#include <memory>

#include "rosbag2_cpp/visibility_control.hpp"

#include "rcpputils/shared_library.hpp"

#include "rosidl_generator_cpp/message_type_support_decl.hpp"

namespace rosbag2_cpp
{

ROSBAG2_CPP_PUBLIC
const rosidl_message_type_support_t *
get_typesupport(const std::string & type, const std::string & typesupport_identifier);
get_typesupport(
const std::string & type, const std::string & typesupport_identifier,
std::shared_ptr<rcpputils::SharedLibrary> & library);

ROSBAG2_CPP_PUBLIC
const std::tuple<std::string, std::string, std::string>
Expand Down
1 change: 0 additions & 1 deletion rosbag2_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<depend>ament_index_cpp</depend>
<depend>pluginlib</depend>
<depend>poco_vendor</depend>
<depend>rcutils</depend>
<depend>rosbag2_storage</depend>
<depend>rosidl_generator_cpp</depend>
Expand Down
8 changes: 6 additions & 2 deletions rosbag2_cpp/src/rosbag2_cpp/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ std::shared_ptr<rosbag2_storage::SerializedBagMessage> Converter::convert(
void Converter::add_topic(const std::string & topic, const std::string & type)
{
ConverterTypeSupport type_support;
type_support.rmw_type_support = get_typesupport(type, "rosidl_typesupport_cpp");
type_support.rmw_type_support = get_typesupport(
type, "rosidl_typesupport_cpp",
library_rosidl_typesupport_cpp_);
type_support.introspection_type_support =
get_typesupport(type, "rosidl_typesupport_introspection_cpp");
get_typesupport(
type, "rosidl_typesupport_introspection_cpp",
library_rosidl_typesupport_introspection_cpp_);

topics_and_types_.insert({topic, type_support});
}
Expand Down
Loading

0 comments on commit 17b3d8e

Please sign in to comment.