mgmt: migrate to new Dispatcher API for control commands

Change-Id: Iaba68dde879fbb562e13ef383e0b753174708baa
diff --git a/daemon/mgmt/cs-manager.cpp b/daemon/mgmt/cs-manager.cpp
index a807df8..3be976f 100644
--- a/daemon/mgmt/cs-manager.cpp
+++ b/daemon/mgmt/cs-manager.cpp
@@ -39,12 +39,15 @@
   , m_cs(cs)
   , m_fwCounters(fwCounters)
 {
-  registerCommandHandler<ndn::nfd::CsConfigCommand>("config",
-    [this] (auto&&, auto&&, auto&&... args) { changeConfig(std::forward<decltype(args)>(args)...); });
-  registerCommandHandler<ndn::nfd::CsEraseCommand>("erase",
-    [this] (auto&&, auto&&, auto&&... args) { erase(std::forward<decltype(args)>(args)...); });
-  registerStatusDatasetHandler("info",
-    [this] (auto&&, auto&&, auto&&... args) { serveInfo(std::forward<decltype(args)>(args)...); });
+  registerCommandHandler<ndn::nfd::CsConfigCommand>([this] (auto&&, auto&&, auto&&... args) {
+    changeConfig(std::forward<decltype(args)>(args)...);
+  });
+  registerCommandHandler<ndn::nfd::CsEraseCommand>([this] (auto&&, auto&&, auto&&... args) {
+    erase(std::forward<decltype(args)>(args)...);
+  });
+  registerStatusDatasetHandler("info", [this] (auto&&, auto&&, auto&&... args) {
+    serveInfo(std::forward<decltype(args)>(args)...);
+  });
 }
 
 void
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index e822f12..34eb8e6 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -49,12 +49,15 @@
   , m_faceTable(faceSystem.getFaceTable())
 {
   // register handlers for ControlCommand
-  registerCommandHandler<ndn::nfd::FaceCreateCommand>("create",
-    [this] (auto&&, auto&&, auto&&... args) { createFace(std::forward<decltype(args)>(args)...); });
-  registerCommandHandler<ndn::nfd::FaceUpdateCommand>("update",
-    [this] (auto&&, auto&&... args) { updateFace(std::forward<decltype(args)>(args)...); });
-  registerCommandHandler<ndn::nfd::FaceDestroyCommand>("destroy",
-    [this] (auto&&, auto&&, auto&&... args) { destroyFace(std::forward<decltype(args)>(args)...); });
+  registerCommandHandler<ndn::nfd::FaceCreateCommand>([this] (auto&&, auto&&, auto&&... args) {
+    createFace(std::forward<decltype(args)>(args)...);
+  });
+  registerCommandHandler<ndn::nfd::FaceUpdateCommand>([this] (auto&&, auto&&... args) {
+    updateFace(std::forward<decltype(args)>(args)...);
+  });
+  registerCommandHandler<ndn::nfd::FaceDestroyCommand>([this] (auto&&, auto&&, auto&&... args) {
+    destroyFace(std::forward<decltype(args)>(args)...);
+  });
 
   // register handlers for StatusDataset
   registerStatusDatasetHandler("list",
diff --git a/daemon/mgmt/fib-manager.cpp b/daemon/mgmt/fib-manager.cpp
index cdae3f6..4de989e 100644
--- a/daemon/mgmt/fib-manager.cpp
+++ b/daemon/mgmt/fib-manager.cpp
@@ -44,12 +44,15 @@
   , m_fib(fib)
   , m_faceTable(faceTable)
 {
-  registerCommandHandler<ndn::nfd::FibAddNextHopCommand>("add-nexthop",
-    [this] (auto&&, auto&&... args) { addNextHop(std::forward<decltype(args)>(args)...); });
-  registerCommandHandler<ndn::nfd::FibRemoveNextHopCommand>("remove-nexthop",
-    [this] (auto&&, auto&&... args) { removeNextHop(std::forward<decltype(args)>(args)...); });
-  registerStatusDatasetHandler("list",
-    [this] (auto&&, auto&&, auto&&... args) { listEntries(std::forward<decltype(args)>(args)...); });
+  registerCommandHandler<ndn::nfd::FibAddNextHopCommand>([this] (auto&&, auto&&... args) {
+    addNextHop(std::forward<decltype(args)>(args)...);
+  });
+  registerCommandHandler<ndn::nfd::FibRemoveNextHopCommand>([this] (auto&&, auto&&... args) {
+    removeNextHop(std::forward<decltype(args)>(args)...);
+  });
+  registerStatusDatasetHandler("list", [this] (auto&&, auto&&, auto&&... args) {
+    listEntries(std::forward<decltype(args)>(args)...);
+  });
 }
 
 void
diff --git a/daemon/mgmt/manager-base.hpp b/daemon/mgmt/manager-base.hpp
index 53a5fc6..ec03463 100644
--- a/daemon/mgmt/manager-base.hpp
+++ b/daemon/mgmt/manager-base.hpp
@@ -76,15 +76,23 @@
   ~ManagerBase();
 
 NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED: // registrations to the dispatcher
-  // difference from ndn::mgmt::ControlCommandHandler: accepts nfd::ControlParameters
+  template<typename Command>
   using ControlCommandHandler = std::function<void(const Name& prefix, const Interest& interest,
-                                                   const ControlParameters& parameters,
+                                                   const typename Command::RequestParameters& parameters,
                                                    const CommandContinuation& done)>;
 
   template<typename Command>
   void
-  registerCommandHandler(const std::string& verb,
-                         ControlCommandHandler handler);
+  registerCommandHandler(ControlCommandHandler<Command> handler)
+  {
+    auto handle = [h = std::move(handler)] (const auto& prefix, const auto& interest,
+                                            const auto& params, const auto& done) {
+      const auto& reqParams = static_cast<const typename Command::RequestParameters&>(params);
+      h(prefix, interest, reqParams, done);
+    };
+    m_dispatcher.addControlCommand<Command>(makeAuthorization(Command::verb.toUri()),
+                                            std::move(handle));
+  }
 
   void
   registerStatusDatasetHandler(const std::string& verb,
@@ -128,34 +136,6 @@
   CommandAuthenticator* m_authenticator = nullptr;
 };
 
-template<typename Command>
-void
-ManagerBase::registerCommandHandler(const std::string& verb, ControlCommandHandler handler)
-{
-  auto validate = [] (const ndn::mgmt::ControlParametersBase& params) {
-    BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&params) != nullptr);
-    try {
-      Command::validateRequest(static_cast<const ControlParameters&>(params));
-      return true;
-    }
-    catch (const std::invalid_argument&) {
-      return false;
-    }
-  };
-
-  auto handle = [handler = std::move(handler)] (const Name& prefix, const Interest& interest,
-                                                const ndn::mgmt::ControlParametersBase& params,
-                                                const CommandContinuation& done) {
-    BOOST_ASSERT(dynamic_cast<const ControlParameters*>(&params) != nullptr);
-    ControlParameters parameters = static_cast<const ControlParameters&>(params);
-    Command::applyDefaultsToRequest(parameters);
-    handler(prefix, interest, parameters, done);
-  };
-
-  m_dispatcher.addControlCommand<ControlParameters>(makeRelPrefix(verb), makeAuthorization(verb),
-                                                    std::move(validate), std::move(handle));
-}
-
 } // namespace nfd
 
 #endif // NFD_DAEMON_MGMT_MANAGER_BASE_HPP
diff --git a/daemon/mgmt/rib-manager.cpp b/daemon/mgmt/rib-manager.cpp
index 865b30f..6cc614a 100644
--- a/daemon/mgmt/rib-manager.cpp
+++ b/daemon/mgmt/rib-manager.cpp
@@ -61,12 +61,15 @@
   , m_paValidator(make_unique<ndn::security::CertificateFetcherDirectFetch>(face))
   , m_isLocalhopEnabled(false)
 {
-  registerCommandHandler<ndn::nfd::RibRegisterCommand>("register",
-    [this] (auto&&, auto&&... args) { registerEntry(std::forward<decltype(args)>(args)...); });
-  registerCommandHandler<ndn::nfd::RibUnregisterCommand>("unregister",
-    [this] (auto&&, auto&&... args) { unregisterEntry(std::forward<decltype(args)>(args)...); });
-  registerStatusDatasetHandler("list",
-    [this] (auto&&, auto&&, auto&&... args) { listEntries(std::forward<decltype(args)>(args)...); });
+  registerCommandHandler<ndn::nfd::RibRegisterCommand>([this] (auto&&, auto&&... args) {
+    registerEntry(std::forward<decltype(args)>(args)...);
+  });
+  registerCommandHandler<ndn::nfd::RibUnregisterCommand>([this] (auto&&, auto&&... args) {
+    unregisterEntry(std::forward<decltype(args)>(args)...);
+  });
+  registerStatusDatasetHandler("list", [this] (auto&&, auto&&, auto&&... args) {
+    listEntries(std::forward<decltype(args)>(args)...);
+  });
 }
 
 void
diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp
index e31ae76..1b4628e 100644
--- a/daemon/mgmt/strategy-choice-manager.cpp
+++ b/daemon/mgmt/strategy-choice-manager.cpp
@@ -42,12 +42,15 @@
   : ManagerBase("strategy-choice", dispatcher, authenticator)
   , m_table(strategyChoice)
 {
-  registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>("set",
-    [this] (auto&&, auto&&, auto&&... args) { setStrategy(std::forward<decltype(args)>(args)...); });
-  registerCommandHandler<ndn::nfd::StrategyChoiceUnsetCommand>("unset",
-    [this] (auto&&, auto&&, auto&&... args) { unsetStrategy(std::forward<decltype(args)>(args)...); });
-  registerStatusDatasetHandler("list",
-    [this] (auto&&, auto&&, auto&&... args) { listChoices(std::forward<decltype(args)>(args)...); });
+  registerCommandHandler<ndn::nfd::StrategyChoiceSetCommand>([this] (auto&&, auto&&, auto&&... args) {
+    setStrategy(std::forward<decltype(args)>(args)...);
+  });
+  registerCommandHandler<ndn::nfd::StrategyChoiceUnsetCommand>([this] (auto&&, auto&&, auto&&... args) {
+    unsetStrategy(std::forward<decltype(args)>(args)...);
+  });
+  registerStatusDatasetHandler("list", [this] (auto&&, auto&&, auto&&... args) {
+    listChoices(std::forward<decltype(args)>(args)...);
+  });
 }
 
 void