ObjFW
OFKernelEventObserver.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
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 #import "socket.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
23 @class OFMutableArray OF_GENERIC(ObjectType);
24 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
25 @class OFDataArray;
26 #ifdef OF_HAVE_THREADS
27 @class OFMutex;
28 #endif
29 @class OFDate;
30 
39 #ifdef OF_HAVE_OPTIONAL_PROTOCOLS
40 @optional
41 #endif
42 
56 - (void)objectIsReadyForReading: (id)object;
57 
63 - (void)objectIsReadyForWriting: (id)object;
64 @end
65 
82 @end
83 
100 @end
101 
112 {
113  OFMutableArray OF_GENERIC(id <OFReadyForReadingObserving>)
114  *_readObjects;
115  OFMutableArray OF_GENERIC(id <OFReadyForWritingObserving>)
116  *_writeObjects;
117  OFMutableArray *_queue;
118  OFDataArray *_queueActions;
119  id <OFKernelEventObserverDelegate> _delegate;
120 #ifdef OF_HAVE_PIPE
121  int _cancelFD[2];
122 #else
123  of_socket_t _cancelFD[2];
124  struct sockaddr_in _cancelAddr;
125 #endif
126 #ifdef OF_HAVE_THREADS
127  OFMutex *_mutex;
128 #endif
129 }
130 
131 #ifdef OF_HAVE_PROPERTIES
132 @property OF_NULLABLE_PROPERTY (assign)
133  id <OFKernelEventObserverDelegate> delegate;
134 #endif
135 
141 + (instancetype)observer;
142 
148 - (nullable id <OFKernelEventObserverDelegate>)delegate;
149 
155 - (void)setDelegate: (nullable id <OFKernelEventObserverDelegate>)delegate;
156 
168 - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object;
169 
178 - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object;
179 
188 - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object;
189 
198 - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object;
199 
203 - (void)observe;
204 
211 - (void)observeForTimeInterval: (of_time_interval_t)timeInterval;
212 
219 - (void)observeUntilDate: (OFDate*)date;
220 
228 - (void)cancel;
229 @end
230 
231 @interface OFObject (OFKernelEventObserverDelegate)
233 @end
234 
235 OF_ASSUME_NONNULL_END
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition: OFKernelEventObserver.h:73
A class for creating mutual exclusions.
Definition: OFMutex.h:29
A class for storing, accessing and comparing dates.
Definition: OFDate.h:30
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:46
A class for storing arbitrary data in an array.
Definition: OFDataArray.h:37
int fileDescriptorForWriting()
Returns the file descriptor for writing that should be checked by the OFKernelEventObserver.
int fileDescriptorForReading()
Returns the file descriptor for reading that should be checked by the OFKernelEventObserver.
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:47
A class that can observe multiple kernel events (e.g. streams being ready to read) at once...
Definition: OFKernelEventObserver.h:111
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
Definition: OFKernelEventObserver.h:91
A protocol that needs to be implemented by delegates for OFKernelEventObserver.
Definition: OFKernelEventObserver.h:38
double of_time_interval_t
A time interval in seconds.
Definition: OFObject.h:90