WalnutDBInfoImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Willie-Sue, April 15, 1986 1:12:55 pm PST
Contents: procedures dealing with the Walnut message database
Initiated by Willie-Sue, January 29, 1985
DIRECTORY
BasicTime USING [GMT],
DB USING [
CreateRelship, DeclareEntity, DomainSubset, EntityInfo, FirstRelship, GetF,
LookupEntity, LookupProperty, NextEntity, ReleaseEntitySet, SetF,
B2V, E2V, I2V, L2VS, T2V, V2B, V2I, V2T,
Entity, EntitySet, Relship, ValueSequence],
IO,
Rope,
WalnutDefs USING [Error, ServerInfo],
WalnutKernelDefs USING [LogExpungePhase],
WalnutDB,
WalnutSchema;
WalnutDBInfoImpl: CEDAR PROGRAM
IMPORTS
DB, IO,
WalnutDefs, WalnutDB, WalnutSchema
EXPORTS WalnutDB =
BEGIN OPEN WalnutSchema;
Types
ROPE: TYPE = Rope.ROPE;
GMT: TYPE = BasicTime.GMT;
Msg: TYPE = ROPE;
Entity: TYPE = DB.Entity;
EntitySet: TYPE = DB.EntitySet;
Relship: TYPE = DB.Relship;
ServerInfo: TYPE = WalnutDefs.ServerInfo;
Operations used during Expunge, NewMail and reading Archive files
GetExpungeInfo: PUBLIC PROC RETURNS[
firstDestroyedMsgPos, bytesInDestroyedMsgs: INT] = {
Gei: PROC = {
rLogInfo: Relship = DB.FirstRelship[gLogInfo];
firstDestroyedMsgPos ← DB.V2I[DB.GetF[rLogInfo, gFirstDestroyedMsgPos]];
bytesInDestroyedMsgs ← DB.V2I[DB.GetF[rLogInfo, gBytesInDestroyedMsgs]]
};
WalnutDB.CarefullyApply[Gei];
};
SetExpungeInfo: PUBLIC PROC[firstDestroyedMsgPos, bytesInDestroyedMsgs: INT] = {
Sei: PROC = {
rLogInfo: Relship = DB.FirstRelship[gLogInfo];
DB.SetF[rLogInfo, gFirstDestroyedMsgPos, DB.I2V[firstDestroyedMsgPos]];
DB.SetF[rLogInfo, gBytesInDestroyedMsgs, DB.I2V[bytesInDestroyedMsgs]];
};
WalnutDB.CarefullyApply[Sei];
};
GetLogExpungePhase: PUBLIC PROC RETURNS[exp: WalnutKernelDefs.LogExpungePhase] = {
Gep: PROC = {
rExpungeInfo: Relship = DB.FirstRelship[gExpungeInfo];
ph: INT DB.V2I[DB.GetF[rExpungeInfo, gLogExpungePhase]];
SELECT ph FROM
0 => exp← idle;
1 => exp← initializingExpungeLog;
2 => exp← writingExpungeLog;
3 => exp← swappingLogs;
ENDCASE => {
SIGNAL WalnutDefs.Error[$db, $Bug, IO.PutFR[badExpVal, IO.int[ph]] ];
exp← idle
};
};
WalnutDB.CarefullyApply[Gep];
};
badExpVal: ROPE = "Bad expungePhase value (%g)";
SetLogExpungePhase: PUBLIC PROC[exp: WalnutKernelDefs.LogExpungePhase] = {
Sep: PROC = {
rExpungeInfo: Relship = DB.FirstRelship[gExpungeInfo];
val: INT;
SELECT exp FROM
idle => val ← 0;
initializingExpungeLog => val ← 1;
writingExpungeLog => val ← 2;
swappingLogs => val ← 3;
ENDCASE => {
ph: INTEGERLOOPHOLE[exp];
SIGNAL WalnutDefs.Error[$db, $Bug,IO.PutFR[badExpVal, IO.int[val]] ];
val ← 0;
};
DB.SetF[rExpungeInfo, gLogExpungePhase, DB.I2V[val]];
};
WalnutDB.CarefullyApply[Sep];
};
GetExpungeProgressInfo: PUBLIC PROC RETURNS[currentLogPos, expungeLogPos: INT] = {
Gepi: PROC = {
rExpungeInfo: Relship = DB.FirstRelship[gExpungeInfo];
currentLogPos ← DB.V2I[DB.GetF[rExpungeInfo, gCurrentLogPos]];
expungeLogPos ← DB.V2I[DB.GetF[rExpungeInfo, gExpungeLogPos]];
};
WalnutDB.CarefullyApply[Gepi];
};
SetExpungeProgressInfo: PUBLIC PROC[currentLogPos, expungeLogPos: INT] = {
Sepi: PROC = {
rExpungeInfo: Relship = DB.FirstRelship[gExpungeInfo];
DB.SetF[rExpungeInfo, gCurrentLogPos, DB.I2V[currentLogPos]];
DB.SetF[rExpungeInfo, gExpungeLogPos, DB.I2V[expungeLogPos]];
};
WalnutDB.CarefullyApply[Sepi];
};
GetExpungeFileID: PUBLIC PROC RETURNS[expungeFileID: INT] = {
Gefi: PROC = {
rExpungeInfo: Relship = DB.FirstRelship[gExpungeInfo];
expungeFileID ← DB.V2I[DB.GetF[rExpungeInfo, gExpungeFileID]]
};
WalnutDB.CarefullyApply[Gefi];
};
SetExpungeFileID: PUBLIC PROC[expungeFileID: INT] = {
Sefi: PROC = {
rExpungeInfo: Relship = DB.FirstRelship[gExpungeInfo];
DB.SetF[rExpungeInfo, gExpungeFileID, DB.I2V[expungeFileID]]
};
WalnutDB.CarefullyApply[Sefi];
};
GetTimeOfLastExpunge: PUBLIC PROC RETURNS[when: GMT] = {
Gtle: PROC = {
rExpungeInfo: Relship = DB.FirstRelship[gExpungeInfo];
when ← DB.V2T[DB.GetF[rExpungeInfo, gTimeOfLastExpunge]]
};
WalnutDB.CarefullyApply[Gtle];
};
SetTimeOfLastExpunge: PUBLIC PROC[when: GMT] = {
Stle: PROC = {
rExpungeInfo: Relship = DB.FirstRelship[gExpungeInfo];
DB.SetF[rExpungeInfo, gTimeOfLastExpunge, DB.T2V[when]]
};
WalnutDB.CarefullyApply[Stle];
};
GetTimeOfLastScavenge: PUBLIC PROC RETURNS[when: GMT] = {
Gtls: PROC = {
rLogInfo: Relship = DB.FirstRelship[gLogInfo];
when ← DB.V2T[DB.GetF[rLogInfo, gTimeOfLastScavenge]]
};
WalnutDB.CarefullyApply[Gtls];
};
SetTimeOfLastScavenge: PUBLIC PROC[when: GMT] = {
Stls: PROC = {
rLogInfo: Relship = DB.FirstRelship[gLogInfo];
DB.SetF[rLogInfo, gTimeOfLastScavenge, DB.T2V[when]]
};
WalnutDB.CarefullyApply[Stls];
};
SetAcceptNewMailPos: PUBLIC PROC[pos: INT] = {
Sanmp: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
DB.SetF[rNewMailInfo, gAcceptNewMailLogPos, DB.I2V[pos]]
};
WalnutDB.CarefullyApply[Sanmp];
};
GetAcceptNewMailPos: PUBLIC PROC RETURNS[pos: INT] = {
Ganmp: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
pos ← DB.V2I[DB.GetF[rNewMailInfo, gAcceptNewMailLogPos]]
};
WalnutDB.CarefullyApply[Ganmp];
};
SetAddingServerMsgs: PUBLIC PROC[addingServerMsgs: BOOL] = {
Sasm: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
DB.SetF[rNewMailInfo, gAddingServerMsgs, DB.B2V[addingServerMsgs]]
};
WalnutDB.CarefullyApply[Sasm];
};
GetAddingServerMsgs: PUBLIC PROC RETURNS[addingServerMsgs: BOOL] = {
Sasm: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
addingServerMsgs← DB.V2B[DB.GetF[rNewMailInfo, gAddingServerMsgs]]
};
WalnutDB.CarefullyApply[Sasm];
};
EnumerateServers: PUBLIC PROC RETURNS[serverList: LIST OF ServerInfo] = {
Gsi: PROC = {
enum: EntitySet ← DB.DomainSubset[ServerDomain, NIL, NIL, First];
se: Entity;
FOR se ← DB.NextEntity[enum], DB.NextEntity[enum] UNTIL se = NIL DO
rel: Relship = DB.LookupProperty[sBasicInfo, se];
si: ServerInfo;
si.server ← DB.EntityInfo[se].name;
si.num ← DB.V2I[DB.GetF[rel, sBINum]];
serverList ← CONS[si, serverList];
ENDLOOP;
DB.ReleaseEntitySet[enum];
};
WalnutDB.CarefullyApply[Gsi];
};
GetServerInfo: PUBLIC PROC[server: ROPE] RETURNS[num: INT] = {
Gsr: PROC = {
se: Entity = DB.LookupEntity[ServerDomain, server];
IF se # NIL THEN {
rel: Relship = DB.LookupProperty[sBasicInfo, se];
num ← DB.V2I[DB.GetF[rel, sBINum]]
}
ELSE num ← 0;
};
WalnutDB.CarefullyApply[Gsr];
};
SetNewMailInfo: PUBLIC PROC[logLen: INT, when: GMT, server: ROPE, num: INT] = {
Snmi: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
IF server # NIL THEN {
se: Entity ← DB.LookupEntity[ServerDomain, server];
IF se = NIL THEN {  -- create this entity
init: DB.ValueSequence = DB.L2VS[LIST[
DB.E2V[DB.DeclareEntity[ServerDomain, server]],
DB.I2V[num]
] ];
[] ← DB.CreateRelship[sBasicInfo, init];
}
ELSE {
rel: Relship = DB.LookupProperty[sBasicInfo, se];
DB.SetF[rel, sBINum, DB.I2V[num]];
};
};
DB.SetF[rNewMailInfo, gNewMailLogLength, DB.I2V[logLen]];
DB.SetF[rNewMailInfo, gLastNewMailTimeStamp, DB.T2V[when]]
};
WalnutDB.CarefullyApply[Snmi];
};
SetNewMailLogLength: PUBLIC PROC[logLen: INT] = {
Gnml: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
DB.SetF[rNewMailInfo, gNewMailLogLength, DB.I2V[logLen]];
};
WalnutDB.CarefullyApply[Gnml];
};
GetNewMailLogLength: PUBLIC PROC RETURNS[logLen: INT] = {
Gnml: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
logLen ← DB.V2I[DB.GetF[rNewMailInfo, gNewMailLogLength]]
};
WalnutDB.CarefullyApply[Gnml];
};
GetLastNewMailTimeStamp: PUBLIC PROC RETURNS[when: GMT] = {
Glnmts: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
when ← DB.V2T[DB.GetF[rNewMailInfo, gLastNewMailTimeStamp]]
};
WalnutDB.CarefullyApply[Glnmts];
};
SetCopyMailLogPos: PUBLIC PROC[pos: INT] = {
Scml: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
DB.SetF[rNewMailInfo, gCopyNewMailLogPos, DB.I2V[pos]]
};
WalnutDB.CarefullyApply[Scml];
};
GetCopyMailLogPos: PUBLIC PROC RETURNS[pos: INT] = {
Gcml: PROC = {
rNewMailInfo: Relship = DB.FirstRelship[gNewMailInfo];
pos ← DB.V2I[DB.GetF[rNewMailInfo, gCopyNewMailLogPos]]
};
WalnutDB.CarefullyApply[Gcml];
};
SetReadArchivePos: PUBLIC PROC[pos: INT] = {
Srap: PROC = {
rReadArchiveInfo: Relship = DB.FirstRelship[gReadArchiveInfo];
DB.SetF[rReadArchiveInfo, gReadArchiveLogPos, DB.I2V[pos]]
};
WalnutDB.CarefullyApply[Srap];
};
GetReadArchivePos: PUBLIC PROC RETURNS[pos: INT] = {
Grap: PROC = {
rReadArchiveInfo: Relship = DB.FirstRelship[gReadArchiveInfo];
pos ← DB.V2I[DB.GetF[rReadArchiveInfo, gReadArchiveLogPos]]
};
WalnutDB.CarefullyApply[Grap];
};
SetCopyReadArchivePos: PUBLIC PROC[pos: INT] = {
Scra: PROC = {
rReadArchiveInfo: Relship = DB.FirstRelship[gReadArchiveInfo];
DB.SetF[rReadArchiveInfo, gCopyReadArchiveLogPos, DB.I2V[pos]]
};
WalnutDB.CarefullyApply[Scra];
};
GetCopyReadArchivePos: PUBLIC PROC RETURNS[pos: INT] = {
Gcra: PROC = {
rReadArchiveInfo: Relship = DB.FirstRelship[gReadArchiveInfo];
pos ← DB.V2I[DB.GetF[rReadArchiveInfo, gCopyReadArchiveLogPos]]
};
WalnutDB.CarefullyApply[Gcra];
};
END.