blob: 2108435f9eb5fa64df62ae898b139eed23ebfdbb [file] [log] [blame]
Junxiao Shidbe71732014-02-21 22:23:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shiee5a4442014-07-27 17:13:43 -07003 * 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 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shiee5a4442014-07-27 17:13:43 -070024 */
Junxiao Shidbe71732014-02-21 22:23:28 -070025
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP
27#define NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP
Junxiao Shidbe71732014-02-21 22:23:28 -070028
29#include "measurements.hpp"
Junxiao Shi7bb01512014-03-05 21:34:09 -070030#include "strategy-choice.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070031
32namespace nfd {
33
34namespace fw {
35class Strategy;
36}
37
38/** \brief allows Strategy to access portion of Measurements table under its namespace
39 */
40class MeasurementsAccessor : noncopyable
41{
42public:
Junxiao Shi7bb01512014-03-05 21:34:09 -070043 MeasurementsAccessor(Measurements& measurements, StrategyChoice& strategyChoice,
44 fw::Strategy* strategy);
Junxiao Shidbe71732014-02-21 22:23:28 -070045
46 ~MeasurementsAccessor();
47
48 /// find or insert a Measurements entry for name
49 shared_ptr<measurements::Entry>
50 get(const Name& name);
51
52 /// find or insert a Measurements entry for fibEntry->getPrefix()
53 shared_ptr<measurements::Entry>
54 get(const fib::Entry& fibEntry);
55
56 /// find or insert a Measurements entry for pitEntry->getName()
57 shared_ptr<measurements::Entry>
58 get(const pit::Entry& pitEntry);
59
60 /** \brief find or insert a Measurements entry for child's parent
61 *
62 * If child is the root entry, returns null.
63 */
64 shared_ptr<measurements::Entry>
65 getParent(shared_ptr<measurements::Entry> child);
66
Junxiao Shidbe71732014-02-21 22:23:28 -070067 /** \brief extend lifetime of an entry
68 *
69 * The entry will be kept until at least now()+lifetime.
70 */
71 void
Junxiao Shiee5a4442014-07-27 17:13:43 -070072 extendLifetime(shared_ptr<measurements::Entry> entry, const time::nanoseconds& lifetime);
Junxiao Shidbe71732014-02-21 22:23:28 -070073
74private:
75 /** \brief perform access control to Measurements entry
76 *
77 * \return entry if strategy has access to namespace, otherwise 0
78 */
79 shared_ptr<measurements::Entry>
80 filter(const shared_ptr<measurements::Entry>& entry);
81
82private:
83 Measurements& m_measurements;
Junxiao Shi7bb01512014-03-05 21:34:09 -070084 StrategyChoice& m_strategyChoice;
Junxiao Shidbe71732014-02-21 22:23:28 -070085 fw::Strategy* m_strategy;
86};
87
88inline shared_ptr<measurements::Entry>
89MeasurementsAccessor::get(const Name& name)
90{
91 return this->filter(m_measurements.get(name));
92}
93
94inline shared_ptr<measurements::Entry>
95MeasurementsAccessor::get(const fib::Entry& fibEntry)
96{
Junxiao Shi7bb01512014-03-05 21:34:09 -070097 return this->filter(m_measurements.get(fibEntry));
Junxiao Shidbe71732014-02-21 22:23:28 -070098}
99
100inline shared_ptr<measurements::Entry>
101MeasurementsAccessor::get(const pit::Entry& pitEntry)
102{
103 return this->filter(m_measurements.get(pitEntry));
104}
105
106inline shared_ptr<measurements::Entry>
107MeasurementsAccessor::getParent(shared_ptr<measurements::Entry> child)
108{
109 return this->filter(m_measurements.getParent(child));
110}
111
Junxiao Shidbe71732014-02-21 22:23:28 -0700112inline void
Junxiao Shiee5a4442014-07-27 17:13:43 -0700113MeasurementsAccessor::extendLifetime(shared_ptr<measurements::Entry> entry,
114 const time::nanoseconds& lifetime)
Junxiao Shidbe71732014-02-21 22:23:28 -0700115{
116 m_measurements.extendLifetime(entry, lifetime);
117}
118
119} // namespace nfd
120
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700121#endif // NFD_DAEMON_TABLE_MEASUREMENTS_ACCESSOR_HPP