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

ibrdtn/ibrdtn/api/Bundle.cpp

Go to the documentation of this file.
00001 /*
00002  * Bundle.cpp
00003  *
00004  *  Created on: 24.07.2009
00005  *      Author: morgenro
00006  */
00007 
00008 #include "ibrdtn/api/Bundle.h"
00009 #include "ibrdtn/api/SecurityManager.h"
00010 #include "ibrdtn/data/PayloadBlock.h"
00011 #include "ibrdtn/data/Exceptions.h"
00012 
00013 namespace dtn
00014 {
00015         namespace api
00016         {
00017                 Bundle::Bundle()
00018                  : _priority(PRIO_MEDIUM)
00019                 {
00020                         _security = SecurityManager::getDefault();
00021                         setPriority(PRIO_MEDIUM);
00022 
00023                         _b._source = dtn::data::EID("api:me");
00024                 }
00025 
00026                 Bundle::Bundle(dtn::data::Bundle &b)
00027                  : _b(b), _priority(PRIO_MEDIUM)
00028                 {
00029                         // read priority
00030                         if (_b._procflags & dtn::data::Bundle::PRIORITY_BIT1)
00031                         {
00032                                 _priority = PRIO_MEDIUM;
00033                         }
00034                         else
00035                         {
00036                                 if (_b._procflags & dtn::data::Bundle::PRIORITY_BIT2) _priority = PRIO_HIGH;
00037                                 else _priority = PRIO_LOW;
00038                         }
00039                 }
00040 
00041                 Bundle::Bundle(dtn::data::EID destination)
00042                  : _priority(PRIO_MEDIUM)
00043                 {
00044                         _b._destination = destination;
00045                         _security = SecurityManager::getDefault();
00046                         setPriority(PRIO_MEDIUM);
00047                 }
00048 
00049                 Bundle::~Bundle()
00050                 {
00051                 }
00052 
00053                 void Bundle::setLifetime(unsigned int lifetime)
00054                 {
00055                         _lifetime = lifetime;
00056 
00057                         // set the lifetime
00058                         _b._lifetime = _lifetime;
00059                 }
00060 
00061                 unsigned int Bundle::getLifetime()
00062                 {
00063                         return _lifetime;
00064                 }
00065 
00066                 void Bundle::requestDeliveredReport()
00067                 {
00068                         _b.set(dtn::data::PrimaryBlock::REQUEST_REPORT_OF_BUNDLE_DELIVERY, true);
00069                 }
00070 
00071                 void Bundle::requestForwardedReport()
00072                 {
00073                         _b.set(dtn::data::PrimaryBlock::REQUEST_REPORT_OF_BUNDLE_FORWARDING, true);
00074                 }
00075 
00076                 void Bundle::requestDeletedReport()
00077                 {
00078                         _b.set(dtn::data::PrimaryBlock::REQUEST_REPORT_OF_BUNDLE_DELETION, true);
00079                 }
00080 
00081                 void Bundle::requestReceptionReport()
00082                 {
00083                         _b.set(dtn::data::PrimaryBlock::REQUEST_REPORT_OF_BUNDLE_RECEPTION, true);
00084                 }
00085 
00086                 Bundle::BUNDLE_PRIORITY Bundle::getPriority()
00087                 {
00088                         return _priority;
00089                 }
00090 
00091                 void Bundle::setPriority(Bundle::BUNDLE_PRIORITY p)
00092                 {
00093                         _priority = p;
00094 
00095                         // set the priority to the real bundle
00096                         switch (_priority)
00097                         {
00098                         case PRIO_LOW:
00099                                 _b._procflags &= ~(dtn::data::Bundle::PRIORITY_BIT1);
00100                                 _b._procflags &= ~(dtn::data::Bundle::PRIORITY_BIT2);
00101                                 break;
00102 
00103                         case PRIO_HIGH:
00104                                 _b._procflags &= ~(dtn::data::Bundle::PRIORITY_BIT1);
00105                                 _b._procflags |= dtn::data::Bundle::PRIORITY_BIT2;
00106                                 break;
00107 
00108                         case PRIO_MEDIUM:
00109                                 _b._procflags |= dtn::data::Bundle::PRIORITY_BIT1;
00110                                 _b._procflags &= ~(dtn::data::Bundle::PRIORITY_BIT2);
00111                                 break;
00112                         }
00113                 }
00114 
00115 
00116                 dtn::data::EID Bundle::getDestination()
00117                 {
00118                         return _b._destination;
00119                 }
00120 
00121                 void Bundle::setReportTo(const dtn::data::EID &eid)
00122                 {
00123                         _b._reportto = eid;
00124                 }
00125 
00126                 dtn::data::EID Bundle::getSource()
00127                 {
00128                         return _b._source;
00129                 }
00130 
00131                 ibrcommon::BLOB::Reference Bundle::getData()
00132                 {
00133                         try {
00134                                 dtn::data::PayloadBlock &p = _b.getBlock<dtn::data::PayloadBlock>();
00135                                 return p.getBLOB();
00136                         } catch(dtn::data::Bundle::NoSuchBlockFoundException ex) {
00137                                 throw dtn::MissingObjectException("No payload block exists!");
00138                         }
00139                 }
00140 
00141                 bool Bundle::operator<(const Bundle& other) const
00142                 {
00143                         return (_b < other._b);
00144                 }
00145 
00146                 bool Bundle::operator>(const Bundle& other) const
00147                 {
00148                         return (_b > other._b);
00149                 }
00150         }
00151 }
00152 

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