Skip to content

Commit

Permalink
Passing down type support information (#342)
Browse files Browse the repository at this point in the history
* Add rmw implementation specific pointer.

Signed-off-by: Miguel Company <[email protected]>

* Changes on rmw_serialize

Signed-off-by: Miguel Company <[email protected]>

* Changes for publishers

Signed-off-by: Miguel Company <[email protected]>

* Changes for subscriptions

Signed-off-by: Miguel Company <[email protected]>

* Changes for services and clients.

Signed-off-by: Miguel Company <[email protected]>

* Solving linters

Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany authored and hidmic committed Jan 14, 2020
1 parent 465d15e commit 3e0aea7
Show file tree
Hide file tree
Showing 28 changed files with 90 additions and 192 deletions.
8 changes: 5 additions & 3 deletions rmw_fastrtps_cpp/include/rmw_fastrtps_cpp/TypeSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ namespace rmw_fastrtps_cpp
class TypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport
{
public:
size_t getEstimatedSerializedSize(const void * ros_message);
size_t getEstimatedSerializedSize(const void * ros_message, const void * impl);

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

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

protected:
TypeSupport();
Expand Down
3 changes: 3 additions & 0 deletions rmw_fastrtps_cpp/src/rmw_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ rmw_create_client(
response_members = static_cast<const message_type_support_callbacks_t *>(
service_members->response_members_->data);

info->request_type_support_impl_ = request_members;
info->response_type_support_impl_ = response_members;

std::string request_type_name = _create_type_name(request_members);
std::string response_type_name = _create_type_name(response_members);

Expand Down
1 change: 1 addition & 0 deletions rmw_fastrtps_cpp/src/rmw_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ rmw_create_publisher(
}

info->typesupport_identifier_ = type_support->typesupport_identifier;
info->type_support_impl_ = type_support->data;

auto callbacks = static_cast<const message_type_support_callbacks_t *>(type_support->data);
std::string type_name = _create_type_name(callbacks);
Expand Down
6 changes: 3 additions & 3 deletions rmw_fastrtps_cpp/src/rmw_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rmw_serialize(

auto callbacks = static_cast<const message_type_support_callbacks_t *>(ts->data);
auto tss = new MessageTypeSupport_cpp(callbacks);
auto data_length = tss->getEstimatedSerializedSize(ros_message);
auto data_length = tss->getEstimatedSerializedSize(ros_message, callbacks);
if (serialized_message->buffer_capacity < data_length) {
if (rmw_serialized_message_resize(serialized_message, data_length) != RMW_RET_OK) {
RMW_SET_ERROR_MSG("unable to dynamically resize serialized message");
Expand All @@ -54,7 +54,7 @@ rmw_serialize(
eprosima::fastcdr::Cdr ser(
buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);

auto ret = tss->serializeROSmessage(ros_message, ser);
auto ret = tss->serializeROSmessage(ros_message, ser, callbacks);
serialized_message->buffer_length = data_length;
serialized_message->buffer_capacity = data_length;
delete tss;
Expand Down Expand Up @@ -85,7 +85,7 @@ rmw_deserialize(
eprosima::fastcdr::Cdr deser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);

auto ret = tss->deserializeROSmessage(deser, ros_message);
auto ret = tss->deserializeROSmessage(deser, ros_message, callbacks);
delete tss;
return ret == true ? RMW_RET_OK : RMW_RET_ERROR;
}
Expand Down
3 changes: 3 additions & 0 deletions rmw_fastrtps_cpp/src/rmw_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ rmw_create_service(
response_members = static_cast<const message_type_support_callbacks_t *>(
service_members->response_members_->data);

info->request_type_support_impl_ = request_members;
info->response_type_support_impl_ = response_members;

std::string request_type_name = _create_type_name(request_members);
std::string response_type_name = _create_type_name(response_members);

Expand Down
1 change: 1 addition & 0 deletions rmw_fastrtps_cpp/src/rmw_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ rmw_create_subscription(
}

info->typesupport_identifier_ = type_support->typesupport_identifier;
info->type_support_impl_ = type_support->data;

auto callbacks = static_cast<const message_type_support_callbacks_t *>(type_support->data);
std::string type_name = _create_type_name(callbacks);
Expand Down
36 changes: 0 additions & 36 deletions rmw_fastrtps_cpp/src/ros_message_serialization.cpp

This file was deleted.

42 changes: 0 additions & 42 deletions rmw_fastrtps_cpp/src/ros_message_serialization.hpp

This file was deleted.

21 changes: 15 additions & 6 deletions rmw_fastrtps_cpp/src/type_support_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,54 @@ void TypeSupport::set_members(const message_type_support_callbacks_t * members)
m_typeSize = 4 + data_size;
}

size_t TypeSupport::getEstimatedSerializedSize(const void * ros_message)
size_t TypeSupport::getEstimatedSerializedSize(const void * ros_message, const void * impl)
{
if (max_size_bound_) {
return m_typeSize;
}

assert(ros_message);
assert(impl);

auto callbacks = static_cast<const message_type_support_callbacks_t *>(impl);

// Encapsulation size + message size
return 4 + members_->get_serialized_size(ros_message);
return 4 + callbacks->get_serialized_size(ros_message);
}

bool TypeSupport::serializeROSmessage(const void * ros_message, eprosima::fastcdr::Cdr & ser)
bool TypeSupport::serializeROSmessage(
const void * ros_message, eprosima::fastcdr::Cdr & ser, const void * impl)
{
assert(ros_message);
assert(impl);

// Serialize encapsulation
ser.serialize_encapsulation();

// If type is not empty, serialize message
if (has_data_) {
return members_->cdr_serialize(ros_message, ser);
auto callbacks = static_cast<const message_type_support_callbacks_t *>(impl);
return callbacks->cdr_serialize(ros_message, ser);
}

// Otherwise, add a dummy byte
ser << (uint8_t)0;
return true;
}

bool TypeSupport::deserializeROSmessage(eprosima::fastcdr::Cdr & deser, void * ros_message)
bool TypeSupport::deserializeROSmessage(
eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl)
{
assert(ros_message);
assert(impl);

// Deserialize encapsulation.
deser.read_encapsulation();

// If type is not empty, deserialize message
if (has_data_) {
return members_->cdr_deserialize(deser, ros_message);
auto callbacks = static_cast<const message_type_support_callbacks_t *>(impl);
return callbacks->cdr_deserialize(deser, ros_message);
}

// Otherwise, consume dummy byte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ template<typename MembersType>
class TypeSupport : public rmw_fastrtps_shared_cpp::TypeSupport
{
public:
size_t getEstimatedSerializedSize(const void * ros_message);
size_t getEstimatedSerializedSize(const void * ros_message, const void * impl);

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

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

protected:
TypeSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,19 +1116,21 @@ size_t TypeSupport<MembersType>::calculateMaxSerializedSize(

template<typename MembersType>
size_t TypeSupport<MembersType>::getEstimatedSerializedSize(
const void * ros_message)
const void * ros_message, const void * impl)
{
if (max_size_bound_) {
return m_typeSize;
}

assert(ros_message);
assert(impl);

// Encapsulation size
size_t ret_val = 4;

if (members_->member_count_ != 0) {
ret_val += TypeSupport::getEstimatedSerializedSize(members_, ros_message, 0);
auto members = static_cast<const MembersType *>(impl);
if (members->member_count_ != 0) {
ret_val += TypeSupport::getEstimatedSerializedSize(members, ros_message, 0);
} else {
ret_val += 1;
}
Expand All @@ -1138,15 +1140,17 @@ size_t TypeSupport<MembersType>::getEstimatedSerializedSize(

template<typename MembersType>
bool TypeSupport<MembersType>::serializeROSmessage(
const void * ros_message, eprosima::fastcdr::Cdr & ser)
const void * ros_message, eprosima::fastcdr::Cdr & ser, const void * impl)
{
assert(ros_message);
assert(impl);

// Serialize encapsulation
ser.serialize_encapsulation();

if (members_->member_count_ != 0) {
TypeSupport::serializeROSmessage(ser, members_, ros_message);
auto members = static_cast<const MembersType *>(impl);
if (members->member_count_ != 0) {
TypeSupport::serializeROSmessage(ser, members, ros_message);
} else {
ser << (uint8_t)0;
}
Expand All @@ -1156,15 +1160,17 @@ bool TypeSupport<MembersType>::serializeROSmessage(

template<typename MembersType>
bool TypeSupport<MembersType>::deserializeROSmessage(
eprosima::fastcdr::Cdr & deser, void * ros_message)
eprosima::fastcdr::Cdr & deser, void * ros_message, const void * impl)
{
assert(ros_message);
assert(impl);

// Deserialize encapsulation.
deser.read_encapsulation();

if (members_->member_count_ != 0) {
TypeSupport::deserializeROSmessage(deser, members_, ros_message, false);
auto members = static_cast<const MembersType *>(impl);
if (members->member_count_ != 0) {
TypeSupport::deserializeROSmessage(deser, members, ros_message, false);
} else {
uint8_t dump = 0;
deser >> dump;
Expand Down
3 changes: 3 additions & 0 deletions rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ rmw_create_client(
untyped_response_members = get_response_ptr(type_support->data,
info->typesupport_identifier_);

info->request_type_support_impl_ = untyped_request_members;
info->response_type_support_impl_ = untyped_response_members;

std::string request_type_name = _create_type_name(untyped_request_members,
info->typesupport_identifier_);
std::string response_type_name = _create_type_name(untyped_response_members,
Expand Down
1 change: 1 addition & 0 deletions rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ rmw_create_publisher(
return nullptr;
}
info->typesupport_identifier_ = type_support->typesupport_identifier;
info->type_support_impl_ = type_support->data;

std::string type_name = _create_type_name(
type_support->data, info->typesupport_identifier_);
Expand Down
6 changes: 3 additions & 3 deletions rmw_fastrtps_dynamic_cpp/src/rmw_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rmw_serialize(
}

auto tss = _create_message_type_support(ts->data, ts->typesupport_identifier);
auto data_length = tss->getEstimatedSerializedSize(ros_message);
auto data_length = tss->getEstimatedSerializedSize(ros_message, ts->data);
if (serialized_message->buffer_capacity < data_length) {
if (rmw_serialized_message_resize(serialized_message, data_length) != RMW_RET_OK) {
RMW_SET_ERROR_MSG("unable to dynamically resize serialized message");
Expand All @@ -54,7 +54,7 @@ rmw_serialize(
eprosima::fastcdr::Cdr ser(
buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR);

auto ret = tss->serializeROSmessage(ros_message, ser);
auto ret = tss->serializeROSmessage(ros_message, ser, ts->data);
serialized_message->buffer_length = data_length;
serialized_message->buffer_capacity = data_length;
delete tss;
Expand Down Expand Up @@ -84,7 +84,7 @@ rmw_deserialize(
eprosima::fastcdr::Cdr deser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
eprosima::fastcdr::Cdr::DDS_CDR);

auto ret = tss->deserializeROSmessage(deser, ros_message);
auto ret = tss->deserializeROSmessage(deser, ros_message, ts->data);
delete tss;
return ret == true ? RMW_RET_OK : RMW_RET_ERROR;
}
Expand Down
3 changes: 3 additions & 0 deletions rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ rmw_create_service(
untyped_response_members = get_response_ptr(type_support->data,
info->typesupport_identifier_);

info->request_type_support_impl_ = untyped_request_members;
info->response_type_support_impl_ = untyped_response_members;

std::string request_type_name = _create_type_name(untyped_request_members,
info->typesupport_identifier_);
std::string response_type_name = _create_type_name(untyped_response_members,
Expand Down
1 change: 1 addition & 0 deletions rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ rmw_create_subscription(
return nullptr;
}
info->typesupport_identifier_ = type_support->typesupport_identifier;
info->type_support_impl_ = type_support->data;

std::string type_name = _create_type_name(
type_support->data, info->typesupport_identifier_);
Expand Down
Loading

0 comments on commit 3e0aea7

Please sign in to comment.