ObjFW
OFTimer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
23 @class OFTimer;
24 @class OFDate;
25 @class OFRunLoop;
26 #ifdef OF_HAVE_THREADS
27 @class OFCondition;
28 #endif
29 
30 #ifdef OF_HAVE_BLOCKS
31 
36 typedef void (^of_timer_block_t)(OFTimer *timer);
37 #endif
38 
45 {
46  OFDate *_fireDate;
47  of_time_interval_t _interval;
48  id _target;
49  id _Nullable _object1, _object2;
50  SEL _selector;
51  uint8_t _arguments;
52  bool _repeats;
53 #ifdef OF_HAVE_BLOCKS
54  of_timer_block_t _block;
55 #endif
56  bool _valid;
57 #ifdef OF_HAVE_THREADS
58  OFCondition *_condition;
59  bool _done;
60 #endif
61  OFRunLoop *_Nullable _inRunLoop;
62 }
63 
68 @property (readonly, nonatomic) of_time_interval_t timeInterval;
69 
73 @property (readonly, nonatomic, getter=isRepeating) bool repeating;
74 
78 @property (readonly, nonatomic, getter=isValid) bool valid;
79 
89 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
90  target: (id)target
91  selector: (SEL)selector
92  repeats: (bool)repeats;
93 
104 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
105  target: (id)target
106  selector: (SEL)selector
107  object: (nullable id)object
108  repeats: (bool)repeats;
109 
123 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
124  target: (id)target
125  selector: (SEL)selector
126  object: (nullable id)object1
127  object: (nullable id)object2
128  repeats: (bool)repeats;
129 
130 #ifdef OF_HAVE_BLOCKS
131 
139 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
140  repeats: (bool)repeats
141  block: (of_timer_block_t)block;
142 #endif
143 
153 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
154  target: (id)target
155  selector: (SEL)selector
156  repeats: (bool)repeats;
157 
168 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
169  target: (id)target
170  selector: (SEL)selector
171  object: (nullable id)object
172  repeats: (bool)repeats;
173 
187 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
188  target: (id)target
189  selector: (SEL)selector
190  object: (nullable id)object1
191  object: (nullable id)object2
192  repeats: (bool)repeats;
193 
194 #ifdef OF_HAVE_BLOCKS
195 
203 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
204  repeats: (bool)repeats
205  block: (of_timer_block_t)block;
206 #endif
207 
208 - init OF_UNAVAILABLE;
209 
222 - initWithFireDate: (OFDate *)fireDate
223  interval: (of_time_interval_t)interval
224  target: (id)target
225  selector: (SEL)selector
226  repeats: (bool)repeats;
227 
241 - initWithFireDate: (OFDate *)fireDate
242  interval: (of_time_interval_t)interval
243  target: (id)target
244  selector: (SEL)selector
245  object: (nullable id)object
246  repeats: (bool)repeats;
247 
264 - initWithFireDate: (OFDate *)fireDate
265  interval: (of_time_interval_t)interval
266  target: (id)target
267  selector: (SEL)selector
268  object: (nullable id)object1
269  object: (nullable id)object2
270  repeats: (bool)repeats;
271 
272 #ifdef OF_HAVE_BLOCKS
273 
284 - initWithFireDate: (OFDate *)fireDate
285  interval: (of_time_interval_t)interval
286  repeats: (bool)repeats
287  block: (of_timer_block_t)block;
288 #endif
289 
294 - (void)fire;
295 
301 - (OFDate *)fireDate;
302 
313 - (void)setFireDate: (OFDate *)fireDate;
314 
318 - (void)invalidate;
319 
320 #ifdef OF_HAVE_THREADS
321 
324 - (void)waitUntilDone;
325 #endif
326 @end
327 
328 OF_ASSUME_NONNULL_END
void fire()
Fires the timer, meaning it will execute the specified selector on the target.
Definition: OFTimer.m:358
void invalidate()
Invalidates the timer, preventing it from firing.
Definition: OFTimer.m:438
of_time_interval_t timeInterval
Definition: OFTimer.h:69
void(^ of_timer_block_t)(OFTimer *timer)
A block to execute when a timer fires.
Definition: OFTimer.h:36
bool repeating
Definition: OFTimer.h:74
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
A class providing a run loop for the application and its processes.
Definition: OFRunLoop.h:41
double of_time_interval_t
A time interval in seconds.
Definition: OFObject.h:91
A protocol for comparing objects.
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
A class for storing, accessing and comparing dates.
Definition: OFDate.h:30
void waitUntilDone()
Waits until the timer fired.
Definition: OFTimer.m:451
bool valid
Definition: OFTimer.h:79
A class for creating and firing timers.
Definition: OFTimer.h:44
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:28