ObjFW
src/OFStreamObserver.h
00001 /*
00002  * Copyright (c) 2008, 2009, 2010, 2011
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 #if !defined(OF_HAVE_POLL) && defined(OF_HAVE_SYS_SELECT_H)
00018 # include <sys/select.h>
00019 #endif
00020 
00021 #import "OFObject.h"
00022 
00023 #ifdef _WIN32
00024 # ifndef _WIN32_WINNT
00025 #  define _WIN32_WINNT 0x0501
00026 # endif
00027 # include <windows.h>
00028 # include <ws2tcpip.h>
00029 #endif
00030 
00031 @class OFStream;
00032 #ifdef OF_HAVE_POLL
00033 @class OFDataArray;
00034 #endif
00035 @class OFMutableArray;
00036 @class OFMutableDictionary;
00037 
00042 #ifndef OF_STREAM_OBSERVER_M
00043 @protocol OFStreamObserverDelegate <OFObject>
00044 #else
00045 @protocol OFStreamObserverDelegate
00046 #endif
00047 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
00048 @optional
00049 #endif
00050 
00055 - (void)streamDidBecomeReadyForReading: (OFStream*)stream;
00056 
00062 - (void)streamDidBecomeReadyForWriting: (OFStream*)stream;
00063 
00069 - (void)streamDidReceiveException: (OFStream*)stream;
00070 @end
00071 
00077 @interface OFStreamObserver: OFObject
00078 {
00079         OFMutableArray *readStreams;
00080         OFMutableArray *writeStreams;
00081         OFMutableArray *queue, *queueInfo;
00082         id <OFStreamObserverDelegate> delegate;
00083 #ifdef OF_HAVE_POLL
00084         OFDataArray *fds;
00085         OFMutableDictionary *fdToStream;
00086 #else
00087         fd_set readfds;
00088         fd_set writefds;
00089         fd_set exceptfds;
00090         int nfds;
00091 #endif
00092         int cancelFd[2];
00093 #ifdef _WIN32
00094         struct sockaddr_in cancelAddr;
00095 #endif
00096 }
00097 
00098 #ifdef OF_HAVE_PROPERTIES
00099 @property (retain) id <OFStreamObserverDelegate> delegate;
00100 #endif
00101 
00105 + observer;
00106 
00110 - (id <OFStreamObserverDelegate>)delegate;
00111 
00117 - (void)setDelegate: (id <OFStreamObserverDelegate>)delegate;
00118 
00132 - (void)addStreamToObserveForReading: (OFStream*)stream;
00133 
00144 - (void)addStreamToObserveForWriting: (OFStream*)stream;
00145 
00154 - (void)removeStreamToObserveForReading: (OFStream*)stream;
00155 
00164 - (void)removeStreamToObserveForWriting: (OFStream*)stream;
00165 
00169 - (void)observe;
00170 
00178 - (BOOL)observeWithTimeout: (int)timeout;
00179 @end
00180 
00181 @interface OFObject (OFStreamObserverDelegate) <OFStreamObserverDelegate>
00182 @end
 All Classes Functions Variables