blob: c7bfb333b5729dabd0deb2d6dccbe48d021dbc8d [file] [log] [blame]
Junxiao Shidbe71732014-02-21 22:23:28 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -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 *
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 Shidbe71732014-02-21 22:23:28 -070024
25#ifndef NFD_TABLE_MEASUREMENTS_ACCESSOR_HPP
26#define NFD_TABLE_MEASUREMENTS_ACCESSOR_HPP
27
28#include "measurements.hpp"
Junxiao Shi7bb01512014-03-05 21:34:09 -070029#include "strategy-choice.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070030
31namespace nfd {
32
33namespace fw {
34class Strategy;
35}
36
37/** \brief allows Strategy to access portion of Measurements table under its namespace
38 */
39class MeasurementsAccessor : noncopyable
40{
41public:
Junxiao Shi7bb01512014-03-05 21:34:09 -070042 MeasurementsAccessor(Measurements& measurements, StrategyChoice& strategyChoice,
43 fw::Strategy* strategy);
Junxiao Shidbe71732014-02-21 22:23:28 -070044
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 Shidbe71732014-02-21 22:23:28 -070066 /** \brief extend lifetime of an entry
67 *
68 * The entry will be kept until at least now()+lifetime.
69 */
70 void
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070071 extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime);
Junxiao Shidbe71732014-02-21 22:23:28 -070072
73private:
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
81private:
82 Measurements& m_measurements;
Junxiao Shi7bb01512014-03-05 21:34:09 -070083 StrategyChoice& m_strategyChoice;
Junxiao Shidbe71732014-02-21 22:23:28 -070084 fw::Strategy* m_strategy;
85};
86
87inline shared_ptr<measurements::Entry>
88MeasurementsAccessor::get(const Name& name)
89{
90 return this->filter(m_measurements.get(name));
91}
92
93inline shared_ptr<measurements::Entry>
94MeasurementsAccessor::get(const fib::Entry& fibEntry)
95{
Junxiao Shi7bb01512014-03-05 21:34:09 -070096 return this->filter(m_measurements.get(fibEntry));
Junxiao Shidbe71732014-02-21 22:23:28 -070097}
98
99inline shared_ptr<measurements::Entry>
100MeasurementsAccessor::get(const pit::Entry& pitEntry)
101{
102 return this->filter(m_measurements.get(pitEntry));
103}
104
105inline shared_ptr<measurements::Entry>
106MeasurementsAccessor::getParent(shared_ptr<measurements::Entry> child)
107{
108 return this->filter(m_measurements.getParent(child));
109}
110
Junxiao Shidbe71732014-02-21 22:23:28 -0700111inline void
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700112MeasurementsAccessor::extendLifetime(measurements::Entry& entry, const time::nanoseconds& lifetime)
Junxiao Shidbe71732014-02-21 22:23:28 -0700113{
114 m_measurements.extendLifetime(entry, lifetime);
115}
116
117} // namespace nfd
118
119#endif // NFD_TABLE_MEASUREMENTS_ACCESSOR_HPP