Skip to content

Commit

Permalink
Refs #3019. Changes for static typesupport on rmw_fastrtps_cpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelCompany committed Jun 12, 2018
1 parent a50cc27 commit b09afa8
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 1,280 deletions.
17 changes: 8 additions & 9 deletions rmw_fastrtps_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ 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)

Expand Down Expand Up @@ -75,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 @@ -84,8 +83,8 @@ 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,16 +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
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include <memory>

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

namespace rmw_fastrtps_cpp
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,12 @@
#include <string>

#include "rmw_fastrtps_cpp/MessageTypeSupport.hpp"
#include "rosidl_typesupport_introspection_cpp/field_types.hpp"

namespace rmw_fastrtps_cpp
{

template<typename MembersType>
MessageTypeSupport<MembersType>::MessageTypeSupport(const MembersType * members)
{
assert(members);
this->members_ = members;

std::string name = std::string(members->package_name_) + "::msg::dds_::" +
members->message_name_ + "_";
this->setName(name.c_str());

// TODO(wjwwood): this could be more intelligent, setting m_typeSize to the
// maximum serialized size of the message, when the message is a bounded one.
if (members->member_count_ != 0) {
this->m_typeSize = static_cast<uint32_t>(this->calculateMaxSerializedSize(members, 0));
} else {
this->m_typeSize = 4;
}
}
template<>
MessageTypeSupport<message_type_support_callbacks_t>::MessageTypeSupport(const message_type_support_callbacks_t * members);

} // namespace rmw_fastrtps_cpp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include <cassert>

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

struct CustomServiceInfo;

namespace rmw_fastrtps_cpp
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <string>

#include "rmw_fastrtps_cpp/ServiceTypeSupport.hpp"
#include "rosidl_typesupport_introspection_cpp/field_types.hpp"

namespace rmw_fastrtps_cpp
{
Expand All @@ -31,45 +30,13 @@ ServiceTypeSupport<MembersType>::ServiceTypeSupport()
{
}

template<typename ServiceMembersType, typename MessageMembersType>
RequestTypeSupport<ServiceMembersType, MessageMembersType>::RequestTypeSupport(
const ServiceMembersType * members)
{
assert(members);
this->members_ = members->request_members_;

std::string name = std::string(members->package_name_) + "::srv::dds_::" +
members->service_name_ + "_Request_";
this->setName(name.c_str());

// TODO(wjwwood): this could be more intelligent, setting m_typeSize to the
// maximum serialized size of the message, when the message is a bounded one.
if (this->members_->member_count_ != 0) {
this->m_typeSize = static_cast<uint32_t>(this->calculateMaxSerializedSize(this->members_, 0));
} else {
this->m_typeSize = 4;
}
}
template<>
RequestTypeSupport<service_type_support_callbacks_t, message_type_support_callbacks_t>::RequestTypeSupport(
const service_type_support_callbacks_t * members);

template<typename ServiceMembersType, typename MessageMembersType>
ResponseTypeSupport<ServiceMembersType, MessageMembersType>::ResponseTypeSupport(
const ServiceMembersType * members)
{
assert(members);
this->members_ = members->response_members_;

std::string name = std::string(members->package_name_) + "::srv::dds_::" +
members->service_name_ + "_Response_";
this->setName(name.c_str());

// TODO(wjwwood): this could be more intelligent, setting m_typeSize to the
// maximum serialized size of the message, when the message is a bounded one.
if (this->members_->member_count_ != 0) {
this->m_typeSize = static_cast<uint32_t>(this->calculateMaxSerializedSize(this->members_, 0));
} else {
this->m_typeSize = 4;
}
}
template<>
ResponseTypeSupport<service_type_support_callbacks_t, message_type_support_callbacks_t>::ResponseTypeSupport(
const service_type_support_callbacks_t * members);

} // namespace rmw_fastrtps_cpp

Expand Down
89 changes: 2 additions & 87 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,94 +27,16 @@

#include "rcutils/logging_macros.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"

namespace rmw_fastrtps_cpp
{

// 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 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;
}
};
class TypeSupport;

template<typename MembersType>
class TypeSupport : public eprosima::fastrtps::TopicDataType
{
public:
bool serializeROSmessage(const void * ros_message, eprosima::fastcdr::Cdr & ser);

bool deserializeROSmessage(eprosima::fastcdr::FastBuffer * data, void * ros_message);

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

bool deserialize(eprosima::fastrtps::rtps::SerializedPayload_t * payload, void * data);
Expand All @@ -131,14 +53,7 @@ class TypeSupport : public eprosima::fastrtps::TopicDataType
size_t calculateMaxSerializedSize(const MembersType * members, size_t current_alignment);

const MembersType * members_;

private:
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);
bool max_size_bound_;
};

} // namespace rmw_fastrtps_cpp
Expand Down
Loading

0 comments on commit b09afa8

Please sign in to comment.