PDPrinterClientImpl.mesa
Michael Plass, November 18, 1983 4:51 pm
DIRECTORY Environment, Rope,
IO, FileIO, MessageWindow, PDInterpBasic, PDPrinterRpcControl, PDPrinter, MesaRPC;
PDPrinterClientImpl:
CEDAR
PROGRAM
IMPORTS IO, FileIO, MessageWindow, PDPrinterRpcControl, PDPrinter, MesaRPC
mess: CARDINAL ← 0;
ReportStatus:
PROC [status: PDInterpBasic.Status] ~ {
s: IO.STREAM ← IO.CreateOutputStreamToRope[];
s.Put[IO.refAny[NEW[PDInterpBasic.Status ← status]]];
s.PutRope[", "];
MessageWindow.Append[IO.GetOutputStreamRope[s], mess MOD 4 = 0];
mess ← mess + 1;
s.Close[];
};
Print:
PUBLIC
PROC [file: Rope.
ROPE] ~
TRUSTED {
requestorName: LONG STRING = "Plass.pa"L;
interfaceName: MesaRPC.InterfaceName ← [instance: requestorName];
stream: IO.STREAM ← FileIO.Open[file];
response: PDPrinter.Response ← [nextWordIndex: 0, status: betweenPages, currentPage: 0];
dataBlock: PDPrinter.DataBlock;
oldStatus: PDInterpBasic.Status ← transmissionComplete;
PDPrinterRpcControl.ImportInterface[[instance: "Plass.pa"]
! MesaRPC.ImportFailed => {
s: IO.STREAM ← IO.CreateOutputStreamToRope[];
s.PutRope["Unable to access PDInterpControl: "];
s.Put[IO.refAny[NEW[MesaRPC.ImportFailure ← why]]];
MessageWindow.Append[IO.GetOutputStreamRope[s], TRUE];
MessageWindow.Blink[];
GOTO Quit;
}
];
BEGIN
ENABLE
UNWIND => {PDPrinterRpcControl.UnimportInterface[];
IO.Close[stream]};
WHILE response.nextWordIndex >= 0
DO
byteIndex: INT ← response.nextWordIndex*2;
bytesRead: INT ← 0;
bytesPerBlock: INT = PDPrinter.maxBlockSize*Environment.bytesPerWord;
stream.SetIndex[byteIndex];
bytesRead ← stream.UnsafeGetBlock[[@(dataBlock.buffer), 0, bytesPerBlock]];
dataBlock.wordIndex ← response.nextWordIndex;
dataBlock.wordCount ← bytesRead/Environment.bytesPerWord;
response ← PDPrinter.TransmitBlock[dataBlock];
IF response.status # oldStatus
THEN {
ReportStatus[response.status];
oldStatus ← response.status;
};
ENDLOOP;
END;
PDPrinterRpcControl.UnimportInterface[];
IO.Close[stream];
EXITS Quit => NULL;
};
END.