Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -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_HPP |
| 8 | #define NFD_TABLE_MEASUREMENTS_HPP |
| 9 | |
| 10 | #include "measurements-entry.hpp" |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 11 | #include "fib-entry.hpp" |
| 12 | #include "pit-entry.hpp" |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 13 | #include "core/time.hpp" |
| 14 | |
| 15 | namespace nfd { |
| 16 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 17 | /** \class Measurement |
| 18 | * \brief represents the Measurements table |
| 19 | */ |
| 20 | class Measurements : noncopyable |
| 21 | { |
| 22 | public: |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 23 | Measurements(); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 24 | |
| 25 | ~Measurements(); |
| 26 | |
| 27 | /// find or insert a Measurements entry for name |
| 28 | shared_ptr<measurements::Entry> |
| 29 | get(const Name& name); |
| 30 | |
| 31 | /// find or insert a Measurements entry for fibEntry->getPrefix() |
| 32 | shared_ptr<measurements::Entry> |
| 33 | get(const fib::Entry& fibEntry); |
| 34 | |
| 35 | /// find or insert a Measurements entry for pitEntry->getName() |
| 36 | shared_ptr<measurements::Entry> |
| 37 | get(const pit::Entry& pitEntry); |
| 38 | |
| 39 | /** \brief find or insert a Measurements entry for child's parent |
| 40 | * |
| 41 | * If child is the root entry, returns null. |
| 42 | */ |
| 43 | shared_ptr<measurements::Entry> |
| 44 | getParent(shared_ptr<measurements::Entry> child); |
| 45 | |
| 46 | // /// perform a longest prefix match |
| 47 | // shared_ptr<fib::Entry> |
| 48 | // findLongestPrefixMatch(const Name& name) const; |
| 49 | // |
| 50 | // /// perform an exact match |
| 51 | // shared_ptr<fib::Entry> |
| 52 | // findExactMatch(const Name& name) const; |
| 53 | |
| 54 | /** \brief extend lifetime of an entry |
| 55 | * |
| 56 | * The entry will be kept until at least now()+lifetime. |
| 57 | */ |
| 58 | void |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 59 | extendLifetime(measurements::Entry& entry, const time::Duration& lifetime); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | void |
| 63 | extendLifetimeInternal( |
| 64 | std::map<Name, shared_ptr<measurements::Entry> >::iterator it, |
Junxiao Shi | dbe7173 | 2014-02-21 22:23:28 -0700 | [diff] [blame] | 65 | const time::Duration& lifetime); |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 66 | |
| 67 | void |
| 68 | cleanup(std::map<Name, shared_ptr<measurements::Entry> >::iterator it); |
| 69 | |
| 70 | private: |
| 71 | std::map<Name, shared_ptr<measurements::Entry> > m_table; |
| 72 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 73 | static const time::Duration s_defaultLifetime; |
| 74 | }; |
| 75 | |
| 76 | } // namespace nfd |
| 77 | |
| 78 | #endif // NFD_TABLE_MEASUREMENTS_HPP |