From d7f44d2179a586ac71d1273f4060e369f2a8ca15 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Thu, 8 Feb 2024 13:14:38 -0500 Subject: [PATCH] don't advertise services if feature not enabled --- image_view/src/image_saver_node.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/image_view/src/image_saver_node.cpp b/image_view/src/image_saver_node.cpp index 4982732d0..8f41a1b68 100644 --- a/image_view/src/image_saver_node.cpp +++ b/image_view/src/image_saver_node.cpp @@ -104,16 +104,21 @@ ImageSaverNode::ImageSaverNode(const rclcpp::NodeOptions & options) std::bind( &ImageSaverNode::service, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); - start_srv_ = this->create_service( - "start", - std::bind( - &ImageSaverNode::callbackStartSave, this, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)); - end_srv_ = this->create_service( - "end", - std::bind( - &ImageSaverNode::callbackEndSave, this, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3)); + + // Advertise start/end services if the feature is enabled + if (request_start_end_) + { + start_srv_ = this->create_service( + "start", + std::bind( + &ImageSaverNode::callbackStartSave, this, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3)); + end_srv_ = this->create_service( + "end", + std::bind( + &ImageSaverNode::callbackEndSave, this, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3)); + } } bool ImageSaverNode::saveImage(