X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/4883c610168ebeb51a54ae8cce12d24638034b08..14a301f7aa7b244c4831006cfc4cfa42185517a4:/ITByteStream.m diff --git a/ITByteStream.m b/ITByteStream.m index eff6eb7..67ecf31 100755 --- a/ITByteStream.m +++ b/ITByteStream.m @@ -17,27 +17,48 @@ { data = [[NSMutableData alloc] init]; lock = [[NSLock alloc] init]; + delegate = nil; } return self; } --(id) initWithStream:(ITByteStream*)stream +-(id) initWithDelegate:(id)d +{ + if (self == [super init]) + { + data = [[NSMutableData alloc] init]; + lock = [[NSLock alloc] init]; + delegate = [d retain]; + } + return self; +} + +-(id) initWithStream:(ITByteStream*)stream delegate:(id)d { if (self == [super init]) { data = [stream->data copy]; lock = [[NSLock alloc] init]; + delegate = [d retain]; } return 0; } --(void) dealloc +-(oneway void) dealloc { + [lock lock]; [data release]; + [lock unlock]; [lock release]; [super dealloc]; } +-(void) setDelegate:(id )d +{ + [delegate release]; + delegate = [d retain]; +} + -(int) availableDataLength { int len; @@ -64,10 +85,29 @@ return ret; } --(void) writeData:(NSData*)_data +-(NSData*) readAllData +{ + NSData *ret; + [lock lock]; + ret = [data autorelease]; + data = [[NSMutableData alloc] init]; + [lock unlock]; + return ret; +} + +-(void) writeData:(in NSData*)_data { [lock lock]; [data appendData:_data]; [lock unlock]; + [delegate newDataAdded:self]; +} + +-(void) writeBytes:(char *)b len:(long)length +{ + [lock lock]; + [data appendBytes:b length:length]; + [lock unlock]; + [delegate newDataAdded:self]; } @end