Skip to content

Commit 5500bc4

Browse files
mauropasseskyegalaxy
authored andcommitted
Include namespaces in service names (#140)
* Include node namespace in IPC Action service name * Include node namespace in IPC Client/Service service name --------- Co-authored-by: Mauro Passerino <[email protected]> (cherry picked from commit f5b2001)
1 parent 403e07f commit 5500bc4

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

rclcpp/include/rclcpp/client.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,11 +967,30 @@ class Client : public ClientBase
967967
// Create a ClientIntraProcess which will be given to the intra-process manager.
968968
using ClientIntraProcessT = rclcpp::experimental::ClientIntraProcess<ServiceT>;
969969

970+
// Expand the given service name.
971+
char * remapped_service_name = NULL;
972+
rcl_allocator_t allocator = rcl_get_default_allocator();
973+
974+
rcl_ret_t ret = rcl_node_resolve_name(
975+
this->get_rcl_node_handle(),
976+
this->get_service_name(),
977+
allocator,
978+
true,
979+
false,
980+
&remapped_service_name);
981+
982+
if (RCL_RET_OK != ret) {
983+
allocator.deallocate(remapped_service_name, allocator.state);
984+
rclcpp::exceptions::throw_from_rcl_error(ret, "client failed to resolve service name");
985+
}
986+
970987
client_intra_process_ = std::make_shared<ClientIntraProcessT>(
971988
context_,
972-
this->get_service_name(),
989+
remapped_service_name,
973990
qos_profile);
974991

992+
allocator.deallocate(remapped_service_name, allocator.state);
993+
975994
// Add it to the intra process manager.
976995
using rclcpp::experimental::IntraProcessManager;
977996
auto ipm = context_->get_sub_context<IntraProcessManager>();

rclcpp/include/rclcpp/service.hpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,33 @@ class Service
594594
// Create a ServiceIntraProcess which will be given to the intra-process manager.
595595
using ServiceIntraProcessT = rclcpp::experimental::ServiceIntraProcess<ServiceT>;
596596

597+
598+
// Expand the given service name.
599+
char * remapped_service_name = NULL;
600+
rcl_allocator_t allocator = rcl_get_default_allocator();
601+
602+
rcl_ret_t ret = rcl_node_resolve_name(
603+
this->get_rcl_node_handle(),
604+
this->get_service_name(),
605+
allocator,
606+
true,
607+
false,
608+
&remapped_service_name);
609+
610+
if (RCL_RET_OK != ret) {
611+
allocator.deallocate(remapped_service_name, allocator.state);
612+
rclcpp::exceptions::throw_from_rcl_error(ret, "service failed to resolve service name");
613+
}
614+
597615
service_intra_process_ = std::make_shared<ServiceIntraProcessT>(
598616
this->shared_from_this(),
599617
any_callback_,
600618
context_,
601-
this->get_service_name(),
619+
remapped_service_name,
602620
qos_profile);
603621

622+
allocator.deallocate(remapped_service_name, allocator.state);
623+
604624
using rclcpp::experimental::IntraProcessManager;
605625
auto ipm = context_->get_sub_context<IntraProcessManager>();
606626
uint64_t intra_process_service_id = ipm->add_intra_process_service(service_intra_process_);

rclcpp_action/include/rclcpp_action/client.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,12 +1011,14 @@ class Client : public ClientBase
10111011
qos_history.feedback_topic_depth = options.feedback_topic_qos.history;
10121012
qos_history.status_topic_depth = options.status_topic_qos.history;
10131013

1014+
std::string remapped_action_name = node_base->resolve_topic_or_service_name(action_name, true);
1015+
10141016
// Create a ActionClientIntraProcess which will be given
10151017
// to the intra-process manager.
10161018
auto context = node_base->get_context();
10171019
ipc_action_client_ = std::make_shared<ActionClientIntraProcessT>(
10181020
context,
1019-
action_name,
1021+
remapped_action_name,
10201022
qos_history,
10211023
std::bind(&Client::handle_status_message, this, std::placeholders::_1),
10221024
std::bind(&Client::handle_feedback_message, this, std::placeholders::_1));

rclcpp_action/include/rclcpp_action/server.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,11 +955,14 @@ class Server : public ServerBase, public std::enable_shared_from_this<Server<Act
955955
std::lock_guard<std::recursive_mutex> lock(ipc_mutex_);
956956

957957
use_intra_process_ = true;
958+
959+
std::string remapped_action_name = node_base->resolve_topic_or_service_name(name, true);
960+
958961
// Create a ActionClientIntraProcess which will be given
959962
// to the intra-process manager.
960963
auto context = node_base->get_context();
961964
ipc_action_server_ = std::make_shared<ActionServerIntraProcessT>(
962-
context, name, qos_history,
965+
context, remapped_action_name, qos_history,
963966
std::bind(&Server::ipc_execute_goal_request_received, this, std::placeholders::_1),
964967
std::bind(&Server::ipc_execute_cancel_request_received, this, std::placeholders::_1),
965968
std::bind(&Server::ipc_execute_result_request_received, this, std::placeholders::_1));

0 commit comments

Comments
 (0)