2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <objc/objc-api.h>
24 #include "NGConcreteStreamFileHandle.h"
25 #include "NGStreamProtocols.h"
26 #include "NGStreamExceptions.h"
27 #include "NGBufferedStream.h"
29 @interface NGStream(FileHandleReset)
31 - (void)resetFileHandle;
35 @implementation NGConcreteStreamFileHandle
37 - (id)initWithStream:(id<NGStream>)_stream {
38 if ((self = [super init])) {
39 self->stream = [_stream retain];
45 if ([stream respondsToSelector:@selector(resetFileHandle)])
46 [(NGStream *)self->stream resetFileHandle];
47 [self->stream release];
53 - (id<NGStream>)stream {
57 /* NSFileHandle operations */
63 - (int)fileDescriptor {
64 if ([self->stream respondsToSelector:@selector(fileDescriptor)])
65 return [(id)self->stream fileDescriptor];
67 [self subclassResponsibility:_cmd];
74 - (void)synchronizeFile {
80 - (NSData *)readDataOfLength:(unsigned int)_length {
84 *(&buffer) = NGMallocAtomic(_length);
88 [stream safeReadBytes:buffer count:_length];
89 data = [[NSData alloc] initWithBytes:buffer length:_length];
92 if ([localException isKindOfClass:[NGEndOfStreamException class]]) {
93 data = [(NGEndOfStreamException *)localException readBytes];
95 data = data ? [data retain] : [[NSData alloc] init];
102 [localException raise];
112 return [data autorelease];
115 - (NSData *)readDataToEndOfFile {
116 NGBufferedStream *bs;
120 *(&data) = [NSMutableData dataWithCapacity:2048];
121 *(&bs) = [self->stream isKindOfClass:[NGBufferedStream class]]
122 ? [self->stream retain]
123 : [(NGBufferedStream *)[NGBufferedStream alloc]
124 initWithSource:self->stream];
128 unsigned got = [bs readBytes:buf count:2048];
129 [data appendBytes:buf length:got];
133 if (![localException isKindOfClass:[NGEndOfStreamException class]]) {
136 [localException raise];
140 [bs release]; bs = nil;
145 - (NSData *)availableData {
146 NSLog(@"NGConcreteStreamFileHandle(availableData) not implemented");
147 [self notImplemented:_cmd];
153 - (void)writeData:(NSData *)_data {
154 [self->stream safeWriteBytes:[_data bytes] count:[_data length]];
159 - (unsigned long long)seekToEndOfFile {
160 NSLog(@"NGConcreteStreamFileHandle(seekToEndOfFile) not implemented");
161 [self notImplemented:_cmd];
164 - (void)seekToFileOffset:(unsigned long long)_offset {
165 [(id<NGPositionableStream>)stream moveToLocation:_offset];
168 - (unsigned long long)offsetInFile {
169 NSLog(@"_NGConcreteFileStreamFileHandle(offsetInFile:) not implemented, abort");
170 [self notImplemented:_cmd];
174 /* asynchronous operations */
176 - (void)acceptConnectionInBackgroundAndNotify {
177 NSLog(@"NGConcreteStreamFileHandle(acceptConnectionInBackgroundAndNotify) "
179 [self notImplemented:_cmd];
181 - (void)acceptConnectionInBackgroundAndNotifyForModes:(NSArray *)_modes {
182 NSLog(@"NGConcreteStreamFileHandle(acceptConnectionInBackgroundAndNotifyForModes:) "
184 [self notImplemented:_cmd];
187 - (void)readInBackgroundAndNotify {
188 NSLog(@"NGConcreteStreamFileHandle(readInBackgroundAndNotify) not implemented");
189 [self notImplemented:_cmd];
191 - (void)readInBackgroundAndNotifyForModes:(NSArray *)_modes {
192 NSLog(@"NGConcreteStreamFileHandle(readInBackgroundAndNotifyForModes:) "
194 [self notImplemented:_cmd];
196 - (void)readToEndOfFileInBackgroundAndNotify {
197 NSLog(@"NGConcreteStreamFileHandle(readToEndOfFileInBackgroundAndNotify)"
199 [self notImplemented:_cmd];
201 - (void)readToEndOfFileInBackgroundAndNotifyForModes:(NSArray *)_modes {
202 NSLog(@"NGConcreteStreamFileHandle("
203 @"readToEndOfFileInBackgroundAndNotifyForModes:)"
205 [self notImplemented:_cmd];
208 - (void)waitForDataInBackgroundAndNotify {
209 NSLog(@"NGConcreteStreamFileHandle("
210 @"waitForDataInBackgroundAndNotify)"
212 [self notImplemented:_cmd];
214 - (void)waitForDataInBackgroundAndNotifyForModes:(NSArray *)_modes {
215 NSLog(@"NGConcreteStreamFileHandle("
216 @"waitForDataInBackgroundAndNotifyForModes:)"
218 [self notImplemented:_cmd];
221 @end /* NGConcreteStreamFileHandle */