From 0d7cf29602f167d8a2e1f03ef285613bb5802d76 Mon Sep 17 00:00:00 2001 From: Sai Kishor Kothakota Date: Mon, 7 Oct 2024 22:19:45 +0200 Subject: [PATCH] constify the part of the controller interface exported state interfaces --- .../chainable_controller_interface.hpp | 2 +- .../include/controller_interface/controller_interface.hpp | 2 +- .../controller_interface/controller_interface_base.hpp | 3 ++- .../src/chainable_controller_interface.cpp | 7 ++++--- controller_interface/src/controller_interface.cpp | 2 +- .../test/test_chainable_controller_interface.cpp | 2 +- controller_manager/src/controller_manager.cpp | 2 +- .../include/hardware_interface/resource_manager.hpp | 2 +- hardware_interface/src/resource_manager.cpp | 4 ++-- 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/controller_interface/include/controller_interface/chainable_controller_interface.hpp b/controller_interface/include/controller_interface/chainable_controller_interface.hpp index 912e224c74..e4e4ec662c 100644 --- a/controller_interface/include/controller_interface/chainable_controller_interface.hpp +++ b/controller_interface/include/controller_interface/chainable_controller_interface.hpp @@ -59,7 +59,7 @@ class ChainableControllerInterface : public ControllerInterfaceBase bool is_chainable() const final; CONTROLLER_INTERFACE_PUBLIC - std::vector export_state_interfaces() final; + std::vector export_state_interfaces() final; CONTROLLER_INTERFACE_PUBLIC std::vector export_reference_interfaces() final; diff --git a/controller_interface/include/controller_interface/controller_interface.hpp b/controller_interface/include/controller_interface/controller_interface.hpp index 5c321b0e42..3455227e1d 100644 --- a/controller_interface/include/controller_interface/controller_interface.hpp +++ b/controller_interface/include/controller_interface/controller_interface.hpp @@ -47,7 +47,7 @@ class ControllerInterface : public controller_interface::ControllerInterfaceBase * \returns empty list. */ CONTROLLER_INTERFACE_PUBLIC - std::vector export_state_interfaces() final; + std::vector export_state_interfaces() final; /** * Controller has no reference interfaces. diff --git a/controller_interface/include/controller_interface/controller_interface_base.hpp b/controller_interface/include/controller_interface/controller_interface_base.hpp index 1f350abeef..2bd01cc326 100644 --- a/controller_interface/include/controller_interface/controller_interface_base.hpp +++ b/controller_interface/include/controller_interface/controller_interface_base.hpp @@ -245,7 +245,8 @@ class ControllerInterfaceBase : public rclcpp_lifecycle::node_interfaces::Lifecy * \returns list of state interfaces for preceding controllers. */ CONTROLLER_INTERFACE_PUBLIC - virtual std::vector export_state_interfaces() = 0; + virtual std::vector + export_state_interfaces() = 0; /** * Set chained mode of a chainable controller. This method triggers internal processes to switch diff --git a/controller_interface/src/chainable_controller_interface.cpp b/controller_interface/src/chainable_controller_interface.cpp index ce19eff9b9..a6d427fe2b 100644 --- a/controller_interface/src/chainable_controller_interface.cpp +++ b/controller_interface/src/chainable_controller_interface.cpp @@ -44,11 +44,11 @@ return_type ChainableControllerInterface::update( return ret; } -std::vector +std::vector ChainableControllerInterface::export_state_interfaces() { auto state_interfaces = on_export_state_interfaces(); - std::vector state_interfaces_ptrs_vec; + std::vector state_interfaces_ptrs_vec; state_interfaces_ptrs_vec.reserve(state_interfaces.size()); ordered_exported_state_interfaces_.reserve(state_interfaces.size()); exported_state_interface_names_.reserve(state_interfaces.size()); @@ -88,7 +88,8 @@ ChainableControllerInterface::export_state_interfaces() } ordered_exported_state_interfaces_.push_back(state_interface); exported_state_interface_names_.push_back(interface_name); - state_interfaces_ptrs_vec.push_back(state_interface); + state_interfaces_ptrs_vec.push_back( + std::const_pointer_cast(state_interface)); } return state_interfaces_ptrs_vec; diff --git a/controller_interface/src/controller_interface.cpp b/controller_interface/src/controller_interface.cpp index 4a22d78666..b254da79d8 100644 --- a/controller_interface/src/controller_interface.cpp +++ b/controller_interface/src/controller_interface.cpp @@ -22,7 +22,7 @@ ControllerInterface::ControllerInterface() : ControllerInterfaceBase() {} bool ControllerInterface::is_chainable() const { return false; } -std::vector +std::vector ControllerInterface::export_state_interfaces() { return {}; diff --git a/controller_interface/test/test_chainable_controller_interface.cpp b/controller_interface/test/test_chainable_controller_interface.cpp index 5233fe0278..12d5599d45 100644 --- a/controller_interface/test/test_chainable_controller_interface.cpp +++ b/controller_interface/test/test_chainable_controller_interface.cpp @@ -95,7 +95,7 @@ TEST_F(ChainableControllerInterfaceTest, interfaces_prefix_is_not_node_name) std::runtime_error); ASSERT_THAT(exported_reference_interfaces, IsEmpty()); // expect empty return because interface prefix is not equal to the node name - std::vector exported_state_interfaces; + std::vector exported_state_interfaces; EXPECT_THROW( { exported_state_interfaces = controller.export_state_interfaces(); }, std::runtime_error); ASSERT_THAT(exported_state_interfaces, IsEmpty()); diff --git a/controller_manager/src/controller_manager.cpp b/controller_manager/src/controller_manager.cpp index bad55e2e1c..f0ad58e535 100644 --- a/controller_manager/src/controller_manager.cpp +++ b/controller_manager/src/controller_manager.cpp @@ -771,7 +771,7 @@ controller_interface::return_type ControllerManager::configure_controller( get_logger(), "Controller '%s' is chainable. Interfaces are being exported to resource manager.", controller_name.c_str()); - std::vector state_interfaces; + std::vector state_interfaces; std::vector ref_interfaces; try { diff --git a/hardware_interface/include/hardware_interface/resource_manager.hpp b/hardware_interface/include/hardware_interface/resource_manager.hpp index ece45e3146..a5592fc492 100644 --- a/hardware_interface/include/hardware_interface/resource_manager.hpp +++ b/hardware_interface/include/hardware_interface/resource_manager.hpp @@ -141,7 +141,7 @@ class HARDWARE_INTERFACE_PUBLIC ResourceManager * \param[in] interfaces list of controller's state interfaces as StateInterfaces. */ void import_controller_exported_state_interfaces( - const std::string & controller_name, std::vector & interfaces); + const std::string & controller_name, std::vector & interfaces); /// Get list of exported tate interface of a controller. /** diff --git a/hardware_interface/src/resource_manager.cpp b/hardware_interface/src/resource_manager.cpp index c59aff0700..e5445491c8 100644 --- a/hardware_interface/src/resource_manager.cpp +++ b/hardware_interface/src/resource_manager.cpp @@ -608,7 +608,7 @@ class ResourceStorage template void import_state_interfaces(HardwareT & hardware) { - std::vector interfaces = hardware.export_state_interfaces(); + auto interfaces = hardware.export_state_interfaces(); const auto interface_names = add_state_interfaces(interfaces); RCLCPP_WARN( @@ -1242,7 +1242,7 @@ bool ResourceManager::state_interface_is_available(const std::string & name) con // CM API: Called in "callback/slow"-thread void ResourceManager::import_controller_exported_state_interfaces( - const std::string & controller_name, std::vector & interfaces) + const std::string & controller_name, std::vector & interfaces) { std::lock_guard guard(resource_interfaces_lock_); auto interface_names = resource_storage_->add_state_interfaces(interfaces);