• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ibrdtn/ibrdtn/data/CustodySignalBlock.cpp

Go to the documentation of this file.
00001 /*
00002  * CustodySignalBlock.cpp
00003  *
00004  *  Created on: 05.06.2009
00005  *      Author: morgenro
00006  */
00007 
00008 #include "ibrdtn/data/Bundle.h"
00009 #include "ibrdtn/data/CustodySignalBlock.h"
00010 #include "ibrdtn/data/BundleString.h"
00011 #include <stdlib.h>
00012 #include <sstream>
00013 
00014 namespace dtn
00015 {
00016         namespace data
00017         {
00018                 CustodySignalBlock::CustodySignalBlock()
00019                  : Block(dtn::data::PayloadBlock::BLOCK_TYPE), _admfield(32), _status(0), _fragment_offset(0),
00020                  _fragment_length(0), _timeofsignal(), _bundle_timestamp(0), _bundle_sequence(0)
00021                 {
00022                 }
00023 
00024                 CustodySignalBlock::~CustodySignalBlock()
00025                 {
00026                 }
00027 
00028                 size_t CustodySignalBlock::getLength() const
00029                 {
00030                         // determine the block size
00031                         size_t len = 0;
00032                         len += sizeof(_admfield);
00033                         len += sizeof(_status);
00034 
00035                         if ( _admfield & 0x01 )
00036                         {
00037                                 len += _fragment_offset.getLength();
00038                                 len += _fragment_length.getLength();
00039                         }
00040 
00041                         len += _timeofsignal.getLength();
00042                         len += _bundle_timestamp.getLength();
00043                         len += _bundle_sequence.getLength();
00044 
00045                         BundleString sourceid(_source.getString());
00046                         len += sourceid.getLength();
00047 
00048                         return len;
00049                 }
00050 
00051                 std::istream& CustodySignalBlock::deserialize(std::istream &stream)
00052                 {
00053                         stream >> _admfield;
00054                         stream >> _status;
00055 
00056                         if ( _admfield & 0x01 )
00057                         {
00058                                 stream >> _fragment_offset;
00059                                 stream >> _fragment_length;
00060                         }
00061 
00062                         stream >> _timeofsignal;
00063                         stream >> _bundle_timestamp;
00064                         stream >> _bundle_sequence;
00065 
00066                         BundleString source;
00067                         stream >> source;
00068                         _source = EID(source);
00069 
00070                         // unset block not processed bit
00071                         set(dtn::data::Block::FORWARDED_WITHOUT_PROCESSED, false);
00072 
00073                         return stream;
00074                 }
00075 
00076                 std::ostream& CustodySignalBlock::serialize(std::ostream &stream) const
00077                 {
00078                         // write the content
00079                         stream << _admfield;
00080                         stream << _status;
00081 
00082                         if ( _admfield & 0x01 )
00083                         {
00084                                 stream << _fragment_offset;
00085                                 stream << _fragment_length;
00086                         }
00087 
00088                         BundleString sourceid(_source.getString());
00089 
00090                         stream << _timeofsignal
00091                            << _bundle_timestamp
00092                            << _bundle_sequence
00093                            << sourceid;
00094 
00095                         return stream;
00096                 }
00097 
00098                 void CustodySignalBlock::setMatch(const dtn::data::MetaBundle& other)
00099                 {
00100                         // set bundle parameter
00101                         if (other.get(Bundle::FRAGMENT))
00102                         {
00103                                 _fragment_offset = other.offset;
00104                                 _fragment_length = other.appdatalength;
00105 
00106                                 if (!(_admfield & 1)) _admfield += 1;
00107                         }
00108 
00109                         _bundle_timestamp = other.timestamp;
00110                         _bundle_sequence = other.sequencenumber;
00111                         _source = other.source;
00112                 }
00113 
00114                 void CustodySignalBlock::setMatch(const dtn::data::Bundle& other)
00115                 {
00116                         // set bundle parameter
00117                         if (other.get(Bundle::FRAGMENT))
00118                         {
00119                                 _fragment_offset = other._fragmentoffset;
00120                                 _fragment_length = other._appdatalength;
00121 
00122                                 if (!(_admfield & 1)) _admfield += 1;
00123                         }
00124 
00125                         _bundle_timestamp = other._timestamp;
00126                         _bundle_sequence = other._sequencenumber;
00127                         _source = other._source;
00128                 }
00129 
00130                 bool CustodySignalBlock::match(const Bundle& other) const
00131                 {
00132                         if (_bundle_timestamp != other._timestamp) return false;
00133                         if (_bundle_sequence != other._sequencenumber) return false;
00134                         if (_source != other._source) return false;
00135 
00136                         // set bundle parameter
00137                         if (other.get(Bundle::FRAGMENT))
00138                         {
00139                                 if (!(_admfield & 1)) return false;
00140                                 if (_fragment_offset != other._fragmentoffset) return false;
00141                                 if (_fragment_length != other._appdatalength) return false;
00142                         }
00143 
00144                         return true;
00145                 }
00146 
00147         }
00148 }

Generated on Wed Mar 30 2011 11:11:49 for IBR-DTNSuite by  doxygen 1.7.1