SpoolControlImpl.mesa
Copyright (C) Xerox Corporation 1982, 1983, 1984, 1985, 1986. All rights reserved.
Last edited by Jacks: 22-Jul-85 15:06:51
Tim Diebert: December 29, 1986 10:42:37 am PST
DIRECTORY
MarkerControl USING [ClientProcsHandle, MarkerStatus],
PrintQueue USING [Empty, QueueStage],
Process USING [Detach],
PSAsyncMsg USING [Proc, PutMesaString],
QueueFile USING [SetTrace],
SpoolControl USING [Control, ControlHandle, ErrorTypes, SpoolStatus, TraceLevel, WaitChoice],
XNS USING [Address],
XNSAddressParsing USING [MyAddress];
SpoolControlImpl: CEDAR MONITOR
IMPORTS PrintQueue, Process, PSAsyncMsg, QueueFile, XNSAddressParsing
EXPORTS SpoolControl = BEGIN
controlRec: SpoolControl.Control ← []; --Initialize record.
control: PUBLIC SpoolControl.ControlHandle ← NEW[SpoolControl.Control ← controlRec];
connectionClosed: CONDITION;
ERRORS
Error: PUBLIC ERROR [errortype: SpoolControl.ErrorTypes] = CODE;
PUBLIC PROCEDURES
Init: PUBLIC ENTRY PROCEDURE [maxConnections: CARDINAL ← 1,
markerProcs: MarkerControl.ClientProcsHandle,
putAsyncMsgFromKey: PSAsyncMsg.Proc]
RETURNS [XNS.Address] = BEGIN
ENABLE UNWIND => NULL;
control^ ← [maxConnections: maxConnections, markerProcs: markerProcs,
putAsyncMsgFromKey: putAsyncMsgFromKey];
RETURN[XNSAddressParsing.MyAddress[]];
END; -- Init
Start: PUBLIC ENTRY PROCEDURE = -- Undoes a Suspend or Disable.
BEGIN OPEN control;
ENABLE UNWIND => NULL;
IF ~allowConnection THEN allowConnection ← TRUE;
abortCurrent ← printingPreempt ← FALSE;
IF trace # none AND allowConnection THEN
PSAsyncMsg.PutMesaString["--Spooling Enabled"];
END; -- Start
Suspend: PUBLIC ENTRY PROCEDURE =
BEGIN ENABLE UNWIND => NULL; -- assumes Preempted for printing!
control.printingPreempt ← TRUE;
IF control.trace # none THEN
PSAsyncMsg.PutMesaString["--Suspend Spooling"];
END; -- Suspend
Stop: PUBLIC ENTRY PROCEDURE [disposeQ: PrintQueue.QueueStage] =
BEGIN -- Abort ongoing activity and refuse new connection requests.
ENABLE UNWIND => NULL;
control.abortedQ ← disposeQ;
control.allowConnection ← FALSE;
control.abortCurrent ← TRUE;
END; -- Stop
Stopped: PUBLIC ENTRY PROCEDURE [wither: SpoolControl.WaitChoice ← dontWait]
RETURNS
[BOOLEAN] =
BEGIN OPEN control; -- ASSUMES Suspend or Stop called
ENABLE UNWIND => NULL;
IF wither = wait THEN
UNTIL currentConnections = 0 DO WAIT connectionClosed; ENDLOOP;
IF trace # none AND currentConnections = 0 THEN
PSAsyncMsg.PutMesaString[
IF ~control.allowConnection THEN "--Spooling Disabled" ELSE "--Spooling Suspended"];
RETURN[currentConnections=0];
END; -- Stopped
ModifyTraceLevel: PUBLIC ENTRY PROCEDURE [trace: SpoolControl.TraceLevel] = BEGIN
ENABLE UNWIND => NULL;
control.trace ← trace;
QueueFile.SetTrace[LOOPHOLE[trace]];
END; -- ModifyTraceLevel
Connections: PUBLIC ENTRY PROCEDURE [number: INTEGER] = BEGIN
Add (subtract) number allowable concurrent network connections.
ENABLE UNWIND => NULL;
NSCommand.PutLine[NSString.StringFromMesaString["Connections param not implemented"]L, TRUE];
END; -- Connections
Status: PUBLIC PROCEDURE RETURNS [spoolStatus: SpoolControl.SpoolStatus] = BEGIN
spoolStatus ← SpoolControl.SpoolStatus[
enabled: control.allowConnection AND NOT control.printingPreempt,
connectionsAllowed: control.maxConnections,
currentConnections: control.currentConnections
];
END; -- Status
Communications Control Procs
FilterConnection: PUBLIC ENTRY PROC =
BEGIN OPEN control; ENABLE UNWIND => NULL;
SELECT TRUE FROM
~allowConnection => RETURN WITH ERROR Error[spoolingDisabled]; -- psBusy
currentConnections >= maxConnections => RETURN WITH ERROR Error[tooManyConnections];
PrintQueue.Empty[inactive] => RETURN WITH ERROR Error[spoolFull];
printingPreempt AND currentConnections < maxConnections => BEGIN
The following code is ackward, but I couldn't get the compiler to accept a better way. **AJ
markerStatus: MarkerControl.MarkerStatus ← markerProcs.status[];
IF markerStatus.activity = markingButInterruptable OR
markerStatus.activity = paused
THEN BEGIN
IF control.trace = verbose THEN PSAsyncMsg.PutMesaString["--Pause Marking"];
markerStatus ← markerProcs.pause[];
IF markerStatus.activity # marking
THEN resumePrinting ← TRUE
ELSE RETURN WITH ERROR Error[busy];
END
ELSE RETURN WITH ERROR Error[busy];
END;
ENDCASE => NULL;
IncrementConnections[];
END; -- FilterConnection.
ConnectionClosed: PUBLIC ENTRY PROCEDURE = BEGIN OPEN control;
ENABLE UNWIND => NULL;
currentConnections ← currentConnections - 1;
IF control.resumePrinting THEN BEGIN
IF control.trace = verbose THEN PSAsyncMsg.PutMesaString["--Resume Marking"];
TRUSTED {Process.Detach[FORK control.markerProcs.resume[]]}; --Avoid MLs where marker can't resume right away.
control.resumePrinting ← FALSE;
END;
NOTIFY connectionClosed;
END; -- ConnectionClosed
IncrementConnections: PRIVATE INTERNAL PROCEDURE = INLINE BEGIN
control.currentConnections ← control.currentConnections + 1;
END; -- IncrementConnections
END.
LOG when - who - what
15-Sep-82 13:14:38 - Beeley - Created from code in TelepressServerImpl.
27-Sep-82 8:03:55 - Alfvin - Converted to Pilot 9.0, Filing 5.0 and Services 5.0.
7-Oct-82 8:29:30 - Alfvin - Add Export/UnexportRemoteProgram's to Start/Stop.
12-Oct-82 16:40:44 - Beeley - Removed Export/UnexportRemoteProgram's (they're now in PSComndImpl).
14-Feb-83 14:03:04 - Beeley - Changed FilterConnection to raise busy in 'printingPreempt AND currentConnections<1' case instead of spoolingDisabled.
13-Jul-83 15:00:52 - Jacks - Removed TelepressServer.Init from Init proc (removing all Telepress support from PS).
5-Aug-83 15:27:45 - Jacks - Changes as part of PSCommand rework: changed CommandInterface.TraceLevel to PSState.TraceLevel.
14-Nov-83 9:41:20 - Jacks - Undid last change: removed PSState dependency and defined TraceLevel locally; updated to new MarkerControl interface.
6-Dec-83 9:34:04 - Jacks - Added PutAsyncMsgFromKey to Init parms, proc is not currently useful; replaced NSCommand.PutAsyncMessage with PSAsyncMsg.PutMesaString
19-Dec-83 15:40:57 - Jacks - Converted to new MarkerControl and PrintQueue.
2-Mar-84 11:36:22 - Jacks - FORKED markerProcs.resume in ConnectionClosed--have a ML problem where marker is waiting for spooler to be done spooling while holding lock in MarkerControlImpl so resume can't complete.
11-Apr-84 16:10:38 - Jacks - Made the enabled field of the SpoolStatus record returned by Status FALSE if printingPreempt is true.
17-Jul-84 14:03:42 - Jacks - Added trace code to ConnectionClosed.
9-Nov-84 11:59:19 - Jacks - Updated to second round of 9.0 ps interface changes.
17-Jun-85 15:47:18 - Jacks - Added copyright notice.
22-Jul-85 15:06:48 - Jacks - Removed RecalculateQueuePages; new PSAsyncMsg and SpoolControlinterfaces.