blob: fe7846c55068c3da1d67c95666ecd16e8966409f [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi5640ec82015-01-07 21:51:19 -07003 * Copyright (c) 2014-2015, Regents of the University of California,
4 * 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 Shifc206962015-01-16 11:12:22 -070029#include "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
Junxiao Shifc206962015-01-16 11:12:22 -070079 /** \return the absolute time when the stored Data becomes expired
80 * \retval time::steady_clock::TimePoint::max() if the stored Data never expires
81 * \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 Shi5640ec82015-01-07 21:51:19 -070097 * \note ChildSelector is not considered
Junxiao Shifc206962015-01-16 11:12:22 -070098 * \pre hasData()
Junxiao Shi5640ec82015-01-07 21:51:19 -070099 */
Junxiao Shia9388182014-12-13 23:16:09 -0700100 bool
101 canSatisfy(const Interest& interest) const;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800102
Junxiao Shifc206962015-01-16 11:12:22 -0700103public: // used by generic ContentStore implementation
104 /** \return true if a Data packet is stored
105 */
Junxiao Shia9388182014-12-13 23:16:09 -0700106 bool
Junxiao Shifc206962015-01-16 11:12:22 -0700107 hasData() const
108 {
109 return m_data != nullptr;
110 }
111
112 /** \brief replaces the stored Data
113 */
114 void
115 setData(shared_ptr<const Data> data, bool isUnsolicited);
116
117 /** \brief replaces the stored Data
118 */
119 void
120 setData(const Data& data, bool isUnsolicited)
121 {
122 this->setData(data.shared_from_this(), isUnsolicited);
123 }
124
125 /** \brief refreshes stale time relative to current time
126 */
127 void
128 updateStaleTime();
129
130 /** \brief clears the entry
131 * \post !hasData()
132 */
133 void
134 reset();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800135
136private:
Junxiao Shia9388182014-12-13 23:16:09 -0700137 shared_ptr<const Data> m_data;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800138 bool m_isUnsolicited;
Junxiao Shifc206962015-01-16 11:12:22 -0700139 time::steady_clock::TimePoint m_staleTime;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700140};
141
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800142} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800143} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800144
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700145#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP