• 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/data/PayloadBlock.h"
00010 #include "ibrdtn/data/Exceptions.h"
00011 
00012 namespace dtn
00013 {
00014         namespace api
00015         {
00016                 Bundle::Bundle()
00017                 {
00018                         setPriority(PRIO_MEDIUM);
00019                         _b._source = dtn::data::EID("api:me");
00020                 }
00021 
00022                 Bundle::Bundle(const dtn::data::Bundle &b)
00023                  : _b(b)
00024                 {
00025                 }
00026 
00027                 Bundle::Bundle(const dtn::data::EID &destination)
00028                 {
00029                         setDestination(destination);
00030                         setPriority(PRIO_MEDIUM);
00031                         _b._source = dtn::data::EID("api:me");
00032                 }
00033 
00034                 Bundle::~Bundle()
00035                 {
00036                 }
00037 
00038                 void Bundle::setLifetime(unsigned int lifetime)
00039                 {
00040                         _b._lifetime = lifetime;
00041                 }
00042 
00043                 unsigned int Bundle::getLifetime() const
00044                 {
00045                         return _b._lifetime;
00046                 }
00047 
00048                 void Bundle::requestDeliveredReport()
00049                 {
00050                         _b.set(dtn::data::PrimaryBlock::REQUEST_REPORT_OF_BUNDLE_DELIVERY, true);
00051                 }
00052 
00053                 void Bundle::requestForwardedReport()
00054                 {
00055                         _b.set(dtn::data::PrimaryBlock::REQUEST_REPORT_OF_BUNDLE_FORWARDING, true);
00056                 }
00057 
00058                 void Bundle::requestDeletedReport()
00059                 {
00060                         _b.set(dtn::data::PrimaryBlock::REQUEST_REPORT_OF_BUNDLE_DELETION, true);
00061                 }
00062 
00063                 void Bundle::requestReceptionReport()
00064                 {
00065                         _b.set(dtn::data::PrimaryBlock::REQUEST_REPORT_OF_BUNDLE_RECEPTION, true);
00066                 }
00067 
00068                 void Bundle::requestCustodyTransfer()
00069                 {
00070                         _b.set(dtn::data::PrimaryBlock::CUSTODY_REQUESTED, true);
00071                         _b._custodian = dtn::data::EID("api:me");
00072                 }
00073 
00074                 void Bundle::requestEncryption()
00075                 {
00076                         _b.set(dtn::data::PrimaryBlock::DTNSEC_REQUEST_ENCRYPT, true);
00077                 }
00078 
00079                 void Bundle::requestSigned()
00080                 {
00081                         _b.set(dtn::data::PrimaryBlock::DTNSEC_REQUEST_SIGN, true);
00082                 }
00083 
00084                 bool Bundle::statusVerified()
00085                 {
00086                         return _b.get(dtn::data::PrimaryBlock::DTNSEC_STATUS_VERIFIED);
00087                 }
00088 
00089                 Bundle::BUNDLE_PRIORITY Bundle::getPriority() const
00090                 {
00091                         if (_b.get(dtn::data::Bundle::PRIORITY_BIT1))
00092                         {
00093                                 return PRIO_MEDIUM;
00094                         }
00095 
00096                         if (_b.get(dtn::data::Bundle::PRIORITY_BIT2))
00097                         {
00098                                 return PRIO_HIGH;
00099                         }
00100 
00101                         return PRIO_LOW;
00102                 }
00103 
00104                 void Bundle::setPriority(Bundle::BUNDLE_PRIORITY p)
00105                 {
00106                         // set the priority to the real bundle
00107                         switch (p)
00108                         {
00109                         case PRIO_LOW:
00110                                 _b.set(dtn::data::Bundle::PRIORITY_BIT1, false);
00111                                 _b.set(dtn::data::Bundle::PRIORITY_BIT2, false);
00112                                 break;
00113 
00114                         case PRIO_HIGH:
00115                                 _b.set(dtn::data::Bundle::PRIORITY_BIT1, false);
00116                                 _b.set(dtn::data::Bundle::PRIORITY_BIT2, true);
00117                                 break;
00118 
00119                         case PRIO_MEDIUM:
00120                                 _b.set(dtn::data::Bundle::PRIORITY_BIT1, true);
00121                                 _b.set(dtn::data::Bundle::PRIORITY_BIT2, false);
00122                                 break;
00123                         }
00124                 }
00125 
00126                 void Bundle::setDestination(const dtn::data::EID &eid, const bool singleton)
00127                 {
00128                         if (singleton)
00129                                 _b.set(dtn::data::Bundle::DESTINATION_IS_SINGLETON, true);
00130                         else
00131                                 _b.set(dtn::data::Bundle::DESTINATION_IS_SINGLETON, false);
00132 
00133                         _b._destination = eid;
00134                 }
00135 
00136                 void Bundle::setReportTo(const dtn::data::EID &eid)
00137                 {
00138                         _b._reportto = eid;
00139                 }
00140 
00141                 dtn::data::EID Bundle::getReportTo() const
00142                 {
00143                         return _b._reportto;
00144                 }
00145 
00146                 dtn::data::EID Bundle::getDestination() const
00147                 {
00148                         return _b._destination;
00149                 }
00150 
00151                 dtn::data::EID Bundle::getSource() const
00152                 {
00153                         return _b._source;
00154                 }
00155 
00156                 dtn::data::EID Bundle::getCustodian() const
00157                 {
00158                         return _b._custodian;
00159                 }
00160 
00161                 ibrcommon::BLOB::Reference Bundle::getData() throw (dtn::MissingObjectException)
00162                 {
00163                         try {
00164                                 dtn::data::PayloadBlock &p = _b.getBlock<dtn::data::PayloadBlock>();
00165                                 return p.getBLOB();
00166                         } catch(const dtn::data::Bundle::NoSuchBlockFoundException&) {
00167                                 throw dtn::MissingObjectException("No payload block exists!");
00168                         }
00169                 }
00170 
00171                 bool Bundle::operator<(const Bundle& other) const
00172                 {
00173                         return (_b < other._b);
00174                 }
00175 
00176                 bool Bundle::operator>(const Bundle& other) const
00177                 {
00178                         return (_b > other._b);
00179                 }
00180         }
00181 }

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