eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'InternalPipeStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: InternalPipeStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--InternalPipeStream

Package:
stx:libbasic2
Category:
Streams
Version:
rev: 1.6 date: 2017/02/15 21:06:09
user: cg
file: InternalPipeStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


not useful on its own, but can be used to talk to a vt100
terminal view ...

See example.


Class protocol:

instance creation
o  new


Instance protocol:

accessing
o  atEnd

o  close
if there is any partner waiting at either side of the queue,
tell it that the pipe is no longer active.
(readers will read an EOF condition, writers will get a write error).
Either side may close the internal pipe.

o  isOpen

o  next
return the next element from the stream (might block until something is written)

o  nextAvailableBytes: nMax into: aBuffer startingAt: startIndex

o  nextPut: anObject
write an element (might wakeup readers)

o  size

initialization
o  contentsSpecies: aClass
by default, I will return a String of elements, if reading multiple elements.
However, you may change this to eg. an array, if desired

o  initialize

queries
o  contentsSpecies

synchronization
o  readWait

o  writeWaitWithTimeoutMs: timeout


Examples:


    |p|

    p := InternalPipeStream new.
    [
        10 timesRepeat:[
            p nextPutLine:'hello'
        ].
    ] fork.

    [
        10 timesRepeat:[
            Transcript showCR:p nextLine
        ].
    ] fork.
    |userInput elizasOutput top terminal|

    userInput    := InternalPipeStream new.
    elizasOutput := InternalPipeStream new.

    top := StandardSystemView new.
    terminal := VT100TerminalView openOnInput: userInput output:elizasOutput in:top.

    top extent:(terminal preferredExtent).
    top label:'The doctor is in'.
    top iconLabel:'doctor'.
    top open.
    top waitUntilVisible.
    top onChangeEvaluate:[:what :aParameter :changedObject | what == #destroyed ifTrue:[userInput close]].

    terminal translateNLToCRNL:true.
    terminal inputTranslateCRToNL:true.
    terminal localEcho:true.

    elizasOutput nextPutLine:'Hi, I am Eliza'.
    elizasOutput nextPutLine:'What is your problem (type end to finish conversation) ?'.
    elizasOutput nextPutLine:''.
    elizasOutput nextPutAll:'>'.

    [top realized] whileTrue:[
        |line answer matchingRule|

        line := userInput nextLine.
        ((line isEmptyOrNil and:[userInput atEnd]) or:[ #('quit' 'exit' 'end' 'bye') includes:line ]) ifTrue:[
            top destroy.
            ^ self
        ].

        answer := 'Tell me more.'.
        elizasOutput nextPutLine:answer.
        elizasOutput nextPutAll:'>'.
    ].


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Tue, 20 Nov 2018 16:19:54 GMT