|
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 friend class Client; 00029 friend class APIClient; 00030 00031 public: 00038 enum BUNDLE_PRIORITY 00039 { 00040 PRIO_LOW = 0, 00041 PRIO_MEDIUM = 1, 00042 PRIO_HIGH = 2 00043 }; 00044 00048 Bundle(); 00049 00054 Bundle(const dtn::data::EID &destination); 00055 00059 virtual ~Bundle(); 00060 00065 void setSingleton(bool val); 00066 00071 void setLifetime(unsigned int lifetime); 00072 00077 unsigned int getLifetime() const; 00078 00083 void requestDeliveredReport(); 00084 00089 void requestForwardedReport(); 00090 00096 void requestDeletedReport(); 00097 00102 void requestReceptionReport(); 00103 00107 void requestCustodyTransfer(); 00108 00114 void requestEncryption(); 00115 00121 void requestSigned(); 00122 00126 void requestCompression(); 00127 00132 bool statusVerified(); 00133 00138 void setPriority(BUNDLE_PRIORITY p); 00139 00144 BUNDLE_PRIORITY getPriority() const; 00145 00153 friend std::ostream &operator<<(std::ostream &stream, const dtn::api::Bundle &b) 00154 { 00155 // To send a bundle, we construct a default serializer. Such a serializer convert 00156 // the bundle data to the standardized form as byte stream. 00157 dtn::data::DefaultSerializer(stream) << b._b; 00158 00159 // Since this method is used to serialize bundles into an StreamConnection, we need to call 00160 // a flush on the StreamConnection. This signals the stream to set the bundle end flag on 00161 // the last segment of streaming. 00162 stream.flush(); 00163 00164 // To support concatenation of streaming calls, we return the reference to the output stream. 00165 return stream; 00166 } 00167 00175 friend std::istream &operator>>(std::istream &stream, dtn::api::Bundle &b) 00176 { 00177 // To receive a bundle, we construct a default deserializer. Such a deserializer 00178 // convert a byte stream into a bundle object. If this deserialization fails 00179 // an exception will be thrown. 00180 dtn::data::DefaultDeserializer(stream) >> b._b; 00181 00182 // To support concatenation of streaming calls, we return the reference to the input stream. 00183 return stream; 00184 } 00185 00191 ibrcommon::BLOB::Reference getData() throw (dtn::MissingObjectException); 00192 00198 void setDestination(const dtn::data::EID &eid, const bool singleton = true); 00199 00205 void setReportTo(const dtn::data::EID &eid); 00206 00211 dtn::data::EID getDestination() const; 00212 00217 dtn::data::EID getSource() const; 00218 00223 dtn::data::EID getReportTo() const; 00224 00229 dtn::data::EID getCustodian() const; 00230 00238 bool operator<(const Bundle& other) const; 00239 00247 bool operator>(const Bundle& other) const; 00248 00249 protected: 00255 Bundle(const dtn::data::Bundle &b); 00256 00257 // base bundle object 00258 dtn::data::Bundle _b; 00259 }; 00260 } 00261 } 00262 00263 #endif /* API_BUNDLE_H_ */