• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

daemon/src/core/BundleStorage.cpp

Go to the documentation of this file.
00001 /*
00002  * BundleStorage.cpp
00003  *
00004  *  Created on: 24.03.2009
00005  *      Author: morgenro
00006  */
00007 
00008 #include "core/BundleCore.h"
00009 #include "core/BundleStorage.h"
00010 #include "core/CustodyEvent.h"
00011 #include "core/BundleGeneratedEvent.h"
00012 #include <ibrdtn/data/BundleID.h>
00013 
00014 namespace dtn
00015 {
00016         namespace core
00017         {
00018                 BundleStorage::BundleStorage()
00019                 {
00020                 }
00021 
00022                 BundleStorage::~BundleStorage()
00023                 {
00024                 }
00025 
00026                 void BundleStorage::remove(const dtn::data::Bundle &b)
00027                 {
00028                         remove(dtn::data::BundleID(b));
00029                 };
00030 
00031                 const dtn::data::EID BundleStorage::acceptCustody(const dtn::data::MetaBundle &meta)
00032                 {
00033                         if (!meta.get(Bundle::CUSTODY_REQUESTED))
00034                                 throw ibrcommon::Exception("custody transfer is not requested for this bundle.");
00035 
00036                         if (meta.custodian == EID())
00037                                 throw ibrcommon::Exception("no previous custodian is set.");
00038 
00039                         // create a new bundle
00040                         Bundle custody_bundle;
00041 
00042                         // set priority to HIGH
00043                         custody_bundle.set(dtn::data::PrimaryBlock::PRIORITY_BIT1, false);
00044                         custody_bundle.set(dtn::data::PrimaryBlock::PRIORITY_BIT2, true);
00045 
00046                         // send a custody signal with accept flag
00047                         CustodySignalBlock &signal = custody_bundle.push_back<CustodySignalBlock>();
00048 
00049                         // set the bundle to match
00050                         signal.setMatch(meta);
00051 
00052                         // set accepted
00053                         signal._status |= 1;
00054 
00055                         custody_bundle.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true);
00056                         custody_bundle._destination = meta.custodian;
00057                         custody_bundle._source = dtn::core::BundleCore::local;
00058 
00059                         // send the custody accepted bundle
00060                         dtn::core::BundleGeneratedEvent::raise(custody_bundle);
00061 
00062                         // raise the custody accepted event
00063                         dtn::core::CustodyEvent::raise(meta, CUSTODY_ACCEPT);
00064 
00065                         return dtn::core::BundleCore::local;
00066                 }
00067 
00068                 void BundleStorage::rejectCustody(const dtn::data::MetaBundle &meta)
00069                 {
00070                         if (!meta.get(Bundle::CUSTODY_REQUESTED))
00071                                 throw ibrcommon::Exception("custody transfer is not requested for this bundle.");
00072 
00073                         if (meta.custodian == EID())
00074                                 throw ibrcommon::Exception("no previous custodian is set.");
00075 
00076                         // create a new bundle
00077                         Bundle b;
00078 
00079                         // send a custody signal with reject flag
00080                         CustodySignalBlock &signal = b.push_back<CustodySignalBlock>();
00081 
00082                         // set the bundle to match
00083                         signal.setMatch(meta);
00084 
00085                         b._destination = meta.custodian;
00086                         b._source = BundleCore::local;
00087 
00088                         // send the custody rejected bundle
00089                         dtn::core::BundleGeneratedEvent::raise(b);
00090 
00091                         // raise the custody rejected event
00092                         dtn::core::CustodyEvent::raise(b, CUSTODY_REJECT);
00093                 }
00094         }
00095 }

Generated on Wed Mar 30 2011 11:11:49 for IBR-DTNSuite by  doxygen 1.7.1