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