IBR-DTNSuite  0.8
ibrdtn/ibrdtn/data/MetaBundle.cpp
Go to the documentation of this file.
00001 /*
00002  * MetaBundle.cpp
00003  *
00004  *  Created on: 16.02.2010
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef METABUNDLE_CPP_
00009 #define METABUNDLE_CPP_
00010 
00011 #include "ibrdtn/data/MetaBundle.h"
00012 #include "ibrdtn/utils/Clock.h"
00013 #include "ibrdtn/data/ScopeControlHopLimitBlock.h"
00014 #include <limits>
00015 
00016 namespace dtn
00017 {
00018         namespace data
00019         {
00020                 MetaBundle::MetaBundle()
00021                  : BundleID(), received(), lifetime(0), destination(), reportto(),
00022                    custodian(), appdatalength(0), procflags(0), expiretime(0), hopcount(std::numeric_limits<std::size_t>::max()), payloadlength(0)
00023                 {
00024                 }
00025 
00026                 MetaBundle::MetaBundle(const dtn::data::BundleID &id)
00027                  : BundleID(id), received(), lifetime(0), destination(), reportto(),
00028                    custodian(), appdatalength(0), procflags(0), expiretime(0), hopcount(std::numeric_limits<std::size_t>::max()), payloadlength(0)
00029                 {
00030                 }
00031 
00032                 MetaBundle::MetaBundle(const dtn::data::Bundle &b)
00033                  : BundleID(b), lifetime(b._lifetime), destination(b._destination), reportto(b._reportto),
00034                    custodian(b._custodian), appdatalength(b._appdatalength), procflags(b._procflags), expiretime(0), hopcount(std::numeric_limits<std::size_t>::max()), payloadlength(0)
00035                 {
00036                         expiretime = dtn::utils::Clock::getExpireTime(b);
00037 
00041                         try {
00042                                 const dtn::data::ScopeControlHopLimitBlock &schl = b.getBlock<const dtn::data::ScopeControlHopLimitBlock>();
00043                                 hopcount = schl.getHopsToLive();
00044                         } catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { };
00045 
00049                         try {
00050                                 const dtn::data::PayloadBlock &pblock = b.getBlock<const dtn::data::PayloadBlock>();
00051                                 payloadlength = pblock.getLength();
00052                         } catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { };
00053                 }
00054 
00055                 MetaBundle::~MetaBundle()
00056                 {}
00057 
00058                 int MetaBundle::getPriority() const
00059                 {
00060                         // read priority
00061                         if (procflags & dtn::data::Bundle::PRIORITY_BIT1)
00062                         {
00063                                 return 0;
00064                         }
00065 
00066                         if (procflags & dtn::data::Bundle::PRIORITY_BIT2)
00067                         {
00068                                 return 1;
00069                         }
00070 
00071                         return -1;
00072                 }
00073 
00074                 bool MetaBundle::get(dtn::data::PrimaryBlock::FLAGS flag) const
00075                 {
00076                         return (procflags & flag);
00077                 }
00078         }
00079 }
00080 
00081 #endif /* METABUNDLE_CPP_ */