Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame^] | 22 | #ifndef NDN_IMS_IN_MEMORY_STORAGE_ENTRY_HPP |
| 23 | #define NDN_IMS_IN_MEMORY_STORAGE_ENTRY_HPP |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 24 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 25 | #include "../data.hpp" |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame^] | 26 | #include "../interest.hpp" |
| 27 | #include "../util/scheduler-scoped-event-id.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 30 | |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame^] | 31 | /** @brief Represents an in-memory storage entry |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 32 | */ |
| 33 | class InMemoryStorageEntry : noncopyable |
| 34 | { |
| 35 | public: |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame] | 36 | /** @brief Create an entry |
| 37 | */ |
| 38 | InMemoryStorageEntry(); |
| 39 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 40 | /** @brief Releases reference counts on shared objects |
| 41 | */ |
| 42 | void |
| 43 | release(); |
| 44 | |
| 45 | /** @brief Returns the name of the Data packet stored in the in-memory storage entry |
| 46 | */ |
| 47 | const Name& |
| 48 | getName() const |
| 49 | { |
| 50 | return m_dataPacket->getName(); |
| 51 | } |
| 52 | |
| 53 | /** @brief Returns the full name (including implicit digest) of the Data packet stored |
| 54 | * in the in-memory storage entry |
| 55 | */ |
| 56 | const Name& |
| 57 | getFullName() const |
| 58 | { |
| 59 | return m_dataPacket->getFullName(); |
| 60 | } |
| 61 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 62 | /** @brief Returns the Data packet stored in the in-memory storage entry |
| 63 | */ |
| 64 | const Data& |
| 65 | getData() const |
| 66 | { |
| 67 | return *m_dataPacket; |
| 68 | } |
| 69 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 70 | /** @brief Changes the content of in-memory storage entry |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame] | 71 | * |
| 72 | * This method also allows data to satisfy Interest with MustBeFresh |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 73 | */ |
| 74 | void |
| 75 | setData(const Data& data); |
| 76 | |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame] | 77 | /** @brief Set eventId for the markStale event. |
| 78 | */ |
| 79 | void |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame^] | 80 | setMarkStaleEventId(unique_ptr<util::scheduler::ScopedEventId> eventId); |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame] | 81 | |
| 82 | /** @brief Disable the data from satisfying interest with MustBeFresh |
| 83 | */ |
| 84 | void |
| 85 | markStale(); |
| 86 | |
| 87 | /** @brief Check if the data can satisfy an interest with MustBeFresh |
| 88 | */ |
| 89 | bool |
| 90 | isFresh() |
| 91 | { |
| 92 | return m_isFresh; |
| 93 | } |
| 94 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 95 | private: |
| 96 | shared_ptr<const Data> m_dataPacket; |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame] | 97 | |
| 98 | bool m_isFresh; |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame^] | 99 | unique_ptr<util::scheduler::ScopedEventId> m_markStaleEventId; |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 102 | } // namespace ndn |
| 103 | |
Junxiao Shi | c542f63 | 2017-07-18 14:20:32 +0000 | [diff] [blame^] | 104 | #endif // NDN_IMS_IN_MEMORY_STORAGE_ENTRY_HPP |