ObjFW
 All Classes Functions Variables
OFStreamObserver.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 
19 #ifdef _WIN32
20 # ifndef _WIN32_WINNT
21 # define _WIN32_WINNT 0x0501
22 # endif
23 # include <ws2tcpip.h>
24 # include <windows.h>
25 #endif
26 
27 @class OFStream;
28 @class OFMutableArray;
29 @class OFMutableDictionary;
30 @class OFDataArray;
31 @class OFMutex;
32 
37 #ifndef OF_STREAM_OBSERVER_M
39 #else
41 #endif
42 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
43 @optional
44 #endif
45 
57 - (void)streamIsReadyForReading: (OFStream*)stream;
58 
64 - (void)streamIsReadyForWriting: (OFStream*)stream;
65 
71 - (void)streamDidReceiveException: (OFStream*)stream;
72 @end
73 
80 {
81  OFMutableArray *readStreams;
82  OFMutableArray *writeStreams;
83  __unsafe_unretained OFStream **FDToStream;
84  size_t maxFD;
85  OFMutableArray *queue;
86  OFDataArray *queueInfo, *queueFDs;
87  id <OFStreamObserverDelegate> delegate;
88  int cancelFD[2];
89 #ifdef _WIN32
90  struct sockaddr_in cancelAddr;
91 #endif
92  OFMutex *mutex;
93 }
94 
95 #ifdef OF_HAVE_PROPERTIES
96 @property (assign) id <OFStreamObserverDelegate> delegate;
97 #endif
98 
104 + (instancetype)observer;
105 
111 - (id <OFStreamObserverDelegate>)delegate;
112 
118 - (void)setDelegate: (id <OFStreamObserverDelegate>)delegate;
119 
133 - (void)addStreamForReading: (OFStream*)stream;
134 
145 - (void)addStreamForWriting: (OFStream*)stream;
146 
155 - (void)removeStreamForReading: (OFStream*)stream;
156 
165 - (void)removeStreamForWriting: (OFStream*)stream;
166 
170 - (void)observe;
171 
179 - (BOOL)observeWithTimeout: (double)timeout;
180 
188 - (void)cancel;
189 
190 - (void)OF_addFileDescriptorForReading: (int)fd;
191 - (void)OF_addFileDescriptorForWriting: (int)fd;
192 - (void)OF_removeFileDescriptorForReading: (int)fd;
193 - (void)OF_removeFileDescriptorForWriting: (int)fd;
194 - (void)OF_processQueue;
195 - (BOOL)OF_processCache;
196 @end
197 
198 @interface OFObject (OFStreamObserverDelegate) <OFStreamObserverDelegate>
199 @end