blob: 442afe373b9215c0a672d83a1301e7951925c3a0 [file] [log] [blame]
akmhoquefa8ee9b2014-03-14 09:06:24 -05001#include <ndn-cpp-dev/face.hpp>
2#include "nlsr_wl.hpp"
3
akmhoque05d5fcf2014-04-15 14:58:45 -05004#define THIS_FILE "nlsr_wl.cpp"
5
akmhoquefa8ee9b2014-03-14 09:06:24 -05006namespace 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 {
akmhoque05d5fcf2014-04-15 14:58:45 -050017 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() )
akmhoquefa8ee9b2014-03-14 09:06:24 -050020 {
21 return std::make_pair(*(it),true);
22 }
23
24 WaitingListEntry wle;
25 return std::make_pair(wle,false);
26
27 }
28
29 bool
akmhoque05d5fcf2014-04-15 14:58:45 -050030 WaitingList::add(std::string respCert, std::string waitee)
akmhoquefa8ee9b2014-03-14 09:06:24 -050031 {
akmhoque05d5fcf2014-04-15 14:58:45 -050032 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() )
akmhoquefa8ee9b2014-03-14 09:06:24 -050035 {
36 WaitingListEntry newWle(respCert);
37 newWle.addWaitee(waitee);
akmhoque05d5fcf2014-04-15 14:58:45 -050038 m_waitingTable.push_back(newWle);
akmhoquefa8ee9b2014-03-14 09:06:24 -050039 return true;
40 }
41 else
42 {
43 return it->addWaitee(waitee);
44 }
45 return false;
46 }
47
48 bool
akmhoque05d5fcf2014-04-15 14:58:45 -050049 WaitingList::remove(std::string respCert)
akmhoquefa8ee9b2014-03-14 09:06:24 -050050 {
akmhoque05d5fcf2014-04-15 14:58:45 -050051 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() )
akmhoquefa8ee9b2014-03-14 09:06:24 -050054 {
55 return false;
56 }
57 else
58 {
akmhoque05d5fcf2014-04-15 14:58:45 -050059 m_waitingTable.erase(it);
akmhoquefa8ee9b2014-03-14 09:06:24 -050060 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}