ObjFW
|
00001 /* 00002 * Copyright (c) 2008, 2009, 2010, 2011, 2012 00003 * Jonathan Schleifer <js@webkeks.org> 00004 * 00005 * All rights reserved. 00006 * 00007 * This file is part of ObjFW. It may be distributed under the terms of the 00008 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in 00009 * the packaging of this file. 00010 * 00011 * Alternatively, it may be distributed under the terms of the GNU General 00012 * Public License, either version 2 or 3, which can be found in the file 00013 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this 00014 * file. 00015 */ 00016 00017 #import "OFObject.h" 00018 00019 #ifdef _WIN32 00020 # ifndef _WIN32_WINNT 00021 # define _WIN32_WINNT 0x0501 00022 # endif 00023 # include <ws2tcpip.h> 00024 # include <windows.h> 00025 #endif 00026 00027 @class OFStream; 00028 @class OFMutableArray; 00029 @class OFMutableDictionary; 00030 @class OFDataArray; 00031 @class OFMutex; 00032 00037 #ifndef OF_STREAM_OBSERVER_M 00038 @protocol OFStreamObserverDelegate <OFObject> 00039 #else 00040 @protocol OFStreamObserverDelegate 00041 #endif 00042 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS 00043 @optional 00044 #endif 00045 00057 - (void)streamIsReadyForReading: (OFStream*)stream; 00058 00064 - (void)streamIsReadyForWriting: (OFStream*)stream; 00065 00071 - (void)streamDidReceiveException: (OFStream*)stream; 00072 @end 00073 00079 @interface OFStreamObserver: OFObject 00080 { 00081 OFMutableArray *readStreams; 00082 OFMutableArray *writeStreams; 00083 OFStream **FDToStream; 00084 size_t maxFD; 00085 OFMutableArray *queue; 00086 OFDataArray *queueInfo, *queueFDs; 00087 id <OFStreamObserverDelegate> delegate; 00088 int cancelFD[2]; 00089 #ifdef _WIN32 00090 struct sockaddr_in cancelAddr; 00091 #endif 00092 OFMutex *mutex; 00093 } 00094 00095 #ifdef OF_HAVE_PROPERTIES 00096 @property (assign) id <OFStreamObserverDelegate> delegate; 00097 #endif 00098 00104 + observer; 00105 00111 - (id <OFStreamObserverDelegate>)delegate; 00112 00118 - (void)setDelegate: (id <OFStreamObserverDelegate>)delegate; 00119 00133 - (void)addStreamForReading: (OFStream*)stream; 00134 00145 - (void)addStreamForWriting: (OFStream*)stream; 00146 00155 - (void)removeStreamForReading: (OFStream*)stream; 00156 00165 - (void)removeStreamForWriting: (OFStream*)stream; 00166 00170 - (void)observe; 00171 00179 - (BOOL)observeWithTimeout: (int)timeout; 00180 00182 - (void)_addFileDescriptorForReading: (int)fd; 00183 - (void)_addFileDescriptorForWriting: (int)fd; 00184 - (void)_removeFileDescriptorForReading: (int)fd; 00185 - (void)_removeFileDescriptorForWriting: (int)fd; 00186 - (void)_processQueue; 00187 - (BOOL)_processCache; 00189 @end 00190 00191 @interface OFObject (OFStreamObserverDelegate) <OFStreamObserverDelegate> 00192 @end