Skip to content

Expose ServiceType in Service public API#3088

Open
SayHey wants to merge 1 commit intoros2:rollingfrom
SayHey:patch-1
Open

Expose ServiceType in Service public API#3088
SayHey wants to merge 1 commit intoros2:rollingfrom
SayHey:patch-1

Conversation

@SayHey
Copy link

@SayHey SayHey commented Mar 4, 2026

Description

The PR exposes ServiceType in rclcpp::Service public API.

Is this user-facing behavior change?

Yes, the change unlocks deduction of the ServiceType of an already declared rclcpp::Service instance, thus avoiding duplicating type information.
Here is an example:

auto init_service = []<typename T>(T& service, const std::string& name, const auto& cb) {
  service = create_service<typename T::element_type::ServiceType>(name, cb);
};

Usage:

rclcpp::Service<long_namespace::MyServiceType>::SharedPtr my_service_; // usually a class member
...
init_service(my_service_, "my_service", my_service_callback); // usually happens in constructor
// my_service_ = create_service<long_namespace::MyServiceType>("my_service", my_service_callback); // current practice

Did you use Generative AI?

No

Signed-off-by: Danil <danil.nev@gmail.com>
Copy link
Collaborator

@jmachowinski jmachowinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with the change, but want a second opinion on the naming.
E.g. ServiceType or ServiceMsgType etc.

@fujitatomoya @mjcarroll any objections or should we just ship it ?

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am good to go with it.

@fujitatomoya
Copy link
Collaborator

Pulls: #3088
Gist: https://gist.githubusercontent.com/fujitatomoya/0ca97ee0dff9c5464ae8e243ce4bd8d4/raw/12c4388ad5eb92e7ea4dfaa2884c6e8b1fe86b30/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18362

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants