GDBInternalPipeStream.st
changeset 7 7a51f98e7162
child 14 535e7f16c05a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GDBInternalPipeStream.st	Mon Jun 02 23:56:27 2014 +0100
@@ -0,0 +1,83 @@
+"{ Package: 'jv:libgdbs' }"
+
+Stream subclass:#GDBInternalPipeStream
+	instanceVariableNames:'queue'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'GDB-Private'
+!
+
+!GDBInternalPipeStream class methodsFor:'instance creation'!
+
+new
+    ^ self basicNew initialize
+! !
+
+!GDBInternalPipeStream methodsFor:'accessing'!
+
+atEnd
+    ^ false . "/ queue notNil
+!
+
+close
+    queue := nil
+!
+
+next
+    "return the next element from the stream (might block until something is written)"
+
+    ^ queue next
+!
+
+nextAvailableBytes:nMax into:aBuffer startingAt:startIndex
+    |n idx ch|
+
+    n := 0.
+    idx := startIndex.
+    [n <= nMax] whileTrue:[
+        ch := queue nextIfEmpty:[^ n ].
+        aBuffer at:idx put:ch.
+        idx := idx + 1.
+        n := n + 1
+    ].
+    ^ n
+!
+
+nextPut:something
+    "write an element (might wakeup readers)"
+
+    queue nextPut:something
+!
+
+size
+    ^ queue size
+! !
+
+!GDBInternalPipeStream methodsFor:'initialization'!
+
+initialize
+    queue := SharedQueue new: 1024.
+
+    "Modified: / 02-06-2014 / 23:30:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!GDBInternalPipeStream methodsFor:'private'!
+
+contentsSpecies
+    "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."
+
+    ^ String
+
+    "Created: / 02-06-2014 / 23:30:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!GDBInternalPipeStream methodsFor:'synchronization'!
+
+readWait
+    queue readSemaphore wait
+! !
+