IBR-DTNSuite  0.10
Registration.h
Go to the documentation of this file.
1 /*
2  * Registration.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 REGISTRATION_H_
23 #define REGISTRATION_H_
24 
25 #include "storage/BundleStorage.h"
26 #include "storage/BundleResult.h"
27 #include <ibrdtn/data/BundleID.h>
28 #include <ibrdtn/data/BundleSet.h>
29 #include <ibrcommon/thread/Queue.h>
30 #include <ibrcommon/thread/Mutex.h>
31 #include <ibrcommon/thread/Timer.h>
32 #include <string>
33 #include <set>
34 
35 namespace dtn
36 {
37  namespace api
38  {
40  {
41  public:
42  static const std::string TAG;
43 
45  {
50  };
51 
53  {
54  public:
55  RegistrationException(string what = "") throw() : Exception(what)
56  {
57  }
58  };
59 
61  {
62  public:
64  {
65  }
66  };
67 
69  {
70  public:
72  {
73  }
74  };
75 
77  {
78  public:
80  {
81  }
82  };
83 
87  Registration();
88 
92  virtual ~Registration();
93 
97  void notify(const NOTIFY_CALL);
98 
103  NOTIFY_CALL wait();
104 
108  void wait_for_bundle(size_t timeout = 0);
109 
113  void subscribe(const dtn::data::EID &endpoint);
114 
118  void unsubscribe(const dtn::data::EID &endpoint);
119 
125  bool hasSubscribed(const dtn::data::EID &endpoint);
126 
130  const std::set<dtn::data::EID> getSubscriptions();
131 
135  bool operator==(const std::string&) const;
136 
140  bool operator==(const Registration&) const;
141 
145  bool operator<(const Registration&) const;
146 
153  dtn::data::Bundle receive() throw (dtn::storage::NoBundleFoundException);
154 
155  dtn::data::MetaBundle receiveMetaBundle() throw (dtn::storage::NoBundleFoundException);
156 
161  void delivered(const dtn::data::MetaBundle &m) const;
162 
167  const dtn::data::EID& getDefaultEID() const;
168 
173  const std::string& getHandle() const;
174 
178  void abort();
179 
184  void reset();
185 
190  void setPersistent(ibrcommon::Timer::time_t lifetime);
191 
195  void unsetPersistent();
196 
202  bool isPersistent();
203 
208  bool isPersistent() const;
209 
213  void setFilterFragments(bool val);
214 
221  ibrcommon::Timer::time_t getExpireTime() const;
222 
227  void attach();
228 
232  void detach();
233 
237  static void processIncomingBundle(const dtn::data::EID &source, dtn::data::Bundle &bundle);
238 
239  protected:
240  void underflow();
241 
242  private:
243  class RegistrationQueue : public dtn::storage::BundleResult {
244  public:
248  RegistrationQueue();
249 
253  virtual ~RegistrationQueue();
254 
260  virtual void put(const dtn::data::MetaBundle &bundle) throw ();
261 
267  dtn::data::MetaBundle pop() throw (const ibrcommon::QueueUnblockedException);
268 
272  void expire(const dtn::data::Timestamp &timestamp) throw ();
273 
277  void abort() throw ();
278 
282  void reset() throw ();
283 
287  bool has(const dtn::data::BundleID &bundle) const throw ();
288 
289  private:
290  // protect variables against concurrent altering
291  ibrcommon::Mutex _lock;
292 
293  // all bundles have to remain in this set to avoid duplicate delivery
294  dtn::data::BundleSet _recv_bundles;
295 
296  // queue where the currently queued bundles are stored
297  ibrcommon::Queue<dtn::data::MetaBundle> _queue;
298  };
299 
300  const std::string _handle;
301  const dtn::data::EID _default_eid;
302 
303  ibrcommon::Mutex _endpoints_lock;
304  std::set<dtn::data::EID> _endpoints;
305  RegistrationQueue _queue;
306 
307  ibrcommon::Mutex _receive_lock;
308  ibrcommon::Conditional _wait_for_cond;
309  bool _no_more_bundles;
310 
311  ibrcommon::Queue<NOTIFY_CALL> _notify_queue;
312 
313  static const std::string alloc_handle();
314  static void free_handle(const std::string &handle);
315 
316  static std::set<std::string> _handles;
317 
318  bool _persistent;
319  bool _detached;
320  ibrcommon::Mutex _attach_lock;
321  ibrcommon::Timer::time_t _expiry;
322 
323  bool _filter_fragments;
324  };
325  }
326 }
327 
328 #endif /* REGISTRATION_H_ */