mgmt: expose link layer counters in Face Dataset

refs #1767

Change-Id: If0b66ead4c2f2741c83396f251cce9a0d83c1520
diff --git a/daemon/face/face-counters.hpp b/daemon/face/face-counters.hpp
index 05303b5..6dc1d6a 100644
--- a/daemon/face/face-counters.hpp
+++ b/daemon/face/face-counters.hpp
@@ -67,7 +67,6 @@
   rep m_value;
 };
 
-
 /** \brief represents a counter of number of bytes
  */
 // ByteCounter is noncopyable, because increment should be called on the counter,
@@ -104,7 +103,6 @@
   rep m_value;
 };
 
-
 /** \brief contains network layer packet counters
  */
 class NetworkLayerCounters : noncopyable
@@ -162,6 +160,20 @@
     return m_nOutDatas;
   }
 
+protected:
+  /** \brief copy current obseverations to a struct
+   *  \param recipient an object with set methods for counters
+   */
+  template<typename R>
+  void
+  copyTo(R& recipient) const
+  {
+    recipient.setNInInterests(this->getNInInterests());
+    recipient.setNInDatas(this->getNInDatas());
+    recipient.setNOutInterests(this->getNOutInterests());
+    recipient.setNOutDatas(this->getNOutDatas());
+  }
+
 private:
   PacketCounter m_nInInterests;
   PacketCounter m_nInDatas;
@@ -169,7 +181,6 @@
   PacketCounter m_nOutDatas;
 };
 
-
 /** \brief contains link layer byte counters
  */
 class LinkLayerCounters : noncopyable
@@ -201,16 +212,38 @@
     return m_nOutBytes;
   }
 
+protected:
+  /** \brief copy current obseverations to a struct
+   *  \param recipient an object with set methods for counters
+   */
+  template<typename R>
+  void
+  copyTo(R& recipient) const
+  {
+    recipient.setNInBytes(this->getNInBytes());
+    recipient.setNOutBytes(this->getNOutBytes());
+  }
+
 private:
   ByteCounter m_nInBytes;
   ByteCounter m_nOutBytes;
 };
 
-
 /** \brief contains counters on face
  */
 class FaceCounters : public NetworkLayerCounters, public LinkLayerCounters
 {
+public:
+  /** \brief copy current obseverations to a struct
+   *  \param recipient an object with set methods for counters
+   */
+  template<typename R>
+  void
+  copyTo(R& recipient) const
+  {
+    this->NetworkLayerCounters::copyTo(recipient);
+    this->LinkLayerCounters::copyTo(recipient);
+  }
 };
 
 } // namespace nfd
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index 4197aa5..385f0a9 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -128,17 +128,13 @@
 ndn::nfd::FaceStatus
 Face::getFaceStatus() const
 {
-  const FaceCounters& counters = getCounters();
-
   ndn::nfd::FaceStatus status;
   status.setFaceId(getId())
     .setRemoteUri(getRemoteUri().toString())
     .setLocalUri(getLocalUri().toString())
-    .setFlags(getFaceFlags(*this))
-    .setNInInterests(counters.getNInInterests())
-    .setNInDatas(counters.getNInDatas())
-    .setNOutInterests(counters.getNOutInterests())
-    .setNOutDatas(counters.getNOutDatas());
+    .setFlags(getFaceFlags(*this));
+
+  this->getCounters().copyTo(status);
 
   return status;
 }
diff --git a/daemon/fw/forwarder-counters.hpp b/daemon/fw/forwarder-counters.hpp
index 7af679a..ba3b57c 100644
--- a/daemon/fw/forwarder-counters.hpp
+++ b/daemon/fw/forwarder-counters.hpp
@@ -34,9 +34,18 @@
  */
 class ForwarderCounters : public NetworkLayerCounters
 {
+public:
+  /** \brief copy current obseverations to a struct
+   *  \param recipient an object with set methods for counters
+   */
+  template<typename R>
+  void
+  copyTo(R& recipient) const
+  {
+    this->NetworkLayerCounters::copyTo(recipient);
+  }
 };
 
-
 } // namespace nfd
 
 #endif // NFD_DAEMON_FW_FORWARDER_COUNTERS_HPP
diff --git a/daemon/mgmt/status-server.cpp b/daemon/mgmt/status-server.cpp
index 148061c..51faca4 100644
--- a/daemon/mgmt/status-server.cpp
+++ b/daemon/mgmt/status-server.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014,  Regents of the University of California,
+ *                      Arizona Board of Regents,
+ *                      Colorado State University,
+ *                      University Pierre & Marie Curie, Sorbonne University,
+ *                      Washington University in St. Louis,
+ *                      Beijing Institute of Technology,
+ *                      The University of Memphis
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,7 +21,7 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #include "status-server.hpp"
 #include "fw/forwarder.hpp"
@@ -71,11 +72,7 @@
   status->setNMeasurementsEntries(m_forwarder.getMeasurements().size());
   status->setNCsEntries(m_forwarder.getCs().size());
 
-  const ForwarderCounters& counters = m_forwarder.getCounters();
-  status->setNInInterests(counters.getNInInterests());
-  status->setNInDatas(counters.getNInDatas());
-  status->setNOutInterests(counters.getNOutInterests());
-  status->setNOutDatas(counters.getNOutDatas());
+  m_forwarder.getCounters().copyTo(*status);
 
   return status;
 }