Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_TABLE_MEASUREMENTS_ACCESSOR_HPP |
| 8 | #define NFD_TABLE_MEASUREMENTS_ACCESSOR_HPP |
| 9 | |
| 10 | #include "measurements.hpp" |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame^] | 11 | #include "strategy-choice.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 12 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | namespace fw { |
| 16 | class Strategy; |
| 17 | } |
| 18 | |
| 19 | /** \brief allows Strategy to access portion of Measurements table under its namespace |
| 20 | */ |
| 21 | class MeasurementsAccessor : noncopyable |
| 22 | { |
| 23 | public: |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame^] | 24 | MeasurementsAccessor(Measurements& measurements, StrategyChoice& strategyChoice, |
| 25 | fw::Strategy* strategy); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 26 | |
| 27 | ~MeasurementsAccessor(); |
| 28 | |
| 29 | /// find or insert a Measurements entry for name |
| 30 | shared_ptr<measurements::Entry> |
| 31 | get(const Name& name); |
| 32 | |
| 33 | /// find or insert a Measurements entry for fibEntry->getPrefix() |
| 34 | shared_ptr<measurements::Entry> |
| 35 | get(const fib::Entry& fibEntry); |
| 36 | |
| 37 | /// find or insert a Measurements entry for pitEntry->getName() |
| 38 | shared_ptr<measurements::Entry> |
| 39 | get(const pit::Entry& pitEntry); |
| 40 | |
| 41 | /** \brief find or insert a Measurements entry for child's parent |
| 42 | * |
| 43 | * If child is the root entry, returns null. |
| 44 | */ |
| 45 | shared_ptr<measurements::Entry> |
| 46 | getParent(shared_ptr<measurements::Entry> child); |
| 47 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 48 | /** \brief extend lifetime of an entry |
| 49 | * |
| 50 | * The entry will be kept until at least now()+lifetime. |
| 51 | */ |
| 52 | void |
| 53 | extendLifetime(measurements::Entry& entry, const time::Duration& lifetime); |
| 54 | |
| 55 | private: |
| 56 | /** \brief perform access control to Measurements entry |
| 57 | * |
| 58 | * \return entry if strategy has access to namespace, otherwise 0 |
| 59 | */ |
| 60 | shared_ptr<measurements::Entry> |
| 61 | filter(const shared_ptr<measurements::Entry>& entry); |
| 62 | |
| 63 | private: |
| 64 | Measurements& m_measurements; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame^] | 65 | StrategyChoice& m_strategyChoice; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 66 | fw::Strategy* m_strategy; |
| 67 | }; |
| 68 | |
| 69 | inline shared_ptr<measurements::Entry> |
| 70 | MeasurementsAccessor::get(const Name& name) |
| 71 | { |
| 72 | return this->filter(m_measurements.get(name)); |
| 73 | } |
| 74 | |
| 75 | inline shared_ptr<measurements::Entry> |
| 76 | MeasurementsAccessor::get(const fib::Entry& fibEntry) |
| 77 | { |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame^] | 78 | return this->filter(m_measurements.get(fibEntry)); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | inline shared_ptr<measurements::Entry> |
| 82 | MeasurementsAccessor::get(const pit::Entry& pitEntry) |
| 83 | { |
| 84 | return this->filter(m_measurements.get(pitEntry)); |
| 85 | } |
| 86 | |
| 87 | inline shared_ptr<measurements::Entry> |
| 88 | MeasurementsAccessor::getParent(shared_ptr<measurements::Entry> child) |
| 89 | { |
| 90 | return this->filter(m_measurements.getParent(child)); |
| 91 | } |
| 92 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 93 | inline void |
| 94 | MeasurementsAccessor::extendLifetime(measurements::Entry& entry, const time::Duration& lifetime) |
| 95 | { |
| 96 | m_measurements.extendLifetime(entry, lifetime); |
| 97 | } |
| 98 | |
| 99 | } // namespace nfd |
| 100 | |
| 101 | #endif // NFD_TABLE_MEASUREMENTS_ACCESSOR_HPP |