IBR-DTN  1.0.0
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 "core/TimeEvent.h"
28 #include "storage/BundleStorage.h"
29 #include "core/Node.h"
30 #include "core/EventReceiver.h"
31 
32 #include <ibrdtn/data/Bundle.h>
33 #include <ibrdtn/data/BundleList.h>
34 
35 namespace dtn
36 {
37  namespace storage
38  {
40  {
41  static const std::string TAG;
42 
43  public:
44  MemoryBundleStorage(const dtn::data::Length maxsize = 0);
45  virtual ~MemoryBundleStorage();
46 
51  virtual void store(const dtn::data::Bundle &bundle);
52 
57  virtual bool contains(const dtn::data::BundleID &id);
58 
63 
70  virtual dtn::data::Bundle get(const dtn::data::BundleID &id);
71 
75  virtual void get(const BundleSelector &cb, BundleResult &result) throw (NoBundleFoundException, BundleSelectorException);
76 
80  virtual const eid_set getDistinctDestinations();
81 
87  void remove(const dtn::data::BundleID &id);
88 
92  void clear();
93 
97  bool empty();
98 
103 
107  void releaseCustody(const dtn::data::EID &custodian, const dtn::data::BundleID &id);
108 
113  void raiseEvent(const dtn::core::TimeEvent &evt) throw ();
114 
118  virtual const std::string getName() const;
119 
120  protected:
121  virtual void componentUp() throw ();
122  virtual void componentDown() throw ();
123 
124  virtual void eventBundleExpired(const dtn::data::MetaBundle &b) throw ();
125 
126  private:
127  ibrcommon::Mutex _bundleslock;
128 
129  typedef std::set<dtn::data::Bundle> bundle_list;
130  bundle_list _bundles;
131  dtn::data::BundleList _list;
132 
133  void __erase(const bundle_list::iterator &iter);
134 
135  struct CMP_BUNDLE_PRIORITY
136  {
137  bool operator() (const dtn::data::MetaBundle& lhs, const dtn::data::MetaBundle& rhs) const
138  {
139  if (lhs.getPriority() > rhs.getPriority())
140  return true;
141 
142  if (lhs.getPriority() != rhs.getPriority())
143  return false;
144 
145  return lhs < rhs;
146  }
147  };
148 
149  typedef std::set<dtn::data::MetaBundle, CMP_BUNDLE_PRIORITY> prio_bundle_set;
150  prio_bundle_set _priority_index;
151 
152  typedef std::map<dtn::data::BundleID, dtn::data::Length> size_map;
153  size_map _bundle_lengths;
154  };
155  }
156 }
157 
158 #endif /* MEMORYBUNDLESTORAGE_H_ */
int getPriority() const
Definition: MetaBundle.cpp:144
virtual dtn::data::MetaBundle info(const dtn::data::BundleID &id)
std::set< dtn::data::EID > eid_set
Definition: BundleSeeker.h:39
size_t Length
Definition: Number.h:33
virtual void store(const dtn::data::Bundle &bundle)
MemoryBundleStorage(const dtn::data::Length maxsize=0)
void releaseCustody(const dtn::data::EID &custodian, const dtn::data::BundleID &id)
virtual const eid_set getDistinctDestinations()
virtual bool contains(const dtn::data::BundleID &id)
virtual const std::string getName() const
size_t Size
Definition: Number.h:34
virtual void eventBundleExpired(const dtn::data::MetaBundle &b)
void raiseEvent(const dtn::core::TimeEvent &evt)