blob: 094ea6e28b540691927a810318c0706a0f162e85 [file] [log] [blame]
Junxiao Shicbba04c2014-01-26 14:21:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "pit-entry.hpp"
8#include <algorithm>
9
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080010namespace nfd {
Junxiao Shicbba04c2014-01-26 14:21:22 -070011namespace pit {
12
13Entry::Entry(const Interest& interest)
14 : m_interest(interest)
15{
16}
17
18const Name&
19Entry::getName() const
20{
21 return m_interest.getName();
22}
23
24const InRecordCollection&
25Entry::getInRecords() const
26{
27 return m_inRecords;
28}
29
30const OutRecordCollection&
31Entry::getOutRecords() const
32{
33 return m_outRecords;
34}
35
36bool
37Entry::isNonceSeen(uint32_t nonce) const
38{
39 return m_nonces.count(nonce) > 0;
40}
41
42static inline bool
43predicate_FaceRecord_Face(const FaceRecord& faceRecord, shared_ptr<Face> face)
44{
45 return faceRecord.getFace() == face;
46}
47
48InRecordCollection::iterator
49Entry::insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest)
50{
51 InRecordCollection::iterator it = std::find_if(m_inRecords.begin(),
52 m_inRecords.end(), bind(&predicate_FaceRecord_Face, _1, face));
53 if (it == m_inRecords.end()) {
54 m_inRecords.push_front(InRecord(face));
55 it = m_inRecords.begin();
56 }
57
58 it->update(interest);
59 m_nonces.insert(interest.getNonce());
60 return it;
61}
62
63void
64Entry::deleteInRecords()
65{
66 m_inRecords.clear();
67}
68
69OutRecordCollection::iterator
70Entry::insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest)
71{
72 OutRecordCollection::iterator it = std::find_if(m_outRecords.begin(),
73 m_outRecords.end(), bind(&predicate_FaceRecord_Face, _1, face));
74 if (it == m_outRecords.end()) {
75 m_outRecords.push_front(OutRecord(face));
76 it = m_outRecords.begin();
77 }
78
79 it->update(interest);
80 m_nonces.insert(interest.getNonce());
81 return it;
82}
83
84void
85Entry::deleteOutRecord(shared_ptr<Face> face)
86{
87 OutRecordCollection::iterator it = std::find_if(m_outRecords.begin(),
88 m_outRecords.end(), bind(&predicate_FaceRecord_Face, _1, face));
89 if (it != m_outRecords.end()) {
90 m_outRecords.erase(it);
91 }
92}
93
94
95} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080096} // namespace nfd