blob: c61345fa34f0fc24f4de1bc4c6616ea65c988f6b [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev319f2c82015-01-07 14:56:53 -08003 * 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/>.
24 *
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070025 * \author Ilya Moiseenko <http://ilyamoiseenko.com/>
26 * \author Junxiao Shi <http://www.cs.arizona.edu/people/shijunxiao/>
27 * \author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070028 */
29
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070030#ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP
31#define NFD_DAEMON_TABLE_CS_ENTRY_HPP
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080032
33#include "common.hpp"
34
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080035namespace nfd {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070036namespace cs {
37
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080038class Entry;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070039
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080040/** \brief represents a base class for CS entry
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080041 */
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080042class Entry : noncopyable
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070043{
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080044public:
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040045 Entry();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080046
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080047 /** \brief returns the name of the Data packet stored in the CS entry
48 * \return{ NDN name }
49 */
50 const Name&
51 getName() const;
52
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070053 /** \brief returns the full name (including implicit digest) of the Data packet stored
54 * in the CS entry
55 * \return{ NDN name }
56 */
57 const Name&
58 getFullName() const;
59
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080060 /** \brief Data packet is unsolicited if this particular NDN node
61 * did not receive an Interest packet for it, or the Interest packet has already expired
62 * \return{ True if the Data packet is unsolicited; otherwise False }
63 */
64 bool
65 isUnsolicited() const;
66
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080067 /** \brief returns the Data packet stored in the CS entry
68 */
69 const Data&
70 getData() const;
71
72 /** \brief changes the content of CS entry and recomputes digest
73 */
74 void
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040075 setData(const Data& data, bool isUnsolicited);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080076
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080077 /** \brief returns the absolute time when Data becomes expired
78 * \return{ Time (resolution up to time::milliseconds) }
79 */
80 const time::steady_clock::TimePoint&
81 getStaleTime() const;
82
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080083 /** \brief refreshes the time when Data becomes expired
84 * according to the current absolute time.
85 */
86 void
87 updateStaleTime();
88
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080089 /** \brief checks if the stored Data is stale
90 */
91 bool
92 isStale() const;
93
94 /** \brief clears CS entry
95 * After reset, *this == Entry()
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080096 */
97 void
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080098 reset();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080099
100private:
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700101 time::steady_clock::TimePoint m_staleAt;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800102 shared_ptr<const Data> m_dataPacket;
103
104 bool m_isUnsolicited;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700105};
106
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400107inline const Name&
108Entry::getName() const
109{
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -0800110 BOOST_ASSERT(m_dataPacket != nullptr);
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -0700111 return m_dataPacket->getName();
112}
113
114inline const Name&
115Entry::getFullName() const
116{
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -0800117 BOOST_ASSERT(m_dataPacket != nullptr);
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -0700118 return m_dataPacket->getFullName();
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400119}
120
121inline const Data&
122Entry::getData() const
123{
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -0800124 BOOST_ASSERT(m_dataPacket != nullptr);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400125 return *m_dataPacket;
126}
127
128inline bool
129Entry::isUnsolicited() const
130{
131 return m_isUnsolicited;
132}
133
134inline const time::steady_clock::TimePoint&
135Entry::getStaleTime() const
136{
137 return m_staleAt;
138}
139
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800140} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800141} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800142
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700143#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP