Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 14b3918 | 2019-04-29 19:19:18 +0000 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 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 | * The University of Memphis. |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP |
| 27 | #define NFD_DAEMON_TABLE_CS_ENTRY_HPP |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 28 | |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 29 | #include "core/common.hpp" |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 31 | namespace nfd { |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 32 | namespace cs { |
| 33 | |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 34 | /** \brief represents a base class for CS entry |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 35 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 36 | class Entry |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 37 | { |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 38 | public: // exposed through ContentStore enumeration |
| 39 | /** \return the stored Data |
| 40 | * \pre hasData() |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 41 | */ |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 42 | const Data& |
| 43 | getData() const |
| 44 | { |
| 45 | BOOST_ASSERT(this->hasData()); |
| 46 | return *m_data; |
| 47 | } |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 48 | |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 49 | /** \return Name of the stored Data |
| 50 | * \pre hasData() |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 51 | */ |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 52 | const Name& |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 53 | getName() const |
| 54 | { |
| 55 | BOOST_ASSERT(this->hasData()); |
| 56 | return m_data->getName(); |
| 57 | } |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 58 | |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 59 | /** \return full name (including implicit digest) of the stored Data |
| 60 | * \pre hasData() |
| 61 | */ |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 62 | const Name& |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 63 | getFullName() const |
| 64 | { |
| 65 | BOOST_ASSERT(this->hasData()); |
| 66 | return m_data->getFullName(); |
| 67 | } |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 68 | |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 69 | /** \return whether the stored Data is unsolicited |
| 70 | * \pre hasData() |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 71 | */ |
| 72 | bool |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 73 | isUnsolicited() const |
| 74 | { |
| 75 | BOOST_ASSERT(this->hasData()); |
| 76 | return m_isUnsolicited; |
| 77 | } |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 78 | |
Eric Newberry | f4056d0 | 2017-05-26 17:31:53 +0000 | [diff] [blame] | 79 | /** \return the absolute time when the stored Data becomes stale |
| 80 | * \note if the returned TimePoint is in the past, the Data is stale |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 81 | * \pre hasData() |
| 82 | */ |
| 83 | const time::steady_clock::TimePoint& |
| 84 | getStaleTime() const |
| 85 | { |
| 86 | BOOST_ASSERT(this->hasData()); |
| 87 | return m_staleTime; |
| 88 | } |
| 89 | |
| 90 | /** \brief checks if the stored Data is stale now |
| 91 | * \pre hasData() |
| 92 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 93 | bool |
| 94 | isStale() const; |
| 95 | |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 96 | /** \brief determines whether Interest can be satisified by the stored Data |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 97 | * \pre hasData() |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 98 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 99 | bool |
| 100 | canSatisfy(const Interest& interest) const; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 101 | |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 102 | public: // used by generic ContentStore implementation |
| 103 | /** \return true if a Data packet is stored |
| 104 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 105 | bool |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 106 | hasData() const |
| 107 | { |
| 108 | return m_data != nullptr; |
| 109 | } |
| 110 | |
| 111 | /** \brief replaces the stored Data |
| 112 | */ |
| 113 | void |
| 114 | setData(shared_ptr<const Data> data, bool isUnsolicited); |
| 115 | |
| 116 | /** \brief replaces the stored Data |
| 117 | */ |
| 118 | void |
| 119 | setData(const Data& data, bool isUnsolicited) |
| 120 | { |
| 121 | this->setData(data.shared_from_this(), isUnsolicited); |
| 122 | } |
| 123 | |
| 124 | /** \brief refreshes stale time relative to current time |
| 125 | */ |
| 126 | void |
| 127 | updateStaleTime(); |
| 128 | |
| 129 | /** \brief clears the entry |
| 130 | * \post !hasData() |
| 131 | */ |
| 132 | void |
| 133 | reset(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 134 | |
| 135 | private: |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 136 | shared_ptr<const Data> m_data; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 137 | bool m_isUnsolicited; |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 138 | time::steady_clock::TimePoint m_staleTime; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 141 | } // namespace cs |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 142 | } // namespace nfd |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 143 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 144 | #endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP |