alternative to assert
[gtkD.git] / gtkD / src / glib / Timeout.d
blob9b07ff0aa495e819b10af2ec4fc5aeb9b1a746e7
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile =
26 * outPack = glib
27 * outFile = Timeout
28 * strct =
29 * realStrct=
30 * ctorStrct=
31 * clss = Timeout
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_timeout_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.MainLoop
45 * - glib.Dataset
46 * - glib.Source
47 * structWrap:
48 * - GDataset* -> Dataset
49 * - GMainLoop* -> MainLoop
50 * - GSource* -> Source
51 * module aliases:
52 * local aliases:
55 module glib.Timeout;
57 version(noAssert)
59 version(Tango)
61 import tango.io.Stdout; // use the tango loging?
65 private import gtkc.glibtypes;
67 private import gtkc.glib;
70 private import glib.MainLoop;
71 private import glib.Dataset;
72 private import glib.Source;
77 /**
78 * Description
79 * The main event loop manages all the available sources of events for
80 * GLib and GTK+ applications. These events can come from any number of
81 * different types of sources such as file descriptors (plain files,
82 * pipes or sockets) and timeouts. New types of event sources can also
83 * be added using g_source_attach().
84 * To allow multiple independent sets of sources to be handled in
85 * different threads, each source is associated with a GMainContext.
86 * A GMainContext can only be running in a single thread, but
87 * sources can be added to it and removed from it from other threads.
88 * Each event source is assigned a priority. The default priority,
89 * G_PRIORITY_DEFAULT, is 0. Values less than 0 denote higher
90 * priorities. Values greater than 0 denote lower priorities. Events
91 * from high priority sources are always processed before events from
92 * lower priority sources.
93 * Idle functions can also be added, and assigned a priority. These will
94 * be run whenever no events with a higher priority are ready to be
95 * processed.
96 * The GMainLoop data type represents a main event loop. A GMainLoop
97 * is created with g_main_loop_new(). After adding the initial event sources,
98 * g_main_loop_run() is called. This continuously checks for new events from
99 * each of the event sources and dispatches them. Finally, the
100 * processing of an event from one of the sources leads to a call to
101 * g_main_loop_quit() to exit the main loop, and g_main_loop_run() returns.
102 * It is possible to create new instances of GMainLoop recursively.
103 * This is often used in GTK+ applications when showing modal dialog
104 * boxes. Note that event sources are associated with a particular
105 * GMainContext, and will be checked and dispatched for all main
106 * loops associated with that GMainContext.
107 * GTK+ contains wrappers of some of these functions, e.g. gtk_main(),
108 * gtk_main_quit() and gtk_events_pending().
109 * Creating new sources types
110 * One of the unusual features of the GTK+ main loop functionality
111 * is that new types of event source can be created and used in
112 * addition to the builtin type of event source. A new event source
113 * type is used for handling GDK events. A new source type is
114 * created by deriving from the GSource
115 * structure. The derived type of source is represented by a
116 * structure that has the GSource structure as a first element,
117 * and other elements specific to the new source type. To create
118 * an instance of the new source type, call g_source_new() passing
119 * in the size of the derived structure and a table of functions.
120 * These GSourceFuncs determine the behavior of the new source
121 * types.
122 * New source types basically interact with with the main context
123 * in two ways. Their prepare function in GSourceFuncs can set
124 * a timeout to determine the maximum amount of time that the
125 * main loop will sleep before checking the source again. In
126 * addition, or as well, the source can add file descriptors to
127 * the set that the main context checks using g_source_add_poll().
128 * <hr>
129 * Customizing the main loop iteration
130 * Single iterations of a GMainContext can be run with
131 * g_main_context_iteration(). In some cases, more detailed control
132 * of exactly how the details of the main loop work is desired,
133 * for instance, when integrating the GMainLoop with an external
134 * main loop. In such cases, you can call the component functions
135 * of g_main_context_iteration() directly. These functions
136 * are g_main_context_prepare(), g_main_context_query(),
137 * g_main_context_check() and g_main_context_dispatch().
138 * The operation of these functions can best be seen in terms
139 * of a state diagram, as shown in Figure1, States of a Main Context.
140 * Figure1.States of a Main Context
142 public class Timeout
196 * Creates a new timeout source.
197 * The source will not initially be associated with any GMainContext
198 * and must be added to one with g_source_attach() before it will be
199 * executed.
200 * interval:
201 * the timeout interval in milliseconds.
202 * Returns:
203 * the newly-created timeout source
205 public static Source sourceNew(uint interval)
207 // GSource* g_timeout_source_new (guint interval);
208 return new Source( g_timeout_source_new(interval) );
212 * Creates a new timeout source.
213 * The source will not initially be associated with any GMainContext
214 * and must be added to one with g_source_attach() before it will be
215 * executed.
216 * The scheduling granularity/accuracy of this timeout source will be
217 * in seconds.
218 * interval:
219 * the timeout interval in seconds
220 * Returns:
221 * the newly-created timeout source
222 * Since 2.14
224 public static Source sourceNewSeconds(uint interval)
226 // GSource* g_timeout_source_new_seconds (guint interval);
227 return new Source( g_timeout_source_new_seconds(interval) );
231 * Sets a function to be called at regular intervals, with the default
232 * priority, G_PRIORITY_DEFAULT. The function is called repeatedly
233 * until it returns FALSE, at which point the timeout is automatically
234 * destroyed and the function will not be called again. The first call
235 * to the function will be at the end of the first interval.
236 * Note that timeout functions may be delayed, due to the processing of other
237 * event sources. Thus they should not be relied on for precise timing.
238 * After each call to the timeout function, the time of the next
239 * timeout is recalculated based on the current time and the given interval
240 * (it does not try to 'catch up' time lost in delays).
241 * If you want to have a timer in the "seconds" range and do not care
242 * about the exact time of the first call of the timer, use the
243 * g_timeout_add_seconds() function; this function allows for more
244 * optimizations and more efficient system power usage.
245 * interval:
246 * the time between calls to the function, in milliseconds
247 * (1/1000ths of a second)
248 * function:
249 * function to call
250 * data:
251 * data to pass to function
252 * Returns:
253 * the ID (greater than 0) of the event source.
255 public static uint add(uint interval, GSourceFunc funct, void* data)
257 // guint g_timeout_add (guint interval, GSourceFunc function, gpointer data);
258 return g_timeout_add(interval, funct, data);
262 * Sets a function to be called at regular intervals, with the given
263 * priority. The function is called repeatedly until it returns
264 * FALSE, at which point the timeout is automatically destroyed and
265 * the function will not be called again. The notify function is
266 * called when the timeout is destroyed. The first call to the
267 * function will be at the end of the first interval.
268 * Note that timeout functions may be delayed, due to the processing of other
269 * event sources. Thus they should not be relied on for precise timing.
270 * After each call to the timeout function, the time of the next
271 * timeout is recalculated based on the current time and the given interval
272 * (it does not try to 'catch up' time lost in delays).
273 * priority:
274 * the priority of the idle source. Typically this will be in the
275 * range between G_PRIORITY_DEFAULT_IDLE and G_PRIORITY_HIGH_IDLE.
276 * interval:
277 * the time between calls to the function, in milliseconds
278 * (1/1000ths of a second)
279 * function:
280 * function to call
281 * data:
282 * data to pass to function
283 * notify:
284 * function to call when the idle is removed, or NULL
285 * Returns:
286 * the ID (greater than 0) of the event source.
288 public static uint addFull(int priority, uint interval, GSourceFunc funct, void* data, GDestroyNotify notify)
290 // guint g_timeout_add_full (gint priority, guint interval, GSourceFunc function, gpointer data, GDestroyNotify notify);
291 return g_timeout_add_full(priority, interval, funct, data, notify);
295 * Sets a function to be called at regular intervals, with the default
296 * priority, G_PRIORITY_DEFAULT. The function is called repeatedly
297 * until it returns FALSE, at which point the timeout is automatically
298 * destroyed and the function will not be called again.
299 * Unlike g_timeout_add(), this function operates at whole second granularity.
300 * The initial starting point of the timer is determined by the implementation
301 * and the implementation is expected to group multiple timers together so that
302 * they fire all at the same time.
303 * To allow this grouping, the interval to the first timer is rounded
304 * and can deviate up to one second from the specified interval.
305 * Subsequent timer iterations will generally run at the specified interval.
306 * Note that timeout functions may be delayed, due to the processing of other
307 * event sources. Thus they should not be relied on for precise timing.
308 * After each call to the timeout function, the time of the next
309 * timeout is recalculated based on the current time and the given interval
310 * If you want timing more precise than whole seconds, use g_timeout_add()
311 * instead.
312 * The grouping of timers to fire at the same time results in a more power
313 * and CPU efficient behavior so if your timer is in multiples of seconds
314 * and you don't require the first timer exactly 1 second from now, the
315 * use of g_timeout_add_second() is prefered over g_timeout_add().
316 * interval:
317 * the time between calls to the function, in seconds
318 * function:
319 * function to call
320 * data:
321 * data to pass to function
322 * Returns:
323 * the ID (greater than 0) of the event source.
324 * Since 2.14
326 public static uint addSeconds(uint interval, GSourceFunc funct, void* data)
328 // guint g_timeout_add_seconds (guint interval, GSourceFunc function, gpointer data);
329 return g_timeout_add_seconds(interval, funct, data);