IBR-DTNSuite
0.8
|
00001 /* 00002 * Block.h 00003 * 00004 * Created on: 29.05.2009 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef BLOCK_H_ 00009 #define BLOCK_H_ 00010 00011 #include "ibrdtn/data/EID.h" 00012 #include "ibrdtn/data/Exceptions.h" 00013 #include "ibrdtn/data/SDNV.h" 00014 #include "ibrdtn/data/Dictionary.h" 00015 #include "ibrdtn/data/Serializer.h" 00016 #include <ibrcommon/Exceptions.h> 00017 #include <list> 00018 00019 namespace dtn 00020 { 00021 namespace security 00022 { 00023 class StrictSerializer; 00024 class MutualSerializer; 00025 } 00026 00027 namespace data 00028 { 00029 class Bundle; 00030 00031 class Block 00032 { 00033 friend class Bundle; 00034 friend class DefaultSerializer; 00035 friend class dtn::security::StrictSerializer; 00036 friend class dtn::security::MutualSerializer; 00037 friend class DefaultDeserializer; 00038 friend class SeparateSerializer; 00039 friend class SeparateDeserializer; 00040 00041 public: 00042 enum ProcFlags 00043 { 00044 REPLICATE_IN_EVERY_FRAGMENT = 1, // 0 - Block must be replicated in every fragment. 00045 TRANSMIT_STATUSREPORT_IF_NOT_PROCESSED = 1 << 0x01, // 1 - Transmit status report if block can't be processed. 00046 DELETE_BUNDLE_IF_NOT_PROCESSED = 1 << 0x02, // 2 - Delete bundle if block can't be processed. 00047 LAST_BLOCK = 1 << 0x03, // 3 - Last block. 00048 DISCARD_IF_NOT_PROCESSED = 1 << 0x04, // 4 - Discard block if it can't be processed. 00049 FORWARDED_WITHOUT_PROCESSED = 1 << 0x05, // 5 - Block was forwarded without being processed. 00050 BLOCK_CONTAINS_EIDS = 1 << 0x06 // 6 - Block contains an EID-reference field. 00051 }; 00052 00053 virtual ~Block(); 00054 00055 virtual void addEID(const dtn::data::EID &eid); 00056 virtual std::list<dtn::data::EID> getEIDList() const; 00057 00058 char getType() const { return _blocktype; } 00059 00060 void set(ProcFlags flag, const bool &value); 00061 bool get(ProcFlags flag) const; 00062 00068 virtual std::ostream &serialize(std::ostream &stream, size_t &length) const = 0; 00069 00075 virtual std::istream &deserialize(std::istream &stream, const size_t length) = 0; 00076 00081 virtual size_t getLength() const = 0; 00082 00083 protected: 00088 Block(char blocktype); 00089 00093 virtual size_t getLength_strict() const; 00094 00100 virtual std::ostream &serialize_strict(std::ostream &stream, size_t &length) const; 00101 00102 // block type of this block 00103 char _blocktype; 00104 00105 // the list of EID references embedded in this block 00106 std::list<dtn::data::EID> _eids; 00107 00108 private: 00109 // block processing flags 00110 size_t _procflags; 00111 }; 00112 } 00113 } 00114 00115 #endif /* BLOCK_H_ */