VolatileBundleStore.cc

00001 // Copyright 2008 Michael Marsh, University of Maryland.
00002 //
00003 // This file is part of pydtn.
00004 //
00005 // pydtn is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // pydtn is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with pydtn.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // The views and conclusions contained in the software and documentation
00019 // are those of the authors and should not be interpreted as representing
00020 // official policies, either expressed or implied, of the University
00021 // of Maryland.
00022 //
00023 // pydtn extends and embeds the Python interpreter, which is
00024 // Copyright 2001-2006 Python Software Foundation, All Rights Reserved,
00025 // and is released under the PSF License Agreement.
00026 //
00027 // RANLUX random number generation uses the Boost library,
00028 // Copyright 1994-2006 by various authors (details in individual files),
00029 // which is released under the Boost Software License, Version 1.0.
00030 
00031 #include "VolatileBundleStore.h"
00032 #include "Node.h"
00033 
00034 using namespace DTN;
00035 
00036 void
00037 VolatileBundleStore::clean()
00038 {
00039    // Get the head of the store.
00040    BundlePointer itr = p_getPointer( BundlePointer() );
00041    BundlePointer prev; // starts as null
00042    while ( ! itr.isNull() )
00043    {
00044       Bundle* b = itr.repr()->bundle();
00045       if ( b->expired() )
00046       {
00047          itr = prev;
00048          p_deleteBundle( b );
00049          m_owner->drop( b, ExpiryDrop::inst );
00050       }
00051       prev = itr;
00052       if ( itr.isNull() )
00053       {
00054          itr = p_getPointer( BundlePointer() );
00055       }
00056       else
00057       {
00058          itr = itr.next();
00059       }
00060    }
00061 }
00062 
00063 BundlePointer
00064 VolatileBundleStore::addBundle( Bundle* b )
00065 {
00066    clean();
00067    return p_addBundle(b);
00068 }
00069 
00070 void
00071 VolatileBundleStore::deleteBundle( Bundle* b )
00072 {
00073    clean();
00074    p_deleteBundle(b);
00075 }
00076 
00077 BundlePointer
00078 VolatileBundleStore::getPointer( const BundlePointer& p )
00079 {
00080    clean();
00081    return p_getPointer(p);
00082 }
00083 
00084 BundlePointer
00085 VolatileBundleStore::getPointer( const ByteString& sender,
00086                                  uint32_t seqNum )
00087 {
00088    clean();
00089    return p_getPointer(sender,seqNum);
00090 }
00091 
00092 bool
00093 VolatileBundleStore::validatePointer( const BundlePointer& p )
00094 {
00095    clean();
00096    return p_validatePointer(p);
00097 }
00098 
00099 size_t
00100 VolatileBundleStore::bytesUsed( bool cleanup )
00101 {
00102    if ( cleanup ) clean();
00103    return p_bytesUsed();
00104 }
00105 
00106 size_t
00107 VolatileBundleStore::bundles( bool cleanup )
00108 {
00109    if ( cleanup ) clean();
00110    return p_bundles();
00111 }
00112 
00113 void
00114 VolatileBundleStore::shrinkStore( size_t s )
00115 {
00116    clean();
00117    p_shrinkStore(s);
00118 }

Generated on Mon Mar 24 11:15:45 2008 for Pydtn Simulator by  doxygen 1.5.4