IBR-DTNSuite  0.10
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  dtn::data::BundleList::Listener &_expire_listener;
58 
59  // bundle list
61 
62  typedef std::map<dtn::data::BundleID, dtn::data::Length> size_map;
63  size_map _bundle_lengths;
64 
65  typedef std::set<dtn::data::BundleID> id_set;
66  id_set _removal_set;
67 
68  public:
70  virtual ~MetaStorage();
71 
72  typedef priority_set::iterator iterator;
73  typedef priority_set::const_iterator const_iterator;
74 
75  iterator begin() { return _priority_index.begin(); }
76  iterator end() { return _priority_index.end(); }
77 
78  const_iterator begin() const { return _priority_index.begin(); }
79  const_iterator end() const { return _priority_index.end(); }
80 
81  bool empty() throw ();
82  size_t size() throw ();
83 
84  bool has(const dtn::data::MetaBundle &m) const throw ();
85  void expire(const dtn::data::Timestamp &timestamp) throw ();
86 
87  template<class T>
88  const dtn::data::MetaBundle& find(const T &id) const throw (NoBundleFoundException)
89  {
91  if (it == _list.end())
92  throw NoBundleFoundException();
93 
94  return (*it);
95  }
96 
97  const dtn::data::MetaBundle& find(const ibrcommon::BloomFilter &filter) const throw (NoBundleFoundException);
98 
99  std::set<dtn::data::EID> getDistinctDestinations() const throw ();
100 
101  void store(const dtn::data::MetaBundle &meta, const dtn::data::Length &space) throw ();
102 
103  void remove(const dtn::data::MetaBundle &meta) throw ();
104 
109  void markRemoved(const dtn::data::MetaBundle &meta) throw ();
110 
114  bool isRemoved(const dtn::data::MetaBundle &meta) const throw ();
115 
119  void clear() throw ();
120 
124  dtn::data::Length getSize(const dtn::data::MetaBundle &meta) throw (NoBundleFoundException);
125 
126  protected:
127  virtual void eventBundleExpired(const dtn::data::MetaBundle &b) throw ();
128  };
129  } /* namespace storage */
130 } /* namespace dtn */
131 #endif /* METASTORAGE_H_ */