/usr/include/d/gtkd-3/glib/MainLoop.d is in libgtkd-3-dev 3.7.5-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | /*
* This file is part of gtkD.
*
* gtkD is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version, with
* some exceptions, please read the COPYING file.
*
* gtkD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with gtkD; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/
// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage
module glib.MainLoop;
private import glib.ConstructionException;
private import glib.MainContext;
private import glib.Source;
private import glib.c.functions;
public import glib.c.types;
public import gtkc.glibtypes;
private import gtkd.Loader;
/**
* The `GMainLoop` struct is an opaque data type
* representing the main event loop of a GLib or GTK+ application.
*/
public class MainLoop
{
/** the main Gtk struct */
protected GMainLoop* gMainLoop;
protected bool ownedRef;
/** Get the main Gtk struct */
public GMainLoop* getMainLoopStruct(bool transferOwnership = false)
{
if (transferOwnership)
ownedRef = false;
return gMainLoop;
}
/** the main Gtk struct as a void* */
protected void* getStruct()
{
return cast(void*)gMainLoop;
}
/**
* Sets our main struct and passes it to the parent class.
*/
public this (GMainLoop* gMainLoop, bool ownedRef = false)
{
this.gMainLoop = gMainLoop;
this.ownedRef = ownedRef;
}
~this ()
{
if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
g_main_loop_unref(gMainLoop);
}
/**
* Creates a new #GMainLoop structure.
*
* Params:
* context = a #GMainContext (if %NULL, the default context will be used).
* isRunning = set to %TRUE to indicate that the loop is running. This
* is not very important since calling g_main_loop_run() will set this to
* %TRUE anyway.
*
* Returns: a new #GMainLoop.
*
* Throws: ConstructionException GTK+ fails to create the object.
*/
public this(MainContext context, bool isRunning)
{
auto p = g_main_loop_new((context is null) ? null : context.getMainContextStruct(), isRunning);
if(p is null)
{
throw new ConstructionException("null returned by new");
}
this(cast(GMainLoop*) p);
}
/**
* Returns the #GMainContext of @loop.
*
* Returns: the #GMainContext of @loop
*/
public MainContext getContext()
{
auto p = g_main_loop_get_context(gMainLoop);
if(p is null)
{
return null;
}
return new MainContext(cast(GMainContext*) p);
}
/**
* Checks to see if the main loop is currently being run via g_main_loop_run().
*
* Returns: %TRUE if the mainloop is currently being run.
*/
public bool isRunning()
{
return g_main_loop_is_running(gMainLoop) != 0;
}
/**
* Stops a #GMainLoop from running. Any calls to g_main_loop_run()
* for the loop will return.
*
* Note that sources that have already been dispatched when
* g_main_loop_quit() is called will still be executed.
*/
public void quit()
{
g_main_loop_quit(gMainLoop);
}
/**
* Increases the reference count on a #GMainLoop object by one.
*
* Returns: @loop
*/
public MainLoop doref()
{
auto p = g_main_loop_ref(gMainLoop);
if(p is null)
{
return null;
}
return new MainLoop(cast(GMainLoop*) p, true);
}
/**
* Runs a main loop until g_main_loop_quit() is called on the loop.
* If this is called for the thread of the loop's #GMainContext,
* it will process events from the loop, otherwise it will
* simply wait.
*/
public void run()
{
g_main_loop_run(gMainLoop);
}
/**
* Decreases the reference count on a #GMainLoop object by one. If
* the result is zero, free the loop and free all associated memory.
*/
public void unref()
{
g_main_loop_unref(gMainLoop);
}
/**
* Returns the currently firing source for this thread.
*
* Returns: The currently firing source or %NULL.
*
* Since: 2.12
*/
public static Source mainCurrentSource()
{
auto p = g_main_current_source();
if(p is null)
{
return null;
}
return new Source(cast(GSource*) p);
}
/**
* Returns the depth of the stack of calls to
* g_main_context_dispatch() on any #GMainContext in the current thread.
* That is, when called from the toplevel, it gives 0. When
* called from within a callback from g_main_context_iteration()
* (or g_main_loop_run(), etc.) it returns 1. When called from within
* a callback to a recursive call to g_main_context_iteration(),
* it returns 2. And so forth.
*
* This function is useful in a situation like the following:
* Imagine an extremely simple "garbage collected" system.
*
* |[<!-- language="C" -->
* static GList *free_list;
*
* gpointer
* allocate_memory (gsize size)
* {
* gpointer result = g_malloc (size);
* free_list = g_list_prepend (free_list, result);
* return result;
* }
*
* void
* free_allocated_memory (void)
* {
* GList *l;
* for (l = free_list; l; l = l->next);
* g_free (l->data);
* g_list_free (free_list);
* free_list = NULL;
* }
*
* [...]
*
* while (TRUE);
* {
* g_main_context_iteration (NULL, TRUE);
* free_allocated_memory();
* }
* ]|
*
* This works from an application, however, if you want to do the same
* thing from a library, it gets more difficult, since you no longer
* control the main loop. You might think you can simply use an idle
* function to make the call to free_allocated_memory(), but that
* doesn't work, since the idle function could be called from a
* recursive callback. This can be fixed by using g_main_depth()
*
* |[<!-- language="C" -->
* gpointer
* allocate_memory (gsize size)
* {
* FreeListBlock *block = g_new (FreeListBlock, 1);
* block->mem = g_malloc (size);
* block->depth = g_main_depth ();
* free_list = g_list_prepend (free_list, block);
* return block->mem;
* }
*
* void
* free_allocated_memory (void)
* {
* GList *l;
*
* int depth = g_main_depth ();
* for (l = free_list; l; );
* {
* GList *next = l->next;
* FreeListBlock *block = l->data;
* if (block->depth > depth)
* {
* g_free (block->mem);
* g_free (block);
* free_list = g_list_delete_link (free_list, l);
* }
*
* l = next;
* }
* }
* ]|
*
* There is a temptation to use g_main_depth() to solve
* problems with reentrancy. For instance, while waiting for data
* to be received from the network in response to a menu item,
* the menu item might be selected again. It might seem that
* one could make the menu item's callback return immediately
* and do nothing if g_main_depth() returns a value greater than 1.
* However, this should be avoided since the user then sees selecting
* the menu item do nothing. Furthermore, you'll find yourself adding
* these checks all over your code, since there are doubtless many,
* many things that the user could do. Instead, you can use the
* following techniques:
*
* 1. Use gtk_widget_set_sensitive() or modal dialogs to prevent
* the user from interacting with elements while the main
* loop is recursing.
*
* 2. Avoid main loop recursion in situations where you can't handle
* arbitrary callbacks. Instead, structure your code so that you
* simply return to the main loop and then get called again when
* there is more work to do.
*
* Returns: The main loop recursion level in the current thread
*/
public static int mainDepth()
{
return g_main_depth();
}
/**
* Polls @fds, as with the poll() system call, but portably. (On
* systems that don't have poll(), it is emulated using select().)
* This is used internally by #GMainContext, but it can be called
* directly if you need to block until a file descriptor is ready, but
* don't want to run the full main loop.
*
* Each element of @fds is a #GPollFD describing a single file
* descriptor to poll. The %fd field indicates the file descriptor,
* and the %events field indicates the events to poll for. On return,
* the %revents fields will be filled with the events that actually
* occurred.
*
* On POSIX systems, the file descriptors in @fds can be any sort of
* file descriptor, but the situation is much more complicated on
* Windows. If you need to use g_poll() in code that has to run on
* Windows, the easiest solution is to construct all of your
* #GPollFDs with g_io_channel_win32_make_pollfd().
*
* Params:
* fds = file descriptors to poll
* nfds = the number of file descriptors in @fds
* timeout = amount of time to wait, in milliseconds, or -1 to wait forever
*
* Returns: the number of entries in @fds whose %revents fields
* were filled in, or 0 if the operation timed out, or -1 on error or
* if the call was interrupted.
*
* Since: 2.20
*/
public static int poll(GPollFD* fds, uint nfds, int timeout)
{
return g_poll(fds, nfds, timeout);
}
}
|