face: face refactoring completion

* delete old Face
* rename LpFace as Face
* eliminate LpFaceWrapper and use new Face

refs #3172

Change-Id: I08c3a5dfb4cc1b9834b30cccd9ab634535d0608c
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index 5489837..b1ed449 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -115,7 +115,7 @@
 AccessStrategy::sendToLastNexthop(const Face& inFace, shared_ptr<pit::Entry> pitEntry, MtInfo& mi,
                                   shared_ptr<fib::Entry> fibEntry)
 {
-  if (mi.lastNexthop == INVALID_FACEID) {
+  if (mi.lastNexthop == face::INVALID_FACEID) {
     NFD_LOG_DEBUG(pitEntry->getInterest() << " no-last-nexthop");
     return false;
   }
@@ -231,7 +231,7 @@
 }
 
 AccessStrategy::MtInfo::MtInfo()
-  : lastNexthop(INVALID_FACEID)
+  : lastNexthop(face::INVALID_FACEID)
   , rtt(1, time::milliseconds(1), 0.1)
 {
 }
diff --git a/daemon/fw/client-control-strategy.cpp b/daemon/fw/client-control-strategy.cpp
index 7cc07fd..1066efa 100644
--- a/daemon/fw/client-control-strategy.cpp
+++ b/daemon/fw/client-control-strategy.cpp
@@ -58,7 +58,7 @@
 
   FaceId outFaceId = static_cast<FaceId>(*tag);
   shared_ptr<Face> outFace = this->getFace(outFaceId);
-  if (!static_cast<bool>(outFace)) {
+  if (outFace == nullptr) {
     // If outFace doesn't exist, it's better to reject the Interest
     // than to use BestRouteStrategy.
     NFD_LOG_WARN("Interest " << interest.getName() <<
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index a8a8053..b4bda23 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -27,6 +27,7 @@
 #include "forwarder.hpp"
 #include "core/global-io.hpp"
 #include "core/logger.hpp"
+#include "face/channel.hpp"
 
 namespace nfd {
 
@@ -34,7 +35,7 @@
 
 FaceTable::FaceTable(Forwarder& forwarder)
   : m_forwarder(forwarder)
-  , m_lastFaceId(FACEID_RESERVED_MAX)
+  , m_lastFaceId(face::FACEID_RESERVED_MAX)
 {
 }
 
@@ -59,22 +60,22 @@
 void
 FaceTable::add(shared_ptr<Face> face)
 {
-  if (face->getId() != INVALID_FACEID && m_faces.count(face->getId()) > 0) {
+  if (face->getId() != face::INVALID_FACEID && m_faces.count(face->getId()) > 0) {
     NFD_LOG_WARN("Trying to add existing face id=" << face->getId() << " to the face table");
     return;
   }
 
   FaceId faceId = ++m_lastFaceId;
-  BOOST_ASSERT(faceId > FACEID_RESERVED_MAX);
+  BOOST_ASSERT(faceId > face::FACEID_RESERVED_MAX);
   this->addImpl(face, faceId);
 }
 
 void
 FaceTable::addReserved(shared_ptr<Face> face, FaceId faceId)
 {
-  BOOST_ASSERT(face->getId() == INVALID_FACEID);
+  BOOST_ASSERT(face->getId() == face::INVALID_FACEID);
   BOOST_ASSERT(m_faces.count(face->getId()) == 0);
-  BOOST_ASSERT(faceId <= FACEID_RESERVED_MAX);
+  BOOST_ASSERT(faceId <= face::FACEID_RESERVED_MAX);
   this->addImpl(face, faceId);
 }
 
@@ -86,30 +87,26 @@
   NFD_LOG_INFO("Added face id=" << faceId << " remote=" << face->getRemoteUri()
                                           << " local=" << face->getLocalUri());
 
-  face->onReceiveInterest.connect(bind(&Forwarder::startProcessInterest,
-                                       &m_forwarder, ref(*face), _1));
-  face->onReceiveData.connect(bind(&Forwarder::startProcessData,
-                                   &m_forwarder, ref(*face), _1));
-  face->onReceiveNack.connect(bind(&Forwarder::startProcessNack,
-                                   &m_forwarder, ref(*face), _1));
-  face->onFail.connectSingleShot(bind(&FaceTable::remove, this, face, _1));
+  face->afterReceiveInterest.connect(bind(&Forwarder::startProcessInterest, &m_forwarder, ref(*face), _1));
+  face->afterReceiveData.connect(bind(&Forwarder::startProcessData, &m_forwarder, ref(*face), _1));
+  face->afterReceiveNack.connect(bind(&Forwarder::startProcessNack, &m_forwarder, ref(*face), _1));
+  connectFaceClosedSignal(*face, bind(&FaceTable::remove, this, face));
 
-  this->onAdd(face);
+  this->afterAdd(face);
 }
 
 void
-FaceTable::remove(shared_ptr<Face> face, const std::string& reason)
+FaceTable::remove(shared_ptr<Face> face)
 {
-  this->onRemove(face);
+  this->beforeRemove(face);
 
   FaceId faceId = face->getId();
   m_faces.erase(faceId);
-  face->setId(INVALID_FACEID);
+  face->setId(face::INVALID_FACEID);
 
   NFD_LOG_INFO("Removed face id=" << faceId <<
                " remote=" << face->getRemoteUri() <<
-               " local=" << face->getLocalUri() <<
-               " (" << reason << ")");
+               " local=" << face->getLocalUri());
 
   m_forwarder.getFib().removeNextHopFromAllEntries(face);
 
diff --git a/daemon/fw/face-table.hpp b/daemon/fw/face-table.hpp
index 67c7932..a9186f6 100644
--- a/daemon/fw/face-table.hpp
+++ b/daemon/fw/face-table.hpp
@@ -1,12 +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,
- *                      The University of Memphis
+ * Copyright (c) 2014-2015,  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.
@@ -75,22 +75,20 @@
 public: // signals
   /** \brief fires after a Face is added
    */
-  signal::Signal<FaceTable, shared_ptr<Face>> onAdd;
+  signal::Signal<FaceTable, shared_ptr<Face>> afterAdd;
 
   /** \brief fires before a Face is removed
    *
    *  FaceId is valid when this event is fired
    */
-  signal::Signal<FaceTable, shared_ptr<Face>> onRemove;
+  signal::Signal<FaceTable, shared_ptr<Face>> beforeRemove;
 
 private:
   void
   addImpl(shared_ptr<Face> face, FaceId faceId);
 
-  // remove is private because it's a handler of face.onFail signal.
-  // face->close() closes the face and triggers .remove()
   void
-  remove(shared_ptr<Face> face, const std::string& reason);
+  remove(shared_ptr<Face> face);
 
   ForwardRange
   getForwardRange() const;
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index e96b87b..280c713 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -108,7 +108,7 @@
   ++m_counters.nInInterests;
 
   // /localhost scope control
-  bool isViolatingLocalhost = !inFace.isLocal() &&
+  bool isViolatingLocalhost = inFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
                               LOCALHOST_NAME.isPrefixOf(interest.getName());
   if (isViolatingLocalhost) {
     NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() <<
@@ -151,7 +151,7 @@
                           shared_ptr<pit::Entry> pitEntry)
 {
   // if multi-access face, drop
-  if (inFace.isMultiAccess()) {
+  if (inFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) {
     NFD_LOG_DEBUG("onInterestLoop face=" << inFace.getId() <<
                   " interest=" << interest.getName() <<
                   " drop");
@@ -244,7 +244,7 @@
 {
   NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName());
 
-  data.setTag(make_shared<lp::IncomingFaceIdTag>(FACEID_CONTENT_STORE));
+  data.setTag(make_shared<lp::IncomingFaceIdTag>(face::FACEID_CONTENT_STORE));
   // XXX should we lookup PIT for other Interests that also match csMatch?
 
   // set PIT straggler timer
@@ -284,7 +284,7 @@
 Forwarder::onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
                               bool wantNewNonce)
 {
-  if (outFace.getId() == INVALID_FACEID) {
+  if (outFace.getId() == face::INVALID_FACEID) {
     NFD_LOG_WARN("onOutgoingInterest face=invalid interest=" << pitEntry->getName());
     return;
   }
@@ -374,7 +374,7 @@
   ++m_counters.nInData;
 
   // /localhost scope control
-  bool isViolatingLocalhost = !inFace.isLocal() &&
+  bool isViolatingLocalhost = inFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
                               LOCALHOST_NAME.isPrefixOf(data.getName());
   if (isViolatingLocalhost) {
     NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() <<
@@ -439,7 +439,7 @@
 Forwarder::onDataUnsolicited(Face& inFace, const Data& data)
 {
   // accept to cache?
-  bool acceptToCache = inFace.isLocal();
+  bool acceptToCache = inFace.getScope() == ndn::nfd::FACE_SCOPE_LOCAL;
   if (acceptToCache) {
     // CS insert
     m_cs.insert(data, true);
@@ -453,14 +453,14 @@
 void
 Forwarder::onOutgoingData(const Data& data, Face& outFace)
 {
-  if (outFace.getId() == INVALID_FACEID) {
+  if (outFace.getId() == face::INVALID_FACEID) {
     NFD_LOG_WARN("onOutgoingData face=invalid data=" << data.getName());
     return;
   }
   NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() << " data=" << data.getName());
 
   // /localhost scope control
-  bool isViolatingLocalhost = !outFace.isLocal() &&
+  bool isViolatingLocalhost = outFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL &&
                               LOCALHOST_NAME.isPrefixOf(data.getName());
   if (isViolatingLocalhost) {
     NFD_LOG_DEBUG("onOutgoingData face=" << outFace.getId() <<
@@ -484,7 +484,7 @@
   ++m_counters.nInNacks;
 
   // if multi-access face, drop
-  if (inFace.isMultiAccess()) {
+  if (inFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) {
     NFD_LOG_DEBUG("onIncomingNack face=" << inFace.getId() <<
                   " nack=" << nack.getInterest().getName() <<
                   "~" << nack.getReason() << " face-is-multi-access");
@@ -537,7 +537,7 @@
 Forwarder::onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
                           const lp::NackHeader& nack)
 {
-  if (outFace.getId() == INVALID_FACEID) {
+  if (outFace.getId() == face::INVALID_FACEID) {
     NFD_LOG_WARN("onOutgoingNack face=invalid" <<
                   " nack=" << pitEntry->getInterest().getName() <<
                   "~" << nack.getReason() << " no-in-record");
@@ -556,7 +556,7 @@
   }
 
   // if multi-access face, drop
-  if (outFace.isMultiAccess()) {
+  if (outFace.getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS) {
     NFD_LOG_DEBUG("onOutgoingNack face=" << outFace.getId() <<
                   " nack=" << pitEntry->getInterest().getName() <<
                   "~" << nack.getReason() << " face-is-multi-access");
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 7b0504e..00fe82f 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -33,8 +33,8 @@
 NFD_LOG_INIT("Strategy");
 
 Strategy::Strategy(Forwarder& forwarder, const Name& name)
-  : afterAddFace(forwarder.getFaceTable().onAdd)
-  , beforeRemoveFace(forwarder.getFaceTable().onRemove)
+  : afterAddFace(forwarder.getFaceTable().afterAdd)
+  , beforeRemoveFace(forwarder.getFaceTable().beforeRemove)
   , m_name(name)
   , m_forwarder(forwarder)
   , m_measurements(m_forwarder.getMeasurements(),