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, _object1, _object2;
49  SEL _selector;
50  uint8_t _arguments;
51  bool _repeats;
52 #ifdef OF_HAVE_BLOCKS
53  of_timer_block_t _block;
54 #endif
55  bool _valid;
56 #ifdef OF_HAVE_THREADS
57  OFCondition *_condition;
58  bool _done;
59 #endif
60  OFRunLoop *_inRunLoop;
61 }
62 
67 @property (readonly, nonatomic) of_time_interval_t timeInterval;
68 
72 @property (readonly, nonatomic, getter=isRepeating) bool repeating;
73 
77 @property (readonly, nonatomic, getter=isValid) bool valid;
78 
88 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
89  target: (id)target
90  selector: (SEL)selector
91  repeats: (bool)repeats;
92 
103 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
104  target: (id)target
105  selector: (SEL)selector
106  object: (nullable id)object
107  repeats: (bool)repeats;
108 
122 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
123  target: (id)target
124  selector: (SEL)selector
125  object: (nullable id)object1
126  object: (nullable id)object2
127  repeats: (bool)repeats;
128 
129 #ifdef OF_HAVE_BLOCKS
130 
138 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
139  repeats: (bool)repeats
140  block: (of_timer_block_t)block;
141 #endif
142 
152 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
153  target: (id)target
154  selector: (SEL)selector
155  repeats: (bool)repeats;
156 
167 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
168  target: (id)target
169  selector: (SEL)selector
170  object: (nullable id)object
171  repeats: (bool)repeats;
172 
186 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
187  target: (id)target
188  selector: (SEL)selector
189  object: (nullable id)object1
190  object: (nullable id)object2
191  repeats: (bool)repeats;
192 
193 #ifdef OF_HAVE_BLOCKS
194 
202 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
203  repeats: (bool)repeats
204  block: (of_timer_block_t)block;
205 #endif
206 
207 - init OF_UNAVAILABLE;
208 
221 - initWithFireDate: (OFDate *)fireDate
222  interval: (of_time_interval_t)interval
223  target: (id)target
224  selector: (SEL)selector
225  repeats: (bool)repeats;
226 
240 - initWithFireDate: (OFDate *)fireDate
241  interval: (of_time_interval_t)interval
242  target: (id)target
243  selector: (SEL)selector
244  object: (nullable id)object
245  repeats: (bool)repeats;
246 
263 - initWithFireDate: (OFDate *)fireDate
264  interval: (of_time_interval_t)interval
265  target: (id)target
266  selector: (SEL)selector
267  object: (nullable id)object1
268  object: (nullable id)object2
269  repeats: (bool)repeats;
270 
271 #ifdef OF_HAVE_BLOCKS
272 
283 - initWithFireDate: (OFDate *)fireDate
284  interval: (of_time_interval_t)interval
285  repeats: (bool)repeats
286  block: (of_timer_block_t)block;
287 #endif
288 
293 - (void)fire;
294 
300 - (OFDate *)fireDate;
301 
312 - (void)setFireDate: (OFDate *)fireDate;
313 
317 - (void)invalidate;
318 
319 #ifdef OF_HAVE_THREADS
320 
323 - (void)waitUntilDone;
324 #endif
325 @end
326 
327 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:68
void(^ of_timer_block_t)(OFTimer *timer)
A block to execute when a timer fires.
Definition: OFTimer.h:36
bool repeating
Definition: OFTimer.h:73
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:78
A class for creating and firing timers.
Definition: OFTimer.h:44
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:28