blob: 6e77b3dee31f8b5b86e00c1abfd62541e9727c42 [file] [log] [blame]
Jiewen Tan99135962014-09-20 02:18:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu404eafd2016-03-06 14:54:25 -08003 * Copyright (c) 2013-2016 Regents of the University of California.
Jiewen Tan99135962014-09-20 02:18:53 -07004 *
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 Yu404eafd2016-03-06 14:54:25 -080028#include "scheduler-scoped-event-id.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070029
30namespace ndn {
31namespace util {
32
33 /** @brief Represents an in-memory storage entry
34 */
35class InMemoryStorageEntry : noncopyable
36{
37public:
Yingdi Yu404eafd2016-03-06 14:54:25 -080038
39 /** @brief Create an entry
40 */
41 InMemoryStorageEntry();
42
Jiewen Tan99135962014-09-20 02:18:53 -070043 /** @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 Yu404eafd2016-03-06 14:54:25 -080076 *
77 * This method also allows data to satisfy Interest with MustBeFresh
Jiewen Tan99135962014-09-20 02:18:53 -070078 */
79 void
80 setData(const Data& data);
81
Yingdi Yu404eafd2016-03-06 14:54:25 -080082 /** @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 Tan99135962014-09-20 02:18:53 -0700100private:
101 shared_ptr<const Data> m_dataPacket;
Yingdi Yu404eafd2016-03-06 14:54:25 -0800102
103 bool m_isFresh;
104 unique_ptr<scheduler::ScopedEventId> m_markStaleEventId;
Jiewen Tan99135962014-09-20 02:18:53 -0700105};
106
107} // namespace util
108} // namespace ndn
109
110#endif // NDN_UTIL_IN_MEMORY_STORAGE_ENTRY_HPP