UFFileWatch:
CEDAR MONITOR
IMPORTS UFFileManager, ViewerOps, Graphics, Process
= BEGIN
DataRec:
TYPE =
RECORD [
paint: PROCESS ← NIL,
timeout: CONDITION
];
waitTime: Process.Ticks ← Process.MsecToTicks[1000];
PaintProcess:
ENTRY
PROCEDURE [viewer: ViewerClasses.Viewer] = {
ENABLE UNWIND => NULL;
d: REF DataRec ← NARROW[viewer.data];
WHILE NOT viewer.destroyed
DO
TRUSTED{ViewerOps.PaintViewer[viewer, client, FALSE, $Update]};
WAIT d.timeout;
ENDLOOP;
};
Create:
PROCEDURE
RETURNS [viewer: ViewerClasses.Viewer] =
TRUSTED {
data: REF DataRec ← NEW[DataRec];
Process.InitializeCondition[@data.timeout, waitTime];
viewer ← ViewerOps.CreateViewer[flavor: $UFFileWatcher, info: [name: "Open Font Files", data: data], paint: FALSE];
Process.Detach[data.paint ← FORK PaintProcess[viewer]];
ViewerOps.PaintViewer[viewer, all];
};
baseLine: NAT ← 12;
indent: NAT ← 6;
FileWatcherPaint: ViewerClasses.PaintProc = {
PaintFileName:
PROC [rope: Rope.
ROPE] = {
Graphics.SetCP[context, indent, Graphics.GetCP[context].y-baseLine];
Graphics.DrawRope[context, rope];
};
PaintNumber:
PROC [i:
INT] = {
IF i<0 THEN {Graphics.DrawChar[context, '-]; i←-i};
IF i>=10 THEN {PaintNumber[i/10]; i←i MOD 10};
Graphics.DrawChar[context, '0+i];
};
IF
NOT clear
THEN {
Graphics.SetColor[context, Graphics.white];
Graphics.DrawBox[context, [-100000, -100000, 100000, 100000]];
};
Graphics.SetColor[context, Graphics.black];
Graphics.SetCP[context, indent, self.ch-baseLine];
Graphics.DrawRope[context, "Number of file permissions: "];
PaintNumber[UFFileManager.PermissionCount[]];
UFFileManager.EnumerateOpenFontFiles[PaintFileName];
};
fileWatcherClass: ViewerClasses.ViewerClass ←
NEW[ViewerClasses.ViewerClassRec ← [
paint: FileWatcherPaint,
tipTable: NIL
]];
TRUSTED {ViewerOps.RegisterViewerClass[$UFFileWatcher, fileWatcherClass]};
[] ← Create[];
END.