blob: 21e4c537c19a61904aacf10b3902ddea817fd14f [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shifef73e42016-03-29 14:15:05 -07003 * Copyright (c) 2014-2016, Regents of the University of California,
Junxiao Shicde37ad2015-12-24 01:02:05 -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.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * 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/>.
Alexander Afanasyev28d586a2014-07-10 20:10:54 -070024 */
Junxiao Shicbba04c2014-01-26 14:21:22 -070025
26#include "pit-entry.hpp"
27#include <algorithm>
28
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080029namespace nfd {
Junxiao Shicbba04c2014-01-26 14:21:22 -070030namespace pit {
31
32Entry::Entry(const Interest& interest)
Alexander Afanasyev28d586a2014-07-10 20:10:54 -070033 : m_interest(interest.shared_from_this())
Junxiao Shicbba04c2014-01-26 14:21:22 -070034{
35}
36
37const Name&
38Entry::getName() const
39{
Alexander Afanasyev28d586a2014-07-10 20:10:54 -070040 return m_interest->getName();
Junxiao Shicbba04c2014-01-26 14:21:22 -070041}
42
Junxiao Shicbba04c2014-01-26 14:21:22 -070043InRecordCollection::iterator
44Entry::insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest)
45{
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070046 auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
47 [&face] (const InRecord& inRecord) { return inRecord.getFace() == face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -070048 if (it == m_inRecords.end()) {
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070049 m_inRecords.emplace_front(face);
Junxiao Shicbba04c2014-01-26 14:21:22 -070050 it = m_inRecords.begin();
51 }
Junxiao Shi11bd9c22014-03-13 20:44:13 -070052
Junxiao Shicbba04c2014-01-26 14:21:22 -070053 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -070054 return it;
55}
56
Junxiao Shi66f91f82014-05-10 17:28:58 -070057InRecordCollection::const_iterator
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070058Entry::getInRecord(const Face& face) const
Junxiao Shi66f91f82014-05-10 17:28:58 -070059{
60 return std::find_if(m_inRecords.begin(), m_inRecords.end(),
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070061 [&face] (const InRecord& inRecord) { return inRecord.getFace().get() == &face; });
Junxiao Shi66f91f82014-05-10 17:28:58 -070062}
63
Junxiao Shicbba04c2014-01-26 14:21:22 -070064void
Junxiao Shi5e5e4452015-09-24 16:56:52 -070065Entry::deleteInRecord(const Face& face)
66{
67 auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
68 [&face] (const InRecord& inRecord) { return inRecord.getFace().get() == &face; });
69 if (it != m_inRecords.end()) {
70 m_inRecords.erase(it);
71 }
72}
73
74void
Junxiao Shicbba04c2014-01-26 14:21:22 -070075Entry::deleteInRecords()
76{
77 m_inRecords.clear();
78}
79
80OutRecordCollection::iterator
81Entry::insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest)
82{
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070083 auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
84 [&face] (const OutRecord& outRecord) { return outRecord.getFace() == face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -070085 if (it == m_outRecords.end()) {
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070086 m_outRecords.emplace_front(face);
Junxiao Shicbba04c2014-01-26 14:21:22 -070087 it = m_outRecords.begin();
88 }
Junxiao Shi11bd9c22014-03-13 20:44:13 -070089
Junxiao Shicbba04c2014-01-26 14:21:22 -070090 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -070091 return it;
92}
93
Junxiao Shi5e5e4452015-09-24 16:56:52 -070094OutRecordCollection::iterator
95Entry::getOutRecord(const Face& face)
Junxiao Shi66f91f82014-05-10 17:28:58 -070096{
97 return std::find_if(m_outRecords.begin(), m_outRecords.end(),
Junxiao Shib2bcbcd2014-11-08 09:30:28 -070098 [&face] (const OutRecord& outRecord) { return outRecord.getFace().get() == &face; });
Junxiao Shi66f91f82014-05-10 17:28:58 -070099}
100
Junxiao Shicbba04c2014-01-26 14:21:22 -0700101void
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700102Entry::deleteOutRecord(const Face& face)
Junxiao Shicbba04c2014-01-26 14:21:22 -0700103{
Junxiao Shib2bcbcd2014-11-08 09:30:28 -0700104 auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
105 [&face] (const OutRecord& outRecord) { return outRecord.getFace().get() == &face; });
Junxiao Shicbba04c2014-01-26 14:21:22 -0700106 if (it != m_outRecords.end()) {
107 m_outRecords.erase(it);
108 }
109}
110
Junxiao Shicbba04c2014-01-26 14:21:22 -0700111} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800112} // namespace nfd