management: Controller::CommandFailCallback exposes ControlResponse

refs #3739

Change-Id: Ib4b66cd99647ab930450fc3b472be565084be160
diff --git a/src/management/nfd-controller.cpp b/src/management/nfd-controller.cpp
index 72299f0..b395d6b 100644
--- a/src/management/nfd-controller.cpp
+++ b/src/management/nfd-controller.cpp
@@ -20,7 +20,8 @@
  */
 
 #include "nfd-controller.hpp"
-#include "nfd-control-response.hpp"
+#include "../face.hpp"
+#include "../security/key-chain.hpp"
 #include "../util/segment-fetcher.hpp"
 
 namespace ndn {
@@ -52,7 +53,7 @@
   const CommandSucceedCallback& onSuccess = onSuccess1 ?
     onSuccess1 : [] (const ControlParameters&) {};
   const CommandFailCallback& onFailure = onFailure1 ?
-    onFailure1 : [] (uint32_t, const std::string&) {};
+    onFailure1 : [] (const ControlResponse&) {};
 
   Name requestName = command->getRequestName(options.getPrefix(), parameters);
   Interest interest(requestName);
@@ -60,10 +61,15 @@
   m_keyChain.sign(interest, options.getSigningInfo());
 
   m_face.expressInterest(interest,
-                         bind(&Controller::processCommandResponse, this, _2,
-                              command, onSuccess, onFailure),
-                         bind(onFailure, ERROR_NACK, "network Nack received"),
-                         bind(onFailure, ERROR_TIMEOUT, "request timed out"));
+    [=] (const Interest&, const Data& data) {
+      this->processCommandResponse(data, command, onSuccess, onFailure);
+    },
+    [=] (const Interest&, const lp::Nack&) {
+      onFailure(ControlResponse(Controller::ERROR_NACK, "network Nack received"));
+    },
+    [=] (const Interest&) {
+      onFailure(ControlResponse(Controller::ERROR_TIMEOUT, "request timed out"));
+    });
 }
 
 void
@@ -77,7 +83,7 @@
       this->processValidatedCommandResponse(*data, command, onSuccess, onFailure);
     },
     [=] (const shared_ptr<const Data>&, const std::string& msg) {
-      onFailure(ERROR_VALIDATION, msg);
+      onFailure(ControlResponse(ERROR_VALIDATION, msg));
     }
   );
 }
@@ -93,13 +99,13 @@
     response.wireDecode(data.getContent().blockFromValue());
   }
   catch (const tlv::Error& e) {
-    onFailure(ERROR_SERVER, e.what());
+    onFailure(ControlResponse(ERROR_SERVER, e.what()));
     return;
   }
 
   uint32_t code = response.getCode();
   if (code >= ERROR_LBOUND) {
-    onFailure(code, response.getText());
+    onFailure(response);
     return;
   }
 
@@ -108,7 +114,7 @@
     parameters.wireDecode(response.getBody());
   }
   catch (const tlv::Error& e) {
-    onFailure(ERROR_SERVER, e.what());
+    onFailure(ControlResponse(ERROR_SERVER, e.what()));
     return;
   }
 
@@ -116,7 +122,7 @@
     command->validateResponse(parameters);
   }
   catch (const ControlCommand::ArgumentError& e) {
-    onFailure(ERROR_SERVER, e.what());
+    onFailure(ControlResponse(ERROR_SERVER, e.what()));
     return;
   }
 
@@ -126,7 +132,7 @@
 void
 Controller::fetchDataset(const Name& prefix,
                          const std::function<void(const ConstBufferPtr&)>& processResponse,
-                         const CommandFailCallback& onFailure,
+                         const DatasetFailCallback& onFailure,
                          const CommandOptions& options)
 {
   Interest baseInterest(prefix);
@@ -137,7 +143,7 @@
 }
 
 void
-Controller::processDatasetFetchError(const CommandFailCallback& onFailure,
+Controller::processDatasetFetchError(const DatasetFailCallback& onFailure,
                                      uint32_t code, std::string msg)
 {
   switch (static_cast<SegmentFetcher::ErrorCode>(code)) {