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

refs #3739

Change-Id: Icf5b3ed0bd997730a024bad2ccd258c8168b4ccb
diff --git a/rib/auto-prefix-propagator.cpp b/rib/auto-prefix-propagator.cpp
index 1d87208..c597e82 100644
--- a/rib/auto-prefix-propagator.cpp
+++ b/rib/auto-prefix-propagator.cpp
@@ -282,7 +282,7 @@
      parameters,
      bind(&AutoPrefixPropagator::afterPropagateSucceed, this, parameters, options, refreshEvent),
      bind(&AutoPrefixPropagator::afterPropagateFail,
-          this, _1, _2, parameters, options, retryWaitTime, retryEvent),
+          this, _1, parameters, options, retryWaitTime, retryEvent),
      options);
 }
 
@@ -296,7 +296,7 @@
   m_nfdController.start<ndn::nfd::RibUnregisterCommand>(
      parameters,
      bind(&AutoPrefixPropagator::afterRevokeSucceed, this, parameters, options, retryWaitTime),
-     bind(&AutoPrefixPropagator::afterRevokeFail, this, _1, _2, parameters, options),
+     bind(&AutoPrefixPropagator::afterRevokeFail, this, _1, parameters, options),
      options);
 }
 
@@ -399,14 +399,14 @@
 }
 
 void
-AutoPrefixPropagator::afterPropagateFail(uint32_t code, const std::string& reason,
+AutoPrefixPropagator::afterPropagateFail(const ndn::nfd::ControlResponse& response,
                                          const ControlParameters& parameters,
                                          const CommandOptions& options,
                                          time::seconds retryWaitTime,
                                          const ndn::Scheduler::Event& retryEvent)
 {
   NFD_LOG_TRACE("fail to propagate " << parameters.getName()
-                                     << "\n\t reason:" << reason
+                                     << "\n\t reason:" << response.getText()
                                      << "\n\t retry wait time: " << retryWaitTime);
 
   auto entryIt = m_propagatedEntries.find(parameters.getName());
@@ -442,12 +442,12 @@
 }
 
 void
-AutoPrefixPropagator::afterRevokeFail(uint32_t code, const std::string& reason,
-                                       const ControlParameters& parameters,
-                                       const CommandOptions& options)
+AutoPrefixPropagator::afterRevokeFail(const ndn::nfd::ControlResponse& response,
+                                      const ControlParameters& parameters,
+                                      const CommandOptions& options)
 {
   NFD_LOG_INFO("fail to revoke the propagation of  " << parameters.getName()
-                                                     << "\n\t reason:" << reason);
+                                                     << "\n\t reason:" << response.getText());
 }
 
 void
diff --git a/rib/auto-prefix-propagator.hpp b/rib/auto-prefix-propagator.hpp
index 11ad67f..483ab68 100644
--- a/rib/auto-prefix-propagator.hpp
+++ b/rib/auto-prefix-propagator.hpp
@@ -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,
@@ -321,15 +321,14 @@
    * If the PropagatedEntry still exists, schedule a retry timer to redo propagation
    * after a duration defined by current retry time @p retryWaitTime
    *
-   * @param code error code.
-   * @param reason error reason in string.
+   * @param response ControlResponse from remote NFD-RIB
    * @param parameters the ControlParameters used by the registration command for propagation
    * @param options the CommandOptions used by registration command for propagation
    * @param retryWaitTime the current wait time before retrying propagation
    * @param retryEvent the event of retrying propagation
    */
   void
-  afterPropagateFail(uint32_t code, const std::string& reason,
+  afterPropagateFail(const ndn::nfd::ControlResponse& response,
                      const ndn::nfd::ControlParameters& parameters,
                      const ndn::nfd::CommandOptions& options,
                      time::seconds retryWaitTime,
@@ -357,13 +356,12 @@
   /**
    * @brief invoked after revocation fails.
    *
-   * @param code error code.
-   * @param reason error reason in string.
+   * @param response ControlResponse from remote NFD-RIB
    * @param parameters the ControlParameters used by the unregistration command for revocation
    * @param options the CommandOptions used by the unregistration command for revocation
    */
   void
-  afterRevokeFail(uint32_t code, const std::string& reason,
+  afterRevokeFail(const ndn::nfd::ControlResponse& response,
                   const ndn::nfd::ControlParameters& parameters,
                   const ndn::nfd::CommandOptions& options);
 
diff --git a/rib/fib-updater.cpp b/rib/fib-updater.cpp
index c467072..c6b4f09 100644
--- a/rib/fib-updater.cpp
+++ b/rib/fib-updater.cpp
@@ -243,7 +243,7 @@
       .setFaceId(update.faceId)
       .setCost(update.cost),
     bind(&FibUpdater::onUpdateSuccess, this, update, onSuccess, onFailure),
-    bind(&FibUpdater::onUpdateError, this, update, onSuccess, onFailure, _1, _2, nTimeouts));
+    bind(&FibUpdater::onUpdateError, this, update, onSuccess, onFailure, _1, nTimeouts));
 }
 
 void
@@ -257,7 +257,7 @@
       .setName(update.name)
       .setFaceId(update.faceId),
     bind(&FibUpdater::onUpdateSuccess, this, update, onSuccess, onFailure),
-    bind(&FibUpdater::onUpdateError, this, update, onSuccess, onFailure, _1, _2, nTimeouts));
+    bind(&FibUpdater::onUpdateError, this, update, onSuccess, onFailure, _1, nTimeouts));
 }
 
 void
@@ -285,16 +285,18 @@
 FibUpdater::onUpdateError(const FibUpdate update,
                           const FibUpdateSuccessCallback& onSuccess,
                           const FibUpdateFailureCallback& onFailure,
-                          uint32_t code, const std::string& error, uint32_t nTimeouts)
+                          const ndn::nfd::ControlResponse& response, uint32_t nTimeouts)
 {
-  NFD_LOG_DEBUG("Failed to apply " << update << " (code: " << code << ", error: " << error << ")");
+  uint32_t code = response.getCode();
+  NFD_LOG_DEBUG("Failed to apply " << update <<
+                " (code: " << code << ", error: " << response.getText() << ")");
 
   if (code == ndn::nfd::Controller::ERROR_TIMEOUT && nTimeouts < MAX_NUM_TIMEOUTS) {
     sendAddNextHopUpdate(update, onSuccess, onFailure, ++nTimeouts);
   }
   else if (code == ERROR_FACE_NOT_FOUND) {
     if (update.faceId == m_batchFaceId) {
-      onFailure(code, error);
+      onFailure(code, response.getText());
     }
     else {
       m_updatesForNonBatchFaceId.remove(update);
@@ -305,7 +307,8 @@
     }
   }
   else {
-    BOOST_THROW_EXCEPTION(Error("Non-recoverable error: " + error + " code: " + to_string(code)));
+    BOOST_THROW_EXCEPTION(Error("Non-recoverable error: " + response.getText() +
+                                " code: " + to_string(code)));
   }
 }
 
diff --git a/rib/fib-updater.hpp b/rib/fib-updater.hpp
index 2d7761a..fed7aed 100644
--- a/rib/fib-updater.hpp
+++ b/rib/fib-updater.hpp
@@ -173,7 +173,7 @@
   onUpdateError(const FibUpdate update,
                 const FibUpdateSuccessCallback& onSuccess,
                 const FibUpdateFailureCallback& onFailure,
-                uint32_t code, const std::string& error, uint32_t nTimeouts);
+                const ndn::nfd::ControlResponse& response, uint32_t nTimeouts);
 
 private:
   /** \brief adds the update to an update list based on its Face ID
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index e581095..dd0abca 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -94,7 +94,7 @@
     ControlParameters()
       .setLocalControlFeature(ndn::nfd::LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID),
     bind(&RibManager::onControlHeaderSuccess, this),
-    bind(&RibManager::onControlHeaderError, this, _1, _2));
+    bind(&RibManager::onControlHeaderError, this, _1));
 }
 
 void
@@ -165,7 +165,7 @@
        .setName(Name(topPrefix).append(MGMT_MODULE_NAME))
        .setFaceId(0),
      bind(&RibManager::onCommandPrefixAddNextHopSuccess, this, cref(topPrefix), _1),
-     bind(&RibManager::onCommandPrefixAddNextHopError, this, cref(topPrefix), _2));
+     bind(&RibManager::onCommandPrefixAddNextHopError, this, cref(topPrefix), _1));
 
   // add top prefix to the dispatcher
   m_addTopPrefix(topPrefix);
@@ -443,9 +443,11 @@
 }
 
 void
-RibManager::onCommandPrefixAddNextHopError(const Name& name, const std::string& msg)
+RibManager::onCommandPrefixAddNextHopError(const Name& name,
+                                           const ndn::nfd::ControlResponse& response)
 {
-  BOOST_THROW_EXCEPTION(Error("Error in setting interest filter (" + name.toUri() + "): " + msg));
+  BOOST_THROW_EXCEPTION(Error("Error in setting interest filter (" + name.toUri() +
+                              "): " + response.getText()));
 }
 
 void
@@ -455,11 +457,11 @@
 }
 
 void
-RibManager::onControlHeaderError(uint32_t code, const std::string& reason)
+RibManager::onControlHeaderError(const ndn::nfd::ControlResponse& response)
 {
   std::ostringstream os;
   os << "Couldn't enable local control header "
-     << "(code: " << code << ", info: " << reason << ")";
+     << "(code: " << response.getCode() << ", info: " << response.getText() << ")";
   BOOST_THROW_EXCEPTION(Error(os.str()));
 }
 
diff --git a/rib/rib-manager.hpp b/rib/rib-manager.hpp
index 55ee394..998a284 100644
--- a/rib/rib-manager.hpp
+++ b/rib/rib-manager.hpp
@@ -169,13 +169,13 @@
                                    const ndn::nfd::ControlParameters& result);
 
   void
-  onCommandPrefixAddNextHopError(const Name& name, const std::string& msg);
+  onCommandPrefixAddNextHopError(const Name& name, const ndn::nfd::ControlResponse& response);
 
   void
   onControlHeaderSuccess();
 
   void
-  onControlHeaderError(uint32_t code, const std::string& reason);
+  onControlHeaderError(const ndn::nfd::ControlResponse& response);
 
 private:
   ndn::Face& m_face;