rclcpp
rclcpp copied to clipboard
Custom allocators for Service/Clients
Feature request
Custom allocators for Service/Clients
Feature description
Currently the allocator for rclcpp services and clients cannot be configured by the user, though publishers and subscribers support this feature. This is useful for systems that implement a non-default allocator and would like to use ros2 services.
Implementation considerations
The implementation could mirror that of rclcpp publishers/subscribers where the create_publisher
/create_subscriber
functions are templated on an AllocatorT
.
https://github.com/ros2/rclcpp/blob/b953bdddf8de213b4a051ecf2d668dad65ff9f89/rclcpp/include/rclcpp/create_publisher.hpp#L38-L52
Steps that would need to be taken would then be:
- Create an analogue of
PublisherOptionsBase
class for Services, i.e.ServiceOptionsBase
.
- Implement a
ServiceOptionsWithAllocator
which templatesServiceOptionsBase
on anAllocatorT
as per implementation withPublisherOptionsWithAllocator
- Update
create_service.hpp
to provide arclcpp::create_service
templated on anAllocatorT
accepting aServiceOptionsWithAllocator
. - Pass the service options containing the custom allocator to
rcl_service_init
- Do the same with clients
It may also be good to copy the Factory design pattern used on the publisher/subscriber implementation for consistency.
Reference:
- https://github.com/ros2/rclcpp/blob/rolling/rclcpp/include/rclcpp/allocator/allocator_common.hpp