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