rib+tools: adapt to Controller::CommandFailCallback with ControlResponse

refs #3739

Change-Id: Icf5b3ed0bd997730a024bad2ccd258c8168b4ccb
diff --git a/tools/ndn-autoconfig/base.cpp b/tools/ndn-autoconfig/base.cpp
index c896e67..a796f4c 100644
--- a/tools/ndn-autoconfig/base.cpp
+++ b/tools/ndn-autoconfig/base.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2016,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -57,7 +57,7 @@
   m_controller.start<nfd::FaceCreateCommand>(nfd::ControlParameters()
                                                .setUri(canonicalUri.toString()),
                                              bind(&Base::onHubConnectSuccess, this, _1),
-                                             bind(&Base::onHubConnectError, this, _1, _2));
+                                             bind(&Base::onHubConnectError, this, _1));
 }
 
 void
@@ -81,10 +81,10 @@
 }
 
 void
-Base::onHubConnectError(uint32_t code, const std::string& error)
+Base::onHubConnectError(const nfd::ControlResponse& response)
 {
   std::ostringstream os;
-  os << "Failed to create face: " << error << " (code: " << code << ")";
+  os << "Failed to create face: " << response.getText() << " (code: " << response.getCode() << ")";
   BOOST_THROW_EXCEPTION(Error(os.str()));
 }
 
@@ -99,7 +99,7 @@
                                                 .setCost(100)
                                                 .setExpirationPeriod(time::milliseconds::max()),
                                               bind(&Base::onPrefixRegistrationSuccess, this, _1),
-                                              bind(&Base::onPrefixRegistrationError, this, _1, _2));
+                                              bind(&Base::onPrefixRegistrationError, this, _1));
 }
 
 void
@@ -109,10 +109,10 @@
 }
 
 void
-Base::onPrefixRegistrationError(uint32_t code, const std::string& error)
+Base::onPrefixRegistrationError(const nfd::ControlResponse& response)
 {
   std::ostringstream os;
-  os << "Failed in name registration, " << error << " (code: " << code << ")";
+  os << "Failed in name registration, " << response.getText() << " (code: " << response.getCode() << ")";
   BOOST_THROW_EXCEPTION(Error(os.str()));
 }
 
diff --git a/tools/ndn-autoconfig/base.hpp b/tools/ndn-autoconfig/base.hpp
index d69f49c..c4c3a9b 100644
--- a/tools/ndn-autoconfig/base.hpp
+++ b/tools/ndn-autoconfig/base.hpp
@@ -93,7 +93,7 @@
   onHubConnectSuccess(const nfd::ControlParameters& resp);
 
   void
-  onHubConnectError(uint32_t code, const std::string& error);
+  onHubConnectError(const nfd::ControlResponse& response);
 
   void
   registerPrefix(const Name& prefix, uint64_t faceId);
@@ -102,7 +102,7 @@
   onPrefixRegistrationSuccess(const nfd::ControlParameters& commandSuccessResult);
 
   void
-  onPrefixRegistrationError(uint32_t code, const std::string& error);
+  onPrefixRegistrationError(const nfd::ControlResponse& response);
 
 protected:
   Face& m_face;
diff --git a/tools/ndn-autoconfig/multicast-discovery.cpp b/tools/ndn-autoconfig/multicast-discovery.cpp
index 2e3f8a2..a474899 100644
--- a/tools/ndn-autoconfig/multicast-discovery.cpp
+++ b/tools/ndn-autoconfig/multicast-discovery.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2016,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -108,7 +108,7 @@
                                                   bind(&MulticastDiscovery::onRegisterSuccess,
                                                        this),
                                                   bind(&MulticastDiscovery::onRegisterFailure,
-                                                       this, _1, _2));
+                                                       this, _1));
     }
   }
 }
@@ -124,9 +124,9 @@
 }
 
 void
-MulticastDiscovery::onRegisterFailure(uint32_t code, const std::string& error)
+MulticastDiscovery::onRegisterFailure(const nfd::ControlResponse& response)
 {
-  std::cerr << "ERROR: " << error << " (code: " << code << ")" << std::endl;
+  std::cerr << "ERROR: " << response.getText() << " (code: " << response.getCode() << ")" << std::endl;
   --nRequestedRegs;
 
   if (nRequestedRegs == nFinishedRegs) {
@@ -150,14 +150,14 @@
   m_controller.start<nfd::StrategyChoiceSetCommand>(parameters,
                                                     bind(&MulticastDiscovery::requestHubData, this),
                                                     bind(&MulticastDiscovery::onSetStrategyFailure,
-                                                         this, _2));
+                                                         this, _1));
 }
 
 void
-MulticastDiscovery::onSetStrategyFailure(const std::string& error)
+MulticastDiscovery::onSetStrategyFailure(const nfd::ControlResponse& response)
 {
   m_nextStageOnFailure("Failed to set multicast strategy for " +
-                       LOCALHOP_HUB_DISCOVERY_PREFIX.toUri() + " namespace (" + error + "). "
+                       LOCALHOP_HUB_DISCOVERY_PREFIX.toUri() + " namespace (" + response.getText() + "). "
                        "Skipping multicast discovery stage");
 }
 
diff --git a/tools/ndn-autoconfig/multicast-discovery.hpp b/tools/ndn-autoconfig/multicast-discovery.hpp
index 8047926..32f7133 100644
--- a/tools/ndn-autoconfig/multicast-discovery.hpp
+++ b/tools/ndn-autoconfig/multicast-discovery.hpp
@@ -69,13 +69,13 @@
   onRegisterSuccess();
 
   void
-  onRegisterFailure(uint32_t code, const std::string& error);
+  onRegisterFailure(const nfd::ControlResponse& response);
 
   void
   setStrategy();
 
   void
-  onSetStrategyFailure(const std::string& error);
+  onSetStrategyFailure(const nfd::ControlResponse& response);
 
   // Start to look for a hub (NDN hub discovery first stage)
   void
diff --git a/tools/nfd-autoreg.cpp b/tools/nfd-autoreg.cpp
index b21fe6d..996c03c 100644
--- a/tools/nfd-autoreg.cpp
+++ b/tools/nfd-autoreg.cpp
@@ -70,10 +70,11 @@
 
   void
   onRegisterCommandFailure(uint64_t faceId, const Name& prefix,
-                           uint32_t code, const std::string& reason)
+                           const nfd::ControlResponse& response)
   {
     std::cerr << "FAILED: register " << prefix << " on face " << faceId
-              << " (code: " << code << ", reason: " << reason << ")" << std::endl;
+              << " (code: " << response.getCode() << ", reason: " << response.getText() << ")"
+              << std::endl;
   }
 
   /**
@@ -137,7 +138,7 @@
             .setCost(m_cost)
             .setExpirationPeriod(time::milliseconds::max()),
           bind(&AutoregServer::onRegisterCommandSuccess, this, faceId, *prefix),
-          bind(&AutoregServer::onRegisterCommandFailure, this, faceId, *prefix, _1, _2));
+          bind(&AutoregServer::onRegisterCommandFailure, this, faceId, *prefix, _1));
       }
   }
 
diff --git a/tools/nfdc/channel-module.cpp b/tools/nfdc/channel-module.cpp
index af55d7b..15cffb4 100644
--- a/tools/nfdc/channel-module.cpp
+++ b/tools/nfdc/channel-module.cpp
@@ -33,7 +33,7 @@
 void
 ChannelModule::fetchStatus(Controller& controller,
                            const function<void()>& onSuccess,
-                           const Controller::CommandFailCallback& onFailure,
+                           const Controller::DatasetFailCallback& onFailure,
                            const CommandOptions& options)
 {
   controller.fetch<ndn::nfd::ChannelDataset>(
diff --git a/tools/nfdc/channel-module.hpp b/tools/nfdc/channel-module.hpp
index e3486a1..6225a27 100644
--- a/tools/nfdc/channel-module.hpp
+++ b/tools/nfdc/channel-module.hpp
@@ -43,7 +43,7 @@
   virtual void
   fetchStatus(Controller& controller,
               const function<void()>& onSuccess,
-              const Controller::CommandFailCallback& onFailure,
+              const Controller::DatasetFailCallback& onFailure,
               const CommandOptions& options) override;
 
   virtual void
diff --git a/tools/nfdc/face-id-fetcher.cpp b/tools/nfdc/face-id-fetcher.cpp
index da09c11..08bc9ff 100644
--- a/tools/nfdc/face-id-fetcher.cpp
+++ b/tools/nfdc/face-id-fetcher.cpp
@@ -164,12 +164,11 @@
 }
 
 void
-FaceIdFetcher::onFaceCreateError(uint32_t code,
-                                 const std::string& error,
+FaceIdFetcher::onFaceCreateError(const ndn::nfd::ControlResponse& response,
                                  const std::string& message)
 {
   std::stringstream ss;
-  ss << message << " : " << error << " (code " << code << ")";
+  ss << message << " : " << response.getText() << " (code " << response.getCode() << ")";
   fail(ss.str());
 }
 
@@ -181,7 +180,7 @@
 
   m_controller.start<ndn::nfd::FaceCreateCommand>(parameters,
     [this] (const ndn::nfd::ControlParameters& result) { succeed(result.getFaceId()); },
-    bind(&FaceIdFetcher::onFaceCreateError, this, _1, _2, "Face creation failed"));
+    bind(&FaceIdFetcher::onFaceCreateError, this, _1, "Face creation failed"));
 }
 
 void
diff --git a/tools/nfdc/face-id-fetcher.hpp b/tools/nfdc/face-id-fetcher.hpp
index 50e0083..cf0eb6f 100644
--- a/tools/nfdc/face-id-fetcher.hpp
+++ b/tools/nfdc/face-id-fetcher.hpp
@@ -88,8 +88,7 @@
   startFaceCreate(const FaceUri& canonicalUri);
 
   void
-  onFaceCreateError(uint32_t code,
-                    const std::string& error,
+  onFaceCreateError(const ndn::nfd::ControlResponse& response,
                     const std::string& message);
 
   void
diff --git a/tools/nfdc/face-module.cpp b/tools/nfdc/face-module.cpp
index 9c5e74c..97e836c 100644
--- a/tools/nfdc/face-module.cpp
+++ b/tools/nfdc/face-module.cpp
@@ -53,7 +53,7 @@
 void
 FaceModule::fetchStatus(Controller& controller,
                         const function<void()>& onSuccess,
-                        const Controller::CommandFailCallback& onFailure,
+                        const Controller::DatasetFailCallback& onFailure,
                         const CommandOptions& options)
 {
   controller.fetch<ndn::nfd::FaceDataset>(
diff --git a/tools/nfdc/face-module.hpp b/tools/nfdc/face-module.hpp
index 3f8020f..27c089b 100644
--- a/tools/nfdc/face-module.hpp
+++ b/tools/nfdc/face-module.hpp
@@ -43,7 +43,7 @@
   virtual void
   fetchStatus(Controller& controller,
               const function<void()>& onSuccess,
-              const Controller::CommandFailCallback& onFailure,
+              const Controller::DatasetFailCallback& onFailure,
               const CommandOptions& options) override;
 
   virtual void
diff --git a/tools/nfdc/fib-module.cpp b/tools/nfdc/fib-module.cpp
index 27d3922..3da24ee 100644
--- a/tools/nfdc/fib-module.cpp
+++ b/tools/nfdc/fib-module.cpp
@@ -33,7 +33,7 @@
 void
 FibModule::fetchStatus(Controller& controller,
                        const function<void()>& onSuccess,
-                       const Controller::CommandFailCallback& onFailure,
+                       const Controller::DatasetFailCallback& onFailure,
                        const CommandOptions& options)
 {
   controller.fetch<ndn::nfd::FibDataset>(
diff --git a/tools/nfdc/fib-module.hpp b/tools/nfdc/fib-module.hpp
index 2472bd5..6c33d64 100644
--- a/tools/nfdc/fib-module.hpp
+++ b/tools/nfdc/fib-module.hpp
@@ -44,7 +44,7 @@
   virtual void
   fetchStatus(Controller& controller,
               const function<void()>& onSuccess,
-              const Controller::CommandFailCallback& onFailure,
+              const Controller::DatasetFailCallback& onFailure,
               const CommandOptions& options) override;
 
   virtual void
diff --git a/tools/nfdc/forwarder-general-module.cpp b/tools/nfdc/forwarder-general-module.cpp
index 481fd40..dc12e96 100644
--- a/tools/nfdc/forwarder-general-module.cpp
+++ b/tools/nfdc/forwarder-general-module.cpp
@@ -38,7 +38,7 @@
 void
 ForwarderGeneralModule::fetchStatus(Controller& controller,
                                     const function<void()>& onSuccess,
-                                    const Controller::CommandFailCallback& onFailure,
+                                    const Controller::DatasetFailCallback& onFailure,
                                     const CommandOptions& options)
 {
   controller.fetch<ndn::nfd::ForwarderGeneralStatusDataset>(
diff --git a/tools/nfdc/forwarder-general-module.hpp b/tools/nfdc/forwarder-general-module.hpp
index 9bcf929..f8c30d8 100644
--- a/tools/nfdc/forwarder-general-module.hpp
+++ b/tools/nfdc/forwarder-general-module.hpp
@@ -48,7 +48,7 @@
   virtual void
   fetchStatus(Controller& controller,
               const function<void()>& onSuccess,
-              const Controller::CommandFailCallback& onFailure,
+              const Controller::DatasetFailCallback& onFailure,
               const CommandOptions& options) override;
 
   void
diff --git a/tools/nfdc/legacy-nfdc.cpp b/tools/nfdc/legacy-nfdc.cpp
index 83a3db8..3e4c0e6 100644
--- a/tools/nfdc/legacy-nfdc.cpp
+++ b/tools/nfdc/legacy-nfdc.cpp
@@ -113,7 +113,7 @@
 
       m_controller.start<ndn::nfd::FibAddNextHopCommand>(parameters,
         bind(&LegacyNfdc::onSuccess, this, _1, "Nexthop insertion succeeded"),
-        bind(&LegacyNfdc::onError, this, _1, _2, "Nexthop insertion failed"));
+        bind(&LegacyNfdc::onError, this, _1, "Nexthop insertion failed"));
     },
     bind(&LegacyNfdc::onObtainFaceIdFailure, this, _1));
 }
@@ -133,7 +133,7 @@
 
       m_controller.start<ndn::nfd::FibRemoveNextHopCommand>(parameters,
         bind(&LegacyNfdc::onSuccess, this, _1, "Nexthop removal succeeded"),
-        bind(&LegacyNfdc::onError, this, _1, _2, "Nexthop removal failed"));
+        bind(&LegacyNfdc::onError, this, _1, "Nexthop removal failed"));
     },
     bind(&LegacyNfdc::onObtainFaceIdFailure, this, _1));
 }
@@ -159,7 +159,7 @@
 
       m_controller.start<ndn::nfd::RibRegisterCommand>(parameters,
         bind(&LegacyNfdc::onSuccess, this, _1, "Successful in name registration"),
-        bind(&LegacyNfdc::onError, this, _1, _2, "Failed in name registration"));
+        bind(&LegacyNfdc::onError, this, _1, "Failed in name registration"));
     },
     bind(&LegacyNfdc::onObtainFaceIdFailure, this, _1));
 }
@@ -180,7 +180,7 @@
 
       m_controller.start<ndn::nfd::RibUnregisterCommand>(parameters,
         bind(&LegacyNfdc::onSuccess, this, _1, "Successful in unregistering name"),
-        bind(&LegacyNfdc::onError, this, _1, _2, "Failed in unregistering name"));
+        bind(&LegacyNfdc::onError, this, _1, "Failed in unregistering name"));
     },
     bind(&LegacyNfdc::onObtainFaceIdFailure, this, _1));
 }
@@ -221,7 +221,7 @@
 
   m_controller.start<ndn::nfd::FaceCreateCommand>(parameters,
     bind(&LegacyNfdc::onSuccess, this, _1, "Face creation succeeded"),
-    bind(&LegacyNfdc::onError, this, _1, _2, "Face creation failed"));
+    bind(&LegacyNfdc::onError, this, _1, "Face creation failed"));
 }
 
 void
@@ -237,7 +237,7 @@
 
       m_controller.start<ndn::nfd::FaceDestroyCommand>(faceParameters,
         bind(&LegacyNfdc::onSuccess, this, _1, "Face destroy succeeded"),
-        bind(&LegacyNfdc::onError, this, _1, _2, "Face destroy failed"));
+        bind(&LegacyNfdc::onError, this, _1, "Face destroy failed"));
     },
     bind(&LegacyNfdc::onObtainFaceIdFailure, this, _1));
 }
@@ -255,7 +255,7 @@
 
   m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
     bind(&LegacyNfdc::onSuccess, this, _1, "Successfully set strategy choice"),
-    bind(&LegacyNfdc::onError, this, _1, _2, "Failed to set strategy choice"));
+    bind(&LegacyNfdc::onError, this, _1, "Failed to set strategy choice"));
 }
 
 void
@@ -268,7 +268,7 @@
 
   m_controller.start<ndn::nfd::StrategyChoiceUnsetCommand>(parameters,
     bind(&LegacyNfdc::onSuccess, this, _1, "Successfully unset strategy choice"),
-    bind(&LegacyNfdc::onError, this, _1, _2, "Failed to unset strategy choice"));
+    bind(&LegacyNfdc::onError, this, _1, "Failed to unset strategy choice"));
 }
 
 void
@@ -278,10 +278,10 @@
 }
 
 void
-LegacyNfdc::onError(uint32_t code, const std::string& error, const std::string& message)
+LegacyNfdc::onError(const ndn::nfd::ControlResponse& response, const std::string& message)
 {
   std::ostringstream os;
-  os << message << ": " << error << " (code: " << code << ")";
+  os << message << ": " << response.getText() << " (code: " << response.getCode() << ")";
   BOOST_THROW_EXCEPTION(Error(os.str()));
 }
 
diff --git a/tools/nfdc/legacy-nfdc.hpp b/tools/nfdc/legacy-nfdc.hpp
index 01ed7b9..5a804a1 100644
--- a/tools/nfdc/legacy-nfdc.hpp
+++ b/tools/nfdc/legacy-nfdc.hpp
@@ -142,13 +142,12 @@
   strategyChoiceUnset();
 
 private:
-
   void
   onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
             const std::string& message);
 
   void
-  onError(uint32_t code, const std::string& error, const std::string& message);
+  onError(const ndn::nfd::ControlResponse& response, const std::string& message);
 
   void
   onCanonizeFailure(const std::string& reason);
diff --git a/tools/nfdc/module.hpp b/tools/nfdc/module.hpp
index f33afac..fae4ce7 100644
--- a/tools/nfdc/module.hpp
+++ b/tools/nfdc/module.hpp
@@ -55,7 +55,7 @@
   virtual void
   fetchStatus(Controller& controller,
               const function<void()>& onSuccess,
-              const Controller::CommandFailCallback& onFailure,
+              const Controller::DatasetFailCallback& onFailure,
               const CommandOptions& options) = 0;
 
   /** \brief format collected status as XML
diff --git a/tools/nfdc/rib-module.cpp b/tools/nfdc/rib-module.cpp
index bf2da3d..266a550 100644
--- a/tools/nfdc/rib-module.cpp
+++ b/tools/nfdc/rib-module.cpp
@@ -33,7 +33,7 @@
 void
 RibModule::fetchStatus(Controller& controller,
                        const function<void()>& onSuccess,
-                       const Controller::CommandFailCallback& onFailure,
+                       const Controller::DatasetFailCallback& onFailure,
                        const CommandOptions& options)
 {
   controller.fetch<ndn::nfd::RibDataset>(
diff --git a/tools/nfdc/rib-module.hpp b/tools/nfdc/rib-module.hpp
index 20e2144..85230aa 100644
--- a/tools/nfdc/rib-module.hpp
+++ b/tools/nfdc/rib-module.hpp
@@ -44,7 +44,7 @@
   virtual void
   fetchStatus(Controller& controller,
               const function<void()>& onSuccess,
-              const Controller::CommandFailCallback& onFailure,
+              const Controller::DatasetFailCallback& onFailure,
               const CommandOptions& options) override;
 
   virtual void
diff --git a/tools/nfdc/strategy-choice-module.cpp b/tools/nfdc/strategy-choice-module.cpp
index c32b5aa..4a6b36f 100644
--- a/tools/nfdc/strategy-choice-module.cpp
+++ b/tools/nfdc/strategy-choice-module.cpp
@@ -33,7 +33,7 @@
 void
 StrategyChoiceModule::fetchStatus(Controller& controller,
                                   const function<void()>& onSuccess,
-                                  const Controller::CommandFailCallback& onFailure,
+                                  const Controller::DatasetFailCallback& onFailure,
                                   const CommandOptions& options)
 {
   controller.fetch<ndn::nfd::StrategyChoiceDataset>(
diff --git a/tools/nfdc/strategy-choice-module.hpp b/tools/nfdc/strategy-choice-module.hpp
index 9c78eb7..4d26896 100644
--- a/tools/nfdc/strategy-choice-module.hpp
+++ b/tools/nfdc/strategy-choice-module.hpp
@@ -43,7 +43,7 @@
   virtual void
   fetchStatus(Controller& controller,
               const function<void()>& onSuccess,
-              const Controller::CommandFailCallback& onFailure,
+              const Controller::DatasetFailCallback& onFailure,
               const CommandOptions& options) override;
 
   virtual void