ObjFW
OFKernelEventObserver.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #ifdef OF_HAVE_SOCKETS
18 # import "OFSocket.h"
19 #endif
20 
21 #ifdef OF_AMIGAOS
22 # include <exec/types.h>
23 # include <exec/tasks.h>
24 #endif
25 
26 OF_ASSUME_NONNULL_BEGIN
27 
28 @class OFMutableArray OF_GENERIC(ObjectType);
29 @class OFDate;
30 #ifdef OF_HAVE_THREADS
31 @class OFMutex;
32 #endif
34 
43 @optional
58 - (void)objectIsReadyForReading: (id)object;
59 
65 - (void)objectIsReadyForWriting: (id)object;
66 
67 #if defined(OF_AMIGAOS) || defined(DOXYGEN)
68 
73 - (void)execSignalWasReceived: (ULONG)signalMask;
74 #endif
75 @end
76 
89 @property (readonly, nonatomic) int fileDescriptorForReading;
90 @end
91 
104 @property (readonly, nonatomic) int fileDescriptorForWriting;
105 @end
106 
107 #ifdef OF_HAVE_SOCKETS
108 
118 {
119  OFMutableArray OF_GENERIC(id <OFReadyForReadingObserving>)
120  *_readObjects;
121  OFMutableArray OF_GENERIC(id <OFReadyForWritingObserving>)
122  *_writeObjects;
123  id <OFKernelEventObserverDelegate> _Nullable _delegate;
124 # if defined(OF_AMIGAOS)
125  struct Task *_waitingTask;
126  ULONG _cancelSignal;
127 # elif defined(OF_HAVE_PIPE)
128  int _cancelFD[2];
129 # else
130  OFSocketHandle _cancelFD[2];
131  struct sockaddr_in _cancelAddr;
132 # endif
133 # ifdef OF_AMIGAOS
134  ULONG _execSignalMask;
135 # endif
136  OF_RESERVE_IVARS(OFKernelEventObserver, 4)
137 }
138 
142 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
144 
145 # if defined(OF_AMIGAOS) || defined(DOXYGEN)
146 
151 @property (nonatomic) ULONG execSignalMask;
152 # endif
153 
159 + (instancetype)observer;
160 
174 - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object;
175 
186 - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object;
187 
198 - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object;
199 
210 - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object;
211 
218 - (void)observe;
219 
228 - (void)observeForTimeInterval: (OFTimeInterval)timeInterval;
229 
238 - (void)observeUntilDate: (OFDate *)date;
239 
246 - (void)cancel;
247 
253 - (bool)of_processReadBuffers;
254 @end
255 #endif
256 
257 OF_ASSUME_NONNULL_END
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
A class for creating mutual exclusions.
Definition: OFMutex.h:32
A class for storing, accessing and comparing dates.
Definition: OFDate.h:29
The root class for all other classes inside ObjFW.
Definition: OFObject.h:686
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:43
double OFTimeInterval
A time interval in seconds.
Definition: OFObject.h:150
A class that can observe multiple kernel events (e.g. streams being ready to read) at once...
Definition: OFKernelEventObserver.h:117
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:33
A class for storing and manipulating arbitrary data in an array.
Definition: OFMutableData.h:25