Skip to content

Commit 1caaebe

Browse files
mauropasseMauro Passerino
andauthored
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]>
1 parent c5b630b commit 1caaebe

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
@@ -922,11 +922,30 @@ class Client : public ClientBase
922922
// Create a ClientIntraProcess which will be given to the intra-process manager.
923923
using ClientIntraProcessT = rclcpp::experimental::ClientIntraProcess<ServiceT>;
924924

925+
// Expand the given service name.
926+
char * remapped_service_name = NULL;
927+
rcl_allocator_t allocator = rcl_get_default_allocator();
928+
929+
rcl_ret_t ret = rcl_node_resolve_name(
930+
this->get_rcl_node_handle(),
931+
this->get_service_name(),
932+
allocator,
933+
true,
934+
false,
935+
&remapped_service_name);
936+
937+
if (RCL_RET_OK != ret) {
938+
allocator.deallocate(remapped_service_name, allocator.state);
939+
rclcpp::exceptions::throw_from_rcl_error(ret, "client failed to resolve service name");
940+
}
941+
925942
client_intra_process_ = std::make_shared<ClientIntraProcessT>(
926943
context_,
927-
this->get_service_name(),
944+
remapped_service_name,
928945
qos_profile);
929946

947+
allocator.deallocate(remapped_service_name, allocator.state);
948+
930949
// Add it to the intra process manager.
931950
using rclcpp::experimental::IntraProcessManager;
932951
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
@@ -945,12 +945,14 @@ class Client : public ClientBase
945945
qos_history.feedback_topic_depth = options.feedback_topic_qos.history;
946946
qos_history.status_topic_depth = options.status_topic_qos.history;
947947

948+
std::string remapped_action_name = node_base->resolve_topic_or_service_name(action_name, true);
949+
948950
// Create a ActionClientIntraProcess which will be given
949951
// to the intra-process manager.
950952
auto context = node_base->get_context();
951953
ipc_action_client_ = std::make_shared<ActionClientIntraProcessT>(
952954
context,
953-
action_name,
955+
remapped_action_name,
954956
qos_history,
955957
std::bind(&Client::handle_status_message, this, std::placeholders::_1),
956958
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
@@ -932,11 +932,14 @@ class Server : public ServerBase, public std::enable_shared_from_this<Server<Act
932932
std::lock_guard<std::recursive_mutex> lock(ipc_mutex_);
933933

934934
use_intra_process_ = true;
935+
936+
std::string remapped_action_name = node_base->resolve_topic_or_service_name(name, true);
937+
935938
// Create a ActionClientIntraProcess which will be given
936939
// to the intra-process manager.
937940
auto context = node_base->get_context();
938941
ipc_action_server_ = std::make_shared<ActionServerIntraProcessT>(
939-
context, name, qos_history,
942+
context, remapped_action_name, qos_history,
940943
std::bind(&Server::ipc_execute_goal_request_received, this, std::placeholders::_1),
941944
std::bind(&Server::ipc_execute_cancel_request_received, this, std::placeholders::_1),
942945
std::bind(&Server::ipc_execute_result_request_received, this, std::placeholders::_1));

0 commit comments

Comments
 (0)