blob: 7a719df2123e0c11cc26b249c1793fb2f29e78e4 [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
Junxiao Shid3c792f2014-01-30 00:46:13 -070037Entry::addNonce(uint32_t nonce)
Junxiao Shicbba04c2014-01-26 14:21:22 -070038{
Junxiao Shid3c792f2014-01-30 00:46:13 -070039 std::pair<std::set<uint32_t>::iterator, bool> insertResult =
40 m_nonces.insert(nonce);
41
42 return insertResult.second;
Junxiao Shicbba04c2014-01-26 14:21:22 -070043}
44
45static inline bool
46predicate_FaceRecord_Face(const FaceRecord& faceRecord, shared_ptr<Face> face)
47{
48 return faceRecord.getFace() == face;
49}
50
51InRecordCollection::iterator
52Entry::insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest)
53{
54 InRecordCollection::iterator it = std::find_if(m_inRecords.begin(),
55 m_inRecords.end(), bind(&predicate_FaceRecord_Face, _1, face));
56 if (it == m_inRecords.end()) {
57 m_inRecords.push_front(InRecord(face));
58 it = m_inRecords.begin();
59 }
60
61 it->update(interest);
Junxiao Shicbba04c2014-01-26 14:21:22 -070062 return it;
63}
64
65void
66Entry::deleteInRecords()
67{
68 m_inRecords.clear();
69}
70
71OutRecordCollection::iterator
72Entry::insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest)
73{
74 OutRecordCollection::iterator it = std::find_if(m_outRecords.begin(),
75 m_outRecords.end(), bind(&predicate_FaceRecord_Face, _1, face));
76 if (it == m_outRecords.end()) {
77 m_outRecords.push_front(OutRecord(face));
78 it = m_outRecords.begin();
79 }
80
81 it->update(interest);
82 m_nonces.insert(interest.getNonce());
83 return it;
84}
85
86void
87Entry::deleteOutRecord(shared_ptr<Face> face)
88{
89 OutRecordCollection::iterator it = std::find_if(m_outRecords.begin(),
90 m_outRecords.end(), bind(&predicate_FaceRecord_Face, _1, face));
91 if (it != m_outRecords.end()) {
92 m_outRecords.erase(it);
93 }
94}
95
96
97} // namespace pit
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080098} // namespace nfd