Skip to content

Commit 6c22766

Browse files
committed
removed smell
1 parent 036cc10 commit 6c22766

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

deep_core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Multi-dimensional tensor smart pointer supporting:
2121
Lifecycle node that handles:
2222
- Dynamic backend plugin loading via pluginlib
2323
- Model loading/unloading lifecycle
24-
- Optional bond connections for nav2 integration
24+
- Optional bond connections for nav2 integration and integration with other lifecycle managers
2525
- Parameter-driven configuration
2626

2727
### Plugin Interfaces

deep_core/include/deep_core/deep_node_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class DeepNodeBase : public rclcpp_lifecycle::LifecycleNode
5656
/**
5757
* @brief Destructor
5858
*/
59-
virtual ~DeepNodeBase();
59+
virtual ~DeepNodeBase() = default;
6060

6161
protected:
6262
/**

deep_core/src/deep_node_base.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ DeepNodeBase::DeepNodeBase(const std::string & node_name, const rclcpp::NodeOpti
2929
plugin_loader_ =
3030
std::make_unique<pluginlib::ClassLoader<DeepBackendPlugin>>("deep_core", "deep_ros::DeepBackendPlugin");
3131
declare_parameters();
32-
33-
// Set up parameter callback for dynamic reconfiguration
34-
parameter_callback_handle_ =
35-
add_on_set_parameters_callback(std::bind(&DeepNodeBase::on_parameter_change, this, std::placeholders::_1));
36-
}
37-
38-
DeepNodeBase::~DeepNodeBase()
39-
{
40-
// Remove parameter callback to prevent callback invocation during destruction
41-
if (parameter_callback_handle_) {
42-
remove_on_set_parameters_callback(parameter_callback_handle_.get());
43-
}
4432
}
4533

4634
void DeepNodeBase::declare_parameters()
@@ -84,6 +72,9 @@ CallbackReturn DeepNodeBase::on_activate(const rclcpp_lifecycle::State & state)
8472
{
8573
RCLCPP_INFO(get_logger(), "Activating DeepNodeBase");
8674

75+
parameter_callback_handle_ =
76+
add_on_set_parameters_callback(std::bind(&DeepNodeBase::on_parameter_change, this, std::placeholders::_1));
77+
8778
// Start bond if enabled
8879
if (bond_enabled_ && bond_) {
8980
bond_->start();
@@ -96,6 +87,12 @@ CallbackReturn DeepNodeBase::on_activate(const rclcpp_lifecycle::State & state)
9687
CallbackReturn DeepNodeBase::on_deactivate(const rclcpp_lifecycle::State & state)
9788
{
9889
RCLCPP_INFO(get_logger(), "Deactivating DeepNodeBase");
90+
91+
if (parameter_callback_handle_) {
92+
remove_on_set_parameters_callback(parameter_callback_handle_.get());
93+
parameter_callback_handle_.reset();
94+
}
95+
9996
return on_deactivate_impl(state);
10097
}
10198

@@ -118,6 +115,11 @@ CallbackReturn DeepNodeBase::on_shutdown(const rclcpp_lifecycle::State & state)
118115
{
119116
RCLCPP_INFO(get_logger(), "Shutting down DeepNodeBase");
120117

118+
if (parameter_callback_handle_) {
119+
remove_on_set_parameters_callback(parameter_callback_handle_.get());
120+
parameter_callback_handle_.reset();
121+
}
122+
121123
// Stop bond if active
122124
if (bond_) {
123125
bond_.reset();

deep_core/test/test_dynamic_parameters.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,18 @@ TEST_CASE_METHOD(deep_ros::test::TestExecutorFixture, "Dynamic model reconfigura
8888
REQUIRE(test_node->get_current_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED);
8989
}
9090

91-
SECTION("Model parameter change rejected when not active")
91+
SECTION("Model parameter change allowed when not active (no callback registered)")
9292
{
9393
// Try to set model_path while in unconfigured state
9494
auto parameters = std::vector<rclcpp::Parameter>{rclcpp::Parameter("model_path", "/some/model/path.onnx")};
9595

9696
auto result = test_node->set_parameters(parameters);
9797

98-
// Should fail because node is not active
99-
REQUIRE(result[0].successful == false);
100-
REQUIRE(result[0].reason.find("Node must be active") != std::string::npos);
98+
// Should succeed because callback is not registered until activation
99+
REQUIRE(result[0].successful == true);
100+
101+
// Verify the parameter was set
102+
REQUIRE(test_node->get_parameter("model_path").as_string() == "/some/model/path.onnx");
101103
}
102104

103105
SECTION("Configuration fails with invalid plugin")

0 commit comments

Comments
 (0)