XNSPrintRequestWatcherImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, October 29, 1986 10:03:43 pm PST
Bill Jackson (bj) February 6, 1987 5:39:11 am PST
Tim Diebert: February 9, 1987 11:00:03 am PST
DIRECTORY
Buttons USING [ButtonProc, Create, Destroy],
Commander USING [CommandProc, Register],
Imager USING [black, MaskRectangle, SetColor, white],
ImagerBackdoor USING [GetBounds],
IO USING [card, PutFR, PutRope, rope, STREAM],
PrintingP4V3 USING [RequestID],
PrintingP4V3Aux USING [ExposeInterpressMasterStatus],
Process USING [Detach],
Rope USING [ROPE],
TypeScript USING [Create],
UserProfile USING [Boolean],
ViewerClasses USING [AdjustProc, DestroyProc, PaintProc, Viewer, ViewerClass, ViewerClassRec],
ViewerIO USING [CreateViewerStreams],
ViewerOps USING [CreateViewer, EnumerateViewers, EnumProc, EstablishViewerPosition, OpenIcon, RegisterViewerClass],
XNSPrint USING [GetPrintRequestList, GetPrintRequestStatus, RequestListChanged, PrintRequest, PrintRequestList, RequestStatus];
XNSPrintRequestWatcherImpl: CEDAR MONITOR
IMPORTS Buttons, Commander, Imager, ImagerBackdoor, IO, PrintingP4V3Aux, Process, TypeScript, UserProfile, ViewerIO, ViewerOps, XNSPrint ~ {
OPEN Printing: PrintingP4V3, PrintingAux: PrintingP4V3Aux, XNSPrint;
Commander Constants
XNSPrintRequestWatcher: ROPE ~ "XNSPrintRequestWatcher";
doc: ROPE ~ "\nCreate viewer to monitor and/or manipulate XNS print requests";
usage: ROPE ~ "Usage: XNSPrintRequestWatcher";
NAMESTRIPE: ROPE ~ "Print Request Manipulation";
TYPESCRIPT: ROPE ~ "///Temp/XNSPrintRequestWatcher.TypeScript";
UserProfile Tags
AUTOOPEN: ROPE ~ "HardcopyWatcher.AutoOpen";
Global State
pendingPrintRequests: PrintRequestList ← NIL;
printManipViewerClass: ViewerClasses.ViewerClass;
watcher: Data ← NIL;
Types
ButtonList: TYPE ~ LIST OF Viewer;
ROPE: TYPE ~ Rope.ROPE;
Viewer: TYPE ~ ViewerClasses.Viewer;
Data: TYPE ~ REF DataRec;
DataRec: TYPE ~ RECORD [
actualRequest: PrintRequest ← NIL, -- only for the ButtonProc
autoOpen: BOOLFALSE,
buttons: ButtonList ← NIL,
requests: PrintRequestList ← NIL,
typeScript: Viewer ← NIL,
typeScriptIn: IO.STREAMNIL,
typeScriptOut: IO.STREAMNIL,
viewer: Viewer ← NIL
];
Display update Procs
WaitTilListChanged: ENTRY PROC ~ {
WAIT RequestListChanged;
};
WatchRequestList: PROC ~ {
enum: ViewerOps.EnumProc ~ {
IF (v.class = printManipViewerClass) THEN UpdateViewer[NARROW [v.data]];
};
DO -- Forever
WaitTilListChanged[];
ViewerOps.EnumerateViewers[enum];
ENDLOOP; -- Forever
};
Procs guarding "watcher" state
ClearWatcher: ENTRY PROC ~ {
watcher ← NIL;
};
ConditionallySetWatcher: ENTRY PROC [new: Data] RETURNS [old: Data] ~ {
old ← watcher;
IF (watcher = NIL) THEN watcher ← new;
};
Commander Proc
RequestWatcherCmd: Commander.CommandProc ~ {
data: Data ← NEW [DataRec];
otherGuy: Data ← ConditionallySetWatcher[data];
IF (otherGuy # NIL) THEN {
UpdateViewer[otherGuy, TRUE];
RETURN;
};
data.autoOpen ← UserProfile.Boolean[AUTOOPEN, FALSE];
data.viewer ← ViewerOps.CreateViewer[
flavor: $XNSPrintRequestWatcher,
info: [name: NAMESTRIPE, data: data]
];
data.typeScript ← TypeScript.Create[[parent: data.viewer, border: TRUE, wh: 60]];
[data.typeScriptIn, data.typeScriptOut] ← ViewerIO.CreateViewerStreams[NIL, data.typeScript, TYPESCRIPT];
TypeScriptWrite[data, "Beginning of Typescript...\n"];
UpdateViewer[data];
};
Viewer Procs
TypeScriptWrite: PUBLIC PROC [data: Data, rope: ROPE] ~ {
IF (data.typeScriptOut # NIL) THEN IO.PutRope[data.typeScriptOut, rope];
};
AdjustProc: ViewerClasses.AdjustProc ~ {
data: Data ← NARROW [self.data];
nButtons: NAT ← 0;
height: INTEGER ← self.wh-12;
FOR buttons: ButtonList ← data.buttons, buttons.rest WHILE (buttons # NIL) DO
button: Viewer ← buttons.first;
nButtons ← nButtons+1;
ViewerOps.EstablishViewerPosition[button, 0, (height-(20*nButtons)), button.ww, button.wh];
ENDLOOP;
ViewerOps.EstablishViewerPosition[data.typeScript, 0, 0, self.ww, (height-(20*nButtons)-4)];
RETURN[TRUE];
};
DestroyProc: ViewerClasses.DestroyProc ~ {
data: Data ← NARROW [self.data];
ClearWatcher[];
};
PaintProc: ViewerClasses.PaintProc = {
data: Data ← NARROW [self.data];
IF (whatChanged = NIL) THEN {
Imager.SetColor[context, Imager.white];
Imager.MaskRectangle[context, ImagerBackdoor.GetBounds[context]];
Imager.SetColor[context, Imager.black];
};
};
UpdateViewer: PROC [data: Data, forceOpen: BOOLFALSE] ~ {
data.requests ← GetPrintRequestList[];
MakeButtons[data];
IF ( (data.autoOpen) OR (forceOpen) ) THEN {
IF (data.viewer.iconic) THEN ViewerOps.OpenIcon[data.viewer];
};
};
Button Procs
ButtonProc: Buttons.ButtonProc ~ {
data: Data ← NARROW [clientData];
msg: ROPENIL;
request: PrintRequest ← data.actualRequest;
requestStatus: RequestStatus;
TypeScriptWrite[data, "Checking: "];
TypeScriptWrite[data, data.actualRequest.fileName];
TypeScriptWrite[data, "\n"];
requestStatus ← XNSPrint.GetPrintRequestStatus[request];
msg ← PrintingAux.ExposeInterpressMasterStatus[requestStatus.status, 1];
TypeScriptWrite[data, "status: ("];
TypeScriptWrite[data, msg];
TypeScriptWrite[data, ") statusMessage: "];
TypeScriptWrite[data, requestStatus.statusMessage];
TypeScriptWrite[data, "\n"];
};
MakeButtons: PROC [data: Data] ~ {
FOR buttons: ButtonList ← data.buttons, buttons.rest WHILE (buttons # NIL) DO
Buttons.Destroy[buttons.first];
ENDLOOP;
data.buttons ← NIL;
FOR pr: PrintRequestList ← data.requests, pr.rest WHILE (pr # NIL) DO
MakeButton[pr.first, data];
ENDLOOP;
[] ← AdjustProc[data.viewer];
};
MakeButton: PROC [request: PrintRequest, data: Data] ~ {
buttonName: ROPENIL;
id: ROPENIL;
IF (request = NIL) THEN RETURN;
FOR n: NAT IN [0..5) DO
id ← IO.PutFR["%g %g", IO.rope[id], IO.card[request.requestID[n]]];
ENDLOOP;
buttonName ← IO.PutFR["%g %g %g",
IO.rope[request.context.printerName], IO.rope[id], IO.rope[request.fileName]];
data.actualRequest ← request;
data.buttons ← CONS[
Buttons.Create[
info: [parent: data.viewer, name: buttonName],
proc: ButtonProc,
clientData: data
],
data.buttons
];
};
Initialization
Init: PROC ~ {
printManipViewerClass ← NEW[ViewerClasses.ViewerClassRec ← [
paint: PaintProc,
adjust: AdjustProc,
destroy: DestroyProc
]];
ViewerOps.RegisterViewerClass[$XNSPrintRequestWatcher, printManipViewerClass];
Commander.Register[XNSPrintRequestWatcher, RequestWatcherCmd, doc];
TRUSTED {Process.Detach[ FORK WatchRequestList]};
};
Init[];
}...