This whole thing could use a rewrite but whatever
[ITFoundation.git] / ITChunkedByteStream.m
index 1299503..cb31795 100755 (executable)
 
 
 @implementation ITChunkedByteStream
+-initWithDelegate:(id)d
+{
+    if (self = [super init]) {
+        q = [[ArrayQueue alloc] init];
+        lock = [[NSLock alloc] init];
+        delegate = [d retain];
+    }
+    return self;
+}
 
+-(BOOL)empty
+{
+    BOOL a;
+    [lock lock];
+    a = [q isEmpty];
+    [lock unlock];
+    return a;
+}
+
+-(NSData*) readData
+{
+    NSData *d;
+    [lock lock];
+    d = (NSData*)[q dequeue];
+    [lock unlock];
+    return d;
+}
+
+-(oneway void) writeData:(in NSData*)d
+{
+    [lock lock];
+    [q enqueue:d];
+    [lock unlock];
+}
+
+-(oneway void) writeBytesNoCopy:(in char *)b len:(unsigned long)length
+{
+    [lock lock];
+    [q enqueue:[NSData dataWithBytesNoCopy:b length:length]];
+    [lock unlock];
+}
+
+-(oneway void) writeBytes:(in char *)b len:(unsigned long)length
+{
+    [lock lock];
+    [q enqueue:[NSData dataWithBytes:b length:length]];
+    [lock unlock];
+}
+-delegate {return delegate;}
+-setDelegate:(id)d {id old = delegate; [delegate release]; delegate = [d retain]; return old;}
 @end