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