IBR-DTNSuite
0.8
|
00001 /* 00002 * BundleStorage.h 00003 * 00004 * Created on: 24.03.2009 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef BUNDLESTORAGE_H_ 00009 #define BUNDLESTORAGE_H_ 00010 00011 #include <ibrdtn/data/Bundle.h> 00012 #include <ibrdtn/data/BundleID.h> 00013 #include <ibrdtn/data/MetaBundle.h> 00014 #include <ibrdtn/data/CustodySignalBlock.h> 00015 #include <ibrcommon/data/BloomFilter.h> 00016 00017 #include <stdexcept> 00018 #include <iterator> 00019 #include <set> 00020 00021 namespace dtn 00022 { 00023 namespace storage 00024 { 00025 class BundleStorage 00026 { 00027 public: 00028 class NoBundleFoundException : public dtn::MissingObjectException 00029 { 00030 public: 00031 NoBundleFoundException(string what = "No bundle match the specified criteria.") throw() : dtn::MissingObjectException(what) 00032 { 00033 }; 00034 }; 00035 00036 class BundleLoadException : public NoBundleFoundException 00037 { 00038 public: 00039 BundleLoadException(string what = "Error while loading bundle data.") throw() : NoBundleFoundException(what) 00040 { 00041 }; 00042 }; 00043 00044 class StorageSizeExeededException : public ibrcommon::Exception 00045 { 00046 public: 00047 StorageSizeExeededException(string what = "No space left in the storage.") throw() : ibrcommon::Exception(what) 00048 { 00049 }; 00050 }; 00051 00052 class BundleFilterCallback 00053 { 00054 public: 00055 virtual ~BundleFilterCallback() {}; 00056 00061 virtual size_t limit() const { return 1; }; 00062 00069 virtual bool shouldAdd(const dtn::data::MetaBundle&) const { return false; }; 00070 }; 00071 00075 virtual ~BundleStorage() = 0; 00076 00081 virtual void store(const dtn::data::Bundle &bundle) = 0; 00082 00088 virtual dtn::data::Bundle get(const dtn::data::BundleID &id) = 0; 00089 00096 virtual const std::list<dtn::data::MetaBundle> get(BundleFilterCallback &cb) = 0; 00097 00102 virtual const std::set<dtn::data::EID> getDistinctDestinations() = 0; 00103 00109 virtual void remove(const dtn::data::BundleID &id) = 0; 00110 00116 void remove(const dtn::data::Bundle &b); 00117 00123 virtual dtn::data::MetaBundle remove(const ibrcommon::BloomFilter &filter); 00124 00128 virtual void clear() {}; 00129 00133 virtual bool empty() { return true; }; 00134 00138 virtual unsigned int count() { return 0; }; 00139 00145 virtual void releaseCustody(const dtn::data::EID &custodian, const dtn::data::BundleID &id) = 0; 00146 00153 const dtn::data::EID acceptCustody(const dtn::data::MetaBundle &meta); 00154 00160 void rejectCustody(const dtn::data::MetaBundle &meta, dtn::data::CustodySignalBlock::REASON_CODE reason = dtn::data::CustodySignalBlock::NO_ADDITIONAL_INFORMATION); 00161 00162 protected: 00166 BundleStorage(); 00167 }; 00168 } 00169 } 00170 00171 #endif /* BUNDLESTORAGE_H_ */