blob: 721a90d724a36338fcfa2a33ebea020153ec4574 [file] [log] [blame]
Jiewen Tan99135962014-09-20 02:18:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shic542f632017-07-18 14:20:32 +00002/*
3 * Copyright (c) 2013-2017 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
Junxiao Shic542f632017-07-18 14:20:32 +000022#ifndef NDN_IMS_IN_MEMORY_STORAGE_ENTRY_HPP
23#define NDN_IMS_IN_MEMORY_STORAGE_ENTRY_HPP
Jiewen Tan99135962014-09-20 02:18:53 -070024
Jiewen Tan99135962014-09-20 02:18:53 -070025#include "../data.hpp"
Junxiao Shic542f632017-07-18 14:20:32 +000026#include "../interest.hpp"
27#include "../util/scheduler-scoped-event-id.hpp"
Jiewen Tan99135962014-09-20 02:18:53 -070028
29namespace ndn {
Jiewen Tan99135962014-09-20 02:18:53 -070030
Junxiao Shic542f632017-07-18 14:20:32 +000031/** @brief Represents an in-memory storage entry
Jiewen Tan99135962014-09-20 02:18:53 -070032 */
33class InMemoryStorageEntry : noncopyable
34{
35public:
Yingdi Yu404eafd2016-03-06 14:54:25 -080036 /** @brief Create an entry
37 */
38 InMemoryStorageEntry();
39
Jiewen Tan99135962014-09-20 02:18:53 -070040 /** @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 Tan99135962014-09-20 02:18:53 -070062 /** @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 Tan99135962014-09-20 02:18:53 -070070 /** @brief Changes the content of in-memory storage entry
Yingdi Yu404eafd2016-03-06 14:54:25 -080071 *
72 * This method also allows data to satisfy Interest with MustBeFresh
Jiewen Tan99135962014-09-20 02:18:53 -070073 */
74 void
75 setData(const Data& data);
76
Yingdi Yu404eafd2016-03-06 14:54:25 -080077 /** @brief Set eventId for the markStale event.
78 */
79 void
Junxiao Shic542f632017-07-18 14:20:32 +000080 setMarkStaleEventId(unique_ptr<util::scheduler::ScopedEventId> eventId);
Yingdi Yu404eafd2016-03-06 14:54:25 -080081
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 Tan99135962014-09-20 02:18:53 -070095private:
96 shared_ptr<const Data> m_dataPacket;
Yingdi Yu404eafd2016-03-06 14:54:25 -080097
98 bool m_isFresh;
Junxiao Shic542f632017-07-18 14:20:32 +000099 unique_ptr<util::scheduler::ScopedEventId> m_markStaleEventId;
Jiewen Tan99135962014-09-20 02:18:53 -0700100};
101
Jiewen Tan99135962014-09-20 02:18:53 -0700102} // namespace ndn
103
Junxiao Shic542f632017-07-18 14:20:32 +0000104#endif // NDN_IMS_IN_MEMORY_STORAGE_ENTRY_HPP