I've no idea here...
[gtkD.git] / src / glib / Source.d
blob2b53de967adedb61f0607818865da344f296495d
1 /*
2 * This file is part of duit.
4 * duit 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 * duit 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 duit; 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 = Source
28 * strct = GSource
29 * realStrct=
30 * ctorStrct=
31 * clss = Source
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_source_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.MainLoop
45 * - glib.Dataset
46 * - glib.Date
47 * - glib.Source
48 * - glib.MainContext
49 * structWrap:
50 * - GDataset* -> Dataset
51 * - GDate* -> Date
52 * - GMainContext* -> MainContext
53 * - GMainLoop* -> MainLoop
54 * - GSource* -> Source
55 * local aliases:
58 module glib.Source;
60 private import glib.glibtypes;
62 private import lib.glib;
64 private import glib.MainLoop;
65 private import glib.Dataset;
66 private import glib.Date;
67 private import glib.Source;
68 private import glib.MainContext;
70 /**
71 * Description
72 * The main event loop manages all the available sources of events for
73 * GLib and GTK+ applications. These events can come from any number of
74 * different types of sources such as file descriptors (plain files,
75 * pipes or sockets) and timeouts. New types of event sources can also
76 * be added using g_source_attach().
77 * To allow multiple independent sets of sources to be handled in
78 * different threads, each source is associated with a GMainContext.
79 * A GMainContext can only be running in a single thread, but
80 * sources can be added to it and removed from it from other threads.
81 * Each event source is assigned a priority. The default priority,
82 * G_PRIORITY_DEFAULT, is 0. Values less than 0 denote higher
83 * priorities. Values greater than 0 denote lower priorities. Events
84 * from high priority sources are always processed before events from
85 * lower priority sources.
86 * Idle functions can also be added, and assigned a priority. These will
87 * be run whenever no events with a higher priority are ready to be
88 * processed.
89 * The GMainLoop data type represents a main event loop. A GMainLoop
90 * is created with g_main_loop_new(). After adding the initial event sources,
91 * g_main_loop_run() is called. This continuously checks for new events from
92 * each of the event sources and dispatches them. Finally, the
93 * processing of an event from one of the sources leads to a call to
94 * g_main_loop_quit() to exit the main loop, and g_main_loop_run() returns.
95 * It is possible to create new instances of GMainLoop recursively.
96 * This is often used in GTK+ applications when showing modal dialog
97 * boxes. Note that event sources are associated with a particular
98 * GMainContext, and will be checked and dispatched for all main
99 * loops associated with that GMainContext.
100 * GTK+ contains wrappers of some of these functions, e.g. gtk_main(),
101 * gtk_main_quit() and gtk_events_pending().
102 * Creating new sources types
103 * One of the unusual features of the GTK+ main loop functionality
104 * is that new types of event source can be created and used in
105 * addition to the builtin type of event source. A new event source
106 * type is used for handling GDK events. A new source type is
107 * created by deriving from the GSource
108 * structure. The derived type of source is represented by a
109 * structure that has the GSource structure as a first element,
110 * and other elements specific to the new source type. To create
111 * an instance of the new source type, call g_source_new() passing
112 * in the size of the derived structure and a table of functions.
113 * These GSourceFuncs determine the behavior of the new source
114 * types.
115 * New source types basically interact with with the main context
116 * in two ways. Their prepare function in GSourceFuncs can set
117 * a timeout to determine the maximum amount of time that the
118 * main loop will sleep before checking the source again. In
119 * addition, or as well, the source can add file descriptors to
120 * the set that the main context checks using g_source_add_poll().
121 * <hr>
122 * Customizing the main loop iteration
123 * Single iterations of a GMainContext can be run with
124 * g_main_context_iteration(). In some cases, more detailed control
125 * of exactly how the details of the main loop work is desired,
126 * for instance, when integrating the GMainLoop with an external
127 * main loop. In such cases, you can call the component functions
128 * of g_main_context_iteration() directly. These functions
129 * are g_main_context_prepare(), g_main_context_query(),
130 * g_main_context_check() and g_main_context_dispatch().
131 * The operation of these functions can best be seen in terms
132 * of a state diagram, as shown in Figure1, States of a Main Context.
133 * Figure1.States of a Main Context
135 public class Source
138 /** the main Gtk struct */
139 protected GSource* gSource;
142 public GSource* getSourceStruct()
144 return gSource;
148 /** the main Gtk struct as a void* */
149 protected void* getStruct()
151 return cast(void*)gSource;
155 * Sets our main struct and passes it to the parent class
157 public this (GSource* gSource)
159 this.gSource = gSource;
232 * Creates a new GSource structure. The size is specified to
233 * allow creating structures derived from GSource that contain
234 * additional data. The size passed in must be at least
235 * sizeof (GSource).
236 * The source will not initially be associated with any GMainContext
237 * and must be added to one with g_source_attach() before it will be
238 * executed.
239 * source_funcs:
240 * structure containing functions that implement
241 * the sources behavior.
242 * struct_size:
243 * size of the GSource structure to create.
244 * Returns:
245 * the newly-created GSource.
247 public this (GSourceFuncs* sourceFuncs, uint structSize)
249 // GSource* g_source_new (GSourceFuncs *source_funcs, guint struct_size);
250 this(cast(GSource*)g_source_new(sourceFuncs, structSize) );
254 * Increases the reference count on a source by one.
255 * source:
256 * a GSource
257 * Returns:
258 * source
260 public Source refe()
262 // GSource* g_source_ref (GSource *source);
263 return new Source( g_source_ref(gSource) );
267 * Decreases the reference count of a source by one. If the
268 * resulting reference count is zero the source and associated
269 * memory will be destroyed.
270 * source:
271 * a GSource
273 public void unref()
275 // void g_source_unref (GSource *source);
276 g_source_unref(gSource);
280 * Sets the source functions (can be used to override
281 * default implementations) of an unattached source.
282 * source:
283 * a GSource
284 * funcs:
285 * the new GSourceFuncs
286 * Since 2.12
288 public void setFuncs(GSourceFuncs* funcs)
290 // void g_source_set_funcs (GSource *source, GSourceFuncs *funcs);
291 g_source_set_funcs(gSource, funcs);
295 * Adds a GSource to a context so that it will be executed within
296 * that context.
297 * source:
298 * a GSource
299 * context:
300 * a GMainContext (if NULL, the default context will be used)
301 * Returns:
302 * the ID (greater than 0) for the source within the
303 * GMainContext.
305 public uint attach(MainContext context)
307 // guint g_source_attach (GSource *source, GMainContext *context);
308 return g_source_attach(gSource, (context is null) ? null : context.getMainContextStruct());
312 * Removes a source from its GMainContext, if any, and mark it as
313 * destroyed. The source cannot be subsequently added to another
314 * context.
315 * source:
316 * a GSource
318 public void destroy()
320 // void g_source_destroy (GSource *source);
321 g_source_destroy(gSource);
325 * Returns whether source has been destroyed.
326 * This is important when you operate upon your objects
327 * from within idle handlers, but may have freed the object
328 * before the dispatch of your idle handler.
329 * static gboolean
330 * idle_callback (gpointer data)
332 * SomeWidget *self = data;
333 * GDK_THREADS_ENTER ();
334 * /+* do stuff with self +/
335 * self->idle_id = 0;
336 * GDK_THREADS_LEAVE ();
337 * return FALSE;
339 * static void
340 * some_widget_do_stuff_later (SomeWidget *self)
342 * self->idle_id = g_idle_add (idle_callback, self);
344 * static void
345 * some_widget_finalize (GObject *object)
347 * SomeWidget *self = SOME_WIDGET (object);
348 * if (self->idle_id)
349 * g_source_remove (self->idle_id);
350 * G_OBJECT_CLASS (parent_class)->finalize (object);
352 * This will fail in a multi-threaded application if the
353 * widget is destroyed before the idle handler fires due
354 * to the use after free in the callback. A solution, to
355 * this particular problem, is to check to if the source
356 * has already been destroy within the callback.
357 * static gboolean
358 * idle_callback (gpointer data)
360 * SomeWidget *self = data;
361 * GDK_THREADS_ENTER();
362 * if (!g_source_is_destroyed (g_main_current_source()))
364 * /+* do stuff with self +/
366 * GDK_THREADS_LEAVE();
367 * return FALSE;
369 * source:
370 * a GSource
371 * Returns:
372 * TRUE if the source has been destroyed
373 * Since 2.12
375 public int isDestroyed()
377 // gboolean g_source_is_destroyed (GSource *source);
378 return g_source_is_destroyed(gSource);
382 * Sets the priority of a source. While the main loop is being
383 * run, a source will be dispatched if it is ready to be dispatched and no sources
384 * at a higher (numerically smaller) priority are ready to be dispatched.
385 * source:
386 * a GSource
387 * priority:
388 * the new priority.
390 public void setPriority(int priority)
392 // void g_source_set_priority (GSource *source, gint priority);
393 g_source_set_priority(gSource, priority);
397 * Gets the priority of a source.
398 * source:
399 * a GSource
400 * Returns:
401 * the priority of the source
403 public int getPriority()
405 // gint g_source_get_priority (GSource *source);
406 return g_source_get_priority(gSource);
410 * Sets whether a source can be called recursively. If can_recurse is
411 * TRUE, then while the source is being dispatched then this source
412 * will be processed normally. Otherwise, all processing of this
413 * source is blocked until the dispatch function returns.
414 * source:
415 * a GSource
416 * can_recurse:
417 * whether recursion is allowed for this source
419 public void setCanRecurse(int canRecurse)
421 // void g_source_set_can_recurse (GSource *source, gboolean can_recurse);
422 g_source_set_can_recurse(gSource, canRecurse);
426 * Checks whether a source is allowed to be called recursively.
427 * see g_source_set_can_recurse().
428 * source:
429 * a GSource
430 * Returns:
431 * whether recursion is allowed.
433 public int getCanRecurse()
435 // gboolean g_source_get_can_recurse (GSource *source);
436 return g_source_get_can_recurse(gSource);
440 * Returns the numeric ID for a particular source. The ID of a source
441 * is a positive integer which is unique within a particular main loop
442 * context. The reverse
443 * mapping from ID to source is done by g_main_context_find_source_by_id().
444 * source:
445 * a GSource
446 * Returns:
447 * the ID (greater than 0) for the source
449 public uint getId()
451 // guint g_source_get_id (GSource *source);
452 return g_source_get_id(gSource);
456 * Gets the GMainContext with which the source is associated.
457 * Calling this function on a destroyed source is an error.
458 * source:
459 * a GSource
460 * Returns:
461 * the GMainContext with which the source is associated,
462 * or NULL if the context has not yet been added
463 * to a source.
465 public MainContext getContext()
467 // GMainContext* g_source_get_context (GSource *source);
468 return new MainContext( g_source_get_context(gSource) );
472 * Sets the callback function for a source. The callback for a source is
473 * called from the source's dispatch function.
474 * The exact type of func depends on the type of source; ie. you
475 * should not count on func being called with data as its first
476 * parameter.
477 * Typically, you won't use this function. Instead use functions specific
478 * to the type of source you are using.
479 * source:
480 * the source
481 * func:
482 * a callback function
483 * data:
484 * the data to pass to callback function
485 * notify:
486 * a function to call when data is no longer in use, or NULL.
488 public void setCallback(GSourceFunc func, void* data, GDestroyNotify notify)
490 // void g_source_set_callback (GSource *source, GSourceFunc func, gpointer data, GDestroyNotify notify);
491 g_source_set_callback(gSource, func, data, notify);
496 * Sets the callback function storing the data as a refcounted callback
497 * "object". This is used internally. Note that calling
498 * g_source_set_callback_indirect() assumes
499 * an initial reference count on callback_data, and thus
500 * callback_funcs->unref will eventually be called once more
501 * than callback_funcs->ref.
502 * source:
503 * the source
504 * callback_data:
505 * pointer to callback data "object"
506 * callback_funcs:
507 * functions for reference counting callback_data
508 * and getting the callback and data
510 public void setCallbackIndirect(void* callbackData, GSourceCallbackFuncs* callbackFuncs)
512 // void g_source_set_callback_indirect (GSource *source, gpointer callback_data, GSourceCallbackFuncs *callback_funcs);
513 g_source_set_callback_indirect(gSource, callbackData, callbackFuncs);
517 * Adds a file descriptor to the set of file descriptors polled for
518 * this source. This is usually combined with g_source_new() to add an
519 * event source. The event source's check function will typically test
520 * the revents field in the GPollFD struct and return TRUE if events need
521 * to be processed.
522 * source:
523 * a GSource
524 * fd:
525 * a GPollFD structure holding information about a file
526 * descriptor to watch.
528 public void addPoll(GPollFD* fd)
530 // void g_source_add_poll (GSource *source, GPollFD *fd);
531 g_source_add_poll(gSource, fd);
535 * Removes a file descriptor from the set of file descriptors polled for
536 * this source.
537 * source:
538 * a GSource
539 * fd:
540 * a GPollFD structure previously passed to g_source_add_poll().
542 public void removePoll(GPollFD* fd)
544 // void g_source_remove_poll (GSource *source, GPollFD *fd);
545 g_source_remove_poll(gSource, fd);
549 * Gets the "current time" to be used when checking
550 * this source. The advantage of calling this function over
551 * calling g_get_current_time() directly is that when
552 * checking multiple sources, GLib can cache a single value
553 * instead of having to repeatedly get the system time.
554 * source:
555 * a GSource
556 * timeval:
557 * GTimeVal structure in which to store current time.
559 public void getCurrentTime(GTimeVal* timeval)
561 // void g_source_get_current_time (GSource *source, GTimeVal *timeval);
562 g_source_get_current_time(gSource, timeval);
566 * Removes the source with the given id from the default main context.
567 * The id of
568 * a GSource is given by g_source_get_id(), or will be returned by the
569 * functions g_source_attach(), g_idle_add(), g_idle_add_full(),
570 * g_timeout_add(), g_timeout_add_full(), g_child_watch_add(),
571 * g_child_watch_add_full(), g_io_add_watch(), and g_io_add_watch_full().
572 * See also g_source_destroy().
573 * tag:
574 * the ID of the source to remove.
575 * Returns:
576 * TRUE if the source was found and removed.
578 public static int remove(uint tag)
580 // gboolean g_source_remove (guint tag);
581 return g_source_remove(tag);
585 * Removes a source from the default main loop context given the
586 * source functions and user data. If multiple sources exist with the
587 * same source functions and user data, only one will be destroyed.
588 * funcs:
589 * The source_funcs passed to g_source_new()
590 * user_data:
591 * the user data for the callback
592 * Returns:
593 * TRUE if a source was found and removed.
595 public static int removeByFuncsUserData(GSourceFuncs* funcs, void* userData)
597 // gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs, gpointer user_data);
598 return g_source_remove_by_funcs_user_data(funcs, userData);
602 * Removes a source from the default main loop context given the user
603 * data for the callback. If multiple sources exist with the same user
604 * data, only one will be destroyed.
605 * user_data:
606 * the user_data for the callback.
607 * Returns:
608 * TRUE if a source was found and removed.
610 public static int removeByUserData(void* userData)
612 // gboolean g_source_remove_by_user_data (gpointer user_data);
613 return g_source_remove_by_user_data(userData);