Stream.mesa (last edited by: Plass, September 4, 1984 12:27:47 pm PDT)
Cedar PilotBridge version.
Copyright (C) Xerox Corporation 1982. All rights reserved.
DIRECTORY
Environment USING [Block, Byte, Word],
IO USING [STREAM];
Stream: DEFINITIONS =
BEGIN
Types
Handle: TYPE = REF Object;
Byte: TYPE = Environment.Byte;
Word: TYPE = Environment.Word;
SubSequenceType: TYPE = [0..256);
Block: TYPE = Environment.Block;
InputOptions: TYPE = RECORD [
terminateOnEndRecord: BOOLEANFALSE,
signalLongBlock: BOOLEANFALSE,
signalShortBlock: BOOLEANFALSE,
signalSSTChange: BOOLEANFALSE,
signalEndOfStream: BOOLEANFALSE,
signalAttention: BOOLEANFALSE,
signalTimeout: BOOLEANTRUE,
signalEndRecord: BOOLEANFALSE];
defaultInputOptions: InputOptions = [];
CompletionCode: TYPE =
{normal, endRecord, sstChange, endOfStream, attention, timeout};
Position: TYPE = LONG CARDINAL;
Milliseconds: TYPE = LONG CARDINAL;
Operations
GetByte: PROCEDURE [sH: Handle] RETURNS [byte: Byte] = INLINE
{RETURN[sH.getByte[sH]]}; -- Get the next byte from the stream.
GetChar: PROCEDURE [sH: Handle] RETURNS [char: CHARACTER] = INLINE
{RETURN[LOOPHOLE[sH.getByte[sH]]]}; -- Get the next character from the stream.
GetWord: PROCEDURE [sH: Handle] RETURNS [word: Word] = INLINE
{RETURN[sH.getWord[sH]]};
Get the next two bytes from the stream, and return them in a word (first
in left half).
GetBlock: PROCEDURE [sH: Handle, block: Block]
RETURNS [
bytesTransferred: CARDINAL, why: CompletionCode, sst: SubSequenceType] =
INLINE {[bytesTransferred, why, sst] ← sH.get[sH, block, sH.options]};
Get the next zero or more bytes from the stream, moving them to the
specified block of memory.
SetInputOptions: PROCEDURE [sH: Handle, options: InputOptions] = INLINE
{sH.options ← options};
Set the input options of the stream.
PutByte: PROCEDURE [sH: Handle, byte: Byte] = INLINE {sH.putByte[sH, byte]};
Put a byte at the next available position in the stream.
PutChar: PROCEDURE [sH: Handle, char: CHARACTER] = INLINE
{sH.putByte[sH, LOOPHOLE[char]]};
Put a character at the next available position in the stream.
PutWord: PROCEDURE [sH: Handle, word: Word] = INLINE {sH.putWord[sH, word]};
Put two bytes into the next available positions in the stream, left half
of word first.
PutBlock: PROCEDURE [
sH: Handle, block: Block, endRecord: BOOLEANFALSE] = INLINE
{sH.put[sH, block, endRecord]};
Put zero or more bytes into the next available positions in the stream,
moving them from a block in memory.
PutString: PROCEDURE [
sH: Handle, string: LONG STRING, endRecord: BOOLEANFALSE] = INLINE
BEGIN
block: Block = [LOOPHOLE[@string.text], 0, string.length];
sH.put[sH, block, endRecord];
END;
SendNow: PROCEDURE [sH: Handle, endRecord: BOOLEANTRUE] = INLINE
{sH.sendNow[sH, endRecord]};
SetSST: PROCEDURE [sH: Handle, sst: SubSequenceType] = INLINE
{sH.setSST[sH, sst]};
Change the current SubSequenceType.
SendAttention: PROCEDURE [sH: Handle, byte: Byte] = INLINE
{sH.sendAttention[sH, byte]};
Send an attention down the stream. It goes both in-band and out-of-band.
WaitForAttention: PROCEDURE [sH: Handle] RETURNS [Byte] = INLINE
{RETURN[sH.waitAttention[sH]]};
Wait for an attention to arrive.
Delete: PROCEDURE [sH: Handle] = INLINE
{sH.delete[sH]};
Delete the stream object.
GetPosition: PROCEDURE [sH: Handle] RETURNS [position: Position] = INLINE
{RETURN[sH.getPosition[sH]]}; -- Get the current position of the stream.
SetPosition: PROCEDURE [sH: Handle, position: Position] = INLINE
{sH.setPosition[sH, position]}; -- Set the current position of the stream
Signals and errors
Attention:  SIGNAL [nextIndex: CARDINAL];
EndOfStream:  SIGNAL [nextIndex: CARDINAL];
LongBlock:  SIGNAL [nextIndex: CARDINAL];
ShortBlock:  ERROR;
SSTChange:  SIGNAL [sst: SubSequenceType, nextIndex: CARDINAL];
TimeOut:  SIGNAL [nextIndex: CARDINAL];
InvalidOperation: ERROR;
EndRecord:  SIGNAL [nextIndex: CARDINAL];
Representation
Object: TYPE = RECORD [
options: InputOptions,
getByte: GetByteProcedure,
putByte: PutByteProcedure,
getWord: GetWordProcedure,
putWord: PutWordProcedure,
get: GetProcedure,
put: PutProcedure,
setSST: SetSSTProcedure,
sendAttention: SendAttentionProcedure,
waitAttention: WaitAttentionProcedure,
delete: DeleteProcedure,
getPosition: GetPositionProcedure,
setPosition: SetPositionProcedure,
sendNow: SendNowProcedure,
clientData:  REF,
getSST:  GetSSTProcedure,
getTimeout:  GetTimeoutProcedure,
setTimeout:  SetTimeoutProcedure];
GetByteProcedure: TYPE = PROCEDURE [sH: Handle] RETURNS [byte: Byte];
PutByteProcedure: TYPE = PROCEDURE [sH: Handle, byte: Byte];
GetWordProcedure: TYPE = PROCEDURE [sH: Handle] RETURNS [word: Word];
PutWordProcedure: TYPE = PROCEDURE [sH: Handle, word: Word];
GetProcedure: TYPE = PROCEDURE [
sH: Handle, block: Block, options: InputOptions]
RETURNS [
bytesTransferred: CARDINAL, why: CompletionCode, sst: SubSequenceType];
PutProcedure: TYPE = PROCEDURE [
sH: Handle, block: Block, endRecord: BOOLEAN];
SetSSTProcedure: TYPE = PROCEDURE [sH: Handle, sst: SubSequenceType];
SendAttentionProcedure: TYPE = PROCEDURE [sH: Handle, byte: Byte];
WaitAttentionProcedure: TYPE = PROCEDURE [sH: Handle] RETURNS [Byte];
DeleteProcedure: TYPE = PROCEDURE [sH: Handle];
GetPositionProcedure: TYPE = PROCEDURE [sH: Handle] RETURNS [position: Position];
SetPositionProcedure: TYPE = PROCEDURE [sH: Handle, position: Position];
SendNowProcedure: TYPE = PROCEDURE [sH: Handle, endRecord: BOOLEAN];
GetSSTProcedure:  TYPE = PROCEDURE [sH: Handle] RETURNS [sst: SubSequenceType];
GetTimeoutProcedure: TYPE = PROCEDURE [sH: Handle] RETURNS [waitTime: Milliseconds];
SetTimeoutProcedure: TYPE = PROCEDURE [sH: Handle, waitTime: Milliseconds];
The following are default values for stream object records
defaultObject: READONLY Object; -- = [
options: defaultInputOptions, (see above)
getByte: DefaultGetByte, (requires sH.get defined)
putByte: DefaultPutByte, (requires sH.put defined)
getWord: DefaultGetWord, (requires one of sH.getByte or sH.get defined)
putWord: DefaultPutWord, (requires one of sH.putByte or sH.put defined)
get: DefaultGet, (requires sH.getByte defined)
put: DefaultPut, (requires sH.putByte defined)
setSST: DefaultSetSST, (raises InvalidOperation)
sendAttention: DefaultSendAttention, (raises InvalidOperation)
waitAttention: DefaultWaitAttention, (raises InvalidOperation)
delete: DefaultDelete, (raises InvalidOperation)
getPosition: DefaultGetPositionProcedure, (raises InvalidOperation)
setPosition: DefaultSetPositionProcedure, (raises InvalidOperation)
sendNow: DefaultSendNowProcedure]; (= sH.put[sH, Block[NIL, 0, 0], TRUE]),
clientData:  NIL,
getSST:  DefaultGetSST,   (raises InvalidOperation)
getTimeout:  DefaultGetTimeoutProcedure, (raises InvalidOperation)
setTimeout:  DefaultSetTimeoutProcedure]; (raises InvalidOperation)
FromIOStreams: PROCEDURE [in, out: IO.STREAM] RETURNS [Handle];
END....
LOG
Time: March 17, 1978 11:39 AM  By: Lauer
Created file
Time: April 6, 1978 3:24 PM  By: Lauer
Updated to conform to revised Functional Specifications
Time: April 18, 1978 9:58 AM  By: Lauer
Updated for compilation by Alpha release of Mesa 4.0 (LONG POINTER is allowed).
Time: May 5, 1978 2:19 PM  By: Lauer
Added GetWord and PutWord
Time: June 22, 1978 8:57 AM  By: Lauer
Added EndOfStream signal, input option, and completion code
Time: July 21, 1978 11:31 AM  By: Lauer
Moved type Block from Stream to Environment; added GetChar and PutChar
Time: August 14, 1978 2:03 PM  By: Lauer
Deleted DeleteModule (can be simulated by Runtime.UnNew[GlobalFrame[p]];
moved "DeleteModuleAfterReturn" to Runtime and renamed it SelfDestruct
Time: February 22, 1979 2:50 PM By: Dalal
Moved a large number of procedures from StreamImpl.mesa to this module as
INLINEs; added the parameter sH to all the procedures of Stream.Object; added Delete
Time: March 13, 1979 10:17 AM  By: Dalal
Modified SendAttention and WaitForAttention to take and return a byte of data respectively
Time: February 1, 1980 7:16 PM  By: McJones
Added object procedures for get/put byte/word; new defaults
Time: August 13, 1980 5:07 PM  By: McJones
Deleted defaults within definition of Object
Time: 11-Aug-81 10:00:10  By: Luniewski
Made a Handle be LONG. Added Get/Set Position procedures and types.
Time: 11-Nov-81 11:20:48  By: Luniewski
Added PutString.
Time: 18-Nov-81 11:36:35  By: Luniewski
Changed all references to PhysicalRecord to just Record.
Added Attention. Added an endRecord argument to SendNow and made it a first
class procedure - no longer an INLINE, it now appears in the Object.
Added signalAttention to InputOptions and defaulted it to FALSE in
defaultInputOptions.
Time: 23-Nov-82 15:41:42  By: Luniewski
Added clientData, getSST, getTimeout and setTimeout to Object. Added new types
GetSSTProcedure, GetTimeoutProcedure and SetTimeoutProcedure. Updated comment
for defaultObject to reflect new fields and that many default procs now raise
InvalidOperation instead of Runtime.UnboundProcedure. Added default values for
all fields in InputOptions; changed defaultInputOptions to use those defaults.
Added type Milliseconds. Added signalEndRecord to InputOptions and the error
EndRecord.