IBR-DTNSuite
0.8
|
00001 /* 00002 * StatusReportBlock.cpp 00003 * 00004 * Created on: 05.06.2009 00005 * Author: morgenro 00006 */ 00007 00008 #include "ibrdtn/data/StatusReportBlock.h" 00009 #include "ibrdtn/data/SDNV.h" 00010 #include "ibrdtn/data/BundleString.h" 00011 #include "ibrdtn/data/PayloadBlock.h" 00012 #include <stdlib.h> 00013 #include <sstream> 00014 00015 namespace dtn 00016 { 00017 namespace data 00018 { 00019 StatusReportBlock::StatusReportBlock() 00020 : Block(dtn::data::PayloadBlock::BLOCK_TYPE), _admfield(16), _status(0), _reasoncode(0), 00021 _fragment_offset(0), _fragment_length(0), _timeof_receipt(), 00022 _timeof_custodyaccept(), _timeof_forwarding(), _timeof_delivery(), 00023 _timeof_deletion(), _bundle_timestamp(0), _bundle_sequence(0) 00024 { 00025 } 00026 00027 StatusReportBlock::~StatusReportBlock() 00028 { 00029 } 00030 00031 size_t StatusReportBlock::getLength() const 00032 { 00033 // determine the block size 00034 size_t len = 0; 00035 len += sizeof(_admfield); 00036 len += sizeof(_status); 00037 len += sizeof(_reasoncode); 00038 00039 if ( _admfield & 0x01 ) 00040 { 00041 len += _fragment_offset.getLength(); 00042 len += _fragment_length.getLength(); 00043 } 00044 00045 if (_status & RECEIPT_OF_BUNDLE) 00046 len += _timeof_receipt.getLength(); 00047 00048 if (_status & CUSTODY_ACCEPTANCE_OF_BUNDLE) 00049 len += _timeof_custodyaccept.getLength(); 00050 00051 if (_status & FORWARDING_OF_BUNDLE) 00052 len += _timeof_forwarding.getLength(); 00053 00054 if (_status & DELIVERY_OF_BUNDLE) 00055 len += _timeof_delivery.getLength(); 00056 00057 if (_status & DELETION_OF_BUNDLE) 00058 len += _timeof_deletion.getLength(); 00059 00060 len += _bundle_timestamp.getLength(); 00061 len += _bundle_sequence.getLength(); 00062 00063 BundleString sourceid(_source.getString()); 00064 len += sourceid.getLength(); 00065 00066 return len; 00067 } 00068 00069 std::ostream& StatusReportBlock::serialize(std::ostream &stream, size_t &length) const 00070 { 00071 stream << _admfield; 00072 stream << _status; 00073 stream << _reasoncode; 00074 00075 if ( _admfield & 0x01 ) 00076 { 00077 stream << _fragment_offset; 00078 stream << _fragment_length; 00079 } 00080 00081 if (_status & RECEIPT_OF_BUNDLE) 00082 stream << _timeof_receipt; 00083 00084 if (_status & CUSTODY_ACCEPTANCE_OF_BUNDLE) 00085 stream << _timeof_custodyaccept; 00086 00087 if (_status & FORWARDING_OF_BUNDLE) 00088 stream << _timeof_forwarding; 00089 00090 if (_status & DELIVERY_OF_BUNDLE) 00091 stream << _timeof_delivery; 00092 00093 if (_status & DELETION_OF_BUNDLE) 00094 stream << _timeof_deletion; 00095 00096 stream << _bundle_timestamp; 00097 stream << _bundle_sequence; 00098 stream << BundleString(_source.getString()); 00099 00100 return stream; 00101 } 00102 00103 std::istream& StatusReportBlock::deserialize(std::istream &stream, const size_t length) 00104 { 00105 stream >> _admfield; 00106 stream >> _status; 00107 stream >> _reasoncode; 00108 00109 if ( _admfield & 0x01 ) 00110 { 00111 stream >> _fragment_offset; 00112 stream >> _fragment_length; 00113 } 00114 00115 if (_status & RECEIPT_OF_BUNDLE) 00116 stream >> _timeof_receipt; 00117 00118 if (_status & CUSTODY_ACCEPTANCE_OF_BUNDLE) 00119 stream >> _timeof_custodyaccept; 00120 00121 if (_status & FORWARDING_OF_BUNDLE) 00122 stream >> _timeof_forwarding; 00123 00124 if (_status & DELIVERY_OF_BUNDLE) 00125 stream >> _timeof_delivery; 00126 00127 if (_status & DELETION_OF_BUNDLE) 00128 stream >> _timeof_deletion; 00129 00130 stream >> _bundle_timestamp; 00131 stream >> _bundle_sequence; 00132 00133 BundleString source; 00134 stream >> source; 00135 _source = EID(source); 00136 00137 // unset block not processed bit 00138 set(dtn::data::Block::FORWARDED_WITHOUT_PROCESSED, false); 00139 00140 return stream; 00141 } 00142 00143 } 00144 }