IBR-DTNSuite 0.6

daemon/src/api/Registration.h

Go to the documentation of this file.
00001 /*
00002  * Registration.h
00003  *
00004  *  Created on: 15.06.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef REGISTRATION_H_
00009 #define REGISTRATION_H_
00010 
00011 #include "core/BundleStorage.h"
00012 #include <ibrdtn/data/BundleID.h>
00013 #include <ibrdtn/data/BundleList.h>
00014 #include <ibrcommon/thread/Queue.h>
00015 #include <string>
00016 #include <set>
00017 
00018 namespace dtn
00019 {
00020         namespace api
00021         {
00022                 class Registration
00023                 {
00024                 public:
00025                         enum NOTIFY_CALL
00026                         {
00027                                 NOTIFY_BUNDLE_AVAILABLE = 0,
00028                                 NOTIFY_NEIGHBOR_AVAILABLE = 1,
00029                                 NOTIFY_NEIGHBOR_UNAVAILABLE = 2,
00030                                 NOTIFY_SHUTDOWN = 3
00031                         };
00032 
00036                         Registration();
00037 
00041                         virtual ~Registration();
00042 
00046                         void notify(const NOTIFY_CALL);
00047 
00052                         NOTIFY_CALL wait();
00053 
00057                         void wait_for_bundle();
00058 
00062                         void subscribe(const dtn::data::EID &endpoint);
00063 
00067                         void unsubscribe(const dtn::data::EID &endpoint);
00068 
00074                         bool hasSubscribed(const dtn::data::EID &endpoint) const;
00075 
00079                         const std::set<dtn::data::EID>& getSubscriptions() const;
00080 
00084                         bool operator==(const std::string&) const;
00085 
00089                         bool operator==(const Registration&) const;
00090 
00094                         bool operator<(const Registration&) const;
00095 
00102                         dtn::data::Bundle receive() throw (dtn::core::BundleStorage::NoBundleFoundException);
00103 
00108                         void delivered(const dtn::data::MetaBundle &m);
00109 
00114                         const std::string& getHandle() const;
00115 
00119                         void abort();
00120 
00121                 protected:
00122                         void underflow();
00123 
00124                 private:
00125                         ibrcommon::Queue<dtn::data::MetaBundle> _queue;
00126                         const std::string _handle;
00127                         std::set<dtn::data::EID> _endpoints;
00128                         dtn::data::BundleList _received_bundles;
00129 
00130                         ibrcommon::Mutex _receive_lock;
00131                         ibrcommon::Conditional _wait_for_cond;
00132                         bool _no_more_bundles;
00133 
00134                         ibrcommon::Queue<NOTIFY_CALL> _notify_queue;
00135 
00136                         static const std::string alloc_handle();
00137                         static void free_handle(const std::string &handle);
00138 
00139                         static std::set<std::string> _handles;
00140                 };
00141         }
00142 }
00143 
00144 #endif /* REGISTRATION_H_ */