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

GraphLog.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 // Last modified on Fri Apr 22 17:27:58 EDT 2005 by ken@xorian.net  
00020 //      modified on Sat Feb 12 12:02:14 PST 2000 by mann  
00021 //      modified on Mon Nov 10 12:15:50 PST 1997 by heydon
00022 
00023 #include <time.h>
00024 #include <Basics.H>
00025 #include <FS.H>
00026 #include <VestaLog.H>
00027 #include <FP.H>
00028 
00029 #include "Model.H"
00030 #include "CacheIndex.H"
00031 #include "Derived.H"
00032 #include "GraphLog.H"
00033 
00034 using std::ostream;
00035 using std::istream;
00036 
00037 /* GraphLog::Entry -------------------------------------------------------- */
00038 
00039 GraphLog::Entry *GraphLog::Entry::Recover(RecoveryReader &rd)
00040   throw (VestaLog::Error, VestaLog::Eof)
00041 {
00042     GraphLog::Kind kind;
00043     rd.readAll((char *)(&kind), sizeof_assert(kind, 4));
00044     switch (kind) {
00045       case RootKind: return NEW_CONSTR(GraphLog::Root, (rd));
00046       case NodeKind: return NEW_CONSTR(GraphLog::Node, (rd));
00047       default:
00048         // This is a fatal error.
00049         {
00050           Text msg = "Invalid graph log format.";
00051 
00052           // This graph log could have been written by a machine of a
00053           // different byte order.  We'll check that and sugest that
00054           // in the error messgae if it looks likely.
00055           GraphLog::Kind kind_swapped =
00056             (GraphLog::Kind) Basics::swab32((Basics::uint32) kind);
00057           if((kind_swapped == RootKind) ||
00058              (kind_swapped == NodeKind))
00059             {
00060               msg += ("  (Maybe the graph log was written by a machine "
00061                       "of a different byte order?)");
00062             }
00063 
00064           throw VestaLog::Error(0, msg);
00065         }
00066     }
00067     return NULL; // not reached
00068 }
00069 
00070 GraphLog::Entry *GraphLog::Entry::Read(istream &ifs)
00071   throw (FS::Failure, FS::EndOfFile)
00072 {
00073     GraphLog::Kind kind;
00074     FS::Read(ifs, (char *)(&kind), sizeof_assert(kind, 4));
00075     switch (kind) {
00076       case RootKind: return NEW_CONSTR(GraphLog::Root, (ifs));
00077       case NodeKind: return NEW_CONSTR(GraphLog::Node, (ifs));
00078       default:
00079         // This is a fatal error.
00080         {
00081           Text msg = "Invalid graph log format.";
00082 
00083           // This graph log could have been written by a machine of a
00084           // different byte order.  We'll check that and sugest that
00085           // in the error messgae if it looks likely.
00086           GraphLog::Kind kind_swapped =
00087             (GraphLog::Kind) Basics::swab32((Basics::uint32) kind);
00088           if((kind_swapped == RootKind) ||
00089              (kind_swapped == NodeKind))
00090             {
00091               msg += ("  (Maybe the graph log was written by a machine "
00092                       "of a different byte order?)");
00093             }
00094 
00095           throw VestaLog::Error(0, msg);
00096         }
00097     }
00098     return NULL; // not reached
00099 }
00100 
00101 void GraphLog::Entry::Debug(ostream &s) const throw ()
00102 {
00103     s << "  ";
00104     switch (kind) {
00105       case NodeKind: s << "Node: "; break;
00106       case RootKind: s << "Root: "; break;
00107       default: assert(false);
00108     }
00109 }
00110 
00111 void GraphLog::Entry::DebugFull(ostream &s) const throw ()
00112 {
00113     GraphLog::Entry::Debug(s);
00114     s << '\n';
00115 }
00116 
00117 /* GraphLog::Node --------------------------------------------------------- */
00118 
00119 void GraphLog::Node::Init(CacheEntry::Index ci, FP::Tag *loc, Model::T model,
00120   CacheEntry::Indices *kids, Derived::Indices *refs) throw ()
00121 {
00122     this->next = (Node *)NULL;
00123     this->ci = ci;
00124     this->loc = loc;
00125     this->model = model;
00126     this->kids = kids;
00127     this->refs = refs;
00128 }
00129 
00130 void GraphLog::Node::Log(VestaLog &log) const
00131   throw (VestaLog::Error)
00132 {
00133     GraphLog::Entry::Log(log);
00134     log.write((char *)(&(this->ci)), sizeof_assert(this->ci, 4));
00135     this->loc->Log(log);
00136     Model::Log(this->model, log);
00137     this->kids->Log(log);
00138     this->refs->Log(log);
00139 }
00140 
00141 void GraphLog::Node::Recover(RecoveryReader &rd)
00142   throw (VestaLog::Error, VestaLog::Eof)
00143 {
00144     rd.readAll((char *)(&(this->ci)), sizeof_assert(this->ci, 4));
00145     this->loc = NEW_CONSTR(FP::Tag, (rd));
00146     Model::Recover(/*OUT*/ this->model, rd);
00147     this->kids = NEW_CONSTR(CacheEntry::Indices, (rd));
00148     this->refs = NEW_CONSTR(Derived::Indices, (rd));
00149 }
00150 
00151 void GraphLog::Node::Write(ostream &ofs) const throw (FS::Failure)
00152 {
00153     GraphLog::Entry::Write(ofs);
00154     FS::Write(ofs, (char *)(&(this->ci)), sizeof_assert(this->ci, 4));
00155     this->loc->Write(ofs);
00156     Model::Write(this->model, ofs);
00157     this->kids->Write(ofs);
00158     this->refs->Write(ofs);
00159 }
00160 
00161 void GraphLog::Node::Read(istream &ifs)
00162   throw (FS::Failure, FS::EndOfFile)
00163 {
00164     FS::Read(ifs, (char *)(&(this->ci)), sizeof_assert(this->ci, 4));
00165     this->loc = NEW_CONSTR(FP::Tag, (ifs));
00166     Model::Read(/*OUT*/ this->model, ifs);
00167     this->kids = NEW_CONSTR(CacheEntry::Indices, (ifs));
00168     this->refs = NEW_CONSTR(Derived::Indices, (ifs));
00169 }
00170 
00171 void GraphLog::Node::Debug(ostream &os) const throw ()
00172 {
00173     GraphLog::Entry::Debug(os);
00174     os << "pk = " << *(this->loc) << ", ci = " << this->ci << ", ...\n";
00175 }
00176 
00177 void GraphLog::Node::DebugFull(ostream &os) const throw ()
00178 {
00179     GraphLog::Entry::DebugFull(os);
00180     os << "    pk = " << *(this->loc) << '\n';
00181     os << "    ci = " << this->ci << '\n';
00182     os << "    model = " << this->model << '\n';
00183     os << "    kids = "; this->kids->Print(os, /*indent=*/ 6);
00184     os << "    refs = "; this->refs->Print(os, /*indent=*/ 6);
00185 }
00186 
00187 /* GraphLog::Root --------------------------------------------------------- */
00188 
00189 void GraphLog::Root::Init(const FP::Tag &pkgVersion, Model::T model,
00190   CacheEntry::Indices *cis, bool done) throw ()
00191 {
00192     this->pkgVersion = pkgVersion;
00193     this->model = model;
00194     (void) time(&(this->ts));
00195     this->cis = cis;
00196     this->done = done;
00197 }
00198 
00199 void GraphLog::Root::Log(VestaLog &log) const
00200   throw (VestaLog::Error)
00201 {
00202     GraphLog::Entry::Log(log);
00203     this->pkgVersion.Log(log);
00204     Model::Log(this->model, log);
00205 
00206     // Log this->ts as a 32-bit integer, as the size of time_t can
00207     // vary between platforms.
00208     Basics::int32 l_ts = this->ts;
00209     log.write((char *)(&l_ts), sizeof_assert(l_ts, 4));
00210 
00211     this->cis->Log(log);
00212 
00213     // Log this->done as a one-byte value, as the size of the bool
00214     // type can vary between platforms/compilers.
00215     bool8 l_done = this->done ? 1 : 0;
00216     log.write((char *)(&l_done), sizeof_assert(l_done, 1));
00217 }
00218 
00219 void GraphLog::Root::Recover(RecoveryReader &rd)
00220   throw (VestaLog::Error, VestaLog::Eof)
00221 {
00222     this->pkgVersion.Recover(rd);
00223     Model::Recover(/*OUT*/ this->model, rd);
00224 
00225     // Recover this->ts as a 32-bit integer
00226     Basics::int32 l_ts;
00227     rd.readAll((char *)(&l_ts), sizeof_assert(l_ts, 4));
00228     this->ts = l_ts;
00229 
00230     this->cis = NEW_CONSTR(CacheEntry::Indices, (rd));
00231 
00232     // Recover done is a one-byte value
00233     bool8 l_done;
00234     rd.readAll((char *)(&l_done), sizeof_assert(l_done, 1));
00235     this->done = (l_done != 0);
00236 }
00237 
00238 void GraphLog::Root::Write(ostream &ofs) const throw (FS::Failure)
00239 {
00240     GraphLog::Entry::Write(ofs);
00241     this->pkgVersion.Write(ofs);
00242     Model::Write(this->model, ofs);
00243 
00244     // Write this->ts as a 32-bit integer
00245     Basics::int32 l_ts = this->ts;
00246     FS::Write(ofs, (char *)(&l_ts), sizeof_assert(l_ts, 4));
00247 
00248     this->cis->Write(ofs);
00249 
00250     // Write this->done as a one-byte value
00251     bool8 l_done = this->done ? 1 : 0;
00252     FS::Write(ofs, (char *)(&l_done), sizeof_assert(l_done, 1));
00253 }
00254 
00255 void GraphLog::Root::Read(istream &ifs)
00256   throw (FS::Failure, FS::EndOfFile)
00257 {
00258     this->pkgVersion.Read(ifs);
00259     Model::Read(/*OUT*/ this->model, ifs);
00260 
00261     // Read this->ts as a 32-bit integer
00262     Basics::int32 l_ts;
00263     FS::Read(ifs, (char *)(&l_ts), sizeof_assert(l_ts, 4));
00264     this->ts = l_ts;
00265 
00266     this->cis = NEW_CONSTR(CacheEntry::Indices, (ifs));
00267 
00268     // Read this->done as a one-byte value
00269     bool8 l_done;
00270     FS::Read(ifs, (char *)(&l_done), sizeof_assert(l_done, 1));
00271     this->done = (l_done != 0);
00272 }
00273 
00274 void GraphLog::Root::Debug(ostream &os) const throw ()
00275 {
00276     GraphLog::Entry::Debug(os);
00277     os << "pkgFP = " << this->pkgVersion;
00278     os << ", model = " << this->model;
00279     /*** Print more debugging info? ***/
00280     os << ", ...\n";
00281 }
00282 
00283 void GraphLog::Root::DebugFull(ostream &os) const throw ()
00284 {
00285 #ifdef CTIME_R_AVAIL
00286     // convert "this->ts" to ASCII
00287     const int BuffSz = 80;
00288     char timeBuff[BuffSz];
00289     int res = ctime_r(&(this->ts), timeBuff, BuffSz);
00290     assert(res == 0);
00291 #else
00292     char *timeBuff = ctime(&(this->ts));
00293     assert(timeBuff != NULL);
00294 #endif
00295 
00296     // print all fields
00297     GraphLog::Entry::DebugFull(os);
00298     os << "    pkgFP = " << this->pkgVersion << '\n';
00299     os << "    model = " << this->model << '\n';
00300     os << "    time = " << timeBuff; // note: "timeBuff" has a trailing '\n'
00301     os << "    done = " << BoolName[done] << '\n';
00302     os << "    cis = "; this->cis->Print(os, /*indent=*/ 6);
00303 }

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