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; Error: PUBLIC ERROR [errortype: SpoolControl.ErrorTypes] = CODE; 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 ENABLE UNWIND => NULL; 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 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 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. ψ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 ERRORS PUBLIC PROCEDURES Add (subtract) number allowable concurrent network connections. NSCommand.PutLine[NSString.StringFromMesaString["Connections param not implemented"]L, TRUE]; Communications Control Procs The following code is ackward, but I couldn't get the compiler to accept a better way. **AJ Κl˜codešœ™KšœR™RKšœ(™(K™.—K˜šΟk ˜ Kšœœ#˜6Kšœ œ˜%Kšœœ ˜Kšœ œ˜'Kšœ œ ˜Kšœ œK˜]Kšœœ ˜Kšœœ ˜$—K˜šΟnœœ˜Kšœ>˜EKšœ˜—˜K˜Kšœ'Οc˜;Kšœ œœ$˜TKšœ œ˜—˜Kšœ™K˜Kšžœœœ(œ˜@—˜Kšœ™—˜šžœœœ œœYœœ ˜¬Kšœœœ˜K˜nKšœ ˜&KšœŸ˜ ——˜š žœœœ œŸ ˜AKšœœ ˜Kšœœœ˜Kšœœœ˜0Kšœ!œ˜'šœœœ˜)K˜/—KšœŸ˜——˜šžœœœ œ˜!Kš œœœœŸ"˜?Kšœœ˜šœœ˜K˜/—KšœŸ ˜——˜šžœœœ œ$˜@KšœŸ>˜DKšœœœ˜K˜Kšœœ˜ Kšœœ˜KšœŸ˜ ——˜š žœœœ œ-œœ˜`Kšœœ Ÿ!˜5Kšœœœ˜šœ˜Kšœœœœ˜?—šœœ˜/˜Kšœœœ˜T——Kšœ˜KšœŸ ˜——˜š žœœœ œ#˜QKšœœœ˜K˜Kšœœ ˜$KšœŸ˜——˜š ž œœœ œ œ˜=Kšœ?™?Kšœœœ˜Kšœ]™]KšœŸ˜——˜š žœœ œœ*˜P˜'Kšœ!œœ˜AK˜+K˜.K˜—KšœŸ ˜——˜Kšœ™K˜šžœœœœ˜%Kš œœ œœœ˜*šœœ˜KšœœœœŸ ˜IKšœ(œœœ˜TKšœœœœ˜Ašœœ(˜@Kšœ[™[K˜@K˜šœ1˜5Kšœ˜šœ˜ K˜Kšœœ/˜NK˜#šœ ˜"Kšœ˜Kšœœœœ ˜#—Kš˜—Kšœœœœ ˜#—Kšœ˜—Kšœœ˜—K˜KšœŸ˜K˜—š žœœœ œœœ ˜>Kšœœœ˜K˜,šœœ˜$Kšœœ.˜MKšœœ!Ÿ1˜nKšœœ˜Kšœ˜—Kšœ˜KšœŸ˜K˜—š žœœœ œ ˜?K˜