IBR-DTNSuite  0.10
MemoryBundleStorage.h
Go to the documentation of this file.
1 /*
2  * MemoryBundleStorage.h
3  *
4  * Copyright (C) 2011 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 MEMORYBUNDLESTORAGE_H_
23 #define MEMORYBUNDLESTORAGE_H_
24 
25 #include "Component.h"
26 #include "core/BundleCore.h"
27 #include "storage/BundleStorage.h"
28 #include "core/Node.h"
29 #include "core/EventReceiver.h"
30 
31 #include <ibrdtn/data/Bundle.h>
32 #include <ibrdtn/data/BundleList.h>
33 
34 namespace dtn
35 {
36  namespace storage
37  {
39  {
40  public:
41  static const std::string TAG;
42 
43  MemoryBundleStorage(const dtn::data::Length maxsize = 0);
44  virtual ~MemoryBundleStorage();
45 
50  virtual void store(const dtn::data::Bundle &bundle);
51 
58  virtual dtn::data::Bundle get(const dtn::data::BundleID &id);
59 
63  virtual void get(const BundleSelector &cb, BundleResult &result) throw (NoBundleFoundException, BundleSelectorException);
64 
68  virtual const eid_set getDistinctDestinations();
69 
75  void remove(const dtn::data::BundleID &id);
76 
82  dtn::data::MetaBundle remove(const ibrcommon::BloomFilter &filter);
83 
87  void clear();
88 
92  bool empty();
93 
98 
102  void releaseCustody(const dtn::data::EID &custodian, const dtn::data::BundleID &id);
103 
108  void raiseEvent(const dtn::core::Event *evt) throw ();
109 
113  virtual const std::string getName() const;
114 
115  protected:
116  virtual void componentUp() throw ();
117  virtual void componentDown() throw ();
118 
119  virtual void eventBundleExpired(const dtn::data::MetaBundle &b) throw ();
120 
121  private:
122  ibrcommon::Mutex _bundleslock;
123 
124  typedef std::set<dtn::data::Bundle> bundle_list;
125  bundle_list _bundles;
126  dtn::data::BundleList _list;
127 
128  void __erase(const bundle_list::iterator &iter);
129 
130  struct CMP_BUNDLE_PRIORITY
131  {
132  bool operator() (const dtn::data::MetaBundle& lhs, const dtn::data::MetaBundle& rhs) const
133  {
134  if (lhs.getPriority() > rhs.getPriority())
135  return true;
136 
137  if (lhs.getPriority() != rhs.getPriority())
138  return false;
139 
140  return lhs < rhs;
141  }
142  };
143 
144  typedef std::set<dtn::data::MetaBundle, CMP_BUNDLE_PRIORITY> prio_bundle_set;
145  prio_bundle_set _priority_index;
146 
147  typedef std::map<dtn::data::BundleID, dtn::data::Length> size_map;
148  size_map _bundle_lengths;
149  };
150  }
151 }
152 
153 #endif /* MEMORYBUNDLESTORAGE_H_ */