Skip to content

Commit

Permalink
Merge pull request #218 from ros2/pr203
Browse files Browse the repository at this point in the history
split rmw_fastrtps_cpp into static and dynamic rmw impl
  • Loading branch information
dirk-thomas authored Jul 25, 2018
2 parents 7d3ff15 + 9c45384 commit 8f6a13c
Show file tree
Hide file tree
Showing 181 changed files with 10,229 additions and 2,356 deletions.
2 changes: 1 addition & 1 deletion fastrtps_cmake_module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
# Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fastrtps_cmake_module/cmake/Modules/FindFastRTPS.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
# Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion fastrtps_cmake_module/fastrtps_cmake_module-extras.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
# Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
24 changes: 12 additions & 12 deletions rmw_fastrtps_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
# Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@ endif()
find_package(ament_cmake_ros REQUIRED)

find_package(rcutils REQUIRED)
find_package(rmw_fastrtps_shared_cpp REQUIRED)

find_package(fastrtps_cmake_module REQUIRED)
find_package(fastcdr REQUIRED CONFIG)
Expand All @@ -36,14 +37,12 @@ find_package(FastRTPS REQUIRED MODULE)

find_package(rmw REQUIRED)
find_package(rosidl_generator_c REQUIRED)
find_package(rosidl_typesupport_introspection_c REQUIRED)
find_package(rosidl_typesupport_introspection_cpp REQUIRED)
find_package(rosidl_typesupport_fastrtps_c REQUIRED)
find_package(rosidl_typesupport_fastrtps_cpp REQUIRED)

include_directories(include)

add_library(rmw_fastrtps_cpp
src/client_service_common.cpp
src/demangle.cpp
src/get_client.cpp
src/get_participant.cpp
src/get_publisher.cpp
Expand Down Expand Up @@ -76,7 +75,6 @@ add_library(rmw_fastrtps_cpp
src/rmw_trigger_guard_condition.cpp
src/rmw_wait.cpp
src/rmw_wait_set.cpp
src/ros_message_serialization.cpp
src/type_support_common.cpp
)
target_link_libraries(rmw_fastrtps_cpp
Expand All @@ -85,8 +83,9 @@ target_link_libraries(rmw_fastrtps_cpp
# specific order: dependents before dependencies
ament_target_dependencies(rmw_fastrtps_cpp
"rcutils"
"rosidl_typesupport_introspection_c"
"rosidl_typesupport_introspection_cpp"
"rosidl_typesupport_fastrtps_c"
"rosidl_typesupport_fastrtps_cpp"
"rmw_fastrtps_shared_cpp"
"rmw"
"rosidl_generator_c"
)
Expand All @@ -102,15 +101,16 @@ PRIVATE "RMW_FASTRTPS_CPP_BUILDING_LIBRARY")
ament_export_include_directories(include)
ament_export_libraries(rmw_fastrtps_cpp)

ament_export_dependencies(rosidl_typesupport_introspection_cpp)
ament_export_dependencies(rosidl_typesupport_introspection_c)
ament_export_dependencies(rosidl_typesupport_fastrtps_cpp)
ament_export_dependencies(rosidl_typesupport_fastrtps_c)
ament_export_dependencies(rosidl_generator_c)
ament_export_dependencies(rcutils)
ament_export_dependencies(rmw_fastrtps_shared_cpp)
ament_export_dependencies(rmw)

register_rmw_implementation(
"c:rosidl_typesupport_c:rosidl_typesupport_introspection_c"
"cpp:rosidl_typesupport_cpp:rosidl_typesupport_introspection_cpp")
"c:rosidl_typesupport_c:rosidl_typesupport_fastrtps_c"
"cpp:rosidl_typesupport_cpp:rosidl_typesupport_fastrtps_cpp")

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
Expand Down
17 changes: 4 additions & 13 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/MessageTypeSupport.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
// Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,28 +15,19 @@
#ifndef RMW_FASTRTPS_CPP__MESSAGETYPESUPPORT_HPP_
#define RMW_FASTRTPS_CPP__MESSAGETYPESUPPORT_HPP_

#include <fastcdr/FastBuffer.h>
#include <fastcdr/Cdr.h>

#include <cassert>
#include <memory>
#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h"

#include "TypeSupport.hpp"
#include "rosidl_typesupport_introspection_cpp/message_introspection.hpp"
#include "rosidl_typesupport_introspection_cpp/field_types.hpp"

namespace rmw_fastrtps_cpp
{

template<typename MembersType>
class MessageTypeSupport : public TypeSupport<MembersType>
class MessageTypeSupport : public TypeSupport
{
public:
explicit MessageTypeSupport(const MembersType * members);
explicit MessageTypeSupport(const message_type_support_callbacks_t * members);
};

} // namespace rmw_fastrtps_cpp

#include "MessageTypeSupport_impl.hpp"

#endif // RMW_FASTRTPS_CPP__MESSAGETYPESUPPORT_HPP_
23 changes: 9 additions & 14 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/ServiceTypeSupport.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
// Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -19,37 +19,32 @@
#include <fastcdr/Cdr.h>
#include <cassert>

#include "TypeSupport.hpp"
#include "rosidl_typesupport_introspection_cpp/field_types.hpp"
#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h"
#include "rosidl_typesupport_fastrtps_cpp/service_type_support.h"

struct CustomServiceInfo;
#include "TypeSupport.hpp"

namespace rmw_fastrtps_cpp
{

template<typename MembersType>
class ServiceTypeSupport : public TypeSupport<MembersType>
class ServiceTypeSupport : public TypeSupport
{
protected:
ServiceTypeSupport();
};

template<typename ServiceMembersType, typename MessageMembersType>
class RequestTypeSupport : public ServiceTypeSupport<MessageMembersType>
class RequestTypeSupport : public ServiceTypeSupport
{
public:
explicit RequestTypeSupport(const ServiceMembersType * members);
explicit RequestTypeSupport(const service_type_support_callbacks_t * members);
};

template<typename ServiceMembersType, typename MessageMembersType>
class ResponseTypeSupport : public ServiceTypeSupport<MessageMembersType>
class ResponseTypeSupport : public ServiceTypeSupport
{
public:
explicit ResponseTypeSupport(const ServiceMembersType * members);
explicit ResponseTypeSupport(const service_type_support_callbacks_t * members);
};

} // namespace rmw_fastrtps_cpp

#include "ServiceTypeSupport_impl.hpp"

#endif // RMW_FASTRTPS_CPP__SERVICETYPESUPPORT_HPP_
140 changes: 7 additions & 133 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
// Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,118 +25,14 @@
#include <cassert>
#include <string>

#include "rcutils/logging_macros.h"
#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h"

#include "rosidl_typesupport_introspection_cpp/field_types.hpp"
#include "rosidl_typesupport_introspection_cpp/identifier.hpp"
#include "rosidl_typesupport_introspection_cpp/message_introspection.hpp"
#include "rosidl_typesupport_introspection_cpp/service_introspection.hpp"
#include "rosidl_typesupport_introspection_cpp/visibility_control.h"

#include "rosidl_typesupport_introspection_c/field_types.h"
#include "rosidl_typesupport_introspection_c/identifier.h"
#include "rosidl_typesupport_introspection_c/message_introspection.h"
#include "rosidl_typesupport_introspection_c/service_introspection.h"
#include "rosidl_typesupport_introspection_c/visibility_control.h"
#include "rmw_fastrtps_shared_cpp/TypeSupport.hpp"

namespace rmw_fastrtps_cpp
{

// Publishers write method will receive a pointer to this struct
struct SerializedData
{
bool is_cdr_buffer; // Whether next field is a pointer to a Cdr or to a plain ros message
void * data;
};

// Helper class that uses template specialization to read/write string types to/from a
// eprosima::fastcdr::Cdr
template<typename MembersType>
struct StringHelper;

// For C introspection typesupport we create intermediate instances of std::string so that
// eprosima::fastcdr::Cdr can handle the string properly.
template<>
struct StringHelper<rosidl_typesupport_introspection_c__MessageMembers>
{
using type = rosidl_generator_c__String;

static size_t next_field_align(void * data, size_t current_alignment)
{
auto c_string = static_cast<rosidl_generator_c__String *>(data);
if (!c_string) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_fastrtps_cpp",
"Failed to cast data as rosidl_generator_c__String")
return current_alignment;
}
if (!c_string->data) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_fastrtps_cpp",
"rosidl_generator_c_String had invalid data")
return current_alignment;
}

current_alignment += eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
current_alignment += 4;
return current_alignment + strlen(c_string->data) + 1;
}

static std::string convert_to_std_string(void * data)
{
auto c_string = static_cast<rosidl_generator_c__String *>(data);
if (!c_string) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_fastrtps_cpp",
"Failed to cast data as rosidl_generator_c__String")
return "";
}
if (!c_string->data) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_fastrtps_cpp",
"rosidl_generator_c_String had invalid data")
return "";
}
return std::string(c_string->data);
}

static std::string convert_to_std_string(rosidl_generator_c__String & data)
{
return std::string(data.data);
}

static void assign(eprosima::fastcdr::Cdr & deser, void * field, bool)
{
std::string str;
deser >> str;
rosidl_generator_c__String * c_str = static_cast<rosidl_generator_c__String *>(field);
rosidl_generator_c__String__assign(c_str, str.c_str());
}
};

// For C++ introspection typesupport we just reuse the same std::string transparently.
template<>
struct StringHelper<rosidl_typesupport_introspection_cpp::MessageMembers>
{
using type = std::string;

static std::string & convert_to_std_string(void * data)
{
return *(static_cast<std::string *>(data));
}

static void assign(eprosima::fastcdr::Cdr & deser, void * field, bool call_new)
{
std::string & str = *(std::string *)field;
if (call_new) {
new(&str) std::string;
}
deser >> str;
}
};

template<typename MembersType>
class TypeSupport : public eprosima::fastrtps::TopicDataType
class TypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport
{
public:
size_t getEstimatedSerializedSize(const void * ros_message);
Expand All @@ -145,38 +41,16 @@ class TypeSupport : public eprosima::fastrtps::TopicDataType

bool deserializeROSmessage(eprosima::fastcdr::Cdr & deser, void * ros_message);

bool serialize(void * data, eprosima::fastrtps::rtps::SerializedPayload_t * payload);

bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t * payload, void * data);

std::function<uint32_t()> getSerializedSizeProvider(void * data);

void * createData();

void deleteData(void * data);

protected:
TypeSupport();

size_t calculateMaxSerializedSize(const MembersType * members, size_t current_alignment);

const MembersType * members_;
bool max_size_bound_;
void set_members(const message_type_support_callbacks_t * members);

private:
size_t getEstimatedSerializedSize(
const MembersType * members, const void * ros_message, size_t current_alignment);

bool serializeROSmessage(
eprosima::fastcdr::Cdr & ser, const MembersType * members, const void * ros_message);

bool deserializeROSmessage(
eprosima::fastcdr::Cdr & deser, const MembersType * members, void * ros_message,
bool call_new);
const message_type_support_callbacks_t * members_;
bool has_data_;
};

} // namespace rmw_fastrtps_cpp

#include "TypeSupport_impl.hpp"

#endif // RMW_FASTRTPS_CPP__TYPESUPPORT_HPP_
2 changes: 1 addition & 1 deletion rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/identifier.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
// Copyright 2016-2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 8f6a13c

Please sign in to comment.