00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
00049 {
00050 Text msg = "Invalid graph log format.";
00051
00052
00053
00054
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;
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
00080 {
00081 Text msg = "Invalid graph log format.";
00082
00083
00084
00085
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;
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
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( 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( 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, 6);
00184 os << " refs = "; this->refs->Print(os, 6);
00185 }
00186
00187
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
00207
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
00214
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( this->model, rd);
00224
00225
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
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
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
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( this->model, ifs);
00260
00261
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
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
00280 os << ", ...\n";
00281 }
00282
00283 void GraphLog::Root::DebugFull(ostream &os) const throw ()
00284 {
00285 #ifdef CTIME_R_AVAIL
00286
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
00297 GraphLog::Entry::DebugFull(os);
00298 os << " pkgFP = " << this->pkgVersion << '\n';
00299 os << " model = " << this->model << '\n';
00300 os << " time = " << timeBuff;
00301 os << " done = " << BoolName[done] << '\n';
00302 os << " cis = "; this->cis->Print(os, 6);
00303 }