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