ObjFW
OFTimer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
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 
63 #ifdef OF_HAVE_PROPERTIES
64 @property (retain) OFDate *fireDate;
65 #endif
66 
76 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
77  target: (id)target
78  selector: (SEL)selector
79  repeats: (bool)repeats;
80 
91 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
92  target: (id)target
93  selector: (SEL)selector
94  object: (nullable id)object
95  repeats: (bool)repeats;
96 
110 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
111  target: (id)target
112  selector: (SEL)selector
113  object: (nullable id)object1
114  object: (nullable id)object2
115  repeats: (bool)repeats;
116 
117 #ifdef OF_HAVE_BLOCKS
118 
126 + (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
127  repeats: (bool)repeats
128  block: (of_timer_block_t)block;
129 #endif
130 
140 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
141  target: (id)target
142  selector: (SEL)selector
143  repeats: (bool)repeats;
144 
155 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
156  target: (id)target
157  selector: (SEL)selector
158  object: (nullable id)object
159  repeats: (bool)repeats;
160 
174 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
175  target: (id)target
176  selector: (SEL)selector
177  object: (nullable id)object1
178  object: (nullable id)object2
179  repeats: (bool)repeats;
180 
181 #ifdef OF_HAVE_BLOCKS
182 
190 + (instancetype)timerWithTimeInterval: (of_time_interval_t)timeInterval
191  repeats: (bool)repeats
192  block: (of_timer_block_t)block;
193 #endif
194 
207 - initWithFireDate: (OFDate*)fireDate
208  interval: (of_time_interval_t)interval
209  target: (id)target
210  selector: (SEL)selector
211  repeats: (bool)repeats;
212 
226 - initWithFireDate: (OFDate*)fireDate
227  interval: (of_time_interval_t)interval
228  target: (id)target
229  selector: (SEL)selector
230  object: (nullable id)object
231  repeats: (bool)repeats;
232 
249 - initWithFireDate: (OFDate*)fireDate
250  interval: (of_time_interval_t)interval
251  target: (id)target
252  selector: (SEL)selector
253  object: (nullable id)object1
254  object: (nullable id)object2
255  repeats: (bool)repeats;
256 
257 #ifdef OF_HAVE_BLOCKS
258 
269 - initWithFireDate: (OFDate*)fireDate
270  interval: (of_time_interval_t)interval
271  repeats: (bool)repeats
272  block: (of_timer_block_t)block;
273 #endif
274 
279 - (void)fire;
280 
286 - (OFDate*)fireDate;
287 
298 - (void)setFireDate: (OFDate*)fireDate;
299 
303 - (void)invalidate;
304 
310 - (bool)isValid;
311 
319 - (of_time_interval_t)timeInterval;
320 
321 #ifdef OF_HAVE_THREADS
322 
325 - (void)waitUntilDone;
326 #endif
327 @end
328 
329 OF_ASSUME_NONNULL_END
A protocol for comparing objects.
Definition: OFObject.h:933
A class for storing, accessing and comparing dates.
Definition: OFDate.h:30
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
void(^ of_timer_block_t)(OFTimer *timer)
A block to execute when a timer fires.
Definition: OFTimer.h:36
A class for creating and firing timers.
Definition: OFTimer.h:44
A class providing a run loop for the application and its processes.
Definition: OFRunLoop.h:40
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:28
double of_time_interval_t
A time interval in seconds.
Definition: OFObject.h:90