Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2016 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 | |
| 22 | #ifndef NDN_UTIL_IN_MEMORY_STORAGE_ENTRY_HPP |
| 23 | #define NDN_UTIL_IN_MEMORY_STORAGE_ENTRY_HPP |
| 24 | |
| 25 | #include "../common.hpp" |
| 26 | #include "../interest.hpp" |
| 27 | #include "../data.hpp" |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame^] | 28 | #include "scheduler-scoped-event-id.hpp" |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace util { |
| 32 | |
| 33 | /** @brief Represents an in-memory storage entry |
| 34 | */ |
| 35 | class InMemoryStorageEntry : noncopyable |
| 36 | { |
| 37 | public: |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame^] | 38 | |
| 39 | /** @brief Create an entry |
| 40 | */ |
| 41 | InMemoryStorageEntry(); |
| 42 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 43 | /** @brief Releases reference counts on shared objects |
| 44 | */ |
| 45 | void |
| 46 | release(); |
| 47 | |
| 48 | /** @brief Returns the name of the Data packet stored in the in-memory storage entry |
| 49 | */ |
| 50 | const Name& |
| 51 | getName() const |
| 52 | { |
| 53 | return m_dataPacket->getName(); |
| 54 | } |
| 55 | |
| 56 | /** @brief Returns the full name (including implicit digest) of the Data packet stored |
| 57 | * in the in-memory storage entry |
| 58 | */ |
| 59 | const Name& |
| 60 | getFullName() const |
| 61 | { |
| 62 | return m_dataPacket->getFullName(); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | /** @brief Returns the Data packet stored in the in-memory storage entry |
| 67 | */ |
| 68 | const Data& |
| 69 | getData() const |
| 70 | { |
| 71 | return *m_dataPacket; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /** @brief Changes the content of in-memory storage entry |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame^] | 76 | * |
| 77 | * This method also allows data to satisfy Interest with MustBeFresh |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 78 | */ |
| 79 | void |
| 80 | setData(const Data& data); |
| 81 | |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame^] | 82 | /** @brief Set eventId for the markStale event. |
| 83 | */ |
| 84 | void |
| 85 | setMarkStaleEventId(unique_ptr<scheduler::ScopedEventId>&& eventId); |
| 86 | |
| 87 | /** @brief Disable the data from satisfying interest with MustBeFresh |
| 88 | */ |
| 89 | void |
| 90 | markStale(); |
| 91 | |
| 92 | /** @brief Check if the data can satisfy an interest with MustBeFresh |
| 93 | */ |
| 94 | bool |
| 95 | isFresh() |
| 96 | { |
| 97 | return m_isFresh; |
| 98 | } |
| 99 | |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 100 | private: |
| 101 | shared_ptr<const Data> m_dataPacket; |
Yingdi Yu | 404eafd | 2016-03-06 14:54:25 -0800 | [diff] [blame^] | 102 | |
| 103 | bool m_isFresh; |
| 104 | unique_ptr<scheduler::ScopedEventId> m_markStaleEventId; |
Jiewen Tan | 9913596 | 2014-09-20 02:18:53 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | } // namespace util |
| 108 | } // namespace ndn |
| 109 | |
| 110 | #endif // NDN_UTIL_IN_MEMORY_STORAGE_ENTRY_HPP |