IBR-DTNSuite
0.8
|
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 00082 time_t getTimestamp() const; 00083 00088 void requestDeliveredReport(); 00089 00094 void requestForwardedReport(); 00095 00101 void requestDeletedReport(); 00102 00107 void requestReceptionReport(); 00108 00112 void requestCustodyTransfer(); 00113 00119 void requestEncryption(); 00120 00126 void requestSigned(); 00127 00131 void requestCompression(); 00132 00137 bool statusVerified(); 00138 00143 void setPriority(BUNDLE_PRIORITY p); 00144 00149 BUNDLE_PRIORITY getPriority() const; 00150 00158 friend std::ostream &operator<<(std::ostream &stream, const dtn::api::Bundle &b) 00159 { 00160 // To send a bundle, we construct a default serializer. Such a serializer convert 00161 // the bundle data to the standardized form as byte stream. 00162 dtn::data::DefaultSerializer(stream) << b._b; 00163 00164 // Since this method is used to serialize bundles into an StreamConnection, we need to call 00165 // a flush on the StreamConnection. This signals the stream to set the bundle end flag on 00166 // the last segment of streaming. 00167 stream.flush(); 00168 00169 // To support concatenation of streaming calls, we return the reference to the output stream. 00170 return stream; 00171 } 00172 00180 friend std::istream &operator>>(std::istream &stream, dtn::api::Bundle &b) 00181 { 00182 // To receive a bundle, we construct a default deserializer. Such a deserializer 00183 // convert a byte stream into a bundle object. If this deserialization fails 00184 // an exception will be thrown. 00185 dtn::data::DefaultDeserializer(stream) >> b._b; 00186 00187 // To support concatenation of streaming calls, we return the reference to the input stream. 00188 return stream; 00189 } 00190 00196 ibrcommon::BLOB::Reference getData() throw (dtn::MissingObjectException); 00197 00203 void setDestination(const dtn::data::EID &eid, const bool singleton = true); 00204 00210 void setReportTo(const dtn::data::EID &eid); 00211 00216 dtn::data::EID getDestination() const; 00217 00222 dtn::data::EID getSource() const; 00223 00228 dtn::data::EID getReportTo() const; 00229 00234 dtn::data::EID getCustodian() const; 00235 00243 bool operator<(const Bundle& other) const; 00244 00252 bool operator>(const Bundle& other) const; 00253 00254 protected: 00260 Bundle(const dtn::data::Bundle &b); 00261 00262 // base bundle object 00263 dtn::data::Bundle _b; 00264 }; 00265 } 00266 } 00267 00268 #endif /* API_BUNDLE_H_ */