go away you include
[ITFoundation.git] / ITChunkedByteStream.m
1 //
2 //  ITChunkedByteStream.m
3 //  ITFoundation
4 //
5 //  Created by Alexander Strange on Tue Jul 22 2003.
6 //  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ITChunkedByteStream.h"
10
11
12 @implementation ITChunkedByteStream
13 -initWithDelegate:(id)d
14 {
15     if (self = [super init]) {
16         q = [[ArrayQueue alloc] init];
17         lock = [[NSLock alloc] init];
18         delegate = [d retain];
19     }
20     return self;
21 }
22
23 -(BOOL)empty
24 {
25     BOOL a;
26     [lock lock];
27     a = [q isEmpty];
28     [lock unlock];
29     return a;
30 }
31
32 -(NSData*) readData
33 {
34     NSData *d;
35     [lock lock];
36     d = (NSData*)[q dequeue];
37     [lock unlock];
38     return d;
39 }
40
41 -(oneway void) writeData:(in NSData*)d
42 {
43     [lock lock];
44     [q enqueue:d];
45     [lock unlock];
46 }
47
48 -(oneway void) writeBytesNoCopy:(in char *)b len:(unsigned long)length
49 {
50     [lock lock];
51     [q enqueue:[NSData dataWithBytesNoCopy:b length:length]];
52     [lock unlock];
53 }
54
55 -(oneway void) writeBytes:(in char *)b len:(unsigned long)length
56 {
57     [lock lock];
58     [q enqueue:[NSData dataWithBytes:b length:length]];
59     [lock unlock];
60 }
61 -delegate {return delegate;}
62 -setDelegate:(id)d {id old = delegate; [delegate release]; delegate = [d retain]; return old;}
63 @end