FingerLogImpl.mesa
Last Edited by: Donahue, April 23, 1985 2:37:25 pm PST
DIRECTORY
Atom,
BasicTime USING [GMT],
Convert,
FingerLog,
FS USING[StreamOpen, Error],
IO,
Rope;
FingerOpsImpl: CEDAR PROGRAM
IMPORTS Atom, Convert, FS, IO
EXPORTS FingerLog =
BEGIN
OPEN FingerLog;
fingerLogName: Rope.ROPE = "///Finger.Log";
fingerStream: IO.STREAM; -- a stream always opened to the finger log file
stateChangeAtom: ATOM = Atom.MakeAtom["StateChange"];
userPropChangeAtom: ATOM = Atom.MakeAtom["UserPropChange"];
machinePropChangeAtom: ATOM = Atom.MakeAtom["MachinePropChange"];
addMachinePropAtom: ATOM = Atom.MakeAtom["AddMachineProp"];
addUserPropAtom: ATOM = Atom.MakeAtom["AddUserProp"];
deleteMachinePropAtom: ATOM = Atom.MakeAtom["DeleteMachineProp"];
deleteUserPropAtom: ATOM = Atom.MakeAtom["DeleteUserProp"];
FlushLog: PUBLIC PROC[] ~ { fingerStream.SetLength[0]; fingerStream.Flush[] };
Log: PUBLIC PROC[ logEntry: LogEntry ] = TRUSTED {
Write the entry on the log file and also on the internal log list
IF fingerStream = NIL THEN fingerStream ← FS.StreamOpen[fingerLogName, $append];
WITH entry: logEntry SELECT FROM
StateChange => {
fingerStream.Put[IO.atom[stateChangeAtom], IO.rope[" "]];
fingerStream.Put[IO.atom[IF entry.event = login THEN $login ELSE $logout], IO.rope[" "]];
fingerStream.Put[IO.rope[entry.user], IO.rope[" "]];
fingerStream.Put[IO.time[entry.time], IO.rope["\n"]] };
UserPropChange => {
fingerStream.Put[IO.atom[userPropChangeAtom], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.user]], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.name]], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.val]], IO.rope[" "]];
fingerStream.Put[IO.time[entry.time], IO.rope["\n"]] };
MachinePropChange => {
fingerStream.Put[IO.atom[machinePropChangeAtom], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.name]], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.val]], IO.rope["\n"]] };
AddMachineProp => {
fingerStream.Put[IO.atom[addMachinePropAtom], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.name]], IO.rope[" "]];
fingerStream.Put[IO.int[entry.version], IO.rope["\n"]] };
AddUserProp => {
fingerStream.Put[IO.atom[addUserPropAtom], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.name]], IO.rope[" "]];
fingerStream.Put[IO.int[entry.version], IO.rope["\n"]] };
DeleteUserProp => {
fingerStream.Put[IO.atom[deleteUserPropAtom], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.name]], IO.rope[" "]];
fingerStream.Put[IO.int[entry.version], IO.rope["\n"]] };
DeleteMachineProp => {
fingerStream.Put[IO.atom[deleteMachinePropAtom], IO.rope[" "]];
fingerStream.Put[IO.rope[Convert.RopeFromRope[entry.name]], IO.rope[" "]];
fingerStream.Put[IO.int[entry.version], IO.rope["\n"]]};
ENDCASE;
fingerStream.Flush[] };
ParseLog: PUBLIC PROC[] RETURNS[ stateLog: LIST OF LogEntry ] ~ {
ENABLE FS.Error => CONTINUE;
fingerStream: IO.STREAM = FS.StreamOpen[fingerLogName, $read];
BEGIN
ENABLE IO.EndOfStream, IO.Error => CONTINUE;
op: ATOM;
nextEntry: LogEntry;
WHILE TRUE DO
op ← fingerStream.GetAtom[];
SELECT op FROM
stateChangeAtom => {
what: ATOM = fingerStream.GetAtom[];
name: Rope.ROPE = fingerStream.GetRopeLiteral[];
when: BasicTime.GMT = fingerStream.GetTime[];
nextEntry ← NEW[ StateChange LogEntryObject ← [StateChange[event: IF what = $login THEN login ELSE logout, user: name, time: when ]] ] };
userPropChangeAtom => {
user: Rope.ROPE = fingerStream.GetRopeLiteral[];
name: Rope.ROPE = fingerStream.GetRopeLiteral[];
val: Rope.ROPE = fingerStream.GetRopeLiteral[];
time: BasicTime.GMT = fingerStream.GetTime[];
nextEntry ← NEW[ UserPropChange LogEntryObject ← [UserPropChange[user: user, name: name, val: val, time: time ]] ] };
machinePropChangeAtom => {
name: Rope.ROPE = fingerStream.GetRopeLiteral[];
val: Rope.ROPE = fingerStream.GetRopeLiteral[];
nextEntry ← NEW[ MachinePropChange LogEntryObject ← [MachinePropChange[name: name, val: val]] ] };
addMachinePropAtom => {
name: Rope.ROPE = fingerStream.GetRopeLiteral[];
version: INT = fingerStream.GetInt[];
nextEntry ← NEW[ AddMachineProp LogEntryObject ← [AddMachineProp[name: name, version: version]] ] };
addUserPropAtom => {
name: Rope.ROPE = fingerStream.GetRopeLiteral[];
version: INT = fingerStream.GetInt[];
nextEntry ← NEW[ AddUserProp LogEntryObject ← [AddUserProp[name: name, version: version]] ] };
deleteUserPropAtom => {
name: Rope.ROPE = fingerStream.GetRopeLiteral[];
version: INT = fingerStream.GetInt[];
nextEntry ← NEW[ DeleteUserProp LogEntryObject ← [DeleteUserProp[name: name, version: version]] ] };
deleteMachinePropAtom => {
name: Rope.ROPE = fingerStream.GetRopeLiteral[];
version: INT = fingerStream.GetInt[];
nextEntry ← NEW[ DeleteMachineProp LogEntryObject ← [DeleteMachineProp[name: name, version: version]] ] };
ENDCASE;
IF stateLog = NIL THEN stateLog ← LIST[nextEntry]
ELSE {
log: LIST OF LogEntry ← stateLog;
WHILE log.rest # NIL DO log ← log.rest ENDLOOP;
log.rest ← LIST[nextEntry]
}
ENDLOOP
END;
IF fingerStream # NIL THEN fingerStream.Close[! IO.Error, FS.Error => CONTINUE]
};
END.