|
IBR-DTNSuite 0.6
|
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 void Bundle::requestCompression() 00085 { 00086 _b.set(dtn::data::PrimaryBlock::IBRDTN_REQUEST_COMPRESSION, true); 00087 } 00088 00089 bool Bundle::statusVerified() 00090 { 00091 return _b.get(dtn::data::PrimaryBlock::DTNSEC_STATUS_VERIFIED); 00092 } 00093 00094 Bundle::BUNDLE_PRIORITY Bundle::getPriority() const 00095 { 00096 if (_b.get(dtn::data::Bundle::PRIORITY_BIT1)) 00097 { 00098 return PRIO_MEDIUM; 00099 } 00100 00101 if (_b.get(dtn::data::Bundle::PRIORITY_BIT2)) 00102 { 00103 return PRIO_HIGH; 00104 } 00105 00106 return PRIO_LOW; 00107 } 00108 00109 void Bundle::setPriority(Bundle::BUNDLE_PRIORITY p) 00110 { 00111 // set the priority to the real bundle 00112 switch (p) 00113 { 00114 case PRIO_LOW: 00115 _b.set(dtn::data::Bundle::PRIORITY_BIT1, false); 00116 _b.set(dtn::data::Bundle::PRIORITY_BIT2, false); 00117 break; 00118 00119 case PRIO_HIGH: 00120 _b.set(dtn::data::Bundle::PRIORITY_BIT1, false); 00121 _b.set(dtn::data::Bundle::PRIORITY_BIT2, true); 00122 break; 00123 00124 case PRIO_MEDIUM: 00125 _b.set(dtn::data::Bundle::PRIORITY_BIT1, true); 00126 _b.set(dtn::data::Bundle::PRIORITY_BIT2, false); 00127 break; 00128 } 00129 } 00130 00131 void Bundle::setDestination(const dtn::data::EID &eid, const bool singleton) 00132 { 00133 if (singleton) 00134 _b.set(dtn::data::Bundle::DESTINATION_IS_SINGLETON, true); 00135 else 00136 _b.set(dtn::data::Bundle::DESTINATION_IS_SINGLETON, false); 00137 00138 _b._destination = eid; 00139 } 00140 00141 void Bundle::setReportTo(const dtn::data::EID &eid) 00142 { 00143 _b._reportto = eid; 00144 } 00145 00146 dtn::data::EID Bundle::getReportTo() const 00147 { 00148 return _b._reportto; 00149 } 00150 00151 dtn::data::EID Bundle::getDestination() const 00152 { 00153 return _b._destination; 00154 } 00155 00156 dtn::data::EID Bundle::getSource() const 00157 { 00158 return _b._source; 00159 } 00160 00161 dtn::data::EID Bundle::getCustodian() const 00162 { 00163 return _b._custodian; 00164 } 00165 00166 ibrcommon::BLOB::Reference Bundle::getData() throw (dtn::MissingObjectException) 00167 { 00168 try { 00169 dtn::data::PayloadBlock &p = _b.getBlock<dtn::data::PayloadBlock>(); 00170 return p.getBLOB(); 00171 } catch(const dtn::data::Bundle::NoSuchBlockFoundException&) { 00172 throw dtn::MissingObjectException("No payload block exists!"); 00173 } 00174 } 00175 00176 bool Bundle::operator<(const Bundle& other) const 00177 { 00178 return (_b < other._b); 00179 } 00180 00181 bool Bundle::operator>(const Bundle& other) const 00182 { 00183 return (_b > other._b); 00184 } 00185 } 00186 }