IBR-DTNSuite 0.6

daemon/src/core/MemoryBundleStorage.h

Go to the documentation of this file.
00001 /*
00002  * MemoryBundleStorage.h
00003  *
00004  *  Created on: 22.11.2010
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef MEMORYBUNDLESTORAGE_H_
00009 #define MEMORYBUNDLESTORAGE_H_
00010 
00011 #include "Component.h"
00012 #include "core/BundleCore.h"
00013 #include "core/BundleStorage.h"
00014 #include "core/Node.h"
00015 #include "core/EventReceiver.h"
00016 
00017 #include <ibrdtn/data/Bundle.h>
00018 #include <ibrdtn/data/BundleList.h>
00019 
00020 namespace dtn
00021 {
00022         namespace core
00023         {
00024                 class MemoryBundleStorage : public BundleStorage, public EventReceiver, public dtn::daemon::IntegratedComponent, private dtn::data::BundleList
00025                 {
00026                 public:
00027                         MemoryBundleStorage(size_t maxsize = 0);
00028                         virtual ~MemoryBundleStorage();
00029 
00034                         virtual void store(const dtn::data::Bundle &bundle);
00035 
00042                         virtual dtn::data::Bundle get(const dtn::data::BundleID &id);
00043 
00047                         virtual const std::list<dtn::data::MetaBundle> get(BundleFilterCallback &cb);
00048 
00054                         void remove(const dtn::data::BundleID &id);
00055 
00061                         dtn::data::MetaBundle remove(const ibrcommon::BloomFilter &filter);
00062 
00066                         void clear();
00067 
00071                         bool empty();
00072 
00076                         unsigned int count();
00077 
00081                         size_t size() const;
00082 
00086                         void releaseCustody(const dtn::data::EID &custodian, const dtn::data::BundleID &id);
00087 
00092                         void raiseEvent(const Event *evt);
00093 
00097                         virtual const std::string getName() const;
00098 
00099                 protected:
00100                         virtual void componentUp();
00101                         virtual void componentDown();
00102 
00103                         virtual void eventBundleExpired(const ExpiringBundle &b);
00104 
00105                 private:
00106                         ibrcommon::Mutex _bundleslock;
00107                         std::set<dtn::data::Bundle> _bundles;
00108 
00109                         struct CMP_BUNDLE_PRIORITY
00110                         {
00111                                 bool operator() (const dtn::data::MetaBundle& lhs, const dtn::data::MetaBundle& rhs) const
00112                                 {
00113                                         if (lhs.getPriority() == rhs.getPriority())
00114                                                 return rhs > lhs;
00115 
00116                                         return (lhs.getPriority() > rhs.getPriority());
00117                                 }
00118                         };
00119 
00120                         std::set<dtn::data::MetaBundle, CMP_BUNDLE_PRIORITY> _priority_index;
00121 
00122                         size_t _maxsize;
00123                         size_t _currentsize;
00124                 };
00125         }
00126 }
00127 
00128 #endif /* MEMORYBUNDLESTORAGE_H_ */