IBR-DTNSuite  0.12
BundleSet.h
Go to the documentation of this file.
1 /*
2  * BundleSet.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  * Created on: 18.12.2012
21  */
22 
23 #ifndef BUNDLESET_H_
24 #define BUNDLESET_H_
25 
27 #include "ibrdtn/data/MetaBundle.h"
29 #include <set>
30 
31 namespace dtn
32 {
33  namespace data
34  {
35  class BundleSet
36  {
37  public:
38  class Listener {
39  public:
40  virtual ~Listener() = 0;
41  virtual void eventBundleExpired(const dtn::data::MetaBundle&) = 0;
42  };
43 
44  class Factory {
45  public:
46  virtual ~Factory() = 0;
47 
48  virtual BundleSetImpl* create(Listener* listener, Size bf_size) = 0;
49  virtual BundleSetImpl* create(const std::string &name, Listener* listener, Size bf_size) = 0;
50  };
51 
56  BundleSet(BundleSet::Listener *listener = NULL, Length bf_size = 1024);
57 
62  BundleSet(const std::string &name, BundleSet::Listener *listener = NULL, Length bf_size = 1024);
63 
67  virtual ~BundleSet();
68 
72  BundleSet(const BundleSet&);
73 
77  BundleSet& operator=(const BundleSet&);
78 
82  virtual void add(const dtn::data::MetaBundle &bundle) throw ();
83 
87  virtual void clear() throw ();
88 
92  virtual bool has(const dtn::data::BundleID &bundle) const throw ();
93 
97  virtual void expire(const Timestamp timestamp) throw ();
98 
102  virtual Size size() const throw ();
103 
107  Length getLength() const throw ();
108 
112  const ibrcommon::BloomFilter& getBloomFilter() const throw ();
113 
117  std::set<dtn::data::MetaBundle> getNotIn(const ibrcommon::BloomFilter &filter) const throw ();
118 
122  void sync() throw ();
123 
124  std::ostream& serialize(std::ostream &stream) const;
125  std::istream& deserialize(std::istream &stream);
126 
127  friend std::ostream &operator<<(std::ostream &stream, const BundleSet &obj);
128  friend std::istream &operator>>(std::istream &stream, BundleSet &obj);
129 
133  static void setFactory(dtn::data::BundleSet::Factory*);
134 
135  private:
136  static BundleSetImpl* __create(Listener* listener, Size bf_size);
137  static BundleSetImpl* __create(const std::string &name, Listener* listener, Size bf_size);
138 
139  refcnt_ptr<BundleSetImpl> _set_impl;
140 
144  static dtn::data::BundleSet::Factory *__factory__;
145  };
146  } /* namespace data */
147 } /* namespace dtn */
148 #endif /* BUNDLESET_H_ */