Skip to content

Commit a19b54f

Browse files
committed
Update descriptor ops to use non-owning pointers
Signed-off-by: CY Chen <cyc@nvidia.com>
1 parent 8cd8b0b commit a19b54f

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

rosidl_buffer/include/rosidl_buffer/buffer.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,12 @@ class Buffer
475475
return impl_->get_backend_type();
476476
}
477477

478-
/// Get the implementation pointer (for serialization) - returns raw pointer
479-
/// for read-only access
478+
/// Get the implementation pointer (read-only).
480479
const BufferImplBase<T> * get_impl() const {return impl_.get();}
481480

481+
/// Get the implementation pointer (mutable, e.g. for descriptor creation).
482+
BufferImplBase<T> * get_impl() {return impl_.get();}
483+
482484
/// Throw exception if not CPU backend.
483485
/// @throws std::runtime_error if backend is not CPU.
484486
void throw_if_not_cpu_backend() const

rosidl_buffer_backend/include/rosidl_buffer_backend/buffer_backend.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ class BufferBackend
5555
virtual std::shared_ptr<void> create_empty_descriptor() const = 0;
5656

5757
/// Create a descriptor message with endpoint awareness.
58-
/// @param impl Type-erased BufferImplBase pointer.
58+
/// @param impl Non-owning, type-erased BufferImplBase pointer (may be mutated).
5959
/// @param endpoint_info Endpoint info for the peer.
6060
/// @return Type-erased descriptor message, or nullptr if the backend cannot
6161
/// handle this endpoint (e.g., the peer does not support this backend).
6262
/// Returning nullptr signals the serialization layer to fall back to
6363
/// CPU-based serialization.
6464
virtual std::shared_ptr<void> create_descriptor_with_endpoint(
65-
const std::shared_ptr<void> & impl,
65+
void * impl,
6666
const rmw_topic_endpoint_info_t & endpoint_info) const = 0;
6767

6868
/// Create a BufferImpl from descriptor with endpoint awareness.
69-
/// @param descriptor Type-erased descriptor message pointer.
69+
/// @param descriptor Non-owning, type-erased descriptor message pointer (read-only).
7070
/// @param endpoint_info Endpoint info for the peer.
7171
/// @return Type-erased BufferImplBase pointer.
7272
virtual std::shared_ptr<void> from_descriptor_with_endpoint(
73-
const std::shared_ptr<void> & descriptor,
73+
const void * descriptor,
7474
const rmw_topic_endpoint_info_t & endpoint_info) const = 0;
7575

7676
/// Hook invoked when creating a local endpoint.

rosidl_buffer_backend/include/rosidl_buffer_backend/buffer_descriptor_ops.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ namespace rosidl
2727
struct BufferDescriptorOps
2828
{
2929
/// Create descriptor with endpoint awareness.
30-
/// Input pointer (`impl`) is a type-erased `BufferImplBase<T>` instance.
30+
/// Input pointer (`impl`) is a non-owning, type-erased `BufferImplBase<T>` instance
31+
/// that the backend may mutate.
3132
/// Return value is a type-erased backend descriptor message instance.
32-
std::function<std::shared_ptr<void>(const std::shared_ptr<void> &,
33+
std::function<std::shared_ptr<void>(void *,
3334
const rmw_topic_endpoint_info_t &)> create_descriptor_with_endpoint;
3435

3536
/// Create buffer impl from descriptor with endpoint awareness.
36-
/// Input pointer (`descriptor`) is a type-erased backend descriptor message.
37+
/// Input pointer (`descriptor`) is a non-owning, type-erased backend descriptor
38+
/// message (read-only).
3739
/// Return value is a type-erased `BufferImplBase<T>` instance.
38-
std::function<std::shared_ptr<void>(const std::shared_ptr<void> &,
40+
std::function<std::shared_ptr<void>(const void *,
3941
const rmw_topic_endpoint_info_t &)> from_descriptor_with_endpoint;
4042
};
4143

0 commit comments

Comments
 (0)