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.13 date: 2022/01/14 14:09:31
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.

copyright

COPYRIGHT (c) 2002 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

instance creation
o  new
(comment from inherited method)
report an error - Streams are created using on:-messages


Instance protocol:

accessing
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
(comment from inherited method)
for compatibility with externalStream:
return true, if this stream is open.

o  size
(comment from inherited method)
return the number of elements in the streamed collection.

initialization
o  contentsSpecies: aCollectionClass
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
(comment from inherited method)
just to ignore initialize to objects which do not need it

queries
o  atEnd
(comment from inherited method)
return true if the end of the stream has been reached;
- we do not know here how to do it, it must be redefined in subclass

o  contentsSpecies
(comment from inherited method)
this should return the class of which an instance is
returned by the #contents method. Here, Array is returned,
since the abstract Stream-class has no idea of the underlying
collection class.
It is redefined in some subclasses - for example, to return String.

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

o  nextAvailableBytes: nMax into: aBuffer startingAt: startIndex
(comment from inherited method)
for compatibility with ExternalStream

o  readWaitWithTimeoutMs: millis
suspend the current process, until the receiver
becomes ready for reading or a timeout (in milliseconds) expired.
If data is already available, return immediate.
With nil millis, wait forever.
Return true if a timeout occurred (i.e. false, if data is available).
The other threads are not affected by the wait.

synchronization
o  readWait
(comment from inherited method)
suspend the current process, until the receiver
becomes ready for reading. If data is already available,
return immediately.
The other threads are not affected by the wait.

o  writeWaitWithTimeoutMs: timeout
(comment from inherited method)
never have to wait

writing
o  nextPut: anObject
write an element (might wakeup readers).
Answer the argument

Usage example(s):

     |s|
     s := InternalPipeStream new.
     s nextPut:$a.
     s nextPut:$b.
     s nextPut:$c.


Examples:


    |p|

    p := InternalPipeStream new.
    [
        10 timesRepeat:[
            p nextPutLine:'hello'.
            Delay waitForSeconds:1.
        ].
    ] 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 matches what|

        ((userInput readWaitWithTimeout:1) not and:[top realized]) ifTrue:[
            line := userInput nextLine.
            ((line isEmptyOrNil and:[userInput atEnd]) or:[ #('quit' 'exit' 'end' 'bye') includes:line ]) ifTrue:[
                top destroy.
                ^ self
            ].
            (matches := line subExpressionsInRegex:'I am (.+)' caseSensitive:false) size == 1 ifTrue:[
                answer := #( 
                            'Why are you %1?'
                            'What makes you think that you are %1?'
                            'Who told you, that you are %1?'
                          ) atRandom bindWithArguments:matches
            ] ifFalse:[
                answer := 'Tell me more.'.
            ].
            elizasOutput nextPutLine:answer.
            elizasOutput nextPutAll:'>'.
        ].
    ].


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 22 Dec 2024 01:16:47 GMT