SchemeEvents.mesa
Copyright Ó 1989, 1991 by Xerox Corporation. All rights reserved.
Created by Michael Plass, February 21, 1989
Michael Plass, February 21, 1989 12:34:03 pm PST
Implements yet another queuing mechanism. This one is pull-model.
DIRECTORY IO USING [STREAM], Rope USING [ROPE];
SchemeEvents: CEDAR DEFINITIONS
~ BEGIN
InputQueue: TYPE ~ REF InputQueueRep; -- private rep below.
InputEvent: TYPE ~ REF; -- one of the following:
MouseEvent: TYPE ~ REF MouseEventRep;
ReadyStreamEvent: TYPE ~ IO.STREAM; -- A stream that has chars available
StreamErrorEvent: TYPE ~ REF StreamErrorEventRep; -- an error occured on this stream
CharEvent: TYPE ~ REF CHAR; -- immutable!
... or anything else the consumer and producer can agree on.
MakeInputQueue: PROC RETURNS [InputQueue];
Reset: PROC [queue: InputQueue];
Kills all outstanding events and stream waiters
Producer side
Enqueue: PROC [queue: InputQueue, a: InputEvent];
The basic queueing mechanism
EnqueueMouse: PROC [queue: InputQueue, me: MouseEventRep];
A convenience proc for a mouse event.
EnqueueStream: PROC [queue: InputQueue, stream: IO.STREAM];
The stream must be an input stream. When at least one character becomes available on it, a ReadyStreamEvent (or a StreamErrorEvent) will be generated. Until then, no other process should try to read from the stream. After the event is generated, EnqueueStream must be called again to generate further events.
FlushAvailableWhitespace: PROC [stream: IO.STREAM] RETURNS [newlineRead: BOOL];
Reads any whitespace characters already on the stream, without blocking. It is often useful to call this before calling EnqueueStream.
Notify: PROC [queue: InputQueue, input: LIST OF REF ANY];
A convenience for parsing TIP-style events
Consumer side
InputAvailable: PROC [queue: InputQueue] RETURNS [BOOL];
The basic queueing mechanism
Dequeue: PROC [queue: InputQueue] RETURNS [a: InputEvent];
Representations
MouseEventRep: TYPE ~ RECORD [action: ATOM ¬ NIL, button: ATOM ¬ NIL, mx, my: INT ¬ 0, args: REF ¬ NIL];
StreamErrorEventRep: TYPE ~ RECORD [stream: IO.STREAM, object: REF, msg: Rope.ROPE];
InputQueueRep: TYPE ~ PRIVATE MONITORED RECORD [
ready: CONDITION,
count: CARD,
head: LIST OF InputEvent,
last: LIST OF InputEvent,
impl: REF ¬ NIL
];
END.