ObjFW
Loading...
Searching...
No Matches
OFTimer.h
Go to the documentation of this file.
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#import "OFRunLoop.h"
18
19OF_ASSUME_NONNULL_BEGIN
20
23@class OFTimer;
24@class OFDate;
25#ifdef OF_HAVE_THREADS
26@class OFCondition;
27#endif
28
29#ifdef OF_HAVE_BLOCKS
35typedef void (^OFTimerBlock)(OFTimer *timer);
36#endif
37
43OF_SUBCLASSING_RESTRICTED
45{
46 OFDate *_fireDate;
47 OFTimeInterval _interval;
48 id _target;
49 id _Nullable _object1, _object2, _object3, _object4;
50 SEL _selector;
51 unsigned char _arguments;
52 bool _repeats;
53#ifdef OF_HAVE_BLOCKS
54 OFTimerBlock _block;
55#endif
56 bool _valid;
57#ifdef OF_HAVE_THREADS
58 OFCondition *_condition;
59 bool _done;
60#endif
61 OFRunLoop *_Nullable _inRunLoop;
62 OFRunLoopMode _Nullable _inRunLoopMode;
63}
64
69@property (readonly, nonatomic) OFTimeInterval timeInterval;
74@property (readonly, nonatomic) bool repeats;
79@property (readonly, nonatomic, getter=isValid) bool valid;
89@property (copy, nonatomic) OFDate *fireDate;
100+ (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
101 target: (id)target
102 selector: (SEL)selector
103 repeats: (bool)repeats;
104
115+ (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
116 target: (id)target
117 selector: (SEL)selector
118 object: (nullable id)object
119 repeats: (bool)repeats;
120
134+ (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
135 target: (id)target
136 selector: (SEL)selector
137 object: (nullable id)object1
138 object: (nullable id)object2
139 repeats: (bool)repeats;
140
156+ (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
157 target: (id)target
158 selector: (SEL)selector
159 object: (nullable id)object1
160 object: (nullable id)object2
161 object: (nullable id)object3
162 repeats: (bool)repeats;
163
181+ (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
182 target: (id)target
183 selector: (SEL)selector
184 object: (nullable id)object1
185 object: (nullable id)object2
186 object: (nullable id)object3
187 object: (nullable id)object4
188 repeats: (bool)repeats;
189
190#ifdef OF_HAVE_BLOCKS
199+ (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
200 repeats: (bool)repeats
201 block: (OFTimerBlock)block;
202#endif
203
213+ (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
214 target: (id)target
215 selector: (SEL)selector
216 repeats: (bool)repeats;
217
228+ (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
229 target: (id)target
230 selector: (SEL)selector
231 object: (nullable id)object
232 repeats: (bool)repeats;
233
247+ (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
248 target: (id)target
249 selector: (SEL)selector
250 object: (nullable id)object1
251 object: (nullable id)object2
252 repeats: (bool)repeats;
253
269+ (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
270 target: (id)target
271 selector: (SEL)selector
272 object: (nullable id)object1
273 object: (nullable id)object2
274 object: (nullable id)object3
275 repeats: (bool)repeats;
276
294+ (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
295 target: (id)target
296 selector: (SEL)selector
297 object: (nullable id)object1
298 object: (nullable id)object2
299 object: (nullable id)object3
300 object: (nullable id)object4
301 repeats: (bool)repeats;
302
303#ifdef OF_HAVE_BLOCKS
312+ (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
313 repeats: (bool)repeats
314 block: (OFTimerBlock)block;
315#endif
316
317- (instancetype)init OF_UNAVAILABLE;
318
331- (instancetype)initWithFireDate: (OFDate *)fireDate
332 interval: (OFTimeInterval)interval
333 target: (id)target
334 selector: (SEL)selector
335 repeats: (bool)repeats;
336
350- (instancetype)initWithFireDate: (OFDate *)fireDate
351 interval: (OFTimeInterval)interval
352 target: (id)target
353 selector: (SEL)selector
354 object: (nullable id)object
355 repeats: (bool)repeats;
356
373- (instancetype)initWithFireDate: (OFDate *)fireDate
374 interval: (OFTimeInterval)interval
375 target: (id)target
376 selector: (SEL)selector
377 object: (nullable id)object1
378 object: (nullable id)object2
379 repeats: (bool)repeats;
380
399- (instancetype)initWithFireDate: (OFDate *)fireDate
400 interval: (OFTimeInterval)interval
401 target: (id)target
402 selector: (SEL)selector
403 object: (nullable id)object1
404 object: (nullable id)object2
405 object: (nullable id)object3
406 repeats: (bool)repeats;
407
428- (instancetype)initWithFireDate: (OFDate *)fireDate
429 interval: (OFTimeInterval)interval
430 target: (id)target
431 selector: (SEL)selector
432 object: (nullable id)object1
433 object: (nullable id)object2
434 object: (nullable id)object3
435 object: (nullable id)object4
436 repeats: (bool)repeats;
437
438#ifdef OF_HAVE_BLOCKS
450- (instancetype)initWithFireDate: (OFDate *)fireDate
451 interval: (OFTimeInterval)interval
452 repeats: (bool)repeats
453 block: (OFTimerBlock)block;
454#endif
455
462- (OFComparisonResult)compare: (OFTimer *)timer;
463
469- (void)fire;
470
474- (void)invalidate;
475
476#ifdef OF_HAVE_THREADS
480- (void)waitUntilDone;
481#endif
482@end
483
484OF_ASSUME_NONNULL_END
OFComparisonResult
A result of a comparison.
Definition OFObject.h:54
double OFTimeInterval
A time interval in seconds.
Definition OFObject.h:150
void(^ OFTimerBlock)(OFTimer *timer)
A block to execute when a timer fires.
Definition OFTimer.h:35
A class implementing a condition variable for thread synchronization.
Definition OFCondition.h:30
A class for storing constant strings using the @"" literal.
Definition OFConstantString.h:38
A class for storing, accessing and comparing dates.
Definition OFDate.h:30
The root class for all other classes inside ObjFW.
Definition OFObject.h:688
A class providing a run loop for the application and its processes.
Definition OFRunLoop.h:62
A class for creating and firing timers.
Definition OFTimer.h:46
A protocol for comparing objects.
Definition OFObject.h:1384