Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rmw_fastrtps_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ add_library(rmw_fastrtps_cpp
src/rmw_get_topic_endpoint_info.cpp
src/rmw_guard_condition.cpp
src/rmw_init.cpp
src/rmw_is_loaned_message_valid.cpp
src/rmw_node.cpp
src/rmw_node_info_and_types.cpp
src/rmw_node_names.cpp
Expand Down
28 changes: 28 additions & 0 deletions rmw_fastrtps_cpp/src/rmw_is_loaned_message_valid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2026 Open Source Robotics Foundation, Inc.
//
// 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 "rmw/rmw.h"
#include "rmw_fastrtps_shared_cpp/rmw_is_loaned_message_valid.hpp"
#include "rmw_fastrtps_cpp/identifier.hpp"
extern "C" {
rmw_ret_t
rmw_is_loaned_message_valid(
const rmw_subscription_t * subscription,
const void * loaned_message,
const rmw_message_info_t * message_info,
bool * is_valid)
{
return rmw_fastrtps_shared_cpp::rmw_is_loaned_message_valid(
subscription, loaned_message, message_info, is_valid);
}
} // extern "C"
1 change: 1 addition & 0 deletions rmw_fastrtps_dynamic_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ add_library(rmw_fastrtps_dynamic_cpp
src/rmw_get_topic_endpoint_info.cpp
src/rmw_guard_condition.cpp
src/rmw_init.cpp
src/rmw_is_loaned_message_valid.cpp
src/rmw_logging.cpp
src/rmw_node.cpp
src/rmw_node_info_and_types.cpp
Expand Down
28 changes: 28 additions & 0 deletions rmw_fastrtps_dynamic_cpp/src/rmw_is_loaned_message_valid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2026 Open Source Robotics Foundation, Inc.
//
// 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 "rmw/rmw.h"
#include "rmw_fastrtps_shared_cpp/rmw_is_loaned_message_valid.hpp"
#include "rmw_fastrtps_dynamic_cpp/identifier.hpp"
extern "C" {
rmw_ret_t
rmw_is_loaned_message_valid(
const rmw_subscription_t * subscription,
const void * loaned_message,
const rmw_message_info_t * message_info,
bool * is_valid)
{
return rmw_fastrtps_shared_cpp::rmw_is_loaned_message_valid(
subscription, loaned_message, message_info, is_valid);
}
} // extern "C"
1 change: 1 addition & 0 deletions rmw_fastrtps_shared_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ add_library(rmw_fastrtps_shared_cpp
src/rmw_get_topic_endpoint_info.cpp
src/rmw_guard_condition.cpp
src/rmw_init.cpp
src/rmw_is_loaned_message_valid.cpp
src/rmw_logging.cpp
src/rmw_node.cpp
src/rmw_node_info_and_types.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2026 Open Source Robotics Foundation, Inc.
//
// 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.

#ifndef RMW_FASTRTPS_SHARED_CPP__RMW_IS_LOANED_MESSAGE_VALID_HPP_
#define RMW_FASTRTPS_SHARED_CPP__RMW_IS_LOANED_MESSAGE_VALID_HPP_

#include "rmw_fastrtps_shared_cpp/visibility_control.h"
#include "rmw/rmw.h"

namespace rmw_fastrtps_shared_cpp
{
/**
* Check if a loaned message is still valid (not overwritten by middleware).
*
* This function checks if the loaned message memory has been invalidated
* by the middleware (e.g., when using shared memory with Fast-DDS data-sharing).
*
* \param[in] subscription The rmw subscription handle
* \param[in] loaned_message Pointer to the loaned message data
* \param[in] message_info Message info containing publisher_gid and sequence_number
* \param[out] is_valid Output parameter indicating if the message is valid
* \return RMW_RET_OK if successful, RMW_RET_INVALID_ARGUMENT if parameters are invalid
*/
RMW_FASTRTPS_SHARED_CPP_PUBLIC
rmw_ret_t
rmw_is_loaned_message_valid(
const rmw_subscription_t * subscription,
const void * loaned_message,
const rmw_message_info_t * message_info,
bool * is_valid);
} // namespace rmw_fastrtps_shared_cpp

#endif // RMW_FASTRTPS_SHARED_CPP__RMW_IS_LOANED_MESSAGE_VALID_HPP_
62 changes: 62 additions & 0 deletions rmw_fastrtps_shared_cpp/src/rmw_is_loaned_message_valid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2026 Open Source Robotics Foundation, Inc.
//
// 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 "rmw_fastrtps_shared_cpp/rmw_is_loaned_message_valid.hpp"
#include <cstdint>

#include "fastdds/dds/subscriber/DataReader.hpp"
#include "fastdds/dds/subscriber/SampleInfo.hpp"
#include "fastdds/rtps/common/Guid.hpp"
#include "fastdds/rtps/common/SequenceNumber.hpp"

#include "rmw_fastrtps_shared_cpp/custom_subscriber_info.hpp"
#include "rmw_fastrtps_shared_cpp/guid_utils.hpp"

namespace rmw_fastrtps_shared_cpp
{

rmw_ret_t
rmw_is_loaned_message_valid(
const rmw_subscription_t * subscription,
const void * loaned_message,
const rmw_message_info_t * message_info,
bool * is_valid)
{
if (!subscription || !loaned_message || !message_info || !is_valid) {
return RMW_RET_INVALID_ARGUMENT;
}

*is_valid = true;
auto * info = static_cast<CustomSubscriberInfo *>(subscription->data);
if (!info || !info->data_reader_) {
return RMW_RET_OK;
}

eprosima::fastdds::dds::SampleInfo sample_info{};
eprosima::fastdds::rtps::GUID_t writer_guid;
copy_from_byte_array_to_fastdds_guid(
message_info->publisher_gid.data, &writer_guid);
uint64_t seq = message_info->publication_sequence_number;
eprosima::fastdds::rtps::SequenceNumber_t seq_num;
seq_num.high = static_cast<int32_t>(seq >> 32);
seq_num.low = static_cast<uint32_t>(seq & 0xFFFFFFFF);
sample_info.sample_identity.writer_guid(writer_guid);
sample_info.sample_identity.sequence_number(seq_num);

*is_valid = info->data_reader_->is_sample_valid(loaned_message, &sample_info);

return RMW_RET_OK;
}

} // namespace rmw_fastrtps_shared_cpp