blob: a35d9e9171f88c93b6c620ddda0a45ff571df3bc [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 Shia9388182014-12-13 23:16:09 -070029#include "cs.hpp"
30#include "core/scheduler.hpp"
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080031
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080032namespace nfd {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070033namespace cs {
34
Junxiao Shia9388182014-12-13 23:16:09 -070035/** \brief an Entry in ContentStore
36 * \note This type is internal to ContentStore.
37 *
38 * An Entry is either a stored Entry which contains a Data packet and related attributes,
39 * or a query Entry which contains a Name that is LessComparable to other stored/query Entry
40 * and is used to lookup a container of entries.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080041 */
Junxiao Shia9388182014-12-13 23:16:09 -070042class Entry
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070043{
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080044public:
Junxiao Shia9388182014-12-13 23:16:09 -070045 /** \brief construct Entry for query
46 * \note Name is implicitly convertible to Entry, so that Name can be passed to
47 * lookup functions on a container of Entry
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040048 */
Junxiao Shia9388182014-12-13 23:16:09 -070049 Entry(const Name& name);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080050
Junxiao Shia9388182014-12-13 23:16:09 -070051 /** \brief construct Entry for storage
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080052 */
Junxiao Shia9388182014-12-13 23:16:09 -070053 Entry(shared_ptr<const Data> data, bool isUnsolicited);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080054
Junxiao Shia9388182014-12-13 23:16:09 -070055 shared_ptr<const Data>
56 getData() const;
57
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070058 const Name&
Junxiao Shi5640ec82015-01-07 21:51:19 -070059 getName() const;
60
61 const Name&
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070062 getFullName() const;
63
Junxiao Shia9388182014-12-13 23:16:09 -070064 /** \return true if entry can become stale, false if entry is never stale
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080065 */
66 bool
Junxiao Shia9388182014-12-13 23:16:09 -070067 canStale() const;
68
69 bool
70 isStale() const;
71
72 void
73 refresh();
74
75 bool
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080076 isUnsolicited() const;
77
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080078 void
Junxiao Shia9388182014-12-13 23:16:09 -070079 unsetUnsolicited();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080080
Junxiao Shi5640ec82015-01-07 21:51:19 -070081 /** \brief determines whether Interest can be satisified by this cached Data
82 * \note ChildSelector is not considered
83 */
Junxiao Shia9388182014-12-13 23:16:09 -070084 bool
85 canSatisfy(const Interest& interest) const;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080086
Junxiao Shia9388182014-12-13 23:16:09 -070087 bool
88 operator<(const Entry& other) const;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080089
90private:
Junxiao Shia9388182014-12-13 23:16:09 -070091 bool
92 isQuery() const;
93
94public:
95 Cs::QueueType queueType;
96 Cs::QueueIt queueIt;
97 scheduler::EventId moveStaleEvent;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080098
99private:
Junxiao Shia9388182014-12-13 23:16:09 -0700100 Name m_queryName;
101 shared_ptr<const Data> m_data;
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700102 time::steady_clock::TimePoint m_staleAt;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800103 bool m_isUnsolicited;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700104};
105
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800106} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800107} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800108
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700109#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP