table: MeasurementsAccessor uses StrategyChoice

This commit also deletes fib::Entry::set/getStrategy attribute.

refs #1276

Change-Id: I57dfe842a8024e0ad9908ba8a9c415d5f4ac1bbe
diff --git a/daemon/table/fib-entry.cpp b/daemon/table/fib-entry.cpp
index 733782b..6a9b686 100644
--- a/daemon/table/fib-entry.cpp
+++ b/daemon/table/fib-entry.cpp
@@ -38,9 +38,9 @@
     it = m_nextHops.end() - 1;
   }
   // now it refers to the NextHop for face
-  
+
   it->setCost(cost);
-  
+
   this->sortNextHops();
 
 }
@@ -53,7 +53,7 @@
   if (it == m_nextHops.end()) {
     return;
   }
-  
+
   m_nextHops.erase(it);
 }
 
@@ -69,12 +69,6 @@
   std::sort(m_nextHops.begin(), m_nextHops.end(), &compare_NextHop_cost);
 }
 
-void
-Entry::setStrategy(shared_ptr<fw::Strategy> strategy)
-{
-  m_strategy = strategy;
-}
-
 
 } // namespace fib
 } // namespace nfd
diff --git a/daemon/table/fib-entry.hpp b/daemon/table/fib-entry.hpp
index f5c0fae..aac8fc5 100644
--- a/daemon/table/fib-entry.hpp
+++ b/daemon/table/fib-entry.hpp
@@ -11,10 +11,6 @@
 
 namespace nfd {
 
-namespace fw {
-class Strategy;
-}
-
 namespace fib {
 
 /** \class NextHopList
@@ -34,29 +30,23 @@
 public:
   explicit
   Entry(const Name& prefix);
-  
+
   const Name&
   getPrefix() const;
-  
+
   const NextHopList&
   getNextHops() const;
-  
+
   bool
   hasNextHop(shared_ptr<Face> face) const;
-  
+
   /// adds a nexthop
   void
   addNextHop(shared_ptr<Face> face, int32_t cost);
-  
+
   /// removes a nexthop
   void
   removeNextHop(shared_ptr<Face> face);
-  
-  const fw::Strategy&
-  getStrategy() const;
-  
-  void
-  setStrategy(shared_ptr<fw::Strategy> strategy);
 
 private:
   /// sorts the nexthop list
@@ -66,7 +56,6 @@
 private:
   Name m_prefix;
   NextHopList m_nextHops;
-  shared_ptr<fw::Strategy> m_strategy;
 };
 
 
@@ -82,13 +71,6 @@
   return m_nextHops;
 }
 
-inline const fw::Strategy&
-Entry::getStrategy() const
-{
-  BOOST_ASSERT(static_cast<bool>(m_strategy));
-  return *m_strategy;
-}
-
 } // namespace fib
 } // namespace nfd
 
diff --git a/daemon/table/measurements-accessor.cpp b/daemon/table/measurements-accessor.cpp
index 97a913b..d1f08de 100644
--- a/daemon/table/measurements-accessor.cpp
+++ b/daemon/table/measurements-accessor.cpp
@@ -5,14 +5,16 @@
  */
 
 #include "measurements-accessor.hpp"
-#include "fw/strategy.hpp"
 
 namespace nfd {
 
+using fw::Strategy;
+
 MeasurementsAccessor::MeasurementsAccessor(Measurements& measurements,
-                                           Fib& fib, fw::Strategy* strategy)
+                                           StrategyChoice& strategyChoice,
+                                           Strategy* strategy)
   : m_measurements(measurements)
-  , m_fib(fib)
+  , m_strategyChoice(strategyChoice)
   , m_strategy(strategy)
 {
 }
@@ -28,9 +30,8 @@
     return entry;
   }
 
-  shared_ptr<fib::Entry> fibEntry = m_fib.findLongestPrefixMatch(*entry);
-  BOOST_ASSERT(static_cast<bool>(fibEntry));
-  if (&fibEntry->getStrategy() == m_strategy) {
+  Strategy& effectiveStrategy = m_strategyChoice.findEffectiveStrategy(*entry);
+  if (&effectiveStrategy == m_strategy) {
     return entry;
   }
   return shared_ptr<measurements::Entry>();
diff --git a/daemon/table/measurements-accessor.hpp b/daemon/table/measurements-accessor.hpp
index 26a6d38..53b30d4 100644
--- a/daemon/table/measurements-accessor.hpp
+++ b/daemon/table/measurements-accessor.hpp
@@ -8,7 +8,7 @@
 #define NFD_TABLE_MEASUREMENTS_ACCESSOR_HPP
 
 #include "measurements.hpp"
-#include "fib.hpp"
+#include "strategy-choice.hpp"
 
 namespace nfd {
 
@@ -21,7 +21,8 @@
 class MeasurementsAccessor : noncopyable
 {
 public:
-  MeasurementsAccessor(Measurements& measurements, Fib& fib, fw::Strategy* strategy);
+  MeasurementsAccessor(Measurements& measurements, StrategyChoice& strategyChoice,
+                       fw::Strategy* strategy);
 
   ~MeasurementsAccessor();
 
@@ -44,14 +45,6 @@
   shared_ptr<measurements::Entry>
   getParent(shared_ptr<measurements::Entry> child);
 
-//  /// perform a longest prefix match
-//  shared_ptr<fib::Entry>
-//  findLongestPrefixMatch(const Name& name) const;
-//
-//  /// perform an exact match
-//  shared_ptr<fib::Entry>
-//  findExactMatch(const Name& name) const;
-
   /** \brief extend lifetime of an entry
    *
    *  The entry will be kept until at least now()+lifetime.
@@ -69,7 +62,7 @@
 
 private:
   Measurements& m_measurements;
-  Fib& m_fib;
+  StrategyChoice& m_strategyChoice;
   fw::Strategy* m_strategy;
 };
 
@@ -82,10 +75,7 @@
 inline shared_ptr<measurements::Entry>
 MeasurementsAccessor::get(const fib::Entry& fibEntry)
 {
-  if (&fibEntry.getStrategy() == m_strategy) {
-    return m_measurements.get(fibEntry);
-  }
-  return shared_ptr<measurements::Entry>();
+  return this->filter(m_measurements.get(fibEntry));
 }
 
 inline shared_ptr<measurements::Entry>
@@ -100,18 +90,6 @@
   return this->filter(m_measurements.getParent(child));
 }
 
-//inline shared_ptr<fib::Entry>
-//MeasurementsAccessor::findLongestPrefixMatch(const Name& name) const
-//{
-//  return this->filter(m_measurements.findLongestPrefixMatch(name));
-//}
-//
-//inline shared_ptr<fib::Entry>
-//MeasurementsAccessor::findExactMatch(const Name& name) const
-//{
-//  return this->filter(m_measurements.findExactMatch(name));
-//}
-
 inline void
 MeasurementsAccessor::extendLifetime(measurements::Entry& entry, const time::Duration& lifetime)
 {
diff --git a/daemon/table/strategy-choice.cpp b/daemon/table/strategy-choice.cpp
index 9e5cb37..c24a5b0 100644
--- a/daemon/table/strategy-choice.cpp
+++ b/daemon/table/strategy-choice.cpp
@@ -7,6 +7,7 @@
 #include "strategy-choice.hpp"
 #include "fw/strategy.hpp"
 #include "pit-entry.hpp"
+#include "measurements-entry.hpp"
 
 namespace nfd {
 
@@ -137,6 +138,12 @@
   return this->findEffectiveStrategy(pitEntry.getName());
 }
 
+Strategy&
+StrategyChoice::findEffectiveStrategy(const measurements::Entry& measurementsEntry) const
+{
+  return this->findEffectiveStrategy(measurementsEntry.getName());
+}
+
 shared_ptr<fw::Strategy>
 StrategyChoice::getStrategy(const Name& strategyName)
 {
diff --git a/daemon/table/strategy-choice.hpp b/daemon/table/strategy-choice.hpp
index 7624dd4..9d45f15 100644
--- a/daemon/table/strategy-choice.hpp
+++ b/daemon/table/strategy-choice.hpp
@@ -59,6 +59,10 @@
   fw::Strategy&
   findEffectiveStrategy(const pit::Entry& pitEntry) const;
 
+  /// get effective strategy for measurementsEntry
+  fw::Strategy&
+  findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
+
   /// number of entries stored
   size_t
   size() const;