fw: accept const shared_ptr<pit::Entry>& in Forwarder pipelines and Strategy actions

refs #3205

Change-Id: Ia683fb1a9e301270f99bcdd4d97493abf3dbec9f
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index ff8e451..89ce166 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -154,7 +154,7 @@
   }
 
   // cancel unsatisfy & straggler timer
-  this->cancelUnsatisfyAndStragglerTimer(pitEntry);
+  this->cancelUnsatisfyAndStragglerTimer(*pitEntry);
 
   // is pending?
   if (!pitEntry->hasInRecords()) {
@@ -190,8 +190,7 @@
 }
 
 void
-Forwarder::onContentStoreMiss(const Face& inFace,
-                              shared_ptr<pit::Entry> pitEntry,
+Forwarder::onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
                               const Interest& interest)
 {
   NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
@@ -203,15 +202,13 @@
   this->setUnsatisfyTimer(pitEntry);
 
   // dispatch to strategy: after incoming Interest
-  this->dispatchToStrategy(pitEntry,
-    [&] (fw::Strategy* strategy) { strategy->afterReceiveInterest(inFace, interest, pitEntry); });
+  this->dispatchToStrategy(*pitEntry,
+    [&] (fw::Strategy& strategy) { strategy.afterReceiveInterest(inFace, interest, pitEntry); });
 }
 
 void
-Forwarder::onContentStoreHit(const Face& inFace,
-                             shared_ptr<pit::Entry> pitEntry,
-                             const Interest& interest,
-                             const Data& data)
+Forwarder::onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
+                             const Interest& interest, const Data& data)
 {
   NFD_LOG_DEBUG("onContentStoreHit interest=" << interest.getName());
 
@@ -226,7 +223,7 @@
 }
 
 void
-Forwarder::onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
+Forwarder::onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
                               bool wantNewNonce)
 {
   if (outFace.getId() == face::INVALID_FACEID) {
@@ -274,7 +271,7 @@
 }
 
 void
-Forwarder::onInterestReject(shared_ptr<pit::Entry> pitEntry)
+Forwarder::onInterestReject(const shared_ptr<pit::Entry>& pitEntry)
 {
   if (fw::hasPendingOutRecords(*pitEntry)) {
     NFD_LOG_ERROR("onInterestReject interest=" << pitEntry->getName() <<
@@ -284,28 +281,28 @@
   NFD_LOG_DEBUG("onInterestReject interest=" << pitEntry->getName());
 
   // cancel unsatisfy & straggler timer
-  this->cancelUnsatisfyAndStragglerTimer(pitEntry);
+  this->cancelUnsatisfyAndStragglerTimer(*pitEntry);
 
   // set PIT straggler timer
   this->setStragglerTimer(pitEntry, false);
 }
 
 void
-Forwarder::onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry)
+Forwarder::onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry)
 {
   NFD_LOG_DEBUG("onInterestUnsatisfied interest=" << pitEntry->getName());
 
   // invoke PIT unsatisfied callback
-  this->dispatchToStrategy(pitEntry,
-    [&] (fw::Strategy* strategy) { strategy->beforeExpirePendingInterest(pitEntry); });
+  this->dispatchToStrategy(*pitEntry,
+    [&] (fw::Strategy& strategy) { strategy.beforeExpirePendingInterest(pitEntry); });
 
   // goto Interest Finalize pipeline
   this->onInterestFinalize(pitEntry, false);
 }
 
 void
-Forwarder::onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
-                              const time::milliseconds& dataFreshnessPeriod)
+Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
+                              time::milliseconds dataFreshnessPeriod)
 {
   NFD_LOG_DEBUG("onInterestFinalize interest=" << pitEntry->getName() <<
                 (isSatisfied ? " satisfied" : " unsatisfied"));
@@ -314,7 +311,7 @@
   this->insertDeadNonceList(*pitEntry, isSatisfied, dataFreshnessPeriod, 0);
 
   // PIT delete
-  this->cancelUnsatisfyAndStragglerTimer(pitEntry);
+  this->cancelUnsatisfyAndStragglerTimer(*pitEntry);
   m_pit.erase(pitEntry);
 }
 
@@ -354,7 +351,7 @@
     NFD_LOG_DEBUG("onIncomingData matching=" << pitEntry->getName());
 
     // cancel unsatisfy & straggler timer
-    this->cancelUnsatisfyAndStragglerTimer(pitEntry);
+    this->cancelUnsatisfyAndStragglerTimer(*pitEntry);
 
     // remember pending downstreams
     for (const pit::InRecord& inRecord : pitEntry->getInRecords()) {
@@ -364,8 +361,8 @@
     }
 
     // invoke PIT satisfy callback
-    this->dispatchToStrategy(pitEntry,
-      [&] (fw::Strategy* strategy) { strategy->beforeSatisfyInterest(pitEntry, inFace, data); });
+    this->dispatchToStrategy(*pitEntry,
+      [&] (fw::Strategy& strategy) { strategy.beforeSatisfyInterest(pitEntry, inFace, data); });
 
     // Dead Nonce List insert if necessary (for out-record of inFace)
     this->insertDeadNonceList(*pitEntry, true, data.getFreshnessPeriod(), &inFace);
@@ -481,12 +478,12 @@
   outRecord->setIncomingNack(nack);
 
   // trigger strategy: after receive NACK
-  this->dispatchToStrategy(pitEntry,
-    [&] (fw::Strategy* strategy) { strategy->afterReceiveNack(inFace, nack, pitEntry); });
+  this->dispatchToStrategy(*pitEntry,
+    [&] (fw::Strategy& strategy) { strategy.afterReceiveNack(inFace, nack, pitEntry); });
 }
 
 void
-Forwarder::onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
+Forwarder::onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace,
                           const lp::NackHeader& nack)
 {
   if (outFace.getId() == face::INVALID_FACEID) {
@@ -598,7 +595,7 @@
 }
 
 void
-Forwarder::setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry)
+Forwarder::setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry)
 {
   pit::InRecordCollection::iterator lastExpiring =
     std::max_element(pitEntry->in_begin(), pitEntry->in_end(), &compare_InRecord_expiry);
@@ -615,8 +612,8 @@
 }
 
 void
-Forwarder::setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
-                             const time::milliseconds& dataFreshnessPeriod)
+Forwarder::setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
+                             time::milliseconds dataFreshnessPeriod)
 {
   time::nanoseconds stragglerTime = time::milliseconds(100);
 
@@ -626,10 +623,10 @@
 }
 
 void
-Forwarder::cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry)
+Forwarder::cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry)
 {
-  scheduler::cancel(pitEntry->m_unsatisfyTimer);
-  scheduler::cancel(pitEntry->m_stragglerTimer);
+  scheduler::cancel(pitEntry.m_unsatisfyTimer);
+  scheduler::cancel(pitEntry.m_stragglerTimer);
 }
 
 static inline void
@@ -641,8 +638,7 @@
 
 void
 Forwarder::insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
-                               const time::milliseconds& dataFreshnessPeriod,
-                               Face* upstream)
+                               time::milliseconds dataFreshnessPeriod, Face* upstream)
 {
   // need Dead Nonce List insert?
   bool needDnl = false;
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index b561d6f..855c24e 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -57,25 +57,37 @@
   ~Forwarder();
 
   const ForwarderCounters&
-  getCounters() const;
+  getCounters() const
+  {
+    return m_counters;
+  }
 
 public: // faces
   FaceTable&
-  getFaceTable();
+  getFaceTable()
+  {
+    return m_faceTable;
+  }
 
   /** \brief get existing Face
    *
    *  shortcut to .getFaceTable().get(face)
    */
   Face*
-  getFace(FaceId id) const;
+  getFace(FaceId id) const
+  {
+    return m_faceTable.get(id);
+  }
 
   /** \brief add new Face
    *
    *  shortcut to .getFaceTable().add(face)
    */
   void
-  addFace(shared_ptr<Face> face);
+  addFace(shared_ptr<Face> face)
+  {
+    m_faceTable.add(face);
+  }
 
 public: // forwarding entrypoints and tables
   /** \brief start incoming Interest processing
@@ -100,28 +112,52 @@
   startProcessNack(Face& face, const lp::Nack& nack);
 
   NameTree&
-  getNameTree();
+  getNameTree()
+  {
+    return m_nameTree;
+  }
 
   Fib&
-  getFib();
+  getFib()
+  {
+    return m_fib;
+  }
 
   Pit&
-  getPit();
+  getPit()
+  {
+    return m_pit;
+  }
 
   Cs&
-  getCs();
+  getCs()
+  {
+    return m_cs;
+  }
 
   Measurements&
-  getMeasurements();
+  getMeasurements()
+  {
+    return m_measurements;
+  }
 
   StrategyChoice&
-  getStrategyChoice();
+  getStrategyChoice()
+  {
+    return m_strategyChoice;
+  }
 
   DeadNonceList&
-  getDeadNonceList();
+  getDeadNonceList()
+  {
+    return m_deadNonceList;
+  }
 
   NetworkRegionTable&
-  getNetworkRegionTable();
+  getNetworkRegionTable()
+  {
+    return m_networkRegionTable;
+  }
 
   /** \brief performs a FIB lookup, considering Link object if present
    */
@@ -142,37 +178,38 @@
   /** \brief Content Store miss pipeline
   */
   VIRTUAL_WITH_TESTS void
-  onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
+  onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
+                     const Interest& interest);
 
   /** \brief Content Store hit pipeline
   */
   VIRTUAL_WITH_TESTS void
-  onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
+  onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
                     const Interest& interest, const Data& data);
 
   /** \brief outgoing Interest pipeline
    */
   VIRTUAL_WITH_TESTS void
-  onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
+  onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
                      bool wantNewNonce = false);
 
   /** \brief Interest reject pipeline
    */
   VIRTUAL_WITH_TESTS void
-  onInterestReject(shared_ptr<pit::Entry> pitEntry);
+  onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
 
   /** \brief Interest unsatisfied pipeline
    */
   VIRTUAL_WITH_TESTS void
-  onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
+  onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
 
   /** \brief Interest finalize pipeline
    *  \param isSatisfied whether the Interest has been satisfied
    *  \param dataFreshnessPeriod FreshnessPeriod of satisfying Data
    */
   VIRTUAL_WITH_TESTS void
-  onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
-                     const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
+  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
+                     time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
 
   /** \brief incoming Data pipeline
    */
@@ -197,18 +234,18 @@
   /** \brief outgoing Nack pipeline
    */
   VIRTUAL_WITH_TESTS void
-  onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace, const lp::NackHeader& nack);
+  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
 
 PROTECTED_WITH_TESTS_ELSE_PRIVATE:
   VIRTUAL_WITH_TESTS void
-  setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
+  setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
 
   VIRTUAL_WITH_TESTS void
-  setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
-                    const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
+  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
+                    time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
 
   VIRTUAL_WITH_TESTS void
-  cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
+  cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
 
   /** \brief insert Nonce to Dead Nonce List if necessary
    *  \param upstream if null, insert Nonces from all out-records;
@@ -216,18 +253,21 @@
    */
   VIRTUAL_WITH_TESTS void
   insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
-                      const time::milliseconds& dataFreshnessPeriod,
-                      Face* upstream);
+                      time::milliseconds dataFreshnessPeriod, Face* upstream);
 
-  /// call trigger (method) on the effective strategy of pitEntry
+  /** \brief call trigger (method) on the effective strategy of pitEntry
+   */
 #ifdef WITH_TESTS
   virtual void
-  dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
+  dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
 #else
   template<class Function>
   void
-  dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
+  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
 #endif
+  {
+    trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
+  }
 
 private:
   ForwarderCounters m_counters;
@@ -248,91 +288,6 @@
   friend class fw::Strategy;
 };
 
-inline const ForwarderCounters&
-Forwarder::getCounters() const
-{
-  return m_counters;
-}
-
-inline FaceTable&
-Forwarder::getFaceTable()
-{
-  return m_faceTable;
-}
-
-inline Face*
-Forwarder::getFace(FaceId id) const
-{
-  return m_faceTable.get(id);
-}
-
-inline void
-Forwarder::addFace(shared_ptr<Face> face)
-{
-  m_faceTable.add(face);
-}
-
-inline NameTree&
-Forwarder::getNameTree()
-{
-  return m_nameTree;
-}
-
-inline Fib&
-Forwarder::getFib()
-{
-  return m_fib;
-}
-
-inline Pit&
-Forwarder::getPit()
-{
-  return m_pit;
-}
-
-inline Cs&
-Forwarder::getCs()
-{
-  return m_cs;
-}
-
-inline Measurements&
-Forwarder::getMeasurements()
-{
-  return m_measurements;
-}
-
-inline StrategyChoice&
-Forwarder::getStrategyChoice()
-{
-  return m_strategyChoice;
-}
-
-inline DeadNonceList&
-Forwarder::getDeadNonceList()
-{
-  return m_deadNonceList;
-}
-
-inline NetworkRegionTable&
-Forwarder::getNetworkRegionTable()
-{
-  return m_networkRegionTable;
-}
-
-#ifdef WITH_TESTS
-inline void
-Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
-#else
-template<class Function>
-inline void
-Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
-#endif
-{
-  fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
-  trigger(&strategy);
-}
-
 } // namespace nfd
 
 #endif // NFD_DAEMON_FW_FORWARDER_HPP
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 53b8935..7e668b6 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -66,7 +66,7 @@
 }
 
 void
-Strategy::sendNacks(shared_ptr<pit::Entry> pitEntry, const lp::NackHeader& header,
+Strategy::sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header,
                     std::initializer_list<const Face*> exceptFaces)
 {
   // populate downstreams with all downstreams faces
diff --git a/daemon/fw/strategy.hpp b/daemon/fw/strategy.hpp
index 4f3da2c..5cea6a6 100644
--- a/daemon/fw/strategy.hpp
+++ b/daemon/fw/strategy.hpp
@@ -50,9 +50,13 @@
   virtual
   ~Strategy();
 
-  /// a Name that represent the Strategy program
+  /** \return a Name that represents the strategy program
+   */
   const Name&
-  getName() const;
+  getName() const
+  {
+    return m_name;
+  }
 
 public: // triggers
   /** \brief trigger after Interest is received
@@ -131,8 +135,11 @@
    *                      rather than reusing a Nonce from one of the PIT in-records
    */
   VIRTUAL_WITH_TESTS void
-  sendInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
-               bool wantNewNonce = false);
+  sendInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
+               bool wantNewNonce = false)
+  {
+    m_forwarder.onOutgoingInterest(pitEntry, outFace, wantNewNonce);
+  }
 
   /** \brief decide that a pending Interest cannot be forwarded
    *  \param pitEntry PIT entry
@@ -141,7 +148,10 @@
    *  forwarded earlier, and does not need to be resent now.
    */
   VIRTUAL_WITH_TESTS void
-  rejectPendingInterest(shared_ptr<pit::Entry> pitEntry);
+  rejectPendingInterest(const shared_ptr<pit::Entry>& pitEntry)
+  {
+    m_forwarder.onInterestReject(pitEntry);
+  }
 
   /** \brief send Nack to outFace
    *  \param pitEntry PIT entry
@@ -151,8 +161,11 @@
    *  The outFace must have a PIT in-record, otherwise this method has no effect.
    */
   VIRTUAL_WITH_TESTS void
-  sendNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
-           const lp::NackHeader& header);
+  sendNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace,
+           const lp::NackHeader& header)
+  {
+    m_forwarder.onOutgoingNack(pitEntry, outFace, header);
+  }
 
   /** \brief send Nack to every face that has an in-record,
    *         except those in \p exceptFaces
@@ -162,21 +175,33 @@
    *  \note This is not an action, but a helper that invokes the sendNack action.
    */
   void
-  sendNacks(shared_ptr<pit::Entry> pitEntry, const lp::NackHeader& header,
+  sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header,
             std::initializer_list<const Face*> exceptFaces = std::initializer_list<const Face*>());
 
 protected: // accessors
   const fib::Entry&
-  lookupFib(const pit::Entry& pitEntry);
+  lookupFib(const pit::Entry& pitEntry)
+  {
+    return m_forwarder.lookupFib(pitEntry);
+  }
 
   MeasurementsAccessor&
-  getMeasurements();
+  getMeasurements()
+  {
+    return m_measurements;
+  }
 
   Face*
-  getFace(FaceId id) const;
+  getFace(FaceId id) const
+  {
+    return m_forwarder.getFace(id);
+  }
 
   const FaceTable&
-  getFaceTable() const;
+  getFaceTable() const
+  {
+    return m_forwarder.getFaceTable();
+  }
 
 protected: // accessors
   signal::Signal<FaceTable, Face&>& afterAddFace;
@@ -194,55 +219,6 @@
   MeasurementsAccessor m_measurements;
 };
 
-inline const Name&
-Strategy::getName() const
-{
-  return m_name;
-}
-
-inline void
-Strategy::sendInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace, bool wantNewNonce)
-{
-  m_forwarder.onOutgoingInterest(pitEntry, outFace, wantNewNonce);
-}
-
-inline void
-Strategy::rejectPendingInterest(shared_ptr<pit::Entry> pitEntry)
-{
-  m_forwarder.onInterestReject(pitEntry);
-}
-
-inline void
-Strategy::sendNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace,
-                   const lp::NackHeader& header)
-{
-  m_forwarder.onOutgoingNack(pitEntry, outFace, header);
-}
-
-inline const fib::Entry&
-Strategy::lookupFib(const pit::Entry& pitEntry)
-{
-  return m_forwarder.lookupFib(pitEntry);
-}
-
-inline MeasurementsAccessor&
-Strategy::getMeasurements()
-{
-  return m_measurements;
-}
-
-inline Face*
-Strategy::getFace(FaceId id) const
-{
-  return m_forwarder.getFace(id);
-}
-
-inline const FaceTable&
-Strategy::getFaceTable() const
-{
-  return m_forwarder.getFaceTable();
-}
-
 } // namespace fw
 } // namespace nfd