Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame^] | 10 | namespace nfd { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 11 | namespace pit { |
| 12 | |
| 13 | Entry::Entry(const Interest& interest) |
| 14 | : m_interest(interest) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | const Name& |
| 19 | Entry::getName() const |
| 20 | { |
| 21 | return m_interest.getName(); |
| 22 | } |
| 23 | |
| 24 | const InRecordCollection& |
| 25 | Entry::getInRecords() const |
| 26 | { |
| 27 | return m_inRecords; |
| 28 | } |
| 29 | |
| 30 | const OutRecordCollection& |
| 31 | Entry::getOutRecords() const |
| 32 | { |
| 33 | return m_outRecords; |
| 34 | } |
| 35 | |
| 36 | bool |
| 37 | Entry::isNonceSeen(uint32_t nonce) const |
| 38 | { |
| 39 | return m_nonces.count(nonce) > 0; |
| 40 | } |
| 41 | |
| 42 | static inline bool |
| 43 | predicate_FaceRecord_Face(const FaceRecord& faceRecord, shared_ptr<Face> face) |
| 44 | { |
| 45 | return faceRecord.getFace() == face; |
| 46 | } |
| 47 | |
| 48 | InRecordCollection::iterator |
| 49 | Entry::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 | |
| 63 | void |
| 64 | Entry::deleteInRecords() |
| 65 | { |
| 66 | m_inRecords.clear(); |
| 67 | } |
| 68 | |
| 69 | OutRecordCollection::iterator |
| 70 | Entry::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 | |
| 84 | void |
| 85 | Entry::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 Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame^] | 96 | } // namespace nfd |