src: Updating code to compile with the latest ndn-cxx library

This commit includes updates against the latest Face API and replaces
uses of deprecated methods.

Change-Id: I33ad398d26f8faf9f9627ff329ce0936e0911ab2
diff --git a/core/face-monitor.hpp b/core/face-monitor.hpp
index 28cfdbd..459b181 100644
--- a/core/face-monitor.hpp
+++ b/core/face-monitor.hpp
@@ -32,7 +32,7 @@
 
 namespace ndn {
 class Face;
-struct PendingInterestId;
+class PendingInterestId;
 }
 
 namespace nfd {
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index f4fc9c8..f485c18 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -59,7 +59,7 @@
 
 RibManager::RibManager()
   : m_face(getGlobalIoService())
-  , m_nfdController(new ndn::nfd::Controller(m_face))
+  , m_nfdController(m_face)
   , m_localhostValidator(m_face)
   , m_localhopValidator(m_face)
   , m_faceMonitor(m_face)
@@ -76,17 +76,27 @@
   BOOST_ASSERT(COMMAND_PREFIX.size() == REMOTE_COMMAND_PREFIX.size());
 
   NFD_LOG_INFO("Setting interest filter on: " << COMMAND_PREFIX);
-  m_face.setController(m_nfdController);
-  m_face.setInterestFilter(COMMAND_PREFIX,
-                           bind(&RibManager::onLocalhostRequest, this, _2),
-                           bind(&RibManager::setInterestFilterFailed, this, _1, _2));
+
+  m_nfdController.start<ndn::nfd::FibAddNextHopCommand>(
+    ControlParameters()
+      .setName(COMMAND_PREFIX),
+    bind(&RibManager::onNrdCommandPrefixAddNextHopSuccess, this, cref(COMMAND_PREFIX)),
+    bind(&RibManager::onNrdCommandPrefixAddNextHopError, this, cref(COMMAND_PREFIX), _2));
+
+  m_face.setInterestFilter(COMMAND_PREFIX, bind(&RibManager::onLocalhostRequest, this, _2));
 
   if (m_isLocalhopEnabled)
     {
       NFD_LOG_INFO("Setting interest filter on: " << REMOTE_COMMAND_PREFIX);
+
+      m_nfdController.start<ndn::nfd::FibAddNextHopCommand>(
+        ControlParameters()
+          .setName(COMMAND_PREFIX),
+        bind(&RibManager::onNrdCommandPrefixAddNextHopSuccess, this, cref(REMOTE_COMMAND_PREFIX)),
+        bind(&RibManager::onNrdCommandPrefixAddNextHopError, this, cref(REMOTE_COMMAND_PREFIX), _2));
+
       m_face.setInterestFilter(REMOTE_COMMAND_PREFIX,
-                               bind(&RibManager::onLocalhopRequest, this, _2),
-                               bind(&RibManager::setInterestFilterFailed, this, _1, _2));
+                               bind(&RibManager::onLocalhopRequest, this, _2));
     }
 
   NFD_LOG_INFO("Start monitoring face create/destroy events");
@@ -122,12 +132,6 @@
 }
 
 void
-RibManager::setInterestFilterFailed(const Name& name, const std::string& msg)
-{
-  throw Error("Error in setting interest filter (" + name.toUri() + "): " + msg);
-}
-
-void
 RibManager::sendResponse(const Name& name,
                          const ControlResponse& response)
 {
@@ -229,7 +233,7 @@
   // Rib tree, then nrd will generate fib updates based on flags and then
   // will add next hops one by one..
   m_managedRib.insert(ribEntry);
-  m_nfdController->start<ndn::nfd::FibAddNextHopCommand>(
+  m_nfdController.start<ndn::nfd::FibAddNextHopCommand>(
     ControlParameters()
       .setName(ribEntry.name)
       .setFaceId(ribEntry.faceId)
@@ -258,7 +262,7 @@
 
   NFD_LOG_TRACE("unregister prefix: " << ribEntry);
 
-  m_nfdController->start<ndn::nfd::FibRemoveNextHopCommand>(
+  m_nfdController.start<ndn::nfd::FibRemoveNextHopCommand>(
     ControlParameters()
       .setName(ribEntry.name)
       .setFaceId(ribEntry.faceId),
@@ -372,6 +376,30 @@
 }
 
 void
+RibManager::onNrdCommandPrefixAddNextHopSuccess(const Name& prefix)
+{
+  NFD_LOG_DEBUG("Successfully registered " + prefix.toUri() + " with NFD");
+}
+
+void
+RibManager::onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg)
+{
+  throw Error("Error in setting interest filter (" + name.toUri() + "): " + msg);
+}
+
+void
+RibManager::onAddNextHopSuccess(const Name& prefix)
+{
+  NFD_LOG_DEBUG("Successfully registered " + prefix.toUri() + " with NFD");
+}
+
+void
+RibManager::onAddNextHopError(const Name& name, const std::string& msg)
+{
+  throw Error("Error in setting interest filter (" + name.toUri() + "): " + msg);
+}
+
+void
 RibManager::onControlHeaderSuccess()
 {
   NFD_LOG_DEBUG("Local control header enabled");
@@ -389,7 +417,7 @@
 void
 RibManager::enableLocalControlHeader()
 {
-  m_nfdController->start<ndn::nfd::FaceEnableLocalControlCommand>(
+  m_nfdController.start<ndn::nfd::FaceEnableLocalControlCommand>(
     ControlParameters()
       .setLocalControlFeature(ndn::nfd::LOCAL_CONTROL_FEATURE_INCOMING_FACE_ID),
     bind(&RibManager::onControlHeaderSuccess, this),
diff --git a/rib/rib-manager.hpp b/rib/rib-manager.hpp
index ef38ae1..1407fb2 100644
--- a/rib/rib-manager.hpp
+++ b/rib/rib-manager.hpp
@@ -120,14 +120,22 @@
                  const RibEntry& ribEntry);
 
   void
+  onNrdCommandPrefixAddNextHopSuccess(const Name& prefix);
+
+  void
+  onNrdCommandPrefixAddNextHopError(const Name& name, const std::string& msg);
+
+  void
+  onAddNextHopSuccess(const Name& prefix);
+
+  void
+  onAddNextHopError(const Name& name, const std::string& msg);
+
+  void
   onControlHeaderSuccess();
 
   void
   onControlHeaderError(uint32_t code, const std::string& reason);
-
-  void
-  setInterestFilterFailed(const Name& name, const std::string& msg);
-
   static bool
   extractParameters(const Name::Component& parameterComponent,
                     ControlParameters& extractedParameters);
@@ -142,7 +150,7 @@
 private:
   Rib m_managedRib;
   ndn::Face m_face;
-  ndn::shared_ptr<ndn::nfd::Controller> m_nfdController;
+  ndn::nfd::Controller m_nfdController;
   ndn::KeyChain m_keyChain;
   ndn::ValidatorConfig m_localhostValidator;
   ndn::ValidatorConfig m_localhopValidator;
diff --git a/tools/ndn-autoconfig-server.cpp b/tools/ndn-autoconfig-server.cpp
index 9873bde..bc038e3 100644
--- a/tools/ndn-autoconfig-server.cpp
+++ b/tools/ndn-autoconfig-server.cpp
@@ -77,6 +77,7 @@
   {
     m_face.setInterestFilter("/localhop/ndn-autoconf/hub",
                              ndn::bind(&NdnAutoconfigServer::onInterest, this, _1, _2),
+                             ndn::RegisterPrefixSuccessCallback(),
                              ndn::bind(&NdnAutoconfigServer::onRegisterFailed, this, _1, _2));
     m_face.processEvents();
   }
diff --git a/tools/ndn-autoconfig.cpp b/tools/ndn-autoconfig.cpp
index fe8ce19..c996566 100644
--- a/tools/ndn-autoconfig.cpp
+++ b/tools/ndn-autoconfig.cpp
@@ -28,6 +28,8 @@
 #include <ndn-cxx/management/nfd-controller.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
 
+#include <boost/lexical_cast.hpp>
+
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <arpa/nameser.h>
@@ -155,7 +157,7 @@
 
     for (ndn::Name::const_reverse_iterator i = identity.rbegin(); i != identity.rend(); i++)
     {
-      serverName.append(i->toEscapedString());
+      serverName.append(i->toUri());
       serverName.append(".");
     }
     serverName += "_homehub._autoconf.named-data.net";
diff --git a/tools/ndn-tlv-peek.cpp b/tools/ndn-tlv-peek.cpp
index ec0a9b0..dc70175 100644
--- a/tools/ndn-tlv-peek.cpp
+++ b/tools/ndn-tlv-peek.cpp
@@ -47,8 +47,6 @@
     , m_timeout(-1)
     , m_prefixName("")
     , m_isDataReceived(false)
-    , m_ioService(new boost::asio::io_service)
-    , m_face(m_ioService)
   {
   }
 
@@ -221,7 +219,6 @@
   ndn::time::milliseconds m_timeout;
   std::string m_prefixName;
   bool m_isDataReceived;
-  ndn::ptr_lib::shared_ptr<boost::asio::io_service> m_ioService;
   ndn::Face m_face;
 };
 
@@ -230,8 +227,8 @@
 int
 main(int argc, char* argv[])
 {
+  ndntlvpeek::NdnTlvPeek ndnTlvPeek(argv[0]);
   int option;
-  ndntlvpeek::NdnTlvPeek ndnTlvPeek (argv[0]);
   while ((option = getopt(argc, argv, "hfrm:M:l:pw:V")) != -1) {
     switch (option) {
     case 'h':
diff --git a/tools/ndn-tlv-poke.cpp b/tools/ndn-tlv-poke.cpp
index f90b735..3f5a3b6 100644
--- a/tools/ndn-tlv-poke.cpp
+++ b/tools/ndn-tlv-poke.cpp
@@ -188,6 +188,7 @@
             m_face.setInterestFilter(m_prefixName,
                                      ndn::bind(&NdnTlvPoke::onInterest,
                                                this, _1, _2, dataPacket),
+                                     ndn::RegisterPrefixSuccessCallback(),
                                      ndn::bind(&NdnTlvPoke::onRegisterFailed,
                                                this, _1, _2));
           }
diff --git a/tools/nfd-autoreg.cpp b/tools/nfd-autoreg.cpp
index 3d8dc98..a219e62 100644
--- a/tools/nfd-autoreg.cpp
+++ b/tools/nfd-autoreg.cpp
@@ -229,7 +229,7 @@
                            bind(&AutoregServer::onNotification, this, _2),
                            bind(&AutoregServer::onTimeout, this, _1));
 
-    boost::asio::signal_set signalSet(*m_face.ioService(), SIGINT, SIGTERM);
+    boost::asio::signal_set signalSet(m_face.getIoService(), SIGINT, SIGTERM);
     signalSet.async_wait(bind(&AutoregServer::signalHandler, this));
 
     m_face.processEvents();
diff --git a/tools/nfd-status.cpp b/tools/nfd-status.cpp
index 1792961..57930e0 100644
--- a/tools/nfd-status.cpp
+++ b/tools/nfd-status.cpp
@@ -30,11 +30,14 @@
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/name.hpp>
 #include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/encoding/buffer-stream.hpp>
 
 #include <ndn-cxx/management/nfd-fib-entry.hpp>
 #include <ndn-cxx/management/nfd-face-status.hpp>
 #include <ndn-cxx/management/nfd-forwarder-status.hpp>
 
+#include <boost/algorithm/string/replace.hpp>
+
 namespace ndn {
 
 class NfdStatus
diff --git a/tools/nfdc.hpp b/tools/nfdc.hpp
index 787ca26..537667e 100644
--- a/tools/nfdc.hpp
+++ b/tools/nfdc.hpp
@@ -27,7 +27,6 @@
 #define NFD_TOOLS_NFDC_HPP
 
 #include <ndn-cxx/face.hpp>
-#include <ndn-cxx/management/controller.hpp>
 #include <ndn-cxx/management/nfd-controller.hpp>
 
 namespace nfdc {