ObjFW
Loading...
Searching...
No Matches
OFKernelEventObserver.h
1/*
2 * Copyright (c) 2008-2024 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
25#ifdef OF_AMIGAOS
26# include <exec/types.h>
27# include <exec/tasks.h>
28#endif
29
30OF_ASSUME_NONNULL_BEGIN
31
32@class OFMutableArray OF_GENERIC(ObjectType);
33@class OFDate;
34#ifdef OF_HAVE_THREADS
35@class OFMutex;
36#endif
37@class OFMutableData;
38
46@protocol OFKernelEventObserverDelegate <OFObject>
47@optional
62- (void)objectIsReadyForReading: (id)object;
63
69- (void)objectIsReadyForWriting: (id)object;
70
71#if defined(OF_AMIGAOS) || defined(DOXYGEN)
77- (void)execSignalWasReceived: (ULONG)signalMask;
78#endif
79@end
80
88@protocol OFReadyForReadingObserving <OFObject>
93@property (readonly, nonatomic) int fileDescriptorForReading;
94@end
95
103@protocol OFReadyForWritingObserving <OFObject>
108@property (readonly, nonatomic) int fileDescriptorForWriting;
109@end
110
111#ifdef OF_HAVE_SOCKETS
122{
123 OFMutableArray OF_GENERIC(id <OFReadyForReadingObserving>)
124 *_readObjects;
125 OFMutableArray OF_GENERIC(id <OFReadyForWritingObserving>)
126 *_writeObjects;
127 id <OFKernelEventObserverDelegate> _Nullable _delegate;
128# if defined(OF_AMIGAOS)
129 struct Task *_waitingTask;
130 ULONG _cancelSignal;
131# elif defined(OF_HAVE_PIPE)
132 int _cancelFD[2];
133# else
134 OFSocketHandle _cancelFD[2];
135 struct sockaddr_in _cancelAddr;
136# endif
137# ifdef OF_AMIGAOS
138 ULONG _execSignalMask;
139# endif
140 OF_RESERVE_IVARS(OFKernelEventObserver, 4)
141}
142
146@property OF_NULLABLE_PROPERTY (assign, nonatomic)
147 id <OFKernelEventObserverDelegate> delegate;
148
149# if defined(OF_AMIGAOS) || defined(DOXYGEN)
155@property (nonatomic) ULONG execSignalMask;
156# endif
157
163+ (instancetype)observer;
164
178- (void)addObjectForReading: (id <OFReadyForReadingObserving>)object;
179
190- (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object;
191
202- (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object;
203
214- (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object;
215
222- (void)observe;
223
232- (void)observeForTimeInterval: (OFTimeInterval)timeInterval;
233
242- (void)observeUntilDate: (OFDate *)date;
243
250- (void)cancel;
251
257- (bool)of_processReadBuffers;
258@end
259#endif
260
261OF_ASSUME_NONNULL_END
double OFTimeInterval
A time interval in seconds.
Definition OFObject.h:154
A class for storing, accessing and comparing dates.
Definition OFDate.h:34
A class that can observe multiple kernel events (e.g. streams being ready to read) at once.
Definition OFKernelEventObserver.h:122
An abstract class for storing, adding and removing objects in an array.
Definition OFMutableArray.h:48
A class for storing and manipulating arbitrary data in an array.
Definition OFMutableData.h:30
A class for creating mutual exclusions.
Definition OFMutex.h:38
The root class for all other classes inside ObjFW.
Definition OFObject.h:692