diff --git a/rclcpp/include/rclcpp/parameter_client.hpp b/rclcpp/include/rclcpp/parameter_client.hpp index ac3250bf8d..a525c8ef8b 100644 --- a/rclcpp/include/rclcpp/parameter_client.hpp +++ b/rclcpp/include/rclcpp/parameter_client.hpp @@ -185,6 +185,29 @@ class SyncParametersClient const std::string & remote_node_name = "", const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters); + RCLCPP_PUBLIC + explicit SyncParametersClient( + rclcpp::Node * node, + const std::string & remote_node_name = "", + const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters); + + RCLCPP_PUBLIC + SyncParametersClient( + rclcpp::executor::Executor::SharedPtr executor, + rclcpp::Node * node, + const std::string & remote_node_name = "", + const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters); + + RCLCPP_PUBLIC + SyncParametersClient( + rclcpp::executor::Executor::SharedPtr executor, + const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface, + const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface, + const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface, + const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface, + const std::string & remote_node_name = "", + const rmw_qos_profile_t & qos_profile = rmw_qos_profile_parameters); + RCLCPP_PUBLIC std::vector get_parameters(const std::vector & parameter_names); @@ -268,7 +291,7 @@ class SyncParametersClient private: rclcpp::executor::Executor::SharedPtr executor_; - rclcpp::Node::SharedPtr node_; + const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface_; AsyncParametersClient::SharedPtr async_parameters_client_; }; diff --git a/rclcpp/src/rclcpp/parameter_client.cpp b/rclcpp/src/rclcpp/parameter_client.cpp index be3666a524..c49f5c2ab2 100644 --- a/rclcpp/src/rclcpp/parameter_client.cpp +++ b/rclcpp/src/rclcpp/parameter_client.cpp @@ -350,10 +350,60 @@ SyncParametersClient::SyncParametersClient( rclcpp::Node::SharedPtr node, const std::string & remote_node_name, const rmw_qos_profile_t & qos_profile) -: executor_(executor), node_(node) +: SyncParametersClient( + executor, + node->get_node_base_interface(), + node->get_node_topics_interface(), + node->get_node_graph_interface(), + node->get_node_services_interface(), + remote_node_name, + qos_profile) +{} + +SyncParametersClient::SyncParametersClient( + rclcpp::Node * node, + const std::string & remote_node_name, + const rmw_qos_profile_t & qos_profile) +: SyncParametersClient( + std::make_shared(), + node, + remote_node_name, + qos_profile) +{} + +SyncParametersClient::SyncParametersClient( + rclcpp::executor::Executor::SharedPtr executor, + rclcpp::Node * node, + const std::string & remote_node_name, + const rmw_qos_profile_t & qos_profile) +: SyncParametersClient( + executor, + node->get_node_base_interface(), + node->get_node_topics_interface(), + node->get_node_graph_interface(), + node->get_node_services_interface(), + remote_node_name, + qos_profile) +{} + +SyncParametersClient::SyncParametersClient( + rclcpp::executor::Executor::SharedPtr executor, + const rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_interface, + const rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_interface, + const rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_interface, + const rclcpp::node_interfaces::NodeServicesInterface::SharedPtr node_services_interface, + const std::string & remote_node_name, + const rmw_qos_profile_t & qos_profile) +: executor_(executor), node_base_interface_(node_base_interface) { async_parameters_client_ = - std::make_shared(node, remote_node_name, qos_profile); + std::make_shared( + node_base_interface, + node_topics_interface, + node_graph_interface, + node_services_interface, + remote_node_name, + qos_profile); } std::vector @@ -361,7 +411,7 @@ SyncParametersClient::get_parameters(const std::vector & parameter_ { auto f = async_parameters_client_->get_parameters(parameter_names); using rclcpp::executors::spin_node_until_future_complete; - if (spin_node_until_future_complete(*executor_, node_->get_node_base_interface(), f) == + if (spin_node_until_future_complete(*executor_, node_base_interface_, f) == rclcpp::executor::FutureReturnCode::SUCCESS) { return f.get(); @@ -385,7 +435,7 @@ SyncParametersClient::get_parameter_types(const std::vector & param auto f = async_parameters_client_->get_parameter_types(parameter_names); using rclcpp::executors::spin_node_until_future_complete; - if (spin_node_until_future_complete(*executor_, node_->get_node_base_interface(), f) == + if (spin_node_until_future_complete(*executor_, node_base_interface_, f) == rclcpp::executor::FutureReturnCode::SUCCESS) { return f.get(); @@ -399,9 +449,8 @@ SyncParametersClient::set_parameters( { auto f = async_parameters_client_->set_parameters(parameters); - auto node_base_interface = node_->get_node_base_interface(); using rclcpp::executors::spin_node_until_future_complete; - if (spin_node_until_future_complete(*executor_, node_base_interface, f) == + if (spin_node_until_future_complete(*executor_, node_base_interface_, f) == rclcpp::executor::FutureReturnCode::SUCCESS) { return f.get(); @@ -416,7 +465,7 @@ SyncParametersClient::set_parameters_atomically( auto f = async_parameters_client_->set_parameters_atomically(parameters); using rclcpp::executors::spin_node_until_future_complete; - if (spin_node_until_future_complete(*executor_, node_->get_node_base_interface(), f) == + if (spin_node_until_future_complete(*executor_, node_base_interface_, f) == rclcpp::executor::FutureReturnCode::SUCCESS) { return f.get(); @@ -433,7 +482,7 @@ SyncParametersClient::list_parameters( auto f = async_parameters_client_->list_parameters(parameter_prefixes, depth); using rclcpp::executors::spin_node_until_future_complete; - if (spin_node_until_future_complete(*executor_, node_->get_node_base_interface(), f) == + if (spin_node_until_future_complete(*executor_, node_base_interface_, f) == rclcpp::executor::FutureReturnCode::SUCCESS) { return f.get();