face: move common declarations to face-common.hpp

Change-Id: I0e3e7a93f0693b0e24ca67493a4229987e792ef4
diff --git a/daemon/face/channel.cpp b/daemon/face/channel.cpp
index ed13cb2..8b1333e 100644
--- a/daemon/face/channel.cpp
+++ b/daemon/face/channel.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-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,7 @@
  */
 
 #include "channel.hpp"
+#include "face.hpp"
 
 namespace nfd {
 namespace face {
@@ -37,14 +38,13 @@
 }
 
 void
-connectFaceClosedSignal(Face& face, const std::function<void()>& f)
+connectFaceClosedSignal(Face& face, std::function<void()> f)
 {
-  face.afterStateChange.connect(
-    [f] (FaceState oldState, FaceState newState) {
-      if (newState == FaceState::CLOSED) {
-        f();
-      }
-    });
+  face.afterStateChange.connect([f = std::move(f)] (auto, FaceState newState) {
+    if (newState == FaceState::CLOSED) {
+      f();
+    }
+  });
 }
 
 } // namespace face
diff --git a/daemon/face/channel.hpp b/daemon/face/channel.hpp
index 6d2c221..4b4b8c6 100644
--- a/daemon/face/channel.hpp
+++ b/daemon/face/channel.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -27,23 +27,12 @@
 #define NFD_DAEMON_FACE_CHANNEL_HPP
 
 #include "channel-log.hpp"
-#include "face.hpp"
-
-#include <boost/logic/tribool.hpp>
+#include "face-common.hpp"
 
 namespace nfd {
 namespace face {
 
-/** \brief Prototype for the callback that is invoked when a face is created
- *         (in response to an incoming connection or after a connection is established)
- */
-using FaceCreatedCallback = std::function<void(const shared_ptr<Face>& face)>;
-
-/** \brief Prototype for the callback that is invoked when a face fails to be created
- */
-using FaceCreationFailedCallback = std::function<void(uint32_t status, const std::string& reason)>;
-
-/** \brief represent a channel that communicates on a local endpoint
+/** \brief Represents a channel that listens on a local endpoint.
  *  \sa FaceSystem
  *
  *  A channel can listen on a local endpoint and initiate outgoing connection from a local endpoint.
@@ -79,31 +68,24 @@
   FaceUri m_uri;
 };
 
-/** \brief Parameters used to set Transport properties or LinkService options on a newly created face
- *
- *  Parameters are passed as a struct rather than individually, so that a future change in the list
- *  of parameters does not require an update to the method signature in all subclasses.
+/** \brief Prototype for the callback that is invoked when a face is created
+ *         (in response to an incoming connection or after a connection is established).
  */
-struct FaceParams
-{
-  ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
-  optional<time::nanoseconds> baseCongestionMarkingInterval;
-  optional<uint64_t> defaultCongestionThreshold;
-  optional<ssize_t> mtu;
-  bool wantLocalFields = false;
-  bool wantLpReliability = false;
-  boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
-};
+using FaceCreatedCallback = std::function<void(const shared_ptr<Face>&)>;
 
-/** \brief invokes a callback when the face is closed
+/** \brief Prototype for the callback that is invoked when a face fails to be created.
+ */
+using FaceCreationFailedCallback = std::function<void(uint32_t status, const std::string& reason)>;
+
+/** \brief Invokes a callback when a face is closed.
  *  \param face the face
  *  \param f the callback to be invoked when the face enters CLOSED state
  *
- *  This function connects a callback to the afterStateChange signal on the \p face,
+ *  This function connects a callback to the afterStateChange signal of \p face,
  *  and invokes \p f when the state becomes CLOSED.
  */
 void
-connectFaceClosedSignal(Face& face, const std::function<void()>& f);
+connectFaceClosedSignal(Face& face, std::function<void()> f);
 
 } // namespace face
 } // namespace nfd
diff --git a/daemon/face/ethernet-channel.cpp b/daemon/face/ethernet-channel.cpp
index 9c27ada..0104b19 100644
--- a/daemon/face/ethernet-channel.cpp
+++ b/daemon/face/ethernet-channel.cpp
@@ -25,6 +25,7 @@
 
 #include "ethernet-channel.hpp"
 #include "ethernet-protocol.hpp"
+#include "face.hpp"
 #include "generic-link-service.hpp"
 #include "unicast-ethernet-transport.hpp"
 #include "common/global.hpp"
diff --git a/daemon/face/face-common.hpp b/daemon/face/face-common.hpp
new file mode 100644
index 0000000..f233309
--- /dev/null
+++ b/daemon/face/face-common.hpp
@@ -0,0 +1,149 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2019,  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.
+ *
+ * NFD 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 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, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_DAEMON_FACE_FACE_COMMON_HPP
+#define NFD_DAEMON_FACE_FACE_COMMON_HPP
+
+#include "core/common.hpp"
+#include "common/logger.hpp"
+
+#include <ndn-cxx/encoding/nfd-constants.hpp>
+
+#include <boost/logic/tribool.hpp>
+
+namespace nfd {
+namespace face {
+
+class Face;
+class LinkService;
+
+/** \brief Identifies a face.
+ */
+using FaceId = uint64_t;
+
+/// indicates an invalid FaceId
+const FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID;
+/// identifies the InternalFace used in management
+const FaceId FACEID_INTERNAL_FACE = 1;
+/// identifies a packet comes from the ContentStore
+const FaceId FACEID_CONTENT_STORE = 254;
+/// identifies the NullFace that drops every packet
+const FaceId FACEID_NULL = 255;
+/// upper bound of reserved FaceIds
+const FaceId FACEID_RESERVED_MAX = 255;
+
+/** \brief Identifies a remote endpoint on the link.
+ *
+ *  This ID is only meaningful in the context of the same Transport.
+ *  Incoming packets from the same remote endpoint have the same EndpointId,
+ *  and incoming packets from different remote endpoints have different EndpointIds.
+ *
+ *  Typically, a point-to-point Transport has only one meaningful EndpointId (usually 0).
+ */
+using EndpointId = uint64_t;
+
+/** \brief Parameters used to set Transport properties or LinkService options on a newly created face.
+ *
+ *  Parameters are passed as a struct rather than individually, so that a future change in the list
+ *  of parameters does not require an update to the method signature in all subclasses.
+ */
+struct FaceParams
+{
+  ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
+  optional<time::nanoseconds> baseCongestionMarkingInterval;
+  optional<uint64_t> defaultCongestionThreshold;
+  optional<ssize_t> mtu;
+  bool wantLocalFields = false;
+  bool wantLpReliability = false;
+  boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
+};
+
+/** \brief For internal use by FaceLogging macros.
+ *
+ *  FaceLogHelper wraps a reference to Face, LinkService, or Transport object.
+ *
+ *  `std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)`
+ *  should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
+ *  which will appear as part of the log message.
+ */
+template<typename T>
+class FaceLogHelper
+{
+public:
+  explicit
+  FaceLogHelper(const T& obj1) noexcept
+    : obj(obj1)
+  {
+  }
+
+public:
+  const T& obj;
+};
+
+} // namespace face
+
+using face::EndpointId;
+using face::FaceId;
+
+} // namespace nfd
+
+/** \defgroup FaceLogging Face logging macros
+ *
+ * These macros augment the log message with some face-specific information,
+ * such as the face ID, that are useful to distinguish which face produced the
+ * message. It is strongly recommended to use these macros instead of the
+ * generic ones for all logging inside Face, LinkService, Transport subclasses.
+ * @{
+ */
+
+/** \cond */
+// implementation detail
+#define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \
+  ::nfd::face::FaceLogHelper< \
+    typename std::remove_cv< \
+      typename std::remove_reference<decltype(*this)>::type \
+    >::type \
+  >(*this) \
+  << msg)
+/** \endcond */
+
+/** \brief Log a message at TRACE level */
+#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
+
+/** \brief Log a message at DEBUG level */
+#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
+
+/** \brief Log a message at INFO level */
+#define NFD_LOG_FACE_INFO(msg)  NFD_LOG_FACE(INFO,  msg)
+
+/** \brief Log a message at WARN level */
+#define NFD_LOG_FACE_WARN(msg)  NFD_LOG_FACE(WARN,  msg)
+
+/** \brief Log a message at ERROR level */
+#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
+
+/** @} */
+
+#endif // NFD_DAEMON_FACE_FACE_COMMON_HPP
diff --git a/daemon/face/face-log.hpp b/daemon/face/face-log.hpp
deleted file mode 100644
index b193d82..0000000
--- a/daemon/face/face-log.hpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2019,  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.
- *
- * NFD 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 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, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_DAEMON_FACE_FACE_LOG_HPP
-#define NFD_DAEMON_FACE_FACE_LOG_HPP
-
-#include "common/logger.hpp"
-
-namespace nfd {
-namespace face {
-
-/** \brief for internal use by FaceLogging macros
- *
- *  FaceLogHelper wraps a Face, LinkService, or Transport object.
- *
- *  std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
- *  should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
- *  which appears as part of the log message.
- */
-template<typename T>
-class FaceLogHelper
-{
-public:
-  explicit
-  FaceLogHelper(const T& obj1)
-    : obj(obj1)
-  {
-  }
-
-public:
-  const T& obj;
-};
-
-} // namespace face
-} // namespace nfd
-
-/** \defgroup FaceLogging Face logging macros
- *
- * These macros augment the log message with some face-specific information,
- * such as the face ID, that are useful to distinguish which face produced the
- * message. It is strongly recommended to use these macros instead of the
- * generic ones for all logging inside Face, LinkService, Transport subclasses.
- * @{
- */
-
-/** \cond */
-#define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \
-  ::nfd::face::FaceLogHelper< \
-    typename std::remove_cv< \
-      typename std::remove_reference<decltype(*this)>::type \
-    >::type \
-  >(*this) \
-  << msg)
-/** \endcond */
-
-/** \brief Log a message at TRACE level */
-#define NFD_LOG_FACE_TRACE(msg) NFD_LOG_FACE(TRACE, msg)
-
-/** \brief Log a message at DEBUG level */
-#define NFD_LOG_FACE_DEBUG(msg) NFD_LOG_FACE(DEBUG, msg)
-
-/** \brief Log a message at INFO level */
-#define NFD_LOG_FACE_INFO(msg)  NFD_LOG_FACE(INFO,  msg)
-
-/** \brief Log a message at WARN level */
-#define NFD_LOG_FACE_WARN(msg)  NFD_LOG_FACE(WARN,  msg)
-
-/** \brief Log a message at ERROR level */
-#define NFD_LOG_FACE_ERROR(msg) NFD_LOG_FACE(ERROR, msg)
-
-/** @} */
-
-#endif // NFD_DAEMON_FACE_FACE_LOG_HPP
diff --git a/daemon/face/face-system.hpp b/daemon/face/face-system.hpp
index 2bcdfad..84a2dce 100644
--- a/daemon/face/face-system.hpp
+++ b/daemon/face/face-system.hpp
@@ -26,7 +26,6 @@
 #ifndef NFD_DAEMON_FACE_FACE_SYSTEM_HPP
 #define NFD_DAEMON_FACE_FACE_SYSTEM_HPP
 
-#include "channel.hpp"
 #include "network-predicate.hpp"
 #include "common/config-file.hpp"
 
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index e96bc31..dc8c20d 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -26,29 +26,14 @@
 #ifndef NFD_DAEMON_FACE_FACE_HPP
 #define NFD_DAEMON_FACE_FACE_HPP
 
+#include "face-common.hpp"
 #include "face-counters.hpp"
-#include "face-log.hpp"
 #include "link-service.hpp"
 #include "transport.hpp"
 
 namespace nfd {
 namespace face {
 
-/** \brief identifies a face
- */
-typedef uint64_t FaceId;
-
-/// indicates an invalid FaceId
-const FaceId INVALID_FACEID = 0;
-/// identifies the InternalFace used in management
-const FaceId FACEID_INTERNAL_FACE = 1;
-/// identifies a packet comes from the ContentStore
-const FaceId FACEID_CONTENT_STORE = 254;
-/// identifies the NullFace that drops every packet
-const FaceId FACEID_NULL = 255;
-/// upper bound of reserved FaceIds
-const FaceId FACEID_RESERVED_MAX = 255;
-
 /** \brief indicates the state of a face
  */
 typedef TransportState FaceState;
@@ -295,8 +280,6 @@
 
 } // namespace face
 
-using face::EndpointId;
-using face::FaceId;
 using face::Face;
 
 } // namespace nfd
diff --git a/daemon/face/link-service.hpp b/daemon/face/link-service.hpp
index 8396137..415c185 100644
--- a/daemon/face/link-service.hpp
+++ b/daemon/face/link-service.hpp
@@ -26,15 +26,13 @@
 #ifndef NFD_DAEMON_FACE_LINK_SERVICE_HPP
 #define NFD_DAEMON_FACE_LINK_SERVICE_HPP
 
-#include "face-log.hpp"
+#include "face-common.hpp"
 #include "transport.hpp"
 #include "common/counter.hpp"
 
 namespace nfd {
 namespace face {
 
-class Face;
-
 /** \brief counters provided by LinkService
  *  \note The type name 'LinkServiceCounters' is implementation detail.
  *        Use 'LinkService::Counters' in public API.
diff --git a/daemon/face/lp-fragmenter.hpp b/daemon/face/lp-fragmenter.hpp
index 51d14d9..d98d752 100644
--- a/daemon/face/lp-fragmenter.hpp
+++ b/daemon/face/lp-fragmenter.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -26,16 +26,13 @@
 #ifndef NFD_DAEMON_FACE_LP_FRAGMENTER_HPP
 #define NFD_DAEMON_FACE_LP_FRAGMENTER_HPP
 
-#include "core/common.hpp"
-#include "face-log.hpp"
+#include "face-common.hpp"
 
 #include <ndn-cxx/lp/packet.hpp>
 
 namespace nfd {
 namespace face {
 
-class LinkService;
-
 /** \brief fragments network-layer packets into NDNLPv2 link-layer packets
  *  \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
  */
diff --git a/daemon/face/lp-reassembler.hpp b/daemon/face/lp-reassembler.hpp
index e9f0556..95c66ff 100644
--- a/daemon/face/lp-reassembler.hpp
+++ b/daemon/face/lp-reassembler.hpp
@@ -26,16 +26,13 @@
 #ifndef NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
 #define NFD_DAEMON_FACE_LP_REASSEMBLER_HPP
 
-#include "face-log.hpp"
-#include "transport.hpp"
+#include "face-common.hpp"
 
 #include <ndn-cxx/lp/packet.hpp>
 
 namespace nfd {
 namespace face {
 
-class LinkService;
-
 /** \brief reassembles fragmented network-layer packets
  *  \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
  */
diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp
index a3cb625..ed87de3 100644
--- a/daemon/face/protocol-factory.hpp
+++ b/daemon/face/protocol-factory.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -27,11 +27,11 @@
 #define NFD_DAEMON_FACE_PROTOCOL_FACTORY_HPP
 
 #include "channel.hpp"
+#include "face.hpp"
 #include "face-system.hpp"
 
 #include <boost/range/adaptor/map.hpp>
 #include <boost/range/algorithm/copy.hpp>
-#include <ndn-cxx/encoding/nfd-constants.hpp>
 
 namespace nfd {
 namespace face {
diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp
index a26c91e..cfbaed6 100644
--- a/daemon/face/tcp-channel.cpp
+++ b/daemon/face/tcp-channel.cpp
@@ -24,6 +24,7 @@
  */
 
 #include "tcp-channel.hpp"
+#include "face.hpp"
 #include "generic-link-service.hpp"
 #include "tcp-transport.hpp"
 #include "common/global.hpp"
diff --git a/daemon/face/transport.hpp b/daemon/face/transport.hpp
index 2dd81a0..dd6bb41 100644
--- a/daemon/face/transport.hpp
+++ b/daemon/face/transport.hpp
@@ -26,29 +26,12 @@
 #ifndef NFD_DAEMON_FACE_TRANSPORT_HPP
 #define NFD_DAEMON_FACE_TRANSPORT_HPP
 
-#include "face-log.hpp"
+#include "face-common.hpp"
 #include "common/counter.hpp"
 
-#include <ndn-cxx/encoding/nfd-constants.hpp>
-
 namespace nfd {
 namespace face {
 
-class Face;
-class LinkService;
-
-/** \brief Identifies a remote endpoint on the link.
- *
- *  This ID is only meaningful in the context of the same Transport.
- *  Incoming packets from the same remote endpoint have the same EndpointId,
- *  and incoming packets from different remote endpoints have different EndpointIds.
- *
- *  Typically, a point-to-point Transport has only one meaningful EndpointId (usually 0).
- *
- *  \sa FaceEndpoint
- */
-using EndpointId = uint64_t;
-
 /** \brief Indicates the state of a transport.
  */
 enum class TransportState {
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index 7f4a4d9..5a23758 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -24,6 +24,7 @@
  */
 
 #include "udp-channel.hpp"
+#include "face.hpp"
 #include "generic-link-service.hpp"
 #include "unicast-udp-transport.hpp"
 #include "common/global.hpp"
diff --git a/daemon/face/unix-stream-channel.cpp b/daemon/face/unix-stream-channel.cpp
index 4ef1a18..b60ba78 100644
--- a/daemon/face/unix-stream-channel.cpp
+++ b/daemon/face/unix-stream-channel.cpp
@@ -24,6 +24,7 @@
  */
 
 #include "unix-stream-channel.hpp"
+#include "face.hpp"
 #include "generic-link-service.hpp"
 #include "unix-stream-transport.hpp"
 #include "common/global.hpp"
diff --git a/daemon/face/websocket-channel.cpp b/daemon/face/websocket-channel.cpp
index 20b6686..a2660c6 100644
--- a/daemon/face/websocket-channel.cpp
+++ b/daemon/face/websocket-channel.cpp
@@ -24,6 +24,7 @@
  */
 
 #include "websocket-channel.hpp"
+#include "face.hpp"
 #include "generic-link-service.hpp"
 #include "websocket-transport.hpp"
 #include "common/global.hpp"