IBR-DTNSuite 0.6

daemon/src/CapsuleWorker.cpp

Go to the documentation of this file.
00001 /*
00002  * CapsuleWorker.cpp
00003  *
00004  *  Created on: 26.04.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #include "CapsuleWorker.h"
00009 #include <ibrdtn/data/PayloadBlock.h>
00010 #include "net/BundleReceivedEvent.h"
00011 #include <ibrdtn/utils/Clock.h>
00012 #include <ibrcommon/Logger.h>
00013 
00014 namespace dtn
00015 {
00016         namespace daemon
00017         {
00018                 CapsuleWorker::CapsuleWorker()
00019                 {
00020                         AbstractWorker::initialize("/bundle-in-bundle", true);
00021                 }
00022 
00023                 CapsuleWorker::~CapsuleWorker()
00024                 {
00025                 }
00026 
00027                 void CapsuleWorker::callbackBundleReceived(const dtn::data::Bundle &capsule)
00028                 {
00029                         try {
00030                                 const PayloadBlock &payload = capsule.getBlock<PayloadBlock>();
00031                                 ibrcommon::BLOB::iostream stream = payload.getBLOB().iostream();
00032 
00033                                 // read the number of bundles
00034                                 SDNV nob; (*stream) >> nob;
00035 
00036                                 // read all offsets
00037                                 for (size_t i = 0; i < (nob.getValue() - 1); i++)
00038                                 {
00039                                         SDNV offset; (*stream) >> offset;
00040                                 }
00041 
00042                                 // create a deserializer for all bundles
00043                                 dtn::data::DefaultDeserializer deserializer(*stream);
00044                                 dtn::data::Bundle b;
00045 
00046                                 try {
00047                                         // read all bundles
00048                                         for (size_t i = 0; i < nob.getValue(); i++)
00049                                         {
00050                                                 // deserialize the next bundle
00051                                                 deserializer >> b;
00052 
00053                                                 // raise default bundle received event
00054                                                 dtn::net::BundleReceivedEvent::raise(capsule._source, b);
00055                                         }
00056                                 }
00057                                 catch (const dtn::InvalidDataException &ex) {
00058                                         // display the rejection
00059                                         IBRCOMMON_LOGGER(warning) << "invalid bundle-data received: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
00060                                 }
00061                         } catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { };
00062                 }
00063         }
00064 }