--- a/servlib/bundling/BPQBlock.cc Wed Oct 26 13:33:11 2011 +0100
+++ b/servlib/bundling/BPQBlock.cc Fri Jan 06 17:28:36 2012 +0000
@@ -19,6 +19,7 @@
#endif
#include "BPQBlock.h"
+#include "BPQFragmentList.h"
#include "Bundle.h"
#include "BundleProtocol.h"
#include "SDNV.h"
@@ -26,10 +27,13 @@
namespace dtn {
BPQBlock::BPQBlock(const Bundle* bundle)
- : Logger("BPQBlock", "/dtn/bundle/bpq")
+ : Logger("BPQBlock", "/dtn/bundle/bpq"),
+ fragments_("fragments")
{
log_info("constructor()");
+ //TODO: Handle an initialisation failure
+
if( bundle->recv_blocks().
has_block(BundleProtocol::QUERY_EXTENSION_BLOCK) ) {
@@ -61,6 +65,14 @@
free(query_val_);
query_val_ = NULL;
}
+
+ BPQFragmentList::iterator iter;
+ for (iter = fragments_.begin();
+ iter != fragments_.end();
+ ++iter) {
+
+ delete *iter;
+ }
}
//----------------------------------------------------------------------
@@ -137,13 +149,15 @@
}
// fragment-values SDNV
- BPQFragmentVec::const_iterator iter;
+ BPQFragmentList::const_iterator iter;
for (iter = fragments_.begin();
iter != fragments_.end();
++iter) {
+ BPQFragment* fragment = *iter;
+
if ( i < len &&
- (encoding_len = SDNV::encode (iter->offset(), &(buf[i]), len -i)) >= 0 ) {
+ (encoding_len = SDNV::encode (fragment->offset(), &(buf[i]), len -i)) >= 0 ) {
i += encoding_len;
} else {
log_err("Error encoding BPQ individual fragment offset");
@@ -151,7 +165,7 @@
}
if ( i < len &&
- (encoding_len = SDNV::encode (iter->length(), &(buf[i]), len -i)) >= 0 ) {
+ (encoding_len = SDNV::encode (fragment->length(), &(buf[i]), len -i)) >= 0 ) {
i += encoding_len;
} else {
log_err("Error encoding BPQ individual fragment length");
@@ -180,13 +194,15 @@
len += query_len_;
len += SDNV::encoding_len(frag_len());
- BPQFragmentVec::const_iterator iter;
+ BPQFragmentList::const_iterator iter;
for (iter = fragments_.begin();
iter != fragments_.end();
++iter) {
- len += SDNV::encoding_len(iter->offset());
- len += SDNV::encoding_len(iter->length());
+ BPQFragment* fragment = *iter;
+
+ len += SDNV::encoding_len(fragment->offset());
+ len += SDNV::encoding_len(fragment->length());
}
return len;
@@ -203,6 +219,13 @@
}
//----------------------------------------------------------------------
+void
+BPQBlock::add_fragment(BPQFragment* new_fragment)
+{
+ fragments_.insert_sorted(new_fragment);
+}
+
+//----------------------------------------------------------------------
int
BPQBlock::initialise(BlockInfo* block, bool created_locally, const Bundle* bundle)
{
@@ -523,8 +546,8 @@
return BP_FAIL;
}
- BPQFragment frag(frag_off, frag_len);
- this->add_fragment(frag);
+
+ add_fragment(new BPQFragment(frag_off, frag_len));
}
return BP_SUCCESS;