Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

VestaLogSeq.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta 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 GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Created on Fri Mar  7 13:45:15 PST 1997 by heydon
00020 
00021 // Last modified on Fri Apr 22 11:35:32 EDT 2005 by ken@xorian.net
00022 //      modified on Thu Mar 13 13:53:58 PST 1997 by heydon
00023 
00024 #include <Basics.H>
00025 #include <FS.H>
00026 #include "VestaLog.H"
00027 #include "Recovery.H"
00028 #include "VestaLogSeq.H"
00029 
00030 using std::fstream;
00031 
00032 void VestaLogSeq::Open(int ver, bool readonly) throw (VestaLog::Error)
00033 {
00034     assert(!this->opened);
00035     this->vlog.open(this->dir, ver, readonly);
00036     this->opened = true;
00037     this->readChkpt = false;
00038     this->chkptFS = (fstream *)NULL;
00039     this->rr = (RecoveryReader *)NULL;
00040 }
00041 
00042 RecoveryReader* VestaLogSeq::Next(int endVer)
00043   throw (VestaLog::Error, FS::Failure)
00044 {
00045     assert(this->opened);
00046 
00047     // handle checkpoint file
00048     if (!this->readChkpt) {
00049         // try opening the checkpoint first
00050         this->readChkpt = true;
00051         if ((this->chkptFS = this->vlog.openCheckpoint()) != (fstream *)NULL) {
00052           return NEW_CONSTR(RecoveryReader, (this->chkptFS));
00053         }
00054     } else if (this->chkptFS != (fstream *)NULL) {
00055         // close previously-opened checkpoint file (if any)
00056         FS::Close(*(this->chkptFS));
00057         this->chkptFS = (fstream *)NULL;
00058     }
00059 
00060     // try opening the next log file
00061     if (this->rr == (RecoveryReader *)NULL) {
00062         // process first log file
00063         if (endVer < 0 || this->vlog.logVersion() < endVer) {
00064           this->rr = NEW_CONSTR(RecoveryReader, (&(this->vlog)));
00065             return this->rr;
00066         }
00067     } else {
00068         // second & subsequent log files
00069         if (this->vlog.nextLog() &&
00070             (endVer < 0 || this->vlog.logVersion() < endVer)) {
00071             return this->rr;
00072         }
00073     }
00074 
00075     // no more log files
00076     return (RecoveryReader *)NULL;
00077 }
00078 
00079 void VestaLogSeq::Close() throw ()
00080 {
00081     assert(this->opened);
00082 
00083     // close previously-opened checkpoint file (if any)
00084     if (this->chkptFS != (fstream *)NULL) {
00085         FS::Close(*(this->chkptFS));
00086         this->chkptFS = (fstream *)NULL;
00087     }
00088 
00089     // close log
00090     this->vlog.close();
00091 
00092     // clean up for re-use
00093     this->opened = false;
00094     this->rr = (RecoveryReader *)NULL;
00095 }

Generated on Mon May 8 00:48:42 2006 for Vesta by  doxygen 1.4.2