akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 1 | #include <ndn-cpp-dev/face.hpp> |
| 2 | #include "nlsr_wl.hpp" |
| 3 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 4 | #define THIS_FILE "nlsr_wl.cpp" |
| 5 | |
akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 6 | namespace nlsr |
| 7 | { |
| 8 | static bool |
| 9 | waitingListCompare(const WaitingListEntry& w1, const std::string& respCert) |
| 10 | { |
| 11 | return w1.getResponsibleCert() == respCert; |
| 12 | } |
| 13 | |
| 14 | std::pair<WaitingListEntry, bool> |
| 15 | WaitingList::getWaitingListEntry(std::string respCert) |
| 16 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 17 | std::list<WaitingListEntry>::iterator it = std::find_if( m_waitingTable.begin(), |
| 18 | m_waitingTable.end(),ndn::bind(&waitingListCompare, _1, respCert)); |
| 19 | if( it != m_waitingTable.end() ) |
akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 20 | { |
| 21 | return std::make_pair(*(it),true); |
| 22 | } |
| 23 | |
| 24 | WaitingListEntry wle; |
| 25 | return std::make_pair(wle,false); |
| 26 | |
| 27 | } |
| 28 | |
| 29 | bool |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 30 | WaitingList::add(std::string respCert, std::string waitee) |
akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 31 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 32 | std::list<WaitingListEntry>::iterator it = std::find_if( m_waitingTable.begin(), |
| 33 | m_waitingTable.end(),ndn::bind(&waitingListCompare, _1, respCert)); |
| 34 | if( it == m_waitingTable.end() ) |
akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 35 | { |
| 36 | WaitingListEntry newWle(respCert); |
| 37 | newWle.addWaitee(waitee); |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 38 | m_waitingTable.push_back(newWle); |
akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 39 | return true; |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | return it->addWaitee(waitee); |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | bool |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 49 | WaitingList::remove(std::string respCert) |
akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 50 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 51 | std::list<WaitingListEntry>::iterator it = std::find_if( m_waitingTable.begin(), |
| 52 | m_waitingTable.end(),ndn::bind(&waitingListCompare, _1, respCert)); |
| 53 | if( it == m_waitingTable.end() ) |
akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 54 | { |
| 55 | return false; |
| 56 | } |
| 57 | else |
| 58 | { |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 59 | m_waitingTable.erase(it); |
akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame] | 60 | return true; |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | std::ostream& |
| 66 | operator<<(std::ostream& os, WaitingList wl) |
| 67 | { |
| 68 | os<<"-------Waiting List--------"<<std::endl; |
| 69 | std::list<WaitingListEntry> wles=wl.getWaitingTable(); |
| 70 | for( std::list<WaitingListEntry> ::iterator it=wles.begin(); |
| 71 | it != wles.end(); ++it) |
| 72 | { |
| 73 | os<<*(it)<<std::endl; |
| 74 | } |
| 75 | return os; |
| 76 | } |
| 77 | } |