PersistentBundleStore.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 "PersistentBundleStore.h"
00032 #include "Node.h"
00033 
00034 using namespace DTN;
00035 
00036 void
00037 PersistentBundleStore::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->recordPersistentRemove( *b, false );
00050          delete b;
00051       }
00052       prev = itr;
00053       if ( itr.isNull() )
00054       {
00055          itr = p_getPointer( BundlePointer() );
00056       }
00057       else
00058       {
00059          itr = itr.next();
00060       }
00061    }
00062 }
00063 
00064 BundlePointer
00065 PersistentBundleStore::addBundle( Bundle* b )
00066 {
00067    clean();
00068    return p_addBundle(b);
00069 }
00070 
00071 void
00072 PersistentBundleStore::deleteBundle( Bundle* b )
00073 {
00074    clean();
00075    p_deleteBundle(b);
00076 }
00077 
00078 BundlePointer
00079 PersistentBundleStore::getPointer( const BundlePointer& p )
00080 {
00081    clean();
00082    return p_getPointer(p);
00083 }
00084 
00085 BundlePointer
00086 PersistentBundleStore::getPointer( const ByteString& sender,
00087                                    uint32_t seqNum )
00088 {
00089    clean();
00090    return p_getPointer(sender,seqNum);
00091 }
00092 
00093 bool
00094 PersistentBundleStore::validatePointer( const BundlePointer& p )
00095 {
00096    clean();
00097    return p_validatePointer(p);
00098 }
00099 
00100 size_t
00101 PersistentBundleStore::bytesUsed( bool cleanup )
00102 {
00103    if ( cleanup ) clean();
00104    return p_bytesUsed();
00105 }
00106 
00107 size_t
00108 PersistentBundleStore::bundles( bool cleanup )
00109 {
00110    if ( cleanup ) clean();
00111    return p_bundles();
00112 }
00113 
00114 void
00115 PersistentBundleStore::shrinkStore( size_t s )
00116 {
00117    clean();
00118    p_shrinkStore(s);
00119 }

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