face/mgmt/fw/tools: add localUri to FaceStatus and FaceEventNotification

refs #1396

Change-Id: I6084745c62c44a409ecbd4a795cb712475e32416
diff --git a/daemon/mgmt/face-flags.hpp b/daemon/mgmt/face-flags.hpp
new file mode 100644
index 0000000..f9c50e1
--- /dev/null
+++ b/daemon/mgmt/face-flags.hpp
@@ -0,0 +1,30 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NFD_MGMT_FACE_FLAGS_HPP
+#define NFD_MGMT_FACE_FLAGS_HPP
+
+#include "face/face.hpp"
+#include <ndn-cpp-dev/management/nfd-face-flags.hpp>
+
+namespace nfd {
+
+inline uint64_t
+getFaceFlags(const Face& face)
+{
+  uint64_t flags = 0;
+  if (face.isLocal()) {
+    flags |= ndn::nfd::FACE_IS_LOCAL;
+  }
+  if (face.isOnDemand()) {
+    flags |= ndn::nfd::FACE_IS_ON_DEMAND;
+  }
+  return flags;
+}
+
+} // namespace nfd
+
+#endif // NFD_MGMT_FACE_FLAGS_HPP
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index e184c00..183af17 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -5,6 +5,7 @@
  */
 
 #include "face-manager.hpp"
+#include "face-flags.hpp"
 
 #include "core/logger.hpp"
 #include "core/face-uri.hpp"
@@ -562,7 +563,7 @@
 {
   m_faceTable.add(newFace);
 
-  NFD_LOG_DEBUG("Created face " << newFace->getUri() << " ID " << newFace->getId());
+  //NFD_LOG_DEBUG("Created face " << newFace->getRemoteUri() << " ID " << newFace->getId());
 }
 
 void
@@ -642,25 +643,27 @@
 void
 FaceManager::onAddFace(shared_ptr<Face> face)
 {
-  ndn::nfd::FaceEventNotification faceCreated(ndn::nfd::FACE_EVENT_CREATED,
-                                              face->getId(),
-                                              face->getUri().toString(),
-                                              (face->isLocal() ? ndn::nfd::FACE_IS_LOCAL : 0) |
-                                              (face->isOnDemand() ? ndn::nfd::FACE_IS_ON_DEMAND : 0));
+  ndn::nfd::FaceEventNotification notification;
+  notification.setKind(ndn::nfd::FACE_EVENT_CREATED)
+              .setFaceId(face->getId())
+              .setRemoteUri(face->getRemoteUri().toString())
+              .setLocalUri(face->getLocalUri().toString())
+              .setFlags(getFaceFlags(*face));
 
-  m_notificationStream.postNotification(faceCreated);
+  m_notificationStream.postNotification(notification);
 }
 
 void
 FaceManager::onRemoveFace(shared_ptr<Face> face)
 {
-  ndn::nfd::FaceEventNotification faceDestroyed(ndn::nfd::FACE_EVENT_DESTROYED,
-                                                face->getId(),
-                                                face->getUri().toString(),
-                                                (face->isLocal() ? ndn::nfd::FACE_IS_LOCAL : 0) |
-                                                (face->isOnDemand() ? ndn::nfd::FACE_IS_ON_DEMAND : 0));
+  ndn::nfd::FaceEventNotification notification;
+  notification.setKind(ndn::nfd::FACE_EVENT_DESTROYED)
+              .setFaceId(face->getId())
+              .setRemoteUri(face->getRemoteUri().toString())
+              .setLocalUri(face->getLocalUri().toString())
+              .setFlags(getFaceFlags(*face));
 
-  m_notificationStream.postNotification(faceDestroyed);
+  m_notificationStream.postNotification(notification);
 }
 
 
diff --git a/daemon/mgmt/face-status-publisher.cpp b/daemon/mgmt/face-status-publisher.cpp
index 3589d7b..06b205f 100644
--- a/daemon/mgmt/face-status-publisher.cpp
+++ b/daemon/mgmt/face-status-publisher.cpp
@@ -5,7 +5,9 @@
  */
 
 #include "face-status-publisher.hpp"
+#include "face-flags.hpp"
 #include "core/logger.hpp"
+#include <ndn-cpp-dev/management/nfd-face-status.hpp>
 
 namespace nfd {
 
@@ -33,45 +35,22 @@
   size_t totalLength = 0;
 
   for (FaceTable::const_reverse_iterator i = m_faceTable.rbegin();
-       i != m_faceTable.rend();
-       ++i)
-    {
-      const shared_ptr<Face>& face = *i;
-      const FaceCounters& counters = face->getCounters();
-      const std::string uri = face->getUri().toString();
+       i != m_faceTable.rend(); ++i) {
+    const shared_ptr<Face>& face = *i;
+    const FaceCounters& counters = face->getCounters();
 
-      size_t statusLength = 0;
+    ndn::nfd::FaceStatus status;
+    status.setFaceId(face->getId())
+          .setRemoteUri(face->getRemoteUri().toString())
+          .setLocalUri(face->getLocalUri().toString())
+          .setFlags(getFaceFlags(*face))
+          .setNInInterests(counters.getNInInterests())
+          .setNInDatas(counters.getNInDatas())
+          .setNOutInterests(counters.getNOutInterests())
+          .setNOutDatas(counters.getNOutDatas());
 
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::NOutDatas,
-                                                     counters.getOutData());
-
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::NOutInterests,
-                                                     counters.getOutInterest());
-
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::NInDatas,
-                                                     counters.getInData());
-
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::NInInterests,
-                                                     counters.getInInterest());
-
-      statusLength += prependByteArrayBlock(outBuffer,
-                                            ndn::tlv::nfd::Uri,
-                                            reinterpret_cast<const uint8_t*>(uri.c_str()),
-                                            uri.size());
-
-      statusLength += prependNonNegativeIntegerBlock(outBuffer,
-                                                     ndn::tlv::nfd::FaceId,
-                                                     face->getId());
-
-      statusLength += outBuffer.prependVarNumber(statusLength);
-      statusLength += outBuffer.prependVarNumber(ndn::tlv::nfd::FaceStatus);
-
-      totalLength += statusLength;
-    }
+    totalLength += status.wireEncode(outBuffer);
+  }
   return totalLength;
 }
 
diff --git a/daemon/mgmt/status-server.cpp b/daemon/mgmt/status-server.cpp
index 5c4bd1a..6176659 100644
--- a/daemon/mgmt/status-server.cpp
+++ b/daemon/mgmt/status-server.cpp
@@ -54,10 +54,10 @@
   status->setNCsEntries(m_forwarder.getCs().size());
 
   const ForwarderCounters& counters = m_forwarder.getCounters();
-  status->setNInInterests(counters.getInInterest());
-  status->setNInDatas(counters.getInData());
-  status->setNOutInterests(counters.getOutInterest());
-  status->setNOutDatas(counters.getOutData());
+  status->setNInInterests(counters.getNInInterests());
+  status->setNInDatas(counters.getNInDatas());
+  status->setNOutInterests(counters.getNOutInterests());
+  status->setNOutDatas(counters.getNOutDatas());
 
   return status;
 }