|
IBR-DTNSuite 0.6
|
00001 /* 00002 * Bundle.h 00003 * 00004 * Created on: 24.07.2009 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef API_BUNDLE_H_ 00009 #define API_BUNDLE_H_ 00010 00011 #include "ibrdtn/data/EID.h" 00012 #include "ibrdtn/data/Bundle.h" 00013 #include <ibrcommon/data/BLOB.h> 00014 00015 #include <iostream> 00016 #include <fstream> 00017 00018 namespace dtn 00019 { 00020 namespace api 00021 { 00026 class Bundle 00027 { 00028 public: 00035 enum BUNDLE_PRIORITY 00036 { 00037 PRIO_LOW = 0, 00038 PRIO_MEDIUM = 1, 00039 PRIO_HIGH = 2 00040 }; 00041 00045 Bundle(); 00046 00051 Bundle(const dtn::data::EID &destination); 00052 00056 virtual ~Bundle(); 00057 00062 void setLifetime(unsigned int lifetime); 00063 00068 unsigned int getLifetime() const; 00069 00074 void requestDeliveredReport(); 00075 00080 void requestForwardedReport(); 00081 00087 void requestDeletedReport(); 00088 00093 void requestReceptionReport(); 00094 00098 void requestCustodyTransfer(); 00099 00105 void requestEncryption(); 00106 00112 void requestSigned(); 00113 00117 void requestCompression(); 00118 00123 bool statusVerified(); 00124 00129 void setPriority(BUNDLE_PRIORITY p); 00130 00135 BUNDLE_PRIORITY getPriority() const; 00136 00144 friend std::ostream &operator<<(std::ostream &stream, const dtn::api::Bundle &b) 00145 { 00146 // To send a bundle, we construct a default serializer. Such a serializer convert 00147 // the bundle data to the standardized form as byte stream. 00148 dtn::data::DefaultSerializer(stream) << b._b; 00149 00150 // Since this method is used to serialize bundles into an StreamConnection, we need to call 00151 // a flush on the StreamConnection. This signals the stream to set the bundle end flag on 00152 // the last segment of streaming. 00153 stream.flush(); 00154 00155 // To support concatenation of streaming calls, we return the reference to the output stream. 00156 return stream; 00157 } 00158 00166 friend std::istream &operator>>(std::istream &stream, dtn::api::Bundle &b) 00167 { 00168 // To receive a bundle, we construct a default deserializer. Such a deserializer 00169 // convert a byte stream into a bundle object. If this deserialization fails 00170 // an exception will be thrown. 00171 dtn::data::DefaultDeserializer(stream) >> b._b; 00172 00173 // To support concatenation of streaming calls, we return the reference to the input stream. 00174 return stream; 00175 } 00176 00182 ibrcommon::BLOB::Reference getData() throw (dtn::MissingObjectException); 00183 00189 void setDestination(const dtn::data::EID &eid, const bool singleton = true); 00190 00196 void setReportTo(const dtn::data::EID &eid); 00197 00202 dtn::data::EID getDestination() const; 00203 00208 dtn::data::EID getSource() const; 00209 00214 dtn::data::EID getReportTo() const; 00215 00220 dtn::data::EID getCustodian() const; 00221 00229 bool operator<(const Bundle& other) const; 00230 00238 bool operator>(const Bundle& other) const; 00239 00240 protected: 00246 Bundle(const dtn::data::Bundle &b); 00247 00248 // base bundle object 00249 dtn::data::Bundle _b; 00250 }; 00251 } 00252 } 00253 00254 #endif /* API_BUNDLE_H_ */