ObjFW
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 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 #import "OFRunLoop.h"
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
27 @class OFTimer;
28 @class OFDate;
29 #ifdef OF_HAVE_THREADS
30 @class OFCondition;
31 #endif
32 
33 #ifdef OF_HAVE_BLOCKS
34 
39 typedef void (^OFTimerBlock)(OFTimer *timer);
40 #endif
41 
47 OF_SUBCLASSING_RESTRICTED
49 {
50  OFDate *_fireDate;
51  OFTimeInterval _interval;
52  id _target;
53  id _Nullable _object1, _object2, _object3, _object4;
54  SEL _selector;
55  unsigned char _arguments;
56  bool _repeats;
57 #ifdef OF_HAVE_BLOCKS
58  OFTimerBlock _block;
59 #endif
60  bool _valid;
61 #ifdef OF_HAVE_THREADS
62  OFCondition *_condition;
63  bool _done;
64 #endif
65  OFRunLoop *_Nullable _inRunLoop;
66  OFRunLoopMode _Nullable _inRunLoopMode;
67 }
68 
73 @property (readonly, nonatomic) OFTimeInterval timeInterval;
74 
78 @property (readonly, nonatomic) bool repeats;
79 
83 @property (readonly, nonatomic, getter=isValid) bool valid;
84 
93 @property (copy, nonatomic) OFDate *fireDate;
94 
104 + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
105  target: (id)target
106  selector: (SEL)selector
107  repeats: (bool)repeats;
108 
119 + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
120  target: (id)target
121  selector: (SEL)selector
122  object: (nullable id)object
123  repeats: (bool)repeats;
124 
138 + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
139  target: (id)target
140  selector: (SEL)selector
141  object: (nullable id)object1
142  object: (nullable id)object2
143  repeats: (bool)repeats;
144 
160 + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
161  target: (id)target
162  selector: (SEL)selector
163  object: (nullable id)object1
164  object: (nullable id)object2
165  object: (nullable id)object3
166  repeats: (bool)repeats;
167 
185 + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
186  target: (id)target
187  selector: (SEL)selector
188  object: (nullable id)object1
189  object: (nullable id)object2
190  object: (nullable id)object3
191  object: (nullable id)object4
192  repeats: (bool)repeats;
193 
194 #ifdef OF_HAVE_BLOCKS
195 
203 + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval
204  repeats: (bool)repeats
205  block: (OFTimerBlock)block;
206 #endif
207 
217 + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
218  target: (id)target
219  selector: (SEL)selector
220  repeats: (bool)repeats;
221 
232 + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
233  target: (id)target
234  selector: (SEL)selector
235  object: (nullable id)object
236  repeats: (bool)repeats;
237 
251 + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
252  target: (id)target
253  selector: (SEL)selector
254  object: (nullable id)object1
255  object: (nullable id)object2
256  repeats: (bool)repeats;
257 
273 + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
274  target: (id)target
275  selector: (SEL)selector
276  object: (nullable id)object1
277  object: (nullable id)object2
278  object: (nullable id)object3
279  repeats: (bool)repeats;
280 
298 + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
299  target: (id)target
300  selector: (SEL)selector
301  object: (nullable id)object1
302  object: (nullable id)object2
303  object: (nullable id)object3
304  object: (nullable id)object4
305  repeats: (bool)repeats;
306 
307 #ifdef OF_HAVE_BLOCKS
308 
316 + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval
317  repeats: (bool)repeats
318  block: (OFTimerBlock)block;
319 #endif
320 
321 - (instancetype)init OF_UNAVAILABLE;
322 
335 - (instancetype)initWithFireDate: (OFDate *)fireDate
336  interval: (OFTimeInterval)interval
337  target: (id)target
338  selector: (SEL)selector
339  repeats: (bool)repeats;
340 
354 - (instancetype)initWithFireDate: (OFDate *)fireDate
355  interval: (OFTimeInterval)interval
356  target: (id)target
357  selector: (SEL)selector
358  object: (nullable id)object
359  repeats: (bool)repeats;
360 
377 - (instancetype)initWithFireDate: (OFDate *)fireDate
378  interval: (OFTimeInterval)interval
379  target: (id)target
380  selector: (SEL)selector
381  object: (nullable id)object1
382  object: (nullable id)object2
383  repeats: (bool)repeats;
384 
403 - (instancetype)initWithFireDate: (OFDate *)fireDate
404  interval: (OFTimeInterval)interval
405  target: (id)target
406  selector: (SEL)selector
407  object: (nullable id)object1
408  object: (nullable id)object2
409  object: (nullable id)object3
410  repeats: (bool)repeats;
411 
432 - (instancetype)initWithFireDate: (OFDate *)fireDate
433  interval: (OFTimeInterval)interval
434  target: (id)target
435  selector: (SEL)selector
436  object: (nullable id)object1
437  object: (nullable id)object2
438  object: (nullable id)object3
439  object: (nullable id)object4
440  repeats: (bool)repeats;
441 
442 #ifdef OF_HAVE_BLOCKS
443 
454 - (instancetype)initWithFireDate: (OFDate *)fireDate
455  interval: (OFTimeInterval)interval
456  repeats: (bool)repeats
457  block: (OFTimerBlock)block;
458 #endif
459 
466 - (OFComparisonResult)compare: (OFTimer *)timer;
467 
473 - (void)fire;
474 
478 - (void)invalidate;
479 
480 #ifdef OF_HAVE_THREADS
481 
484 - (void)waitUntilDone;
485 #endif
486 @end
487 
488 OF_ASSUME_NONNULL_END
A protocol for comparing objects.
Definition: OFObject.h:1388
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
OFComparisonResult
A result of a comparison.
Definition: OFObject.h:58
double OFTimeInterval
A time interval in seconds.
Definition: OFObject.h:154
A class for creating and firing timers.
Definition: OFTimer.h:48
A class providing a run loop for the application and its processes.
Definition: OFRunLoop.h:65
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:33
void(^ OFTimerBlock)(OFTimer *timer)
A block to execute when a timer fires.
Definition: OFTimer.h:39