face: use lambda expression and smart pointers

Refs: #2112

Change-Id: I73aab91b0b6841c55ef2892493901a13b7382cdd
diff --git a/src/face.cpp b/src/face.cpp
index 744ee0d..b36f955 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -39,7 +39,7 @@
   , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
-  construct(m_internalKeyChain);
+  construct(*m_internalKeyChain);
 }
 
 Face::Face(boost::asio::io_service& ioService)
@@ -48,7 +48,7 @@
   , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
-  construct(m_internalKeyChain);
+  construct(*m_internalKeyChain);
 }
 
 Face::Face(const std::string& host, const std::string& port/* = "6363"*/)
@@ -57,8 +57,7 @@
   , m_internalKeyChain(new KeyChain())
   , m_impl(new Impl(*this))
 {
-  construct(make_shared<TcpTransport>(host, port),
-            m_internalKeyChain);
+  construct(make_shared<TcpTransport>(host, port), *m_internalKeyChain);
 }
 
 Face::Face(const shared_ptr<Transport>& transport)
@@ -68,8 +67,7 @@
   , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
-  construct(transport,
-            m_internalKeyChain);
+  construct(transport, *m_internalKeyChain);
 }
 
 Face::Face(const shared_ptr<Transport>& transport,
@@ -79,8 +77,7 @@
   , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
-  construct(transport,
-            m_internalKeyChain);
+  construct(transport, *m_internalKeyChain);
 }
 
 Face::Face(shared_ptr<Transport> transport,
@@ -91,12 +88,11 @@
   , m_isDirectNfdFibManagementRequested(false)
   , m_impl(new Impl(*this))
 {
-  construct(transport,
-            &keyChain);
+  construct(transport, keyChain);
 }
 
 void
-Face::construct(KeyChain* keyChain)
+Face::construct(KeyChain& keyChain)
 {
   // transport=unix:///var/run/nfd.sock
   // transport=tcp://localhost:6363
@@ -121,7 +117,6 @@
       throw ConfigFile::Error(error.what());
     }
 
-  shared_ptr<Transport> transport;
   const std::string protocol = uri->getScheme();
 
   if (protocol == "unix")
@@ -140,10 +135,9 @@
 }
 
 void
-Face::construct(shared_ptr<Transport> transport,
-                KeyChain* keyChain)
+Face::construct(shared_ptr<Transport> transport, KeyChain& keyChain)
 {
-  m_nfdController = new nfd::Controller(*this, *keyChain);
+  m_nfdController.reset(new nfd::Controller(*this, keyChain));
 
   m_impl->m_pitTimeoutCheckTimerActive = false;
   m_transport = transport;
@@ -181,15 +175,7 @@
     }
 }
 
-Face::~Face()
-{
-  if (m_internalKeyChain != nullptr) {
-    delete m_internalKeyChain;
-  }
-
-  delete m_nfdController;
-  delete m_impl;
-}
+Face::~Face() = default;
 
 const PendingInterestId*
 Face::expressInterest(const Interest& interest, const OnData& onData, const OnTimeout& onTimeout)
@@ -201,8 +187,7 @@
     throw Error("Interest size exceeds maximum limit");
 
   // If the same ioService thread, dispatch directly calls the method
-  m_ioService.dispatch(bind(&Impl::asyncExpressInterest, m_impl,
-                            interestToExpress, onData, onTimeout));
+  m_ioService.dispatch([=] { m_impl->asyncExpressInterest(interestToExpress, onData, onTimeout); });
 
   return reinterpret_cast<const PendingInterestId*>(interestToExpress.get());
 }
@@ -236,13 +221,13 @@
   }
 
   // If the same ioService thread, dispatch directly calls the method
-  m_ioService.dispatch(bind(&Impl::asyncPutData, m_impl, dataPtr));
+  m_ioService.dispatch([=] { m_impl->asyncPutData(dataPtr); });
 }
 
 void
 Face::removePendingInterest(const PendingInterestId* pendingInterestId)
 {
-  m_ioService.post(bind(&Impl::asyncRemovePendingInterest, m_impl, pendingInterestId));
+  m_ioService.post([=] { m_impl->asyncRemovePendingInterest(pendingInterestId); });
 }
 
 size_t
@@ -343,7 +328,7 @@
   shared_ptr<InterestFilterRecord> filter =
     make_shared<InterestFilterRecord>(interestFilter, onInterest);
 
-  getIoService().post(bind(&Impl::asyncSetInterestFilter, m_impl, filter));
+  getIoService().post([=] { m_impl->asyncSetInterestFilter(filter); });
 
   return reinterpret_cast<const InterestFilterId*>(filter.get());
 }
@@ -386,14 +371,15 @@
 void
 Face::unsetInterestFilter(const RegisteredPrefixId* registeredPrefixId)
 {
-  m_ioService.post(bind(&Impl::asyncUnregisterPrefix, m_impl, registeredPrefixId,
-                        UnregisterPrefixSuccessCallback(), UnregisterPrefixFailureCallback()));
+  m_ioService.post([=] { m_impl->asyncUnregisterPrefix(registeredPrefixId,
+                                                       UnregisterPrefixSuccessCallback(),
+                                                       UnregisterPrefixFailureCallback()); });
 }
 
 void
 Face::unsetInterestFilter(const InterestFilterId* interestFilterId)
 {
-  m_ioService.post(bind(&Impl::asyncUnsetInterestFilter, m_impl, interestFilterId));
+  m_ioService.post([=] { m_impl->asyncUnsetInterestFilter(interestFilterId); });
 }
 
 void
@@ -401,8 +387,7 @@
                        const UnregisterPrefixSuccessCallback& onSuccess,
                        const UnregisterPrefixFailureCallback& onFailure)
 {
-  m_ioService.post(bind(&Impl::asyncUnregisterPrefix, m_impl, registeredPrefixId,
-                        onSuccess, onFailure));
+  m_ioService.post([=] { m_impl->asyncUnregisterPrefix(registeredPrefixId,onSuccess, onFailure); });
 }
 
 void
@@ -449,7 +434,7 @@
 void
 Face::shutdown()
 {
-  m_ioService.post(bind(&Face::asyncShutdown, this));
+  m_ioService.post([this] { this->asyncShutdown(); });
 }
 
 void