• 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                         _destination_filter.insert(dtn::core::BundleCore::local);
00021                 }
00022 
00023                 BundleStorage::~BundleStorage()
00024                 {
00025                 }
00026 
00027                 void BundleStorage::addToFilter(const dtn::data::EID &eid)
00028                 {
00029                         _destination_filter.insert(eid);
00030                 }
00031 
00032                 void BundleStorage::remove(const dtn::data::Bundle &b)
00033                 {
00034                         remove(dtn::data::BundleID(b));
00035                 };
00036 
00037                 void BundleStorage::acceptCustody(dtn::data::Bundle &bundle)
00038                 {
00039                         if (bundle._custodian == EID()) return;
00040 
00041                         if (bundle._procflags & Bundle::CUSTODY_REQUESTED)
00042                         {
00043                                 // we are the new custodian for this bundle
00044                                 bundle._custodian = dtn::core::BundleCore::local;
00045 
00046                                 // create a new bundle
00047                                 Bundle b;
00048 
00049                                 // send a custody signal with accept flag
00050                                 CustodySignalBlock &signal = b.push_back<CustodySignalBlock>();
00051 
00052                                 // set the bundle to match
00053                                 signal.setMatch(bundle);
00054 
00055                                 // set accepted
00056                                 signal._status |= 1;
00057 
00058                                 b._destination = bundle._custodian;
00059                                 b._source = dtn::core::BundleCore::local;
00060 
00061                                 // send the custody accepted bundle
00062                                 dtn::core::BundleGeneratedEvent::raise(b);
00063 
00064                                 // raise the custody accepted event
00065                                 dtn::core::CustodyEvent::raise(b, CUSTODY_ACCEPT);
00066                         }
00067                 }
00068 
00069                 void BundleStorage::rejectCustody(const dtn::data::Bundle &bundle)
00070                 {
00071                         if (bundle._custodian == EID()) return;
00072 
00073                         if (bundle._procflags & Bundle::CUSTODY_REQUESTED)
00074                         {
00075                                 // create a new bundle
00076                                 Bundle b;
00077 
00078                                 // send a custody signal with reject flag
00079                                 CustodySignalBlock &signal = b.push_back<CustodySignalBlock>();
00080 
00081                                 // set the bundle to match
00082                                 signal.setMatch(bundle);
00083 
00084                                 b._destination = bundle._custodian;
00085                                 b._source = BundleCore::local;
00086 
00087                                 // send the custody rejected bundle
00088                                 dtn::core::BundleGeneratedEvent::raise(b);
00089 
00090                                 // raise the custody rejected event
00091                                 dtn::core::CustodyEvent::raise(b, CUSTODY_REJECT);
00092                         }
00093                 }
00094         }
00095 }

Generated on Thu Nov 11 2010 09:49:46 for IBR-DTNSuite by  doxygen 1.7.1