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 |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 37 | Entry::addNonce(uint32_t nonce) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 38 | { |
Junxiao Shi | d3c792f | 2014-01-30 00:46:13 -0700 | [diff] [blame] | 39 | std::pair<std::set<uint32_t>::iterator, bool> insertResult = |
| 40 | m_nonces.insert(nonce); |
| 41 | |
| 42 | return insertResult.second; |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static inline bool |
| 46 | predicate_FaceRecord_Face(const FaceRecord& faceRecord, shared_ptr<Face> face) |
| 47 | { |
| 48 | return faceRecord.getFace() == face; |
| 49 | } |
| 50 | |
| 51 | InRecordCollection::iterator |
| 52 | Entry::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 Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 62 | return it; |
| 63 | } |
| 64 | |
| 65 | void |
| 66 | Entry::deleteInRecords() |
| 67 | { |
| 68 | m_inRecords.clear(); |
| 69 | } |
| 70 | |
| 71 | OutRecordCollection::iterator |
| 72 | Entry::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 | |
| 86 | void |
| 87 | Entry::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 Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 98 | } // namespace nfd |