ObjFW
OFKernelEventObserver.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
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 OFDate;
25 #ifdef OF_HAVE_THREADS
26 @class OFMutex;
27 #endif
29 
38 @optional
53 - (void)objectIsReadyForReading: (id)object;
54 
60 - (void)objectIsReadyForWriting: (id)object;
61 @end
62 
78 - (int)fileDescriptorForReading;
79 @end
80 
96 - (int)fileDescriptorForWriting;
97 @end
98 
109 {
110  OFMutableArray OF_GENERIC(id <OFReadyForReadingObserving>)
111  *_readObjects;
112  OFMutableArray OF_GENERIC(id <OFReadyForWritingObserving>)
113  *_writeObjects;
114  id <OFKernelEventObserverDelegate> _Nullable _delegate;
115 #ifdef OF_HAVE_PIPE
116  int _cancelFD[2];
117 #else
118  of_socket_t _cancelFD[2];
119  struct sockaddr_in _cancelAddr;
120 #endif
121 #ifdef OF_HAVE_THREADS
122  OFMutex *_mutex;
123 #endif
124  OFMutableData *_queueActions;
125  OFMutableArray *_queueObjects;
126 }
127 
131 @property OF_NULLABLE_PROPERTY (nonatomic, assign)
132  id <OFKernelEventObserverDelegate> delegate;
133 
139 + (instancetype)observer;
140 
152 - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object;
153 
162 - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object;
163 
172 - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object;
173 
182 - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object;
183 
187 - (void)observe;
188 
195 - (void)observeForTimeInterval: (of_time_interval_t)timeInterval;
196 
203 - (void)observeUntilDate: (OFDate *)date;
204 
212 - (void)cancel;
213 @end
214 
215 OF_ASSUME_NONNULL_END
nonatomic
Definition: OFKernelEventObserver.h:131
void cancel()
Cancels the currently blocking observe call.
Definition: OFKernelEventObserver.m:417
A protocol that needs to be implemented by delegates for OFKernelEventObserver.
Definition: OFKernelEventObserver.h:28
instancetype observer()
Creates a new OFKernelEventObserver.
Definition: OFKernelEventObserver.m:78
void observe()
Observes all objects and blocks until an event happens on an object.
Definition: OFKernelEventObserver.m:402
A class for creating mutual exclusions.
Definition: OFMutex.h:29
double of_time_interval_t
A time interval in seconds.
Definition: OFObject.h:91
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
A class for storing, accessing and comparing dates.
Definition: OFDate.h:30
A class that can observe multiple kernel events (e.g. streams being ready to read) at once...
Definition: OFKernelEventObserver.h:108
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:40
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
A class for storing and manipulating arbitrary data in an array.
Definition: OFMutableData.h:29