IBR-DTNSuite  0.12
MetaStorage.h
Go to the documentation of this file.
1 /*
2  * MetaStorage.h
3  *
4  * Copyright (C) 2013 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef METASTORAGE_H_
23 #define METASTORAGE_H_
24 
25 #include <storage/BundleSelector.h>
26 #include <ibrdtn/data/Bundle.h>
27 #include <ibrdtn/data/BundleList.h>
29 #include <stdint.h>
30 
31 namespace dtn
32 {
33  namespace storage
34  {
36  {
37  public:
39  {
40  bool operator() (const dtn::data::MetaBundle& lhs, const dtn::data::MetaBundle& rhs) const
41  {
42  if (lhs.getPriority() > rhs.getPriority())
43  return true;
44 
45  if (lhs.getPriority() != rhs.getPriority())
46  return false;
47 
48  return lhs < rhs;
49  }
50  };
51 
52  typedef std::set<dtn::data::MetaBundle, CMP_BUNDLE_PRIORITY> priority_set;
53 
54  private:
55  priority_set _priority_index;
56 
57  // bundle list
59 
60  typedef std::map<dtn::data::BundleID, dtn::data::Length> size_map;
61  size_map _bundle_lengths;
62 
63  typedef std::set<dtn::data::BundleID> id_set;
64  id_set _removal_set;
65 
66  public:
68  virtual ~MetaStorage();
69 
70  typedef priority_set::iterator iterator;
71  typedef priority_set::const_iterator const_iterator;
72 
73  iterator begin() { return _priority_index.begin(); }
74  iterator end() { return _priority_index.end(); }
75 
76  const_iterator begin() const { return _priority_index.begin(); }
77  const_iterator end() const { return _priority_index.end(); }
78 
79  bool empty() throw ();
80  size_t size() throw ();
81 
82  bool contains(const dtn::data::BundleID &id) const throw ();
83  void expire(const dtn::data::Timestamp &timestamp) throw ();
84 
85  template<class T>
86  const dtn::data::MetaBundle& find(const T &id) const throw (NoBundleFoundException)
87  {
89  if (it == _list.end())
90  throw NoBundleFoundException();
91 
92  return (*it);
93  }
94 
95  const dtn::data::MetaBundle& find(const ibrcommon::BloomFilter &filter) const throw (NoBundleFoundException);
96 
97  std::set<dtn::data::EID> getDistinctDestinations() const throw ();
98 
99  void store(const dtn::data::MetaBundle &meta, const dtn::data::Length &space) throw ();
100 
105  dtn::data::Length remove(const dtn::data::MetaBundle &meta) throw ();
106 
111  void markRemoved(const dtn::data::MetaBundle &meta) throw ();
112 
116  bool isRemoved(const dtn::data::MetaBundle &meta) const throw ();
117 
121  void clear() throw ();
122  };
123  } /* namespace storage */
124 } /* namespace dtn */
125 #endif /* METASTORAGE_H_ */