blob: 53b30d44d1f539c9c657f352373767b49eddd77e [file] [log] [blame]
Junxiao Shidbe71732014-02-21 22:23:28 -07001/* -*- 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 Shi7bb01512014-03-05 21:34:09 -070011#include "strategy-choice.hpp"
Junxiao Shidbe71732014-02-21 22:23:28 -070012
13namespace nfd {
14
15namespace fw {
16class Strategy;
17}
18
19/** \brief allows Strategy to access portion of Measurements table under its namespace
20 */
21class MeasurementsAccessor : noncopyable
22{
23public:
Junxiao Shi7bb01512014-03-05 21:34:09 -070024 MeasurementsAccessor(Measurements& measurements, StrategyChoice& strategyChoice,
25 fw::Strategy* strategy);
Junxiao Shidbe71732014-02-21 22:23:28 -070026
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 Shidbe71732014-02-21 22:23:28 -070048 /** \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
55private:
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
63private:
64 Measurements& m_measurements;
Junxiao Shi7bb01512014-03-05 21:34:09 -070065 StrategyChoice& m_strategyChoice;
Junxiao Shidbe71732014-02-21 22:23:28 -070066 fw::Strategy* m_strategy;
67};
68
69inline shared_ptr<measurements::Entry>
70MeasurementsAccessor::get(const Name& name)
71{
72 return this->filter(m_measurements.get(name));
73}
74
75inline shared_ptr<measurements::Entry>
76MeasurementsAccessor::get(const fib::Entry& fibEntry)
77{
Junxiao Shi7bb01512014-03-05 21:34:09 -070078 return this->filter(m_measurements.get(fibEntry));
Junxiao Shidbe71732014-02-21 22:23:28 -070079}
80
81inline shared_ptr<measurements::Entry>
82MeasurementsAccessor::get(const pit::Entry& pitEntry)
83{
84 return this->filter(m_measurements.get(pitEntry));
85}
86
87inline shared_ptr<measurements::Entry>
88MeasurementsAccessor::getParent(shared_ptr<measurements::Entry> child)
89{
90 return this->filter(m_measurements.getParent(child));
91}
92
Junxiao Shidbe71732014-02-21 22:23:28 -070093inline void
94MeasurementsAccessor::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