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