blob: eb30d5814d483db981ab3b29dc508760efb667a4 [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi14b39182019-04-29 19:19:18 +00002/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shi5640ec82015-01-07 21:51:19 -07004 * 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 Moiseenko76cf77a2014-03-05 14:35:51 -080010 *
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070011 * 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 Shi0fcb41e2014-01-24 10:29:43 -070024 */
25
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP
27#define NFD_DAEMON_TABLE_CS_ENTRY_HPP
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080028
Junxiao Shi9f5b01d2016-08-05 03:54:28 +000029#include "core/common.hpp"
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080030
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070032namespace cs {
33
Junxiao Shifc206962015-01-16 11:12:22 -070034/** \brief represents a base class for CS entry
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080035 */
Junxiao Shia9388182014-12-13 23:16:09 -070036class Entry
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070037{
Junxiao Shifc206962015-01-16 11:12:22 -070038public: // exposed through ContentStore enumeration
39 /** \return the stored Data
40 * \pre hasData()
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040041 */
Junxiao Shifc206962015-01-16 11:12:22 -070042 const Data&
43 getData() const
44 {
45 BOOST_ASSERT(this->hasData());
46 return *m_data;
47 }
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080048
Junxiao Shifc206962015-01-16 11:12:22 -070049 /** \return Name of the stored Data
50 * \pre hasData()
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080051 */
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070052 const Name&
Junxiao Shifc206962015-01-16 11:12:22 -070053 getName() const
54 {
55 BOOST_ASSERT(this->hasData());
56 return m_data->getName();
57 }
Junxiao Shi5640ec82015-01-07 21:51:19 -070058
Junxiao Shifc206962015-01-16 11:12:22 -070059 /** \return full name (including implicit digest) of the stored Data
60 * \pre hasData()
61 */
Junxiao Shi5640ec82015-01-07 21:51:19 -070062 const Name&
Junxiao Shifc206962015-01-16 11:12:22 -070063 getFullName() const
64 {
65 BOOST_ASSERT(this->hasData());
66 return m_data->getFullName();
67 }
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070068
Junxiao Shifc206962015-01-16 11:12:22 -070069 /** \return whether the stored Data is unsolicited
70 * \pre hasData()
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080071 */
72 bool
Junxiao Shifc206962015-01-16 11:12:22 -070073 isUnsolicited() const
74 {
75 BOOST_ASSERT(this->hasData());
76 return m_isUnsolicited;
77 }
Junxiao Shia9388182014-12-13 23:16:09 -070078
Eric Newberryf4056d02017-05-26 17:31:53 +000079 /** \return the absolute time when the stored Data becomes stale
80 * \note if the returned TimePoint is in the past, the Data is stale
Junxiao Shifc206962015-01-16 11:12:22 -070081 * \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 Shia9388182014-12-13 23:16:09 -070093 bool
94 isStale() const;
95
Junxiao Shifc206962015-01-16 11:12:22 -070096 /** \brief determines whether Interest can be satisified by the stored Data
Junxiao Shifc206962015-01-16 11:12:22 -070097 * \pre hasData()
Junxiao Shi5640ec82015-01-07 21:51:19 -070098 */
Junxiao Shia9388182014-12-13 23:16:09 -070099 bool
100 canSatisfy(const Interest& interest) const;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800101
Junxiao Shifc206962015-01-16 11:12:22 -0700102public: // used by generic ContentStore implementation
103 /** \return true if a Data packet is stored
104 */
Junxiao Shia9388182014-12-13 23:16:09 -0700105 bool
Junxiao Shifc206962015-01-16 11:12:22 -0700106 hasData() const
107 {
108 return m_data != nullptr;
109 }
110
111 /** \brief replaces the stored Data
112 */
113 void
114 setData(shared_ptr<const Data> data, bool isUnsolicited);
115
116 /** \brief replaces the stored Data
117 */
118 void
119 setData(const Data& data, bool isUnsolicited)
120 {
121 this->setData(data.shared_from_this(), isUnsolicited);
122 }
123
124 /** \brief refreshes stale time relative to current time
125 */
126 void
127 updateStaleTime();
128
129 /** \brief clears the entry
130 * \post !hasData()
131 */
132 void
133 reset();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800134
135private:
Junxiao Shia9388182014-12-13 23:16:09 -0700136 shared_ptr<const Data> m_data;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800137 bool m_isUnsolicited;
Junxiao Shifc206962015-01-16 11:12:22 -0700138 time::steady_clock::TimePoint m_staleTime;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700139};
140
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800141} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800142} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800143
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700144#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP