mgmt: adapt to API changes in ndn-cxx ControlCommand and Dispatcher

Change-Id: Iabedb5d6bbe34883c21015c8d74f68e9ba2a7f58
diff --git a/src/update/manager-base.cpp b/src/update/manager-base.cpp
index 3e0b612..88c61da 100644
--- a/src/update/manager-base.cpp
+++ b/src/update/manager-base.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2023,  The University of Memphis,
+ * Copyright (c) 2014-2025,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -53,11 +53,10 @@
 void
 CommandManagerBase::advertiseAndInsertPrefix(const ndn::Name& prefix,
                                              const ndn::Interest& interest,
-                                             const ndn::mgmt::ControlParameters& parameters,
+                                             const ndn::mgmt::ControlParametersBase& parameters,
                                              const ndn::mgmt::CommandContinuation& done)
 {
-  const ndn::nfd::ControlParameters& castParams =
-    static_cast<const ndn::nfd::ControlParameters&>(parameters);
+  const auto& castParams = static_cast<const ndn::nfd::ControlParameters&>(parameters);
 
   // Only build a Name LSA if the added name is new
   if (m_namePrefixList.insert(castParams.getName())) {
@@ -95,11 +94,10 @@
 void
 CommandManagerBase::withdrawAndRemovePrefix(const ndn::Name& prefix,
                                             const ndn::Interest& interest,
-                                            const ndn::mgmt::ControlParameters& parameters,
+                                            const ndn::mgmt::ControlParametersBase& parameters,
                                             const ndn::mgmt::CommandContinuation& done)
 {
-  const ndn::nfd::ControlParameters& castParams =
-    static_cast<const ndn::nfd::ControlParameters&>(parameters);
+  const auto& castParams = static_cast<const ndn::nfd::ControlParameters&>(parameters);
 
   // Only build a Name LSA if the added name is new
   if (m_namePrefixList.erase(castParams.getName())) {
diff --git a/src/update/manager-base.hpp b/src/update/manager-base.hpp
index db6ef62..12b6f3c 100644
--- a/src/update/manager-base.hpp
+++ b/src/update/manager-base.hpp
@@ -65,18 +65,14 @@
 PUBLIC_WITH_TESTS_ELSE_PROTECTED:
   /*! \brief Validate the parameters for a given command.
    */
-  template<typename T>
+  template<typename Command>
   static bool
-  validateParameters(const ndn::mgmt::ControlParameters& parameters)
+  validateParameters(const ndn::mgmt::ControlParametersBase& parameters)
   {
-    const auto* castParams = dynamic_cast<const ndn::nfd::ControlParameters*>(&parameters);
-    BOOST_ASSERT(castParams != nullptr);
-
-    T command;
     try {
-      command.validateRequest(*castParams);
+      Command::validateRequest(dynamic_cast<const ndn::nfd::ControlParameters&>(parameters));
     }
-    catch (const ndn::nfd::ControlCommand::ArgumentError&) {
+    catch (const ndn::nfd::ArgumentError&) {
       throw;
     }
     catch (const std::exception& e) {
@@ -110,7 +106,7 @@
   void
   advertiseAndInsertPrefix(const ndn::Name& prefix,
                            const ndn::Interest& interest,
-                           const ndn::mgmt::ControlParameters& parameters,
+                           const ndn::mgmt::ControlParametersBase& parameters,
                            const ndn::mgmt::CommandContinuation& done);
 
   /*! \brief remove desired name prefix from the advertised name prefix list
@@ -119,7 +115,7 @@
   void
   withdrawAndRemovePrefix(const ndn::Name& prefix,
                           const ndn::Interest& interest,
-                          const ndn::mgmt::ControlParameters& parameters,
+                          const ndn::mgmt::ControlParametersBase& parameters,
                           const ndn::mgmt::CommandContinuation& done);
 
   /*! \brief save an advertised prefix to the nlsr configuration file
diff --git a/src/update/prefix-update-commands.cpp b/src/update/prefix-update-commands.cpp
index e783086..da43fe7 100644
--- a/src/update/prefix-update-commands.cpp
+++ b/src/update/prefix-update-commands.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2019,  The University of Memphis,
+/*
+ * Copyright (c) 2014-2025,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -17,33 +17,28 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #include "prefix-update-commands.hpp"
 
-namespace nlsr {
-namespace update {
+namespace nlsr::update {
 
-WithdrawPrefixCommand::WithdrawPrefixCommand()
-  : ControlCommand("nlsr", "withdraw")
-{
-  m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
-  m_responseValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
+const AdvertisePrefixCommand::RequestFormat AdvertisePrefixCommand::s_requestFormat =
+    RequestFormat()
+    .required(ndn::nfd::CONTROL_PARAMETER_NAME)
+    .optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
+const AdvertisePrefixCommand::ResponseFormat AdvertisePrefixCommand::s_responseFormat =
+    ResponseFormat()
+    .required(ndn::nfd::CONTROL_PARAMETER_NAME)
+    .optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
 
-  m_requestValidator.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
-  m_responseValidator.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
-}
+const WithdrawPrefixCommand::RequestFormat WithdrawPrefixCommand::s_requestFormat =
+    RequestFormat()
+    .required(ndn::nfd::CONTROL_PARAMETER_NAME)
+    .optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
+const WithdrawPrefixCommand::ResponseFormat WithdrawPrefixCommand::s_responseFormat =
+    ResponseFormat()
+    .required(ndn::nfd::CONTROL_PARAMETER_NAME)
+    .optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
 
-AdvertisePrefixCommand::AdvertisePrefixCommand()
-  : ControlCommand("nlsr", "advertise")
-{
-  m_requestValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
-  m_responseValidator.required(ndn::nfd::CONTROL_PARAMETER_NAME);
-
-  m_requestValidator.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
-  m_responseValidator.optional(ndn::nfd::CONTROL_PARAMETER_FLAGS);
-
-}
-
-} // namespace update
-} // namespace nlsr
+} // namespace nlsr::update
diff --git a/src/update/prefix-update-commands.hpp b/src/update/prefix-update-commands.hpp
index ce851a9..0f2f889 100644
--- a/src/update/prefix-update-commands.hpp
+++ b/src/update/prefix-update-commands.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  The University of Memphis,
+/*
+ * Copyright (c) 2014-2025,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -17,10 +17,10 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 /*! \file
- * Define parameters for commands to manipulate advertised name prefixes
+ * Define parameters for commands to manipulate advertised name prefixes.
  *
  * These classes serve to define what parameters are required for
  * Prefix Update commands. We assume these commands are secure because
@@ -36,22 +36,18 @@
 
 #include <ndn-cxx/mgmt/nfd/control-command.hpp>
 
-namespace nlsr {
-namespace update {
+namespace nlsr::update {
 
-class WithdrawPrefixCommand : public ndn::nfd::ControlCommand
+class AdvertisePrefixCommand : public ndn::nfd::ControlCommand<AdvertisePrefixCommand>
 {
-public:
-  WithdrawPrefixCommand();
+  NDN_CXX_CONTROL_COMMAND(AdvertisePrefixCommand, "nlsr", "advertise");
 };
 
-class AdvertisePrefixCommand : public ndn::nfd::ControlCommand
+class WithdrawPrefixCommand : public ndn::nfd::ControlCommand<WithdrawPrefixCommand>
 {
-public:
-  AdvertisePrefixCommand();
+  NDN_CXX_CONTROL_COMMAND(WithdrawPrefixCommand, "nlsr", "withdraw");
 };
 
-} // namespace update
-} // namespace nlsr
+} // namespace nlsr::update
 
 #endif // NLSR_UPDATE_PREFIX_UPDATE_COMMANDS_HPP
diff --git a/src/update/prefix-update-processor.cpp b/src/update/prefix-update-processor.cpp
index 6edfae7..1a1b5da 100644
--- a/src/update/prefix-update-processor.cpp
+++ b/src/update/prefix-update-processor.cpp
@@ -79,7 +79,7 @@
 PrefixUpdateProcessor::makeAuthorization()
 {
   return [=] (const ndn::Name& prefix, const ndn::Interest& interest,
-              const ndn::mgmt::ControlParameters* params,
+              const ndn::mgmt::ControlParametersBase* params,
               const ndn::mgmt::AcceptContinuation& accept,
               const ndn::mgmt::RejectContinuation& reject) {
     m_validator.validate(interest,