Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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 | |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 79 | /** \return the absolute time when the stored Data becomes expired |
| 80 | * \retval time::steady_clock::TimePoint::max() if the stored Data never expires |
| 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 | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 97 | * \note ChildSelector is not considered |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 98 | * \pre hasData() |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 99 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 100 | bool |
| 101 | canSatisfy(const Interest& interest) const; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 102 | |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 103 | public: // used by generic ContentStore implementation |
| 104 | /** \return true if a Data packet is stored |
| 105 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 106 | bool |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 107 | hasData() const |
| 108 | { |
| 109 | return m_data != nullptr; |
| 110 | } |
| 111 | |
| 112 | /** \brief replaces the stored Data |
| 113 | */ |
| 114 | void |
| 115 | setData(shared_ptr<const Data> data, bool isUnsolicited); |
| 116 | |
| 117 | /** \brief replaces the stored Data |
| 118 | */ |
| 119 | void |
| 120 | setData(const Data& data, bool isUnsolicited) |
| 121 | { |
| 122 | this->setData(data.shared_from_this(), isUnsolicited); |
| 123 | } |
| 124 | |
| 125 | /** \brief refreshes stale time relative to current time |
| 126 | */ |
| 127 | void |
| 128 | updateStaleTime(); |
| 129 | |
| 130 | /** \brief clears the entry |
| 131 | * \post !hasData() |
| 132 | */ |
| 133 | void |
| 134 | reset(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 135 | |
| 136 | private: |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 137 | shared_ptr<const Data> m_data; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 138 | bool m_isUnsolicited; |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 139 | time::steady_clock::TimePoint m_staleTime; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 142 | } // namespace cs |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 143 | } // namespace nfd |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 144 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 145 | #endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP |