IPPrinterRemoteStreamLocalStub.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, September 5, 1984 10:18:39 pm PDT
Tim Diebert: July 2, 1986 9:13:19 am PDT
Rick Beach, December 11, 1985 4:08:14 pm PST
DIRECTORY
BasicTime,
IO,
FS,
Rope,
IPPrinterRemoteStream,
STP;
IPPrinterRemoteStreamLocalStub: PROGRAM
IMPORTS FS, IO, Rope, STP
EXPORTS IPPrinterRemoteStream
= BEGIN
Error: PUBLIC ERROR [expl: ROPE, retryable: BOOL] = CODE;
ROPE: TYPE ~ Rope.ROPE;
Retryable: PROC [local: BOOL, code: ATOM, stpCode: STP.ErrorCode] RETURNS [BOOL] = {
IF local THEN RETURN [SELECT code FROM $connectionTimedOut, $connectionRejected => TRUE, ENDCASE => FALSE];
RETURN [SELECT stpCode FROM connectionTimedOut, connectionRejected, connectionClosed, noConnection, noNameLookupResponse => TRUE, ENDCASE => FALSE];
};
Lookup: PUBLIC PROC [fileName: ROPE, createDate: BasicTime.GMT, name, password: ROPE] RETURNS [fullFName: ROPE, bytes: INT, createDateRope: ROPE] = {
BEGIN ENABLE UNWIND => {};
time: BasicTime.GMT;
[fullFName: fullFName, bytes: bytes, created: time] ← FS.FileInfo[fileName ! FS.Error => Error[expl: error.explanation, retryable: FALSE]];
createDateRope ← IO.PutR[IO.time[time]];
END;
};
Read: PUBLIC PROC [fileName: ROPE, name, password: ROPE, toStream: IO.STREAM] = {
MyRead[fileName, name, password, toStream !
FS.Error => ERROR Error[expl: error.explanation, retryable: Retryable[TRUE, error.code, undefinedError]]];
};
MyRead: PROC [fileName: ROPE, name, password: ROPE, toStream: IO.STREAM] = {
stream: IO.STREAM ← toStream;
cp: FS.ComponentPositions; server, file: ROPE;
[fileName, cp] ← FS.ExpandName[fileName
! FS.Error => ERROR Error[expl: error.explanation, retryable: Retryable[TRUE, error.code, undefinedError]]];
server ← Rope.Substr[fileName, cp.server.start, cp.server.length];
file ← Rope.Substr[fileName, cp.dir.start-1];
BEGIN ENABLE UNWIND => {IF stream # NIL THEN {IO.Close[stream]; stream ← NIL}};
IF Rope.IsEmpty[server] THEN
{stream ← NIL; ERROR Error[expl: "Local File", retryable: FALSE]};
BEGIN
stp: STP.Handle ← STP.Create[];
open: BOOLFALSE;
Confirm: STP.ConfirmProcType = TRUSTED BEGIN
-- PROC[file: Rope.ROPE] RETURNS [answer: Confirmation, localStream: IO.STREAM]
RETURN[do, stream];
END;
BEGIN
ENABLE UNWIND => {IF open THEN stp.Close[ ! STP.Error => TRUSTED {CONTINUE}];
IF stream # NIL THEN {IO.Close[stream]; stream ← NIL}};
[] ← STP.Open[stp, server
! STP.Error => TRUSTED {ERROR Error[expl: error, retryable: FALSE]}];
open ← TRUE;
STP.Login[stp, name, password];
STP.Retrieve[stp, file, Confirm
! STP.Error => TRUSTED {ERROR Error[expl: error, retryable: FALSE]}];
STP.Close[stp ! STP.Error => TRUSTED {CONTINUE}];
IO.Close[stream];
stream ← NIL
END;
END;
END;
};
END.