management: Controller allows empty callbacks

refs #3653

Change-Id: Id112960fa3f9f52854687b798c4632a922297ff2
diff --git a/src/management/nfd-controller.cpp b/src/management/nfd-controller.cpp
index 0a56777..5fc755d 100644
--- a/src/management/nfd-controller.cpp
+++ b/src/management/nfd-controller.cpp
@@ -45,10 +45,15 @@
 void
 Controller::startCommand(const shared_ptr<ControlCommand>& command,
                          const ControlParameters& parameters,
-                         const CommandSucceedCallback& onSuccess,
-                         const CommandFailCallback& onFailure,
+                         const CommandSucceedCallback& onSuccess1,
+                         const CommandFailCallback& onFailure1,
                          const CommandOptions& options)
 {
+  const CommandSucceedCallback& onSuccess = onSuccess1 ?
+    onSuccess1 : [] (const ControlParameters&) {};
+  const CommandFailCallback& onFailure = onFailure1 ?
+    onFailure1 : [] (uint32_t, const std::string&) {};
+
   Name requestName = command->getRequestName(options.getPrefix(), parameters);
   Interest interest(requestName);
   interest.setInterestLifetime(options.getTimeout());
@@ -73,16 +78,14 @@
   try {
     response.wireDecode(data.getContent().blockFromValue());
   }
-  catch (tlv::Error& e) {
-    if (static_cast<bool>(onFailure))
-      onFailure(ERROR_SERVER, e.what());
+  catch (const tlv::Error& e) {
+    onFailure(ERROR_SERVER, e.what());
     return;
   }
 
   uint32_t code = response.getCode();
   if (code >= ERROR_LBOUND) {
-    if (static_cast<bool>(onFailure))
-      onFailure(code, response.getText());
+    onFailure(code, response.getText());
     return;
   }
 
@@ -90,23 +93,20 @@
   try {
     parameters.wireDecode(response.getBody());
   }
-  catch (tlv::Error& e) {
-    if (static_cast<bool>(onFailure))
-      onFailure(ERROR_SERVER, e.what());
+  catch (const tlv::Error& e) {
+    onFailure(ERROR_SERVER, e.what());
     return;
   }
 
   try {
     command->validateResponse(parameters);
   }
-  catch (ControlCommand::ArgumentError& e) {
-    if (static_cast<bool>(onFailure))
-      onFailure(ERROR_SERVER, e.what());
+  catch (const ControlCommand::ArgumentError& e) {
+    onFailure(ERROR_SERVER, e.what());
     return;
   }
 
-  if (static_cast<bool>(onSuccess))
-    onSuccess(parameters);
+  onSuccess(parameters);
 }
 
 void
diff --git a/src/management/nfd-controller.hpp b/src/management/nfd-controller.hpp
index 3ae1cf2..9fa721b 100644
--- a/src/management/nfd-controller.hpp
+++ b/src/management/nfd-controller.hpp
@@ -164,10 +164,15 @@
 template<typename Dataset>
 inline void
 Controller::fetchDataset(shared_ptr<Dataset> dataset,
-                         const std::function<void(typename Dataset::ResultType)>& onSuccess,
-                         const CommandFailCallback& onFailure,
+                         const std::function<void(typename Dataset::ResultType)>& onSuccess1,
+                         const CommandFailCallback& onFailure1,
                          const CommandOptions& options)
 {
+  const std::function<void(typename Dataset::ResultType)>& onSuccess = onSuccess1 ?
+    onSuccess1 : [] (const typename Dataset::ResultType&) {};
+  const CommandFailCallback& onFailure = onFailure1 ?
+    onFailure1 : [] (uint32_t, const std::string&) {};
+
   Name prefix = dataset->getDatasetPrefix(options.getPrefix());
   this->fetchDataset(prefix,
                      bind(&Controller::processDatasetResponse<Dataset>, this, dataset, onSuccess, onFailure, _1),
@@ -190,6 +195,7 @@
     onFailure(ERROR_SERVER, ex.what());
     return;
   }
+
   onSuccess(result);
 }