Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology |
| 9 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame^] | 25 | #ifndef NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP |
| 26 | #define NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 27 | |
| 28 | #include "measurements.hpp" |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 29 | #include "strategy-choice.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
| 32 | |
| 33 | namespace fw { |
| 34 | class Strategy; |
| 35 | } |
| 36 | |
| 37 | /** \brief allows Strategy to access portion of Measurements table under its namespace |
| 38 | */ |
| 39 | class MeasurementsAccessor : noncopyable |
| 40 | { |
| 41 | public: |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 42 | MeasurementsAccessor(Measurements& measurements, StrategyChoice& strategyChoice, |
| 43 | fw::Strategy* strategy); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 44 | |
| 45 | ~MeasurementsAccessor(); |
| 46 | |
| 47 | /// find or insert a Measurements entry for name |
| 48 | shared_ptr<measurements::Entry> |
| 49 | get(const Name& name); |
| 50 | |
| 51 | /// find or insert a Measurements entry for fibEntry->getPrefix() |
| 52 | shared_ptr<measurements::Entry> |
| 53 | get(const fib::Entry& fibEntry); |
| 54 | |
| 55 | /// find or insert a Measurements entry for pitEntry->getName() |
| 56 | shared_ptr<measurements::Entry> |
| 57 | get(const pit::Entry& pitEntry); |
| 58 | |
| 59 | /** \brief find or insert a Measurements entry for child's parent |
| 60 | * |
| 61 | * If child is the root entry, returns null. |
| 62 | */ |
| 63 | shared_ptr<measurements::Entry> |
| 64 | getParent(shared_ptr<measurements::Entry> child); |
| 65 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 66 | /** \brief extend lifetime of an entry |
| 67 | * |
| 68 | * The entry will be kept until at least now()+lifetime. |
| 69 | */ |
| 70 | void |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 71 | extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | /** \brief perform access control to Measurements entry |
| 75 | * |
| 76 | * \return entry if strategy has access to namespace, otherwise 0 |
| 77 | */ |
| 78 | shared_ptr<measurements::Entry> |
| 79 | filter(const shared_ptr<measurements::Entry>& entry); |
| 80 | |
| 81 | private: |
| 82 | Measurements& m_measurements; |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 83 | StrategyChoice& m_strategyChoice; |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 84 | fw::Strategy* m_strategy; |
| 85 | }; |
| 86 | |
| 87 | inline shared_ptr<measurements::Entry> |
| 88 | MeasurementsAccessor::get(const Name& name) |
| 89 | { |
| 90 | return this->filter(m_measurements.get(name)); |
| 91 | } |
| 92 | |
| 93 | inline shared_ptr<measurements::Entry> |
| 94 | MeasurementsAccessor::get(const fib::Entry& fibEntry) |
| 95 | { |
Junxiao Shi | 7bb0151 | 2014-03-05 21:34:09 -0700 | [diff] [blame] | 96 | return this->filter(m_measurements.get(fibEntry)); |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | inline shared_ptr<measurements::Entry> |
| 100 | MeasurementsAccessor::get(const pit::Entry& pitEntry) |
| 101 | { |
| 102 | return this->filter(m_measurements.get(pitEntry)); |
| 103 | } |
| 104 | |
| 105 | inline shared_ptr<measurements::Entry> |
| 106 | MeasurementsAccessor::getParent(shared_ptr<measurements::Entry> child) |
| 107 | { |
| 108 | return this->filter(m_measurements.getParent(child)); |
| 109 | } |
| 110 | |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 111 | inline void |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 112 | MeasurementsAccessor::extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime) |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 113 | { |
| 114 | m_measurements.extendLifetime(entry, lifetime); |
| 115 | } |
| 116 | |
| 117 | } // namespace nfd |
| 118 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame^] | 119 | #endif // NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP |