IBR-DTNSuite  0.12
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  static const std::string TAG;
41 
42  public:
43  MemoryBundleStorage(const dtn::data::Length maxsize = 0);
44  virtual ~MemoryBundleStorage();
45 
50  virtual void store(const dtn::data::Bundle &bundle);
51 
56  virtual bool contains(const dtn::data::BundleID &id);
57 
62 
69  virtual dtn::data::Bundle get(const dtn::data::BundleID &id);
70 
74  virtual void get(const BundleSelector &cb, BundleResult &result) throw (NoBundleFoundException, BundleSelectorException);
75 
79  virtual const eid_set getDistinctDestinations();
80 
86  void remove(const dtn::data::BundleID &id);
87 
91  void clear();
92 
96  bool empty();
97 
102 
106  void releaseCustody(const dtn::data::EID &custodian, const dtn::data::BundleID &id);
107 
112  void raiseEvent(const dtn::core::Event *evt) throw ();
113 
117  virtual const std::string getName() const;
118 
119  protected:
120  virtual void componentUp() throw ();
121  virtual void componentDown() throw ();
122 
123  virtual void eventBundleExpired(const dtn::data::MetaBundle &b) throw ();
124 
125  private:
126  ibrcommon::Mutex _bundleslock;
127 
128  typedef std::set<dtn::data::Bundle> bundle_list;
129  bundle_list _bundles;
130  dtn::data::BundleList _list;
131 
132  void __erase(const bundle_list::iterator &iter);
133 
134  struct CMP_BUNDLE_PRIORITY
135  {
136  bool operator() (const dtn::data::MetaBundle& lhs, const dtn::data::MetaBundle& rhs) const
137  {
138  if (lhs.getPriority() > rhs.getPriority())
139  return true;
140 
141  if (lhs.getPriority() != rhs.getPriority())
142  return false;
143 
144  return lhs < rhs;
145  }
146  };
147 
148  typedef std::set<dtn::data::MetaBundle, CMP_BUNDLE_PRIORITY> prio_bundle_set;
149  prio_bundle_set _priority_index;
150 
151  typedef std::map<dtn::data::BundleID, dtn::data::Length> size_map;
152  size_map _bundle_lengths;
153  };
154  }
155 }
156 
157 #endif /* MEMORYBUNDLESTORAGE_H_ */