blob: 39a7192106e8f28253dfbb1f3d26c867a0bd1e11 [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 }
akmhoque53353462014-04-22 08:43:45 -050020 WaitingListEntry wle;
21 return std::make_pair(wle, false);
akmhoque53353462014-04-22 08:43:45 -050022}
23
24bool
25WaitingList::add(std::string respCert, std::string waitee)
26{
27 std::list<WaitingListEntry>::iterator it = std::find_if(m_waitingTable.begin(),
28 m_waitingTable.end(), ndn::bind(&waitingListCompare, _1, respCert));
29 if (it == m_waitingTable.end())
30 {
31 WaitingListEntry newWle(respCert);
32 newWle.addWaitee(waitee);
33 m_waitingTable.push_back(newWle);
34 return true;
35 }
36 else
37 {
38 return it->addWaitee(waitee);
39 }
40 return false;
41}
42
43bool
44WaitingList::remove(std::string respCert)
45{
46 std::list<WaitingListEntry>::iterator it = std::find_if(m_waitingTable.begin(),
47 m_waitingTable.end(), ndn::bind(&waitingListCompare, _1, respCert));
48 if (it == m_waitingTable.end())
49 {
50 return false;
51 }
52 else
53 {
54 m_waitingTable.erase(it);
55 return true;
56 }
57 return false;
58}
59
60std::ostream&
61operator<<(std::ostream& os, WaitingList wl)
62{
63 os << "-------Waiting List--------" << std::endl;
64 std::list<WaitingListEntry> wles = wl.getWaitingTable();
65 for (std::list<WaitingListEntry> ::iterator it = wles.begin();
66 it != wles.end(); ++it)
67 {
68 os << *(it) << std::endl;
69 }
70 return os;
71}
72}//namespace nlsr