Add face list display

Change-Id: Ide96107acc8ad59cefb0a619968d5c27cd9e94bb
diff --git a/src/face-status.cpp b/src/face-status.cpp
new file mode 100644
index 0000000..5a85ef4
--- /dev/null
+++ b/src/face-status.cpp
@@ -0,0 +1,157 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "face-status.hpp"
+#include "face-status.moc"
+
+namespace ndn {
+
+FaceStatusModel::FaceStatusModel(QObject* parent/* = 0*/)
+  : QAbstractListModel(parent)
+{
+  connect(this, SIGNAL(onDataReceived(std::vector<ndn::nfd::FaceStatus>)), this,
+          SLOT(updateStatus(std::vector<ndn::nfd::FaceStatus>)),
+          Qt::QueuedConnection);
+}
+
+int
+FaceStatusModel::rowCount(const QModelIndex& parent/* = QModelIndex()*/) const
+{
+  return m_items.count();
+}
+
+void
+FaceStatusModel::addItem(const FaceStatusItem& item)
+{
+  beginInsertRows(QModelIndex(), rowCount(), rowCount());
+  m_items << item;
+  endInsertRows();
+}
+
+QVariant
+FaceStatusModel::data(const QModelIndex& index, int role) const
+{
+  if (index.row() < 0 || index.row() >= m_items.count()) {
+    return QVariant();
+  }
+
+  const FaceStatusItem& item = m_items.at(index.row());
+  if (role == FaceIdRole) {
+    return static_cast<uint>(item.faceId());
+  }
+  else if (role == RemoteRole) {
+    return item.remote();
+  }
+  else if (role == LocalRole) {
+    return item.local();
+  }
+  else if (role == ScopeRole) {
+    return item.scope();
+  }
+  else if (role == PersistencyRole) {
+    return item.persistency();
+  }
+  else if (role == LinkTypeRole) {
+    return item.linkType();
+  }
+  else if (role == InInterestRole) {
+    return static_cast<uint>(item.inInterest());
+  }
+  else if (role == OutInterestRole) {
+    return static_cast<uint>(item.outInterest());
+  }
+  else if (role == InDataRole) {
+    return static_cast<uint>(item.inData());
+  }
+  else if (role == OutDataRole) {
+    return static_cast<uint>(item.outData());
+  }
+  else if (role == InByteRole) {
+    return static_cast<uint>(item.inByte());
+  }
+  else if (role == OutByteRole) {
+    return static_cast<uint>(item.outByte());
+  }
+  else if (role == InNackRole) {
+    return static_cast<uint>(item.inNack());
+  }
+  else if (role == OutNackRole) {
+    return static_cast<uint>(item.outNack());
+  }
+
+  return QVariant();
+}
+
+QHash<int, QByteArray>
+FaceStatusModel::roleNames() const
+{
+  QHash<int, QByteArray> roles;
+  roles[FaceIdRole] = "faceId";
+  roles[RemoteRole] = "remote";
+  roles[LocalRole] = "local";
+  roles[ScopeRole] = "scope";
+  roles[PersistencyRole] = "persistency";
+  roles[LinkTypeRole] = "linkType";
+  roles[InInterestRole] = "inInterest";
+  roles[OutInterestRole] = "outInterest";
+  roles[InDataRole] = "inData";
+  roles[OutDataRole] = "outData";
+  roles[InByteRole] = "inByte";
+  roles[OutByteRole] = "outByte";
+  roles[InNackRole] = "inNack";
+  roles[OutNackRole] = "outNack";
+  return roles;
+}
+
+void
+FaceStatusModel::clear()
+{
+  beginResetModel();
+  m_items.clear();
+  endResetModel();
+}
+
+void
+FaceStatusModel::updateStatus(std::vector<ndn::nfd::FaceStatus> status)
+{
+  beginResetModel();
+  m_items.clear();
+  for (auto const& faceEntry : status) {
+    QString faceScope = (faceEntry.getFaceScope() == ndn::nfd::FACE_SCOPE_LOCAL) ? QString("Local") : QString("Non-Local");
+    QString facePersistency = (faceEntry.getFacePersistency() == ndn::nfd::FACE_PERSISTENCY_PERSISTENT) ? QString("Persistent") :
+                              ((faceEntry.getFacePersistency() == ndn::nfd::FACE_PERSISTENCY_PERMANENT) ? QString("Permanent") :
+                              QString("On-Demand"));
+    QString faceLinkType = (faceEntry.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) ? QString("Multi-Access") :
+                           QString("Point-to-Point");
+    addItem(FaceStatusItem(faceEntry.getFaceId(), QString::fromStdString(faceEntry.getRemoteUri()),
+                           QString::fromStdString(faceEntry.getLocalUri()), faceScope, facePersistency, faceLinkType,
+                           faceEntry.getNInInterests(), faceEntry.getNOutInterests(), faceEntry.getNInDatas(),
+                           faceEntry.getNOutDatas(), faceEntry.getNInBytes(), faceEntry.getNOutBytes(),
+                           faceEntry.getNInNacks(), faceEntry.getNOutNacks()));
+  }
+  endResetModel();
+}
+
+void
+FaceStatusModel::onTimeout()
+{
+  std::cerr << "Request timed out (should not really happen)" << std::endl;
+}
+
+} // namespace ndn
diff --git a/src/face-status.hpp b/src/face-status.hpp
new file mode 100644
index 0000000..1131317
--- /dev/null
+++ b/src/face-status.hpp
@@ -0,0 +1,212 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017, Regents of the University of California,
+ *
+ * This file is part of NFD Control Center.  See AUTHORS.md for complete list of NFD
+ * authors and contributors.
+ *
+ * NFD Control Center is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with NFD
+ * Control Center, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NCC_FACE_STATUS_HPP
+#define NCC_FACE_STATUS_HPP
+
+#include <QtCore/QAbstractListModel>
+#include <QtCore/QStringList>
+
+#include <ndn-cxx/mgmt/nfd/face-status.hpp>
+
+namespace ndn {
+
+class FaceStatusItem
+{
+public:
+  FaceStatusItem(uint64_t faceId, const QString& remote, const QString& local, const QString& scope, const QString& persistency,
+                 const QString& linkType, uint64_t inInterest, uint64_t outInterest, uint64_t inData, uint64_t outData,
+                 uint64_t inByte, uint64_t outByte, uint64_t inNack, uint64_t outNack)
+    : m_faceId(faceId)
+    , m_remote(remote)
+    , m_local(local)
+    , m_scope(scope)
+    , m_persistency(persistency)
+    , m_linkType(linkType)
+    , m_inInterest(inInterest)
+    , m_outInterest(outInterest)
+    , m_inData(inData)
+    , m_outData(outData)
+    , m_inByte(inByte)
+    , m_outByte(outByte)
+    , m_inNack(inNack)
+    , m_outNack(outNack)
+  {
+  }
+
+  uint64_t
+  faceId() const
+  {
+    return m_faceId;
+  }
+
+  const QString&
+  remote() const
+  {
+    return m_remote;
+  }
+
+  const QString&
+  local() const
+  {
+    return m_local;
+  }
+
+  const QString&
+  scope() const
+  {
+    return m_scope;
+  }
+
+  const QString&
+  persistency() const
+  {
+    return m_persistency;
+  }
+
+  const QString&
+  linkType() const
+  {
+    return m_linkType;
+  }
+
+  uint64_t
+  inInterest() const
+  {
+    return m_inInterest;
+  }
+
+  uint64_t
+  outInterest() const
+  {
+    return m_outInterest;
+  }
+
+  uint64_t
+  inData() const
+  {
+    return m_inData;
+  }
+
+  uint64_t
+  outData() const
+  {
+    return m_outData;
+  }
+
+  uint64_t
+  inByte() const
+  {
+    return m_inByte;
+  }
+
+  uint64_t
+  outByte() const
+  {
+    return m_outByte;
+  }
+
+  uint64_t
+  inNack() const
+  {
+    return m_inNack;
+  }
+
+  uint64_t
+  outNack() const
+  {
+    return m_outNack;
+  }
+
+private:
+  uint64_t m_faceId;
+  QString m_remote;
+  QString m_local;
+  QString m_scope;
+  QString m_persistency;
+  QString m_linkType;
+  uint64_t m_inInterest;
+  uint64_t m_outInterest;
+  uint64_t m_inData;
+  uint64_t m_outData;
+  uint64_t m_inByte;
+  uint64_t m_outByte;
+  uint64_t m_inNack;
+  uint64_t m_outNack;
+};
+
+class FaceStatusModel : public QAbstractListModel
+{
+  Q_OBJECT
+
+signals:
+  void
+  onDataReceived(std::vector<ndn::nfd::FaceStatus> status);
+
+public:
+  enum FaceStatusRoles {
+    FaceIdRole = Qt::UserRole + 1,
+    RemoteRole,
+    LocalRole,
+    ScopeRole,
+    PersistencyRole,
+    LinkTypeRole,
+    InInterestRole,
+    OutInterestRole,
+    InDataRole,
+    OutDataRole,
+    InByteRole,
+    OutByteRole,
+    InNackRole,
+    OutNackRole
+  };
+
+  explicit
+  FaceStatusModel(QObject* parent = 0);
+
+  int
+  rowCount(const QModelIndex& parent = QModelIndex()) const;
+
+  void
+  addItem(const FaceStatusItem& item);
+
+  QVariant
+  data(const QModelIndex& index, int role) const;
+
+  QHash<int, QByteArray>
+  roleNames() const;
+
+  void
+  clear();
+
+  void
+  onTimeout();
+
+private slots:
+
+  void
+  updateStatus(std::vector<ndn::nfd::FaceStatus> status);
+
+private:
+  QList<FaceStatusItem> m_items;
+};
+
+} // namespace ndn
+
+#endif // NCC_FACE_STATUS_HPP
diff --git a/src/main.cpp b/src/main.cpp
index a3e125f..9d42157 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -160,6 +160,7 @@
 Q_DECLARE_METATYPE(ndn::nfd::ForwarderStatus)
 Q_DECLARE_METATYPE(std::vector<ndn::nfd::FibEntry>)
 Q_DECLARE_METATYPE(std::vector<ndn::nfd::RibEntry>)
+Q_DECLARE_METATYPE(std::vector<ndn::nfd::FaceStatus>)
 
 int
 main(int argc, char *argv[])
@@ -168,6 +169,7 @@
   qRegisterMetaType<ndn::nfd::ForwarderStatus>();
   qRegisterMetaType<std::vector<ndn::nfd::FibEntry>>();
   qRegisterMetaType<std::vector<ndn::nfd::RibEntry>>();
+  qRegisterMetaType<std::vector<ndn::nfd::FaceStatus>>();
 
   QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
   QApplication app(argc, argv);
diff --git a/src/status-viewer.cpp b/src/status-viewer.cpp
index de7bab9..6bc5879 100644
--- a/src/status-viewer.cpp
+++ b/src/status-viewer.cpp
@@ -31,6 +31,7 @@
   QQmlContext* s_context = s_engine.rootContext();
 
   s_context->setContextProperty("forwarderModel", &s_forwarderStatusModel);
+  s_context->setContextProperty("faceModel", &s_faceModel);
   s_context->setContextProperty("fibModel", &s_fibModel);
   s_context->setContextProperty("ribModel", &s_ribModel);
   s_context->setContextProperty("statusViewer", this);
@@ -45,6 +46,12 @@
 }
 
 void
+StatusViewer::onFaceStatusRetrieved(const std::vector<nfd::FaceStatus>& status)
+{
+  emit s_faceModel.onDataReceived(status);
+}
+
+void
 StatusViewer::onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status)
 {
   emit s_fibModel.onDataReceived(status);
@@ -68,6 +75,8 @@
 {
   s_controller->fetch<ndn::nfd::ForwarderGeneralStatusDataset>(bind(&StatusViewer::onStatusRetrieved, this, _1),
                                                               bind(&StatusViewer::onStatusTimeout, this));
+  s_controller->fetch<ndn::nfd::FaceDataset>(bind(&StatusViewer::onFaceStatusRetrieved, this, _1),
+                                             bind(&StatusViewer::onStatusTimeout, this));
   s_controller->fetch<ndn::nfd::FibDataset>(bind(&StatusViewer::onFibStatusRetrieved, this, _1),
                                            bind(&StatusViewer::onStatusTimeout, this));
   s_controller->fetch<ndn::nfd::RibDataset>(bind(&StatusViewer::onRibStatusRetrieved, this, _1),
diff --git a/src/status-viewer.hpp b/src/status-viewer.hpp
index e7e4113..b627bdb 100644
--- a/src/status-viewer.hpp
+++ b/src/status-viewer.hpp
@@ -21,12 +21,14 @@
 #define NCC_STATUS_VIEWER_HPP
 
 #include "forwarder-status.hpp"
+#include "face-status.hpp"
 #include "fib-status.hpp"
 #include "rib-status.hpp"
 
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/name.hpp>
 #include <ndn-cxx/util/scheduler.hpp>
+#include <ndn-cxx/mgmt/nfd/face-status.hpp>
 #include <ndn-cxx/mgmt/nfd/fib-entry.hpp>
 #include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
 #include <ndn-cxx/mgmt/nfd/controller.hpp>
@@ -49,6 +51,9 @@
   onStatusRetrieved(const nfd::ForwarderStatus& status);
 
   void
+  onFaceStatusRetrieved(const std::vector<nfd::FaceStatus>& status);
+
+  void
   onFibStatusRetrieved(const std::vector<nfd::FibEntry>& status);
 
   void
@@ -78,6 +83,7 @@
   QQmlApplicationEngine s_engine;
 
   ForwarderStatusModel s_forwarderStatusModel;
+  FaceStatusModel s_faceModel;
   FibStatusModel s_fibModel;
   RibStatusModel s_ribModel;
 };
diff --git a/src/status.qml b/src/status.qml
index c288056..c4bb56c 100644
--- a/src/status.qml
+++ b/src/status.qml
@@ -39,6 +39,87 @@
             }
         }
         Tab {
+            title: "Face"
+            TableView {
+                anchors.fill: parent
+                anchors.topMargin: 20
+                anchors.bottomMargin: 20
+                anchors.leftMargin: 20
+                anchors.rightMargin: 20
+                model: faceModel
+                TableViewColumn{
+                    role: "faceId"
+                    title: "Face ID"
+                    width: 60
+                }
+                TableViewColumn{
+                    role: "remote"
+                    title: "Remote URI"
+                    width: 150
+                }
+                TableViewColumn{
+                    role: "local"
+                    title: "Local URI"
+                    width: 150
+                }
+                TableViewColumn{
+                    role: "scope"
+                    title: "Scope"
+                    width: 70
+                }
+                TableViewColumn{
+                    role: "persistency"
+                    title: "Persistency"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "linkType"
+                    title: "LinkType"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "inInterest"
+                    title: "In Interests"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "outInterest"
+                    title: "Out Interests"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "inData"
+                    title: "In Data"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "outData"
+                    title: "Out Data"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "inByte"
+                    title: "In Bytes"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "outByte"
+                    title: "Out Bytes"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "inNack"
+                    title: "In Nacks"
+                    width: 100
+                }
+                TableViewColumn{
+                    role: "outNack"
+                    title: "Out Nacks"
+                    width: 100
+                }
+            }
+        }
+        Tab {
             title: "FIB"
             TableView {
                 anchors.fill: parent