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

Recovery.H

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 //
00020 // Recovery.H
00021 // Last modified on Thu Jul 15 13:59:08 EDT 2004 by ken@xorian.net
00022 //      modified on Tue Feb  8 14:04:35 PST 2000 by mann
00023 //
00024 // Code to drive recovery from log for repository server
00025 // 
00026 
00027 #ifndef _VSRECOVER
00028 #define _VSRECOVER 1
00029 
00030 #include "VestaLog.H"
00031 #include "Basics.H"
00032 
00033 // Link with -L/proj/vesta/lib -llog to use the VestaLog and Recovery
00034 // interfaces.
00035 
00036 // Wrapper class that makes reading from istreams and VestaLogs look
00037 // the same.  (It would make for nicer packaging if we had made VestaLog 
00038 // an iostream instead, but that involves a lot of hacking and is 
00039 // nonportable between different C++ libraries.)
00040 //
00041 class RecoveryReader {
00042   public:
00043     // Constructors
00044     RecoveryReader(VestaLog* vl) throw();
00045   RecoveryReader(std::istream* is) throw();
00046 
00047     // Ordinary read routines
00048     void get(char &c)
00049       throw(VestaLog::Eof, VestaLog::Error);
00050     void get(char* p, int n, char term='\n')
00051       throw(VestaLog::Eof, VestaLog::Error);
00052     int read(char* p, int n)
00053       throw(VestaLog::Error);
00054     void readAll(char* p, int n)
00055       throw(VestaLog::Eof, VestaLog::Error);
00056     bool eof()
00057       throw(VestaLog::Error);
00058 
00059     // Special read routines for parsing the log.  The c argument
00060     //  is a lookahead character.  All the routines skip leading
00061     //  whitespace.  Within a quoted string, " and \ characters must
00062     //  be escaped as \" and \\.
00063     typedef char Ident[256]; // null-terminated alphanumeric string
00064     void skipWhite(char& c)
00065       throw(VestaLog::Eof, VestaLog::Error);
00066     void requireChar(char& c, char required)
00067       throw(VestaLog::Eof, VestaLog::Error);
00068     void getIdent(char& c, Ident id)
00069       throw(VestaLog::Eof, VestaLog::Error);
00070     void getLong(char& c, long& n)
00071       throw(VestaLog::Eof, VestaLog::Error);
00072     void getULong(char& c, unsigned long& n)
00073       throw(VestaLog::Eof, VestaLog::Error);
00074     void getLongId(char& c, Byte32& value) // value is the LongId.value field
00075       throw(VestaLog::Eof, VestaLog::Error);
00076     void getQuotedString(char& c, char* buf, int maxLen)
00077       throw(VestaLog::Eof, VestaLog::Error);  // too long => Error
00078     void getNewQuotedString(char& c, char*& string)
00079       throw(VestaLog::Eof, VestaLog::Error);  // caller must free string
00080 
00081   private:
00082     VestaLog* vl_;
00083     std::istream* is_;
00084 };
00085 
00086 // Driver for recovery.  Assumes each log record is of the form:
00087 //  '(' ident arbitrary-data ')'
00088 // Here single-quotes surround literal data, ident is a string of
00089 // alphanumeric characters terminated by a non-alphanumeric (which is
00090 // included in arbitrary-data), and arbitrary-data is a string of
00091 // arbitrary bytes.  RecoverFrom parses the fixed part of this syntax,
00092 // calling a registered callback for each ident it finds to parse the
00093 // arbitrary-data part.  When the callback is made, c is a lookahead
00094 // character that has already been read from the reader.  On return, c
00095 // should be a new lookahead character unless Eof (or Error) is
00096 // thrown.
00097 extern void RecoverFrom(RecoveryReader* rr) throw(VestaLog::Error);
00098 
00099 // Function type for callbacks made by RecoverFrom
00100 typedef void RecoveryCallback(RecoveryReader* rr, char &c)
00101      /*throw(VestaLog::Eof, VestaLog::Error)*/;
00102 
00103 extern void RegisterRecoveryCallback(RecoveryReader::Ident id,
00104                                      RecoveryCallback* rc)
00105      throw();
00106 
00107 #endif // _VSRECOVER

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