00001 /* 00002 * BundleList.cpp 00003 * 00004 * Created on: 19.02.2010 00005 * Author: morgenro 00006 */ 00007 00008 #include "ibrdtn/data/BundleList.h" 00009 #include "ibrdtn/utils/Clock.h" 00010 00011 namespace dtn 00012 { 00013 namespace data 00014 { 00015 BundleList::BundleList() 00016 { } 00017 00018 BundleList::~BundleList() 00019 { } 00020 00021 void BundleList::add(const dtn::data::MetaBundle bundle) 00022 { 00023 // insert bundle id to the private list 00024 _bundles.insert(bundle); 00025 00026 // insert the bundle to the public list 00027 std::set<dtn::data::MetaBundle>::insert(bundle); 00028 } 00029 00030 void BundleList::remove(const dtn::data::MetaBundle bundle) 00031 { 00032 // delete bundle id in the private list 00033 _bundles.erase(bundle); 00034 00035 // delete bundle id in the public list 00036 std::set<dtn::data::MetaBundle>::erase(bundle); 00037 } 00038 00039 void BundleList::clear() 00040 { 00041 _bundles.clear(); 00042 std::set<dtn::data::MetaBundle>::clear(); 00043 } 00044 00045 void BundleList::expire(const size_t timestamp) 00046 { 00047 // we can not expire bundles if we have no idea of time 00048 if (dtn::utils::Clock::quality == 0) return; 00049 00050 std::set<ExpiringBundle>::iterator iter = _bundles.begin(); 00051 00052 while (iter != _bundles.end()) 00053 { 00054 const ExpiringBundle &b = (*iter); 00055 00056 if ( b.expiretime >= timestamp ) break; 00057 00058 // raise expired event 00059 eventBundleExpired( b ); 00060 00061 // remove this item in public list 00062 std::set<dtn::data::MetaBundle>::erase( b.bundle ); 00063 00064 // remove this item in private list 00065 _bundles.erase( iter++ ); 00066 } 00067 } 00068 00069 BundleList::ExpiringBundle::ExpiringBundle(const MetaBundle b) 00070 : bundle(b), expiretime(dtn::utils::Clock::getExpireTime(b.getTimestamp(), b.lifetime)) 00071 { } 00072 00073 BundleList::ExpiringBundle::~ExpiringBundle() 00074 { } 00075 00076 bool BundleList::ExpiringBundle::operator!=(const ExpiringBundle& other) const 00077 { 00078 return !(other == *this); 00079 } 00080 00081 bool BundleList::ExpiringBundle::operator==(const ExpiringBundle& other) const 00082 { 00083 return (other.bundle == this->bundle); 00084 } 00085 00086 bool BundleList::ExpiringBundle::operator<(const ExpiringBundle& other) const 00087 { 00088 if (expiretime < other.expiretime) return true; 00089 if (expiretime != other.expiretime) return false; 00090 00091 if (bundle < other.bundle) return true; 00092 00093 return false; 00094 } 00095 00096 bool BundleList::ExpiringBundle::operator>(const ExpiringBundle& other) const 00097 { 00098 return !(((*this) < other) || ((*this) == other)); 00099 } 00100 } 00101 }
1.6.3