IBR-DTNSuite  0.12
SchedulingBundleIndex.cpp
Go to the documentation of this file.
1 /*
2  * SchedulingBundleIndex.cpp
3  *
4  * Created on: 21.01.2013
5  * Author: morgenro
6  */
7 
9 
10 namespace dtn
11 {
12  namespace routing
13  {
15  {
16  }
17 
19  {
20  }
21 
23  {
24  ibrcommon::MutexLock l(_index_mutex);
25  _priority_index.insert(b);
26  }
27 
29  {
30  ibrcommon::MutexLock l(_index_mutex);
31  for (priority_index::const_iterator iter = _priority_index.begin(); iter != _priority_index.end(); ++iter)
32  {
33  const dtn::data::MetaBundle &b = (*iter);
34  if (id == (const dtn::data::BundleID&)b) {
35  _priority_index.erase(iter);
36  return;
37  }
38  }
39  }
40 
42  {
43  bool unlimited = (cb.limit() <= 0);
44  size_t added = 0;
45 
46  ibrcommon::MutexLock l(_index_mutex);
47  for (priority_index::const_iterator iter = _priority_index.begin(); iter != _priority_index.end(); ++iter)
48  {
49  const dtn::data::MetaBundle &b = (*iter);
50  if (cb.shouldAdd(b)) {
51  result.put(b);
52  added++;
53  }
54 
55  if (!unlimited && (added >= cb.limit())) break;
56  }
57 
58  if (added == 0)
60  }
61 
62  const std::set<dtn::data::EID> SchedulingBundleIndex::getDistinctDestinations()
63  {
64  std::set<dtn::data::EID> ret;
65 
66  ibrcommon::MutexLock l(_index_mutex);
67  for (priority_index::const_iterator iter = _priority_index.begin(); iter != _priority_index.end(); ++iter)
68  {
69  const dtn::data::MetaBundle &b = (*iter);
70  ret.insert(b.destination);
71  }
72 
73  return ret;
74  }
75  } /* namespace routing */
76 } /* namespace dtn */