-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose raw CDR stream for publish and subscribe #186
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4847d18
publish raw function
Karsten1987 40dbb47
take raw
Karsten1987 30e512c
linters
Karsten1987 9644f70
add rmw_serialize functions
Karsten1987 fbf2e8e
rmw_fastrtps_cpp/src/rmw_serialize memory leak when creating typesupport
Karsten1987 48b6f79
linters
Karsten1987 0151654
comparison size_t with unsigned int
Karsten1987 0a215eb
remove asserts
Karsten1987 13bdb7c
refactor take code
Karsten1987 1ee0447
use rcutls macro
Karsten1987 f882044
changes for rebase
Karsten1987 80866cf
warn unused
Karsten1987 a1e0261
fix typo
Karsten1987 a0f4776
raw->serialized
Karsten1987 ea5adda
use size_t (#206)
wjwwood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,41 +21,79 @@ | |
|
||
#include "rmw_fastrtps_cpp/custom_publisher_info.hpp" | ||
#include "rmw_fastrtps_cpp/identifier.hpp" | ||
#include "ros_message_serialization.hpp" | ||
#include "rmw_fastrtps_cpp/macros.hpp" | ||
|
||
#include "./ros_message_serialization.hpp" | ||
|
||
extern "C" | ||
{ | ||
rmw_ret_t | ||
rmw_publish(const rmw_publisher_t * publisher, const void * ros_message) | ||
{ | ||
assert(publisher); | ||
assert(ros_message); | ||
rmw_ret_t returnedValue = RMW_RET_ERROR; | ||
auto error_allocator = rcutils_get_default_allocator(); | ||
RCUTILS_CHECK_FOR_NULL_WITH_MSG( | ||
publisher, "publisher pointer is null", return RMW_RET_ERROR, error_allocator); | ||
RCUTILS_CHECK_FOR_NULL_WITH_MSG( | ||
ros_message, "ros_message pointer is null", return RMW_RET_ERROR, error_allocator); | ||
|
||
if (publisher->implementation_identifier != eprosima_fastrtps_identifier) { | ||
RMW_SET_ERROR_MSG("publisher handle not from this implementation"); | ||
return RMW_RET_ERROR; | ||
} | ||
|
||
auto info = static_cast<CustomPublisherInfo *>(publisher->data); | ||
assert(info); | ||
RCUTILS_CHECK_FOR_NULL_WITH_MSG( | ||
info, "publisher info pointer is null", return RMW_RET_ERROR, error_allocator); | ||
|
||
eprosima::fastcdr::FastBuffer buffer; | ||
eprosima::fastcdr::Cdr ser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, | ||
eprosima::fastcdr::Cdr::DDS_CDR); | ||
|
||
if (_serialize_ros_message(ros_message, ser, info->type_support_, | ||
if (!_serialize_ros_message(ros_message, ser, info->type_support_, | ||
info->typesupport_identifier_)) | ||
{ | ||
if (info->publisher_->write(&ser)) { | ||
returnedValue = RMW_RET_OK; | ||
} else { | ||
RMW_SET_ERROR_MSG("cannot publish data"); | ||
} | ||
} else { | ||
RMW_SET_ERROR_MSG("cannot serialize data"); | ||
return RMW_RET_ERROR; | ||
} | ||
if (!info->publisher_->write(&ser)) { | ||
RMW_SET_ERROR_MSG("cannot publish data"); | ||
return RMW_RET_ERROR; | ||
} | ||
|
||
return RMW_RET_OK; | ||
} | ||
|
||
rmw_ret_t | ||
rmw_publish_raw(const rmw_publisher_t * publisher, const rmw_message_raw_t * raw_message) | ||
{ | ||
auto error_allocator = rcutils_get_default_allocator(); | ||
RCUTILS_CHECK_FOR_NULL_WITH_MSG( | ||
publisher, "publisher pointer is null", return RMW_RET_ERROR, error_allocator); | ||
RCUTILS_CHECK_FOR_NULL_WITH_MSG( | ||
raw_message, "raw_message pointer is null", return RMW_RET_ERROR, error_allocator); | ||
|
||
if (publisher->implementation_identifier != eprosima_fastrtps_identifier) { | ||
RMW_SET_ERROR_MSG("publisher handle not from this implementation"); | ||
return RMW_RET_ERROR; | ||
} | ||
|
||
auto info = static_cast<CustomPublisherInfo *>(publisher->data); | ||
RCUTILS_CHECK_FOR_NULL_WITH_MSG( | ||
info, "publisher info pointer is null", return RMW_RET_ERROR, error_allocator); | ||
|
||
eprosima::fastcdr::FastBuffer buffer(raw_message->buffer, raw_message->buffer_length); | ||
eprosima::fastcdr::Cdr ser( | ||
buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); | ||
if (!ser.jump(raw_message->buffer_length)) { | ||
RMW_SET_ERROR_MSG("cannot correctly set raw buffer"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't you return from here? Or is ok to continue the function when this error happens? I don't know what this function does off-hand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return RMW_RET_ERROR; | ||
} | ||
|
||
if (!info->publisher_->write(&ser)) { | ||
RMW_SET_ERROR_MSG("cannot publish data"); | ||
return RMW_RET_ERROR; | ||
} | ||
|
||
return returnedValue; | ||
return RMW_RET_OK; | ||
} | ||
} // extern "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2016 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. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "fastcdr/FastBuffer.h" | ||
|
||
#include "rmw/error_handling.h" | ||
#include "rmw/raw_message.h" | ||
#include "rmw/rmw.h" | ||
|
||
#include "./type_support_common.hpp" | ||
#include "./ros_message_serialization.hpp" | ||
|
||
extern "C" | ||
{ | ||
rmw_ret_t | ||
rmw_serialize( | ||
const void * ros_message, | ||
const rosidl_message_type_support_t * type_support, | ||
rmw_message_raw_t * raw_message) | ||
{ | ||
const rosidl_message_type_support_t * ts = get_message_typesupport_handle( | ||
type_support, rosidl_typesupport_introspection_c__identifier); | ||
if (!ts) { | ||
ts = get_message_typesupport_handle( | ||
type_support, rosidl_typesupport_introspection_cpp::typesupport_identifier); | ||
if (!ts) { | ||
RMW_SET_ERROR_MSG("type support not from this implementation"); | ||
return RMW_RET_ERROR; | ||
} | ||
} | ||
|
||
auto tss = _create_message_type_support(ts->data, ts->typesupport_identifier); | ||
eprosima::fastcdr::FastBuffer buffer; | ||
eprosima::fastcdr::Cdr ser( | ||
buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::Cdr::DDS_CDR); | ||
|
||
auto ret = _serialize_ros_message(ros_message, ser, tss, ts->typesupport_identifier); | ||
auto data_length = static_cast<unsigned int>(ser.getSerializedDataLength()); | ||
if (raw_message->buffer_capacity < data_length) { | ||
rmw_raw_message_resize(raw_message, data_length); | ||
} | ||
memcpy(raw_message->buffer, ser.getBufferPointer(), data_length); | ||
raw_message->buffer_length = data_length; | ||
raw_message->buffer_capacity = data_length; | ||
_delete_typesupport(tss, ts->typesupport_identifier); | ||
return ret == true ? RMW_RET_OK : RMW_RET_ERROR; | ||
} | ||
|
||
rmw_ret_t | ||
rmw_deserialize( | ||
const rmw_message_raw_t * raw_message, | ||
const rosidl_message_type_support_t * type_support, | ||
void * ros_message) | ||
{ | ||
const rosidl_message_type_support_t * ts = get_message_typesupport_handle( | ||
type_support, rosidl_typesupport_introspection_c__identifier); | ||
if (!ts) { | ||
ts = get_message_typesupport_handle( | ||
type_support, rosidl_typesupport_introspection_cpp::typesupport_identifier); | ||
if (!ts) { | ||
RMW_SET_ERROR_MSG("type support not from this implementation"); | ||
return RMW_RET_ERROR; | ||
} | ||
} | ||
|
||
auto tss = _create_message_type_support(ts->data, ts->typesupport_identifier); | ||
eprosima::fastcdr::FastBuffer buffer(raw_message->buffer, raw_message->buffer_length); | ||
eprosima::fastcdr::Cdr deser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, | ||
eprosima::fastcdr::Cdr::DDS_CDR); | ||
|
||
auto ret = _deserialize_ros_message(deser, ros_message, tss, ts->typesupport_identifier); | ||
_delete_typesupport(tss, ts->typesupport_identifier); | ||
return ret == true ? RMW_RET_OK : RMW_RET_ERROR; | ||
} | ||
} // extern "C" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get a compiler error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it supposed to beEdit: oops, I didn't read the comment.buffer->resize()
?