Use ndn::mgmt::Dispatcher for repo commands

refs #4129

Change-Id: Idb7826fc76b6660ce76d69e7e88a9e922c55a2e1
diff --git a/tools/ndngetfile.cpp b/tools/ndngetfile.cpp
index 4d26763..9764ca6 100644
--- a/tools/ndngetfile.cpp
+++ b/tools/ndngetfile.cpp
@@ -187,8 +187,9 @@
   if (m_retryCount++ < MAX_RETRY) {
     // Retransmit the interest
     fetchData(interest.getName());
-    if (m_verbose)
-      std::cerr << "TIMEOUT: retransmit interest for " << interest.getName() << std::endl;
+    if (m_verbose) {
+        std::cerr << "TIMEOUT: retransmit interest for " << interest.getName() << std::endl;
+    }
   }
   else {
     std::cerr << "TIMEOUT: last interest sent for segment #" << (m_nextSegment - 1) << std::endl;
@@ -225,48 +226,50 @@
   int opt;
   while ((opt = getopt(argc, argv, "vsul:w:o:")) != -1) {
     switch (opt) {
-    case 'v':
-      verbose = true;
-      break;
-    case 's':
-      single = true;
-      break;
-    case 'u':
-      versioned = true;
-      break;
-    case 'l':
-      try {
-        interestLifetime = boost::lexical_cast<int>(optarg);
-      }
-      catch (const boost::bad_lexical_cast&) {
-        std::cerr << "ERROR: -l option should be an integer." << std::endl;
-        return 1;
-      }
-      interestLifetime = std::max(interestLifetime, 0);
-      break;
-    case 'w':
-      try {
-        timeout = boost::lexical_cast<int>(optarg);
-      }
-      catch (const boost::bad_lexical_cast&) {
-        std::cerr << "ERROR: -w option should be an integer." << std::endl;
-        return 1;
-      }
-      timeout = std::max(timeout, 0);
-      break;
-    case 'o':
-      outputFile = optarg;
-      break;
-    default:
-      return usage(argv[0]);
+      case 'v':
+        verbose = true;
+        break;
+      case 's':
+        single = true;
+        break;
+      case 'u':
+        versioned = true;
+        break;
+      case 'l':
+        try {
+          interestLifetime = boost::lexical_cast<int>(optarg);
+        }
+        catch (const boost::bad_lexical_cast&) {
+          std::cerr << "ERROR: -l option should be an integer." << std::endl;
+          return 1;
+        }
+        interestLifetime = std::max(interestLifetime, 0);
+        break;
+      case 'w':
+        try {
+          timeout = boost::lexical_cast<int>(optarg);
+        }
+        catch (const boost::bad_lexical_cast&) {
+          std::cerr << "ERROR: -w option should be an integer." << std::endl;
+          return 1;
+        }
+        timeout = std::max(timeout, 0);
+        break;
+      case 'o':
+        outputFile = optarg;
+        break;
+      default:
+        return usage(argv[0]);
     }
   }
 
-  if (optind < argc)
+  if (optind < argc) {
     name = argv[optind];
+  }
 
-  if (name.empty())
+  if (name.empty()) {
     return usage(argv[0]);
+  }
 
   std::streambuf* buf;
   std::ofstream of;
diff --git a/tools/ndnputfile.cpp b/tools/ndnputfile.cpp
index 583d478..b4f40f4 100644
--- a/tools/ndnputfile.cpp
+++ b/tools/ndnputfile.cpp
@@ -265,7 +265,8 @@
 NdnPutFile::onInsertCommandResponse(const ndn::Interest& interest, const ndn::Data& data)
 {
   RepoCommandResponse response(data.getContent().blockFromValue());
-  int statusCode = response.getStatusCode();
+  //int statusCode = response.getStatusCode();
+  int statusCode = response.getCode();
   if (statusCode >= 400) {
     BOOST_THROW_EXCEPTION(Error("insert command failed with code " +
                                 boost::lexical_cast<std::string>(statusCode)));
@@ -397,7 +398,7 @@
 NdnPutFile::onCheckCommandResponse(const ndn::Interest& interest, const ndn::Data& data)
 {
   RepoCommandResponse response(data.getContent().blockFromValue());
-  int statusCode = response.getStatusCode();
+  int statusCode = response.getCode();
   if (statusCode >= 400) {
     BOOST_THROW_EXCEPTION(Error("Insert check command failed with code: " +
                                 boost::lexical_cast<std::string>(statusCode)));
@@ -542,8 +543,8 @@
   if (argc != 3)
     usage();
 
-  ndnPutFile.repoPrefix = Name(argv[0]);
-  ndnPutFile.ndnName = Name(argv[1]);
+  ndnPutFile.repoPrefix = Name(argv[0]); std::cout << "Repo prefix: " << argv[0] << std::endl;
+  ndnPutFile.ndnName = Name(argv[1]);    std::cout << "NDN name: " << argv[1] << std::endl;
   if (strcmp(argv[2], "-") == 0) {
 
     ndnPutFile.insertStream = &std::cin;
diff --git a/tools/ndnrepowatch.cpp b/tools/ndnrepowatch.cpp
index 0707c87..b844c00 100644
--- a/tools/ndnrepowatch.cpp
+++ b/tools/ndnrepowatch.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2017, Regents of the University of California.
+ * Copyright (c) 2014-2018, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -24,6 +24,8 @@
 #include <ndn-cxx/security/command-interest-signer.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
 #include <ndn-cxx/security/signing-helpers.hpp>
+
+#include <boost/asio/io_service.hpp>
 #include <ndn-cxx/util/scheduler.hpp>
 
 #include <stdint.h>
@@ -201,7 +203,7 @@
 NdnRepoWatch::onWatchCommandResponse(const ndn::Interest& interest, const ndn::Data& data)
 {
   RepoCommandResponse response(data.getContent().blockFromValue());
-  int statusCode = response.getStatusCode();
+  int statusCode = response.getCode();
   if (statusCode >= 400) {
     BOOST_THROW_EXCEPTION(Error("Watch command failed with code " +
                                 boost::lexical_cast<std::string>(statusCode)));
@@ -264,7 +266,7 @@
 NdnRepoWatch::onStopCommandResponse(const ndn::Interest& interest, ndn::Data& data)
 {
   RepoCommandResponse response(data.getContent().blockFromValue());
-  int statusCode = response.getStatusCode();
+  int statusCode = response.getCode();
   if (statusCode != 101) {
     BOOST_THROW_EXCEPTION(Error("Watch stop command failed with code: " +
                                 boost::lexical_cast<std::string>(statusCode)));
diff --git a/tools/wscript b/tools/wscript
index aadf3a4..0a9fcbf 100644
--- a/tools/wscript
+++ b/tools/wscript
@@ -8,6 +8,6 @@
             bld(features=['cxx', 'cxxprogram'],
                 target='%s' % (str(app.change_ext('', '.cpp'))),
                 source=app,
-                use='NDN_CXX',
+                use=["NDN_CXX", "ndn-repo-objects"],
                 includes="../src",
                 )