27 #include <ibrcommon/thread/MutexLock.h>
28 #include <ibrcommon/Logger.h>
35 : _faulty(false), _maxsize(maxsize), _currentsize(0)
50 if (!meta.
get(Bundle::CUSTODY_REQUESTED))
51 throw ibrcommon::Exception(
"custody transfer is not requested for this bundle.");
54 throw ibrcommon::Exception(
"no previous custodian is set.");
74 signal.
write(payload);
95 if (!meta.
get(Bundle::CUSTODY_REQUESTED))
96 throw ibrcommon::Exception(
"custody transfer is not requested for this bundle.");
99 throw ibrcommon::Exception(
"no previous custodian is set.");
115 signal.
write(payload);
138 ibrcommon::MutexLock l(_sizelock);
141 if ((_maxsize > 0) && (_currentsize + size > _maxsize))
147 _currentsize += size;
152 ibrcommon::MutexLock l(_sizelock);
153 if (size > _currentsize)
156 IBRCOMMON_LOGGER_TAG(
"BundleStorage", critical) <<
"More space to free than allocated." << IBRCOMMON_LOGGER_ENDL;
160 _currentsize -= size;
166 ibrcommon::MutexLock l(_sizelock);
172 IBRCOMMON_LOGGER_DEBUG_TAG(
"BundleStorage", 2) <<
"add bundle to index: " << b.toString() << IBRCOMMON_LOGGER_ENDL;
174 for (index_list::iterator it = _indexes.begin(); it != _indexes.end(); ++it) {
182 IBRCOMMON_LOGGER_DEBUG_TAG(
"BundleStorage", 2) <<
"remove bundle from index: " <<
id.toString() << IBRCOMMON_LOGGER_ENDL;
184 for (index_list::iterator it = _indexes.begin(); it != _indexes.end(); ++it) {
192 ibrcommon::MutexLock l(_index_lock);
193 _indexes.insert(index);
198 ibrcommon::MutexLock l(_index_lock);
199 _indexes.erase(index);
static void inject(const dtn::data::EID &source, dtn::data::Bundle &bundle)
static dtn::data::EID local
dtn::data::Length size() const
void attach(dtn::storage::BundleIndex *index)
virtual void write(dtn::data::PayloadBlock &p) const
const dtn::data::EID acceptCustody(const dtn::data::MetaBundle &meta)
virtual void add(const dtn::data::MetaBundle &b)=0
static void raise(const dtn::data::MetaBundle &bundle, const EventCustodyAction action)
virtual ~BundleStorage()=0
virtual void remove(const dtn::data::BundleID &id)=0
void detach(dtn::storage::BundleIndex *index)
void setMatch(const dtn::data::MetaBundle &other)
void rejectCustody(const dtn::data::MetaBundle &meta, dtn::data::CustodySignalBlock::REASON_CODE reason=dtn::data::CustodySignalBlock::NO_ADDITIONAL_INFORMATION)
void freeSpace(const dtn::data::Length &size)
virtual void remove(const dtn::data::BundleID &id)=0
void allocSpace(const dtn::data::Length &size)
void eventBundleAdded(const dtn::data::MetaBundle &b)
void eventBundleRemoved(const dtn::data::BundleID &id)
BundleStorage(const dtn::data::Length &maxsize)
void set(FLAGS flag, bool value)