ObjFW
OFKernelEventObserver.h
1 /*
2  * Copyright (c) 2008-2025 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 #ifdef OF_HAVE_SOCKETS
22 # import "OFSocket.h"
23 #endif
24 #import "OFRunLoop.h"
25 
26 #ifdef OF_AMIGAOS
27 # include <exec/types.h>
28 # include <exec/tasks.h>
29 #endif
30 
31 OF_ASSUME_NONNULL_BEGIN
32 
33 @class OFMutableArray OF_GENERIC(ObjectType);
34 @class OFDate;
36 
44 @optional
59 - (void)objectIsReadyForReading: (id)object;
60 
66 - (void)objectIsReadyForWriting: (id)object;
67 
68 #if defined(OF_AMIGAOS) || defined(DOXYGEN)
69 
74 - (void)execSignalWasReceived: (ULONG)signalMask;
75 #endif
76 @end
77 
89 @property (readonly, nonatomic) int fileDescriptorForReading;
90 @end
91 
103 @property (readonly, nonatomic) int fileDescriptorForWriting;
104 @end
105 
106 #ifdef OF_HAVE_SOCKETS
107 
116 {
117  OFMutableArray OF_GENERIC(id <OFReadyForReadingObserving>)
118  *_readObjects;
119  OFMutableArray OF_GENERIC(id <OFReadyForWritingObserving>)
120  *_writeObjects;
121  id <OFKernelEventObserverDelegate> _Nullable _delegate;
122 # if defined(OF_AMIGAOS)
123  struct Task *_waitingTask;
124  ULONG _cancelSignal;
125 # elif defined(OF_HAVE_PIPE)
126  int _cancelFD[2];
127 # else
128  OFSocketHandle _cancelFD[2];
129  struct sockaddr_in _cancelAddr;
130 # endif
131 # ifdef OF_AMIGAOS
132  ULONG _execSignalMask;
133 # endif
134  OF_RESERVE_IVARS(OFKernelEventObserver, 4)
135 }
136 
140 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
142 
143 # if defined(OF_AMIGAOS) || defined(DOXYGEN)
144 
149 @property (nonatomic) ULONG execSignalMask;
150 # endif
151 
152 # ifdef OF_HAVE_CLASS_PROPERTIES
153 @property (class, readonly, nonatomic) bool handlesForeignEvents;
154 # endif
155 
161 + (instancetype)observer;
162 
171 + (bool)handlesForeignEvents;
172 
178 - (instancetype)init;
179 
194 - (instancetype)initWithRunLoopMode: (nullable OFRunLoopMode)runLoopMode;
195 
209 - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object;
210 
221 - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object;
222 
233 - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object;
234 
245 - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object;
246 
253 - (void)observe;
254 
263 - (void)observeForTimeInterval: (OFTimeInterval)timeInterval;
264 
273 - (void)observeUntilDate: (OFDate *)date;
274 
281 - (void)cancel;
282 
293 - (bool)processReadBuffers;
294 @end
295 #endif
296 
297 OF_ASSUME_NONNULL_END
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
A class for storing, accessing and comparing dates.
Definition: OFDate.h:33
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:41
The root class for all other classes inside ObjFW.
Definition: OFObject.h:690
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:47
double OFTimeInterval
A time interval in seconds.
Definition: OFObject.h:154
A class that can observe multiple kernel events (e.g. streams being ready to read) at once...
Definition: OFKernelEventObserver.h:115
This protocol is implemented by classes which can be observed for readiness for writing by OFKernelEv...
A protocol that needs to be implemented by delegates for OFKernelEventObserver.
Definition: OFKernelEventObserver.h:35
A class for storing and manipulating arbitrary data in an array.
Definition: OFMutableData.h:29