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: BOOLEAN ← FALSE,
signalLongBlock: BOOLEAN ← FALSE,
signalShortBlock: BOOLEAN ← FALSE,
signalSSTChange: BOOLEAN ← FALSE,
signalEndOfStream: BOOLEAN ← FALSE,
signalAttention: BOOLEAN ← FALSE,
signalTimeout: BOOLEAN ← TRUE,
signalEndRecord: BOOLEAN ← FALSE];
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:
BOOLEAN ←
FALSE] =
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: BOOLEAN ← FALSE] = INLINE
BEGIN
block: Block = [LOOPHOLE[@string.text], 0, string.length];
sH.put[sH, block, endRecord];
END;
SendNow:
PROCEDURE [sH: Handle, endRecord:
BOOLEAN ←
TRUE] =
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....