1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gobject/types"
12)
13
14// Prototype of a #GChildWatchSource callback, called when a child
15// process has exited.
16//
17// To interpret @wait_status, see the documentation for
18// [func@GLib.spawn_check_wait_status]. In particular,
19// on Unix platforms, note that it is usually not equal
20// to the integer passed to `exit()` or returned from `main()`.
21type ChildWatchFunc func(Pid, int, uintptr)
22
23// Specifies the type of function passed to [func@GLib.clear_handle_id] The
24// implementation is expected to free the resource identified by @handle_id;
25// for instance, if @handle_id is a [struct@GLib.Source] ID,
26// [func@GLib.Source.remove] can be used.
27type ClearHandleFunc func(uint)
28
29// Dispose function for @source. See [method@GLib.Source.set_dispose_function]
30// for details.
31type SourceDisposeFunc func(*Source)
32
33// This is just a placeholder for #GClosureMarshal,
34// which cannot be used here for dependency reasons.
35type SourceDummyMarshal func()
36
37// Specifies the type of function passed to [func@GLib.timeout_add],
38// [func@GLib.timeout_add_full], [func@GLib.idle_add], and
39// [func@GLib.idle_add_full].
40//
41// When calling [method@GLib.Source.set_callback], you may need to cast a
42// function of a different type to this type. Use [func@GLib.SOURCE_FUNC] to
43// avoid warnings about incompatible function types.
44type SourceFunc func(uintptr) bool
45
46// Checks if the source is ready to be dispatched.
47//
48// Called after all the file descriptors are polled. The source
49// should return %TRUE if it is ready to be dispatched. Note that some
50// time may have passed since the previous prepare function was called,
51// so the source should be checked again here.
52//
53// Since 2.36 this may be `NULL`, in which case the effect is
54// as if the function always returns `FALSE`.
55type SourceFuncsCheckFunc func(*Source) bool
56
57// Dispatches the source callback.
58//
59// Called to dispatch the event source, after it has returned
60// `TRUE` in either its prepare or its check function, or if a ready time
61// has been reached. The dispatch function receives a callback function and
62// user data. The callback function may be `NULL` if the source was never
63// connected to a callback using [method@GLib.Source.set_callback]. The dispatch
64// function should call the callback function with @user_data and whatever
65// additional parameters are needed for this type of event source. The
66// return value of the dispatch function should be [const@GLib.SOURCE_REMOVE]
67// if the source should be removed or [const@GLib.SOURCE_CONTINUE] to keep it.
68type SourceFuncsDispatchFunc func(*Source, uintptr, uintptr) bool
69
70// Finalizes the source.
71//
72// Called when the source is finalized. At this point, the source
73// will have been destroyed, had its callback cleared, and have been removed
74// from its [type@GLib.MainContext], but it will still have its final reference
75// count, so methods can be called on it from within this function.
76type SourceFuncsFinalizeFunc func(*Source)
77
78// Checks the source for readiness.
79//
80// Called before all the file descriptors are polled. If the
81// source can determine that it is ready here (without waiting for the
82// results of the poll call) it should return %TRUE. It can also return
83// a @timeout_ value which should be the maximum timeout (in milliseconds)
84// which should be passed to the poll call. The actual timeout used will
85// be `-1` if all sources returned `-1`, or it will be the minimum of all
86// the @timeout_ values returned which were greater than or equal to `0`.
87// If the prepare function returns a timeout and the source also has a
88// ready time set, then the lower of the two will be used.
89//
90// Since 2.36 this may be `NULL`, in which case the effect is as if the
91// function always returns `FALSE` with a timeout of `-1`.
92type SourceFuncsPrepareFunc func(*Source, *int) bool
93
94// A source function that is only called once before being removed from the main
95// context automatically.
96//
97// See: [func@GLib.idle_add_once], [func@GLib.timeout_add_once]
98type SourceOnceFunc func(uintptr)
99
100// The `GMainContext` struct is an opaque data
101// type representing a set of sources to be handled in a main loop.
102type MainContext struct {
103 _ structs.HostLayout
104}
105
106var xMainContextGLibType func() types.GType
107
108func MainContextGLibType() types.GType {
109 return xMainContextGLibType()
110}
111
112func (x *MainContext) GoPointer() uintptr {
113 return uintptr(unsafe.Pointer(x))
114}
115
116var xNewMainContext func() *MainContext
117
118// Creates a new [struct@GLib.MainContext] structure.
119func NewMainContext() *MainContext {
120
121 cret := xNewMainContext()
122 return cret
123}
124
125var xNewMainContextWithFlags func(MainContextFlags) *MainContext
126
127// Creates a new [struct@GLib.MainContext] structure.
128func NewMainContextWithFlags(FlagsVar MainContextFlags) *MainContext {
129
130 cret := xNewMainContextWithFlags(FlagsVar)
131 return cret
132}
133
134var xMainContextAcquire func(uintptr) bool
135
136// Tries to become the owner of the specified context.
137//
138// If some other thread is the owner of the context,
139// returns false immediately. Ownership is properly
140// recursive: the owner can require ownership again
141// and will release ownership when [method@GLib.MainContext.release]
142// is called as many times as [method@GLib.MainContext.acquire].
143//
144// You must be the owner of a context before you
145// can call [method@GLib.MainContext.prepare], [method@GLib.MainContext.query],
146// [method@GLib.MainContext.check], [method@GLib.MainContext.dispatch],
147// [method@GLib.MainContext.release].
148//
149// Since 2.76 @context can be `NULL` to use the global-default
150// main context.
151func (x *MainContext) Acquire() bool {
152
153 cret := xMainContextAcquire(x.GoPointer())
154 return cret
155}
156
157var xMainContextAddPoll func(uintptr, *PollFD, int)
158
159// Adds a file descriptor to the set of file descriptors polled for
160// this context.
161//
162// This will very seldom be used directly. Instead
163// a typical event source will use `g_source_add_unix_fd()` instead.
164func (x *MainContext) AddPoll(FdVar *PollFD, PriorityVar int) {
165
166 xMainContextAddPoll(x.GoPointer(), FdVar, PriorityVar)
167
168}
169
170var xMainContextCheck func(uintptr, int, []PollFD, int) bool
171
172// Passes the results of polling back to the main loop.
173//
174// You should be
175// careful to pass @fds and its length @n_fds as received from
176// [method@GLib.MainContext.query], as this functions relies on assumptions
177// on how @fds is filled.
178//
179// You must have successfully acquired the context with
180// [method@GLib.MainContext.acquire] before you may call this function.
181//
182// Since 2.76 @context can be `NULL` to use the global-default
183// main context.
184func (x *MainContext) Check(MaxPriorityVar int, FdsVar []PollFD, NFdsVar int) bool {
185
186 cret := xMainContextCheck(x.GoPointer(), MaxPriorityVar, FdsVar, NFdsVar)
187 return cret
188}
189
190var xMainContextDispatch func(uintptr)
191
192// Dispatches all pending sources.
193//
194// You must have successfully acquired the context with
195// [method@GLib.MainContext.acquire] before you may call this function.
196//
197// Since 2.76 @context can be `NULL` to use the global-default
198// main context.
199func (x *MainContext) Dispatch() {
200
201 xMainContextDispatch(x.GoPointer())
202
203}
204
205var xMainContextFindSourceByFuncsUserData func(uintptr, *SourceFuncs, uintptr) *Source
206
207// Finds a source with the given source functions and user data.
208//
209// If multiple sources exist with the same source function and user data,
210// the first one found will be returned.
211func (x *MainContext) FindSourceByFuncsUserData(FuncsVar *SourceFuncs, UserDataVar uintptr) *Source {
212
213 cret := xMainContextFindSourceByFuncsUserData(x.GoPointer(), FuncsVar, UserDataVar)
214 return cret
215}
216
217var xMainContextFindSourceById func(uintptr, uint) *Source
218
219// Finds a [struct@GLib.Source] given a pair of context and ID.
220//
221// It is a programmer error to attempt to look up a non-existent source.
222//
223// More specifically: source IDs can be reissued after a source has been
224// destroyed and therefore it is never valid to use this function with a
225// source ID which may have already been removed. An example is when
226// scheduling an idle to run in another thread with [func@GLib.idle_add]: the
227// idle may already have run and been removed by the time this function
228// is called on its (now invalid) source ID. This source ID may have
229// been reissued, leading to the operation being performed against the
230// wrong source.
231func (x *MainContext) FindSourceById(SourceIdVar uint) *Source {
232
233 cret := xMainContextFindSourceById(x.GoPointer(), SourceIdVar)
234 return cret
235}
236
237var xMainContextFindSourceByUserData func(uintptr, uintptr) *Source
238
239// Finds a source with the given user data for the callback.
240//
241// If multiple sources exist with the same user data, the first
242// one found will be returned.
243func (x *MainContext) FindSourceByUserData(UserDataVar uintptr) *Source {
244
245 cret := xMainContextFindSourceByUserData(x.GoPointer(), UserDataVar)
246 return cret
247}
248
249var xMainContextGetPollFunc func(uintptr) uintptr
250
251// Gets the poll function set by [method@GLib.MainContext.set_poll_func].
252func (x *MainContext) GetPollFunc() uintptr {
253
254 cret := xMainContextGetPollFunc(x.GoPointer())
255 return cret
256}
257
258var xMainContextInvoke func(uintptr, uintptr, uintptr)
259
260// Invokes a function in such a way that @context is owned during the
261// invocation of @function.
262//
263// If @context is `NULL` then the global-default main context — as
264// returned by [func@GLib.MainContext.default] — is used.
265//
266// If @context is owned by the current thread, @function is called
267// directly. Otherwise, if @context is the thread-default main context
268// of the current thread and [method@GLib.MainContext.acquire] succeeds,
269// then @function is called and [method@GLib.MainContext.release] is called
270// afterwards.
271//
272// In any other case, an idle source is created to call @function and
273// that source is attached to @context (presumably to be run in another
274// thread). The idle source is attached with [const@GLib.PRIORITY_DEFAULT]
275// priority. If you want a different priority, use
276// [method@GLib.MainContext.invoke_full].
277//
278// Note that, as with normal idle functions, @function should probably return
279// [const@GLib.SOURCE_REMOVE]. If it returns [const@GLib.SOURCE_CONTINUE], it
280// will be continuously run in a loop (and may prevent this call from returning).
281func (x *MainContext) Invoke(FunctionVar *SourceFunc, DataVar uintptr) {
282
283 var FunctionVarRef uintptr
284 if FunctionVar != nil {
285 FunctionVarPtr := uintptr(unsafe.Pointer(FunctionVar))
286 if cbRefPtr, ok := GetCallback(FunctionVarPtr); ok {
287 FunctionVarRef = cbRefPtr
288 } else {
289 fcb := func(arg0 uintptr) bool {
290 cbFn := *FunctionVar
291 return cbFn(arg0)
292 }
293 FunctionVarRef = purego.NewCallback(fcb)
294 SaveCallbackWithClosure(FunctionVarPtr, FunctionVarRef, FunctionVar)
295 }
296 }
297
298 xMainContextInvoke(x.GoPointer(), FunctionVarRef, DataVar)
299
300}
301
302var xMainContextInvokeFull func(uintptr, int, uintptr, uintptr, uintptr)
303
304// Invokes a function in such a way that @context is owned during the
305// invocation of @function.
306//
307// This function is the same as [method@GLib.MainContext.invoke] except that it
308// lets you specify the priority in case @function ends up being
309// scheduled as an idle and also lets you give a [callback@GLib.DestroyNotify]
310// for @data.
311//
312// The @notify function should not assume that it is called from any particular
313// thread or with any particular context acquired.
314func (x *MainContext) InvokeFull(PriorityVar int, FunctionVar *SourceFunc, DataVar uintptr, NotifyVar *DestroyNotify) {
315
316 var FunctionVarRef uintptr
317 if FunctionVar != nil {
318 FunctionVarPtr := uintptr(unsafe.Pointer(FunctionVar))
319 if cbRefPtr, ok := GetCallback(FunctionVarPtr); ok {
320 FunctionVarRef = cbRefPtr
321 } else {
322 fcb := func(arg0 uintptr) bool {
323 cbFn := *FunctionVar
324 return cbFn(arg0)
325 }
326 FunctionVarRef = purego.NewCallback(fcb)
327 SaveCallbackWithClosure(FunctionVarPtr, FunctionVarRef, FunctionVar)
328 }
329 }
330
331 var NotifyVarRef uintptr
332 if NotifyVar != nil {
333 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
334 if cbRefPtr, ok := GetCallback(NotifyVarPtr); ok {
335 NotifyVarRef = cbRefPtr
336 } else {
337 fcb := func(arg0 uintptr) {
338 cbFn := *NotifyVar
339 cbFn(arg0)
340 }
341 NotifyVarRef = purego.NewCallback(fcb)
342 SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
343 }
344 }
345
346 xMainContextInvokeFull(x.GoPointer(), PriorityVar, FunctionVarRef, DataVar, NotifyVarRef)
347
348}
349
350var xMainContextIsOwner func(uintptr) bool
351
352// Determines whether this thread holds the (recursive)
353// ownership of this [struct@GLib.MainContext].
354//
355// This is useful to
356// know before waiting on another thread that may be
357// blocking to get ownership of @context.
358func (x *MainContext) IsOwner() bool {
359
360 cret := xMainContextIsOwner(x.GoPointer())
361 return cret
362}
363
364var xMainContextIteration func(uintptr, bool) bool
365
366// Runs a single iteration for the given main loop.
367//
368// This involves
369// checking to see if any event sources are ready to be processed,
370// then if no events sources are ready and @may_block is true, waiting
371// for a source to become ready, then dispatching the highest priority
372// events sources that are ready. Otherwise, if @may_block is false,
373// this function does not wait for sources to become ready, and only the highest
374// priority sources which are already ready (if any) will be dispatched.
375//
376// Note that even when @may_block is true, it is still possible for
377// [method@GLib.MainContext.iteration] to return false, since the wait may
378// be interrupted for other reasons than an event source becoming ready.
379func (x *MainContext) Iteration(MayBlockVar bool) bool {
380
381 cret := xMainContextIteration(x.GoPointer(), MayBlockVar)
382 return cret
383}
384
385var xMainContextPending func(uintptr) bool
386
387// Checks if any sources have pending events for the given context.
388func (x *MainContext) Pending() bool {
389
390 cret := xMainContextPending(x.GoPointer())
391 return cret
392}
393
394var xMainContextPopThreadDefault func(uintptr)
395
396// Pops @context off the thread-default context stack (verifying that
397// it was on the top of the stack).
398func (x *MainContext) PopThreadDefault() {
399
400 xMainContextPopThreadDefault(x.GoPointer())
401
402}
403
404var xMainContextPrepare func(uintptr, *int) bool
405
406// Prepares to poll sources within a main loop.
407//
408// The resulting information
409// for polling is determined by calling [method@GLib.MainContext.query].
410//
411// You must have successfully acquired the context with
412// [method@GLib.MainContext.acquire] before you may call this function.
413func (x *MainContext) Prepare(PriorityVar *int) bool {
414
415 cret := xMainContextPrepare(x.GoPointer(), PriorityVar)
416 return cret
417}
418
419var xMainContextPushThreadDefault func(uintptr)
420
421// Acquires @context and sets it as the thread-default context for the
422// current thread. This will cause certain asynchronous operations
423// (such as most [Gio](../gio/index.html)-based I/O) which are
424// started in this thread to run under @context and deliver their
425// results to its main loop, rather than running under the global
426// default main context in the main thread. Note that calling this function
427// changes the context returned by [func@GLib.MainContext.get_thread_default],
428// not the one returned by [func@GLib.MainContext.default], so it does not
429// affect the context used by functions like [func@GLib.idle_add].
430//
431// Normally you would call this function shortly after creating a new
432// thread, passing it a [struct@GLib.MainContext] which will be run by a
433// [struct@GLib.MainLoop] in that thread, to set a new default context for all
434// async operations in that thread. In this case you may not need to
435// ever call [method@GLib.MainContext.pop_thread_default], assuming you want
436// the new [struct@GLib.MainContext] to be the default for the whole lifecycle
437// of the thread.
438//
439// If you don’t have control over how the new thread was created (e.g.
440// in the new thread isn’t newly created, or if the thread life
441// cycle is managed by a #GThreadPool), it is always suggested to wrap
442// the logic that needs to use the new [struct@GLib.MainContext] inside a
443// [method@GLib.MainContext.push_thread_default] /
444// [method@GLib.MainContext.pop_thread_default] pair, otherwise threads that
445// are re-used will end up never explicitly releasing the
446// [struct@GLib.MainContext] reference they hold.
447//
448// In some cases you may want to schedule a single operation in a
449// non-default context, or temporarily use a non-default context in
450// the main thread. In that case, you can wrap the call to the
451// asynchronous operation inside a
452// [method@GLib.MainContext.push_thread_default] /
453// [method@GLib.MainContext.pop_thread_default] pair, but it is up to you to
454// ensure that no other asynchronous operations accidentally get
455// started while the non-default context is active.
456//
457// Beware that libraries that predate this function may not correctly
458// handle being used from a thread with a thread-default context. For example,
459// see `g_file_supports_thread_contexts()`.
460func (x *MainContext) PushThreadDefault() {
461
462 xMainContextPushThreadDefault(x.GoPointer())
463
464}
465
466var xMainContextPusherNew func(uintptr) *MainContextPusher
467
468// Push @main_context as the new thread-default main context for the current
469// thread, using [method@GLib.MainContext.push_thread_default], and return a
470// new [alias@GLib.MainContextPusher]. Pop with g_main_context_pusher_free().
471// Using [method@GLib.MainContext.pop_thread_default] on @main_context while a
472// [alias@GLib.MainContextPusher] exists for it can lead to undefined behaviour.
473//
474// Using two [alias@GLib.MainContextPusher]s in the same scope is not allowed,
475// as it leads to an undefined pop order.
476//
477// This is intended to be used with g_autoptr(). Note that g_autoptr()
478// is only available when using GCC or clang, so the following example
479// will only work with those compilers:
480// |[
481// typedef struct
482//
483// {
484// ...
485// GMainContext *context;
486// ...
487// } MyObject;
488//
489// static void
490// my_object_do_stuff (MyObject *self)
491//
492// {
493// g_autoptr(GMainContextPusher) pusher = g_main_context_pusher_new (self->context);
494//
495// // Code with main context as the thread default here
496//
497// if (cond)
498// // No need to pop
499// return;
500//
501// // Optionally early pop
502// g_clear_pointer (&pusher, g_main_context_pusher_free);
503//
504// // Code with main context no longer the thread default here
505// }
506//
507// ]|
508func (x *MainContext) PusherNew() *MainContextPusher {
509
510 cret := xMainContextPusherNew(x.GoPointer())
511 return cret
512}
513
514var xMainContextQuery func(uintptr, int, *int, *[]PollFD, int) int
515
516// Determines information necessary to poll this main loop.
517//
518// You should
519// be careful to pass the resulting @fds array and its length @n_fds
520// as-is when calling [method@GLib.MainContext.check], as this function relies
521// on assumptions made when the array is filled.
522//
523// You must have successfully acquired the context with
524// [method@GLib.MainContext.acquire] before you may call this function.
525func (x *MainContext) Query(MaxPriorityVar int, TimeoutVar *int, FdsVar *[]PollFD, NFdsVar int) int {
526
527 cret := xMainContextQuery(x.GoPointer(), MaxPriorityVar, TimeoutVar, FdsVar, NFdsVar)
528 return cret
529}
530
531var xMainContextRef func(uintptr) *MainContext
532
533// Increases the reference count on a [struct@GLib.MainContext] object by one.
534func (x *MainContext) Ref() *MainContext {
535
536 cret := xMainContextRef(x.GoPointer())
537 return cret
538}
539
540var xMainContextRelease func(uintptr)
541
542// Releases ownership of a context previously acquired by this thread
543// with [method@GLib.MainContext.acquire].
544//
545// If the context was acquired multiple
546// times, the ownership will be released only when [method@GLib.MainContext.release]
547// is called as many times as it was acquired.
548//
549// You must have successfully acquired the context with
550// [method@GLib.MainContext.acquire] before you may call this function.
551func (x *MainContext) Release() {
552
553 xMainContextRelease(x.GoPointer())
554
555}
556
557var xMainContextRemovePoll func(uintptr, *PollFD)
558
559// Removes file descriptor from the set of file descriptors to be
560// polled for a particular context.
561func (x *MainContext) RemovePoll(FdVar *PollFD) {
562
563 xMainContextRemovePoll(x.GoPointer(), FdVar)
564
565}
566
567var xMainContextSetPollFunc func(uintptr, uintptr)
568
569// Sets the function to use to handle polling of file descriptors.
570//
571// It will be used instead of the [`poll()`](man:poll(2)) system call
572// (or GLib’s replacement function, which is used where
573// `poll()` isn’t available).
574//
575// This function could possibly be used to integrate the GLib event
576// loop with an external event loop.
577func (x *MainContext) SetPollFunc(FuncVar *PollFunc) {
578
579 var FuncVarRef uintptr
580 if FuncVar != nil {
581 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
582 if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
583 FuncVarRef = cbRefPtr
584 } else {
585 fcb := func(arg0 *PollFD, arg1 uint, arg2 int) int {
586 cbFn := *FuncVar
587 return cbFn(arg0, arg1, arg2)
588 }
589 FuncVarRef = purego.NewCallback(fcb)
590 SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
591 }
592 }
593
594 xMainContextSetPollFunc(x.GoPointer(), FuncVarRef)
595
596}
597
598var xMainContextUnref func(uintptr)
599
600// Decreases the reference count on a [struct@GLib.MainContext] object by one.
601// If
602// the result is zero, free the context and free all associated memory.
603func (x *MainContext) Unref() {
604
605 xMainContextUnref(x.GoPointer())
606
607}
608
609var xMainContextWait func(uintptr, *Cond, *Mutex) bool
610
611// Tries to become the owner of the specified context, and waits on @cond if
612// another thread is the owner.
613//
614// This is the same as [method@GLib.MainContext.acquire], but if another thread
615// is the owner, atomically drop @mutex and wait on @cond until
616// that owner releases ownership or until @cond is signaled, then
617// try again (once) to become the owner.
618func (x *MainContext) Wait(CondVar *Cond, MutexVar *Mutex) bool {
619
620 cret := xMainContextWait(x.GoPointer(), CondVar, MutexVar)
621 return cret
622}
623
624var xMainContextWakeup func(uintptr)
625
626// Wake up @context if it’s currently blocking in
627// [method@GLib.MainContext.iteration], causing it to stop blocking.
628//
629// The @context could be blocking waiting for a source to become ready.
630// Otherwise, if @context is not currently blocking, this function causes the
631// next invocation of [method@GLib.MainContext.iteration] to return without
632// blocking.
633//
634// This API is useful for low-level control over [struct@GLib.MainContext]; for
635// example, integrating it with main loop implementations such as
636// [struct@GLib.MainLoop].
637//
638// Another related use for this function is when implementing a main
639// loop with a termination condition, computed from multiple threads:
640//
641// ```c
642//
643// #define NUM_TASKS 10
644// static gint tasks_remaining = NUM_TASKS; // (atomic)
645// ...
646//
647// while (g_atomic_int_get (&tasks_remaining) != 0)
648// g_main_context_iteration (NULL, TRUE);
649//
650// ```
651//
652// Then in a thread:
653// ```c
654//
655// perform_work ();
656//
657// if (g_atomic_int_dec_and_test (&tasks_remaining))
658// g_main_context_wakeup (NULL);
659//
660// ```
661func (x *MainContext) Wakeup() {
662
663 xMainContextWakeup(x.GoPointer())
664
665}
666
667// The `GMainLoop` struct is an opaque data type
668// representing the main event loop of a GLib or GTK application.
669type MainLoop struct {
670 _ structs.HostLayout
671}
672
673var xMainLoopGLibType func() types.GType
674
675func MainLoopGLibType() types.GType {
676 return xMainLoopGLibType()
677}
678
679func (x *MainLoop) GoPointer() uintptr {
680 return uintptr(unsafe.Pointer(x))
681}
682
683var xNewMainLoop func(*MainContext, bool) *MainLoop
684
685// Creates a new [struct@GLib.MainLoop] structure.
686func NewMainLoop(ContextVar *MainContext, IsRunningVar bool) *MainLoop {
687
688 cret := xNewMainLoop(ContextVar, IsRunningVar)
689 return cret
690}
691
692var xMainLoopGetContext func(uintptr) *MainContext
693
694// Returns the [struct@GLib.MainContext] of @loop.
695func (x *MainLoop) GetContext() *MainContext {
696
697 cret := xMainLoopGetContext(x.GoPointer())
698 return cret
699}
700
701var xMainLoopIsRunning func(uintptr) bool
702
703// Checks to see if the main loop is currently being run via
704// [method@GLib.MainLoop.run].
705func (x *MainLoop) IsRunning() bool {
706
707 cret := xMainLoopIsRunning(x.GoPointer())
708 return cret
709}
710
711var xMainLoopQuit func(uintptr)
712
713// Stops a [struct@GLib.MainLoop] from running. Any calls to
714// [method@GLib.MainLoop.run] for the loop will return.
715//
716// Note that sources that have already been dispatched when
717// [method@GLib.MainLoop.quit] is called will still be executed.
718func (x *MainLoop) Quit() {
719
720 xMainLoopQuit(x.GoPointer())
721
722}
723
724var xMainLoopRef func(uintptr) *MainLoop
725
726// Increases the reference count on a [struct@GLib.MainLoop] object by one.
727func (x *MainLoop) Ref() *MainLoop {
728
729 cret := xMainLoopRef(x.GoPointer())
730 return cret
731}
732
733var xMainLoopRun func(uintptr)
734
735// Runs a main loop until [method@GLib.MainLoop.quit] is called on the loop.
736//
737// If this is called from the thread of the loop’s [struct@GLib.MainContext],
738// it will process events from the loop, otherwise it will
739// simply wait.
740func (x *MainLoop) Run() {
741
742 xMainLoopRun(x.GoPointer())
743
744}
745
746var xMainLoopUnref func(uintptr)
747
748// Decreases the reference count on a [struct@GLib.MainLoop] object by one.
749//
750// If the result is zero, the loop and all associated memory are freed.
751func (x *MainLoop) Unref() {
752
753 xMainLoopUnref(x.GoPointer())
754
755}
756
757// The `GSource` struct is an opaque data type
758// representing an event source.
759type Source struct {
760 _ structs.HostLayout
761
762 CallbackData uintptr
763
764 CallbackFuncs *SourceCallbackFuncs
765
766 SourceFuncs *SourceFuncs
767
768 RefCount uint
769
770 Context *MainContext
771
772 Priority int32
773
774 Flags uint
775
776 SourceId uint
777
778 PollFds *SList
779
780 Prev *Source
781
782 Next *Source
783
784 Name uintptr
785
786 Priv *SourcePrivate
787}
788
789var xSourceGLibType func() types.GType
790
791func SourceGLibType() types.GType {
792 return xSourceGLibType()
793}
794
795func (x *Source) GoPointer() uintptr {
796 return uintptr(unsafe.Pointer(x))
797}
798
799var xNewSource func(*SourceFuncs, uint) *Source
800
801// Creates a new [struct@GLib.Source] structure.
802//
803// The size is specified to
804// allow creating structures derived from [struct@GLib.Source] that contain
805// additional data. The size passed in must be at least
806// `sizeof (GSource)`.
807//
808// The source will not initially be associated with any [struct@GLib.MainContext]
809// and must be added to one with [method@GLib.Source.attach] before it will be
810// executed.
811func NewSource(SourceFuncsVar *SourceFuncs, StructSizeVar uint) *Source {
812
813 cret := xNewSource(SourceFuncsVar, StructSizeVar)
814 return cret
815}
816
817var xSourceAddChildSource func(uintptr, *Source)
818
819// Adds @child_source to @source as a ‘polled’ source.
820//
821// When @source is added to a [struct@GLib.MainContext], @child_source will be
822// automatically added with the same priority. When @child_source is triggered,
823// it will cause @source to dispatch (in addition to calling its own callback),
824// and when @source is destroyed, it will destroy @child_source as well.
825//
826// The @source will also still be dispatched if its own prepare/check functions
827// indicate that it is ready.
828//
829// If you don’t need @child_source to do anything on its own when it
830// triggers, you can call `g_source_set_dummy_callback()` on it to set a
831// callback that does nothing (except return true if appropriate).
832//
833// The @source will hold a reference on @child_source while @child_source
834// is attached to it.
835//
836// This API is only intended to be used by implementations of [struct@GLib.Source].
837// Do not call this API on a [struct@GLib.Source] that you did not create.
838func (x *Source) AddChildSource(ChildSourceVar *Source) {
839
840 xSourceAddChildSource(x.GoPointer(), ChildSourceVar)
841
842}
843
844var xSourceAddPoll func(uintptr, *PollFD)
845
846// Adds a file descriptor to the set of file descriptors polled for
847// this source.
848//
849// This is usually combined with [ctor@GLib.Source.new] to add an
850// event source. The event source’s check function will typically test
851// the @revents field in the [struct@GLib.PollFD] struct and return true if
852// events need to be processed.
853//
854// This API is only intended to be used by implementations of [struct@GLib.Source].
855// Do not call this API on a [struct@GLib.Source] that you did not create.
856//
857// Using this API forces the linear scanning of event sources on each
858// main loop iteration. Newly-written event sources should try to use
859// `g_source_add_unix_fd()` instead of this API.
860func (x *Source) AddPoll(FdVar *PollFD) {
861
862 xSourceAddPoll(x.GoPointer(), FdVar)
863
864}
865
866var xSourceAddUnixFd func(uintptr, int, IOCondition) uintptr
867
868// Monitors @fd for the IO events in @events.
869//
870// The tag returned by this function can be used to remove or modify the
871// monitoring of the @fd using [method@GLib.Source.remove_unix_fd] or
872// [method@GLib.Source.modify_unix_fd].
873//
874// It is not necessary to remove the file descriptor before destroying the
875// source; it will be cleaned up automatically.
876//
877// This API is only intended to be used by implementations of [struct@GLib.Source].
878// Do not call this API on a [struct@GLib.Source] that you did not create.
879//
880// As the name suggests, this function is not available on Windows.
881func (x *Source) AddUnixFd(FdVar int, EventsVar IOCondition) uintptr {
882
883 cret := xSourceAddUnixFd(x.GoPointer(), FdVar, EventsVar)
884 return cret
885}
886
887var xSourceAttach func(uintptr, *MainContext) uint
888
889// Adds a [struct@GLib.Source] to a @context so that it will be executed within
890// that context.
891//
892// Remove it by calling [method@GLib.Source.destroy].
893//
894// This function is safe to call from any thread, regardless of which thread
895// the @context is running in.
896func (x *Source) Attach(ContextVar *MainContext) uint {
897
898 cret := xSourceAttach(x.GoPointer(), ContextVar)
899 return cret
900}
901
902var xSourceDestroy func(uintptr)
903
904// Removes a source from its [struct@GLib.MainContext], if any, and marks it as
905// destroyed.
906//
907// The source cannot be subsequently added to another
908// context. It is safe to call this on sources which have already been
909// removed from their context.
910//
911// This does not unref the [struct@GLib.Source]: if you still hold a reference,
912// use [method@GLib.Source.unref] to drop it.
913//
914// This function is safe to call from any thread, regardless of which thread
915// the [struct@GLib.MainContext] is running in.
916//
917// If the source is currently attached to a [struct@GLib.MainContext],
918// destroying it will effectively unset the callback similar to calling
919// [method@GLib.Source.set_callback]. This can mean, that the data’s
920// [callback@GLib.DestroyNotify] gets called right away.
921func (x *Source) Destroy() {
922
923 xSourceDestroy(x.GoPointer())
924
925}
926
927var xSourceDupContext func(uintptr) *MainContext
928
929// Gets a reference to the [struct@GLib.MainContext] with which the source is
930// associated.
931//
932// You can call this on a source that has been destroyed. You can
933// always call this function on the source returned from
934// [func@GLib.main_current_source].
935func (x *Source) DupContext() *MainContext {
936
937 cret := xSourceDupContext(x.GoPointer())
938 return cret
939}
940
941var xSourceGetCanRecurse func(uintptr) bool
942
943// Checks whether a source is allowed to be called recursively.
944//
945// See [method@GLib.Source.set_can_recurse].
946func (x *Source) GetCanRecurse() bool {
947
948 cret := xSourceGetCanRecurse(x.GoPointer())
949 return cret
950}
951
952var xSourceGetContext func(uintptr) *MainContext
953
954// Gets the [struct@GLib.MainContext] with which the source is associated.
955//
956// You can call this on a source that has been destroyed, provided
957// that the [struct@GLib.MainContext] it was attached to still exists (in which
958// case it will return that [struct@GLib.MainContext]). In particular, you can
959// always call this function on the source returned from
960// [func@GLib.main_current_source]. But calling this function on a source
961// whose [struct@GLib.MainContext] has been destroyed is an error.
962//
963// If the associated [struct@GLib.MainContext] could be destroy concurrently from
964// a different thread, then this function is not safe to call and
965// [method@GLib.Source.dup_context] should be used instead.
966func (x *Source) GetContext() *MainContext {
967
968 cret := xSourceGetContext(x.GoPointer())
969 return cret
970}
971
972var xSourceGetCurrentTime func(uintptr, *TimeVal)
973
974// This function ignores @source and is otherwise the same as
975// [func@GLib.get_current_time].
976func (x *Source) GetCurrentTime(TimevalVar *TimeVal) {
977
978 xSourceGetCurrentTime(x.GoPointer(), TimevalVar)
979
980}
981
982var xSourceGetId func(uintptr) uint
983
984// Returns the numeric ID for a particular source.
985//
986// The ID of a source
987// is a positive integer which is unique within a particular main loop
988// context. The reverse mapping from ID to source is done by
989// [method@GLib.MainContext.find_source_by_id].
990//
991// You can only call this function while the source is associated to a
992// [struct@GLib.MainContext] instance; calling this function before
993// [method@GLib.Source.attach] or after [method@GLib.Source.destroy] yields
994// undefined behavior. The ID returned is unique within the
995// [struct@GLib.MainContext] instance passed to [method@GLib.Source.attach].
996func (x *Source) GetId() uint {
997
998 cret := xSourceGetId(x.GoPointer())
999 return cret
1000}
1001
1002var xSourceGetName func(uintptr) string
1003
1004// Gets a name for the source, used in debugging and profiling.
1005//
1006// The
1007// name may be `NULL` if it has never been set with [method@GLib.Source.set_name].
1008func (x *Source) GetName() string {
1009
1010 cret := xSourceGetName(x.GoPointer())
1011 return cret
1012}
1013
1014var xSourceGetPriority func(uintptr) int
1015
1016// Gets the priority of a source.
1017func (x *Source) GetPriority() int {
1018
1019 cret := xSourceGetPriority(x.GoPointer())
1020 return cret
1021}
1022
1023var xSourceGetReadyTime func(uintptr) int64
1024
1025// Gets the ‘ready time’ of @source, as set by
1026// [method@GLib.Source.set_ready_time].
1027//
1028// Any time before or equal to the current monotonic time (including zero)
1029// is an indication that the source will fire immediately.
1030func (x *Source) GetReadyTime() int64 {
1031
1032 cret := xSourceGetReadyTime(x.GoPointer())
1033 return cret
1034}
1035
1036var xSourceGetTime func(uintptr) int64
1037
1038// Gets the time to be used when checking this source.
1039//
1040// The advantage of
1041// calling this function over calling [func@GLib.get_monotonic_time] directly is
1042// that when checking multiple sources, GLib can cache a single value
1043// instead of having to repeatedly get the system monotonic time.
1044//
1045// The time here is the system monotonic time, if available, or some
1046// other reasonable alternative otherwise. See [func@GLib.get_monotonic_time].
1047func (x *Source) GetTime() int64 {
1048
1049 cret := xSourceGetTime(x.GoPointer())
1050 return cret
1051}
1052
1053var xSourceIsDestroyed func(uintptr) bool
1054
1055// Returns whether @source has been destroyed.
1056//
1057// This is important when you operate upon your objects
1058// from within idle handlers, but may have freed the object
1059// before the dispatch of your idle handler.
1060//
1061// ```c
1062// static gboolean
1063// idle_callback (gpointer data)
1064//
1065// {
1066// SomeWidget *self = data;
1067//
1068// g_mutex_lock (&self->idle_id_mutex);
1069// // do stuff with self
1070// self->idle_id = 0;
1071// g_mutex_unlock (&self->idle_id_mutex);
1072//
1073// return G_SOURCE_REMOVE;
1074// }
1075//
1076// static void
1077// some_widget_do_stuff_later (SomeWidget *self)
1078//
1079// {
1080// g_mutex_lock (&self->idle_id_mutex);
1081// self->idle_id = g_idle_add (idle_callback, self);
1082// g_mutex_unlock (&self->idle_id_mutex);
1083// }
1084//
1085// static void
1086// some_widget_init (SomeWidget *self)
1087//
1088// {
1089// g_mutex_init (&self->idle_id_mutex);
1090//
1091// // ...
1092// }
1093//
1094// static void
1095// some_widget_finalize (GObject *object)
1096//
1097// {
1098// SomeWidget *self = SOME_WIDGET (object);
1099//
1100// if (self->idle_id)
1101// g_source_remove (self->idle_id);
1102//
1103// g_mutex_clear (&self->idle_id_mutex);
1104//
1105// G_OBJECT_CLASS (parent_class)->finalize (object);
1106// }
1107//
1108// ```
1109//
1110// This will fail in a multi-threaded application if the
1111// widget is destroyed before the idle handler fires due
1112// to the use after free in the callback. A solution, to
1113// this particular problem, is to check to if the source
1114// has already been destroy within the callback.
1115//
1116// ```c
1117// static gboolean
1118// idle_callback (gpointer data)
1119//
1120// {
1121// SomeWidget *self = data;
1122//
1123// g_mutex_lock (&self->idle_id_mutex);
1124// if (!g_source_is_destroyed (g_main_current_source ()))
1125// {
1126// // do stuff with self
1127// }
1128// g_mutex_unlock (&self->idle_id_mutex);
1129//
1130// return FALSE;
1131// }
1132//
1133// ```
1134//
1135// Calls to this function from a thread other than the one acquired by the
1136// [struct@GLib.MainContext] the [struct@GLib.Source] is attached to are typically
1137// redundant, as the source could be destroyed immediately after this function
1138// returns. However, once a source is destroyed it cannot be un-destroyed, so
1139// this function can be used for opportunistic checks from any thread.
1140func (x *Source) IsDestroyed() bool {
1141
1142 cret := xSourceIsDestroyed(x.GoPointer())
1143 return cret
1144}
1145
1146var xSourceModifyUnixFd func(uintptr, uintptr, IOCondition)
1147
1148// Updates the event mask to watch for the file descriptor identified by @tag.
1149//
1150// The @tag is the tag returned from [method@GLib.Source.add_unix_fd].
1151//
1152// If you want to remove a file descriptor, don’t set its event mask to zero.
1153// Instead, call [method@GLib.Source.remove_unix_fd].
1154//
1155// This API is only intended to be used by implementations of [struct@GLib.Source].
1156// Do not call this API on a [struct@GLib.Source] that you did not create.
1157//
1158// As the name suggests, this function is not available on Windows.
1159func (x *Source) ModifyUnixFd(TagVar uintptr, NewEventsVar IOCondition) {
1160
1161 xSourceModifyUnixFd(x.GoPointer(), TagVar, NewEventsVar)
1162
1163}
1164
1165var xSourceQueryUnixFd func(uintptr, uintptr) IOCondition
1166
1167// Queries the events reported for the file descriptor corresponding to @tag
1168// on @source during the last poll.
1169//
1170// The return value of this function is only defined when the function
1171// is called from the check or dispatch functions for @source.
1172//
1173// This API is only intended to be used by implementations of [struct@GLib.Source].
1174// Do not call this API on a [struct@GLib.Source] that you did not create.
1175//
1176// As the name suggests, this function is not available on Windows.
1177func (x *Source) QueryUnixFd(TagVar uintptr) IOCondition {
1178
1179 cret := xSourceQueryUnixFd(x.GoPointer(), TagVar)
1180 return cret
1181}
1182
1183var xSourceRef func(uintptr) *Source
1184
1185// Increases the reference count on a source by one.
1186func (x *Source) Ref() *Source {
1187
1188 cret := xSourceRef(x.GoPointer())
1189 return cret
1190}
1191
1192var xSourceRemoveChildSource func(uintptr, *Source)
1193
1194// Detaches @child_source from @source and destroys it.
1195//
1196// This API is only intended to be used by implementations of [struct@GLib.Source].
1197// Do not call this API on a [struct@GLib.Source] that you did not create.
1198func (x *Source) RemoveChildSource(ChildSourceVar *Source) {
1199
1200 xSourceRemoveChildSource(x.GoPointer(), ChildSourceVar)
1201
1202}
1203
1204var xSourceRemovePoll func(uintptr, *PollFD)
1205
1206// Removes a file descriptor from the set of file descriptors polled for
1207// this source.
1208//
1209// This API is only intended to be used by implementations of [struct@GLib.Source].
1210// Do not call this API on a [struct@GLib.Source] that you did not create.
1211func (x *Source) RemovePoll(FdVar *PollFD) {
1212
1213 xSourceRemovePoll(x.GoPointer(), FdVar)
1214
1215}
1216
1217var xSourceRemoveUnixFd func(uintptr, uintptr)
1218
1219// Reverses the effect of a previous call to [method@GLib.Source.add_unix_fd].
1220//
1221// You only need to call this if you want to remove a file descriptor from being
1222// watched while keeping the same source around. In the normal case you
1223// will just want to destroy the source.
1224//
1225// This API is only intended to be used by implementations of [struct@GLib.Source].
1226// Do not call this API on a [struct@GLib.Source] that you did not create.
1227//
1228// As the name suggests, this function is not available on Windows.
1229func (x *Source) RemoveUnixFd(TagVar uintptr) {
1230
1231 xSourceRemoveUnixFd(x.GoPointer(), TagVar)
1232
1233}
1234
1235var xSourceSetCallback func(uintptr, uintptr, uintptr, uintptr)
1236
1237// Sets the callback function for a source. The callback for a source is
1238// called from the source’s dispatch function.
1239//
1240// The exact type of @func depends on the type of source; ie. you
1241// should not count on @func being called with @data as its first
1242// parameter. Cast @func with [func@GLib.SOURCE_FUNC] to avoid warnings about
1243// incompatible function types.
1244//
1245// See [main loop memory management](main-loop.html#memory-management-of-sources) for details
1246// on how to handle memory management of @data.
1247//
1248// Typically, you won’t use this function. Instead use functions specific
1249// to the type of source you are using, such as [func@GLib.idle_add] or
1250// [func@GLib.timeout_add].
1251//
1252// It is safe to call this function multiple times on a source which has already
1253// been attached to a context. The changes will take effect for the next time
1254// the source is dispatched after this call returns.
1255//
1256// Note that [method@GLib.Source.destroy] for a currently attached source has the effect
1257// of also unsetting the callback.
1258func (x *Source) SetCallback(FuncVar *SourceFunc, DataVar uintptr, NotifyVar *DestroyNotify) {
1259
1260 var FuncVarRef uintptr
1261 if FuncVar != nil {
1262 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
1263 if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
1264 FuncVarRef = cbRefPtr
1265 } else {
1266 fcb := func(arg0 uintptr) bool {
1267 cbFn := *FuncVar
1268 return cbFn(arg0)
1269 }
1270 FuncVarRef = purego.NewCallback(fcb)
1271 SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
1272 }
1273 }
1274
1275 var NotifyVarRef uintptr
1276 if NotifyVar != nil {
1277 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
1278 if cbRefPtr, ok := GetCallback(NotifyVarPtr); ok {
1279 NotifyVarRef = cbRefPtr
1280 } else {
1281 fcb := func(arg0 uintptr) {
1282 cbFn := *NotifyVar
1283 cbFn(arg0)
1284 }
1285 NotifyVarRef = purego.NewCallback(fcb)
1286 SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
1287 }
1288 }
1289
1290 xSourceSetCallback(x.GoPointer(), FuncVarRef, DataVar, NotifyVarRef)
1291
1292}
1293
1294var xSourceSetCallbackIndirect func(uintptr, uintptr, *SourceCallbackFuncs)
1295
1296// Sets the callback function storing the data as a reference counted callback
1297// ‘object’.
1298//
1299// This is used internally. Note that calling
1300// [method@GLib.Source.set_callback_indirect] assumes
1301// an initial reference count on @callback_data, and thus
1302// `callback_funcs->unref` will eventually be called once more than
1303// `callback_funcs->ref`.
1304//
1305// It is safe to call this function multiple times on a source which has already
1306// been attached to a context. The changes will take effect for the next time
1307// the source is dispatched after this call returns.
1308func (x *Source) SetCallbackIndirect(CallbackDataVar uintptr, CallbackFuncsVar *SourceCallbackFuncs) {
1309
1310 xSourceSetCallbackIndirect(x.GoPointer(), CallbackDataVar, CallbackFuncsVar)
1311
1312}
1313
1314var xSourceSetCanRecurse func(uintptr, bool)
1315
1316// Sets whether a source can be called recursively.
1317//
1318// If @can_recurse is true, then while the source is being dispatched then this
1319// source will be processed normally. Otherwise, all processing of this
1320// source is blocked until the dispatch function returns.
1321func (x *Source) SetCanRecurse(CanRecurseVar bool) {
1322
1323 xSourceSetCanRecurse(x.GoPointer(), CanRecurseVar)
1324
1325}
1326
1327var xSourceSetDisposeFunction func(uintptr, uintptr)
1328
1329// Set @dispose as dispose function on @source.
1330//
1331// The @dispose function will be called once the reference count of @source
1332// reaches zero but before any of the state of the source is freed, especially
1333// before the finalize function (set as part of the [type@GLib.SourceFuncs]) is
1334// called.
1335//
1336// This means that at this point @source is still a valid [struct@GLib.Source]
1337// and it is allow for the reference count to increase again until @dispose
1338// returns.
1339//
1340// The dispose function can be used to clear any ‘weak’ references to
1341// the @source in other data structures in a thread-safe way where it is
1342// possible for another thread to increase the reference count of @source again
1343// while it is being freed.
1344//
1345// The finalize function can not be used for this purpose as at that
1346// point @source is already partially freed and not valid any more.
1347//
1348// This should only ever be called from [struct@GLib.Source] implementations.
1349func (x *Source) SetDisposeFunction(DisposeVar *SourceDisposeFunc) {
1350
1351 var DisposeVarRef uintptr
1352 if DisposeVar != nil {
1353 DisposeVarPtr := uintptr(unsafe.Pointer(DisposeVar))
1354 if cbRefPtr, ok := GetCallback(DisposeVarPtr); ok {
1355 DisposeVarRef = cbRefPtr
1356 } else {
1357 fcb := func(arg0 *Source) {
1358 cbFn := *DisposeVar
1359 cbFn(arg0)
1360 }
1361 DisposeVarRef = purego.NewCallback(fcb)
1362 SaveCallbackWithClosure(DisposeVarPtr, DisposeVarRef, DisposeVar)
1363 }
1364 }
1365
1366 xSourceSetDisposeFunction(x.GoPointer(), DisposeVarRef)
1367
1368}
1369
1370var xSourceSetFuncs func(uintptr, *SourceFuncs)
1371
1372// Sets the source functions of an unattached source.
1373//
1374// These can be used to override the default implementations for the type
1375// of @source.
1376func (x *Source) SetFuncs(FuncsVar *SourceFuncs) {
1377
1378 xSourceSetFuncs(x.GoPointer(), FuncsVar)
1379
1380}
1381
1382var xSourceSetName func(uintptr, string)
1383
1384// Sets a name for the source, used in debugging and profiling.
1385//
1386// The name defaults to `NULL`.
1387//
1388// The source name should describe in a human-readable way
1389// what the source does. For example, ‘X11 event queue’
1390// or ‘GTK repaint idle handler’.
1391//
1392// It is permitted to call this function multiple times, but is not
1393// recommended due to the potential performance impact. For example,
1394// one could change the name in the `check` function of a
1395// [struct@GLib.SourceFuncs] to include details like the event type in the
1396// source name.
1397//
1398// Use caution if changing the name while another thread may be
1399// accessing it with [method@GLib.Source.get_name]; that function does not copy
1400// the value, and changing the value will free it while the other thread
1401// may be attempting to use it.
1402//
1403// Also see [method@GLib.Source.set_static_name].
1404func (x *Source) SetName(NameVar string) {
1405
1406 xSourceSetName(x.GoPointer(), NameVar)
1407
1408}
1409
1410var xSourceSetPriority func(uintptr, int)
1411
1412// Sets the priority of a source.
1413//
1414// While the main loop is being run, a
1415// source will be dispatched if it is ready to be dispatched and no
1416// sources at a higher (numerically smaller) priority are ready to be
1417// dispatched.
1418//
1419// A child source always has the same priority as its parent. It is not
1420// permitted to change the priority of a source once it has been added
1421// as a child of another source.
1422func (x *Source) SetPriority(PriorityVar int) {
1423
1424 xSourceSetPriority(x.GoPointer(), PriorityVar)
1425
1426}
1427
1428var xSourceSetReadyTime func(uintptr, int64)
1429
1430// Sets a source to be dispatched when the given monotonic time is
1431// reached (or passed).
1432//
1433// If the monotonic time is in the past (as it
1434// always will be if @ready_time is `0`) then the source will be
1435// dispatched immediately.
1436//
1437// If @ready_time is `-1` then the source is never woken up on the basis
1438// of the passage of time.
1439//
1440// Dispatching the source does not reset the ready time. You should do
1441// so yourself, from the source dispatch function.
1442//
1443// Note that if you have a pair of sources where the ready time of one
1444// suggests that it will be delivered first but the priority for the
1445// other suggests that it would be delivered first, and the ready time
1446// for both sources is reached during the same main context iteration,
1447// then the order of dispatch is undefined.
1448//
1449// It is a no-op to call this function on a [struct@GLib.Source] which has
1450// already been destroyed with [method@GLib.Source.destroy].
1451//
1452// This API is only intended to be used by implementations of [struct@GLib.Source].
1453// Do not call this API on a [struct@GLib.Source] that you did not create.
1454func (x *Source) SetReadyTime(ReadyTimeVar int64) {
1455
1456 xSourceSetReadyTime(x.GoPointer(), ReadyTimeVar)
1457
1458}
1459
1460var xSourceSetStaticName func(uintptr, string)
1461
1462// A variant of [method@GLib.Source.set_name] that does not
1463// duplicate the @name, and can only be used with
1464// string literals.
1465func (x *Source) SetStaticName(NameVar string) {
1466
1467 xSourceSetStaticName(x.GoPointer(), NameVar)
1468
1469}
1470
1471var xSourceUnref func(uintptr)
1472
1473// Decreases the reference count of a source by one.
1474//
1475// If the resulting reference count is zero the source and associated
1476// memory will be destroyed.
1477func (x *Source) Unref() {
1478
1479 xSourceUnref(x.GoPointer())
1480
1481}
1482
1483// The `GSourceCallbackFuncs` struct contains
1484// functions for managing callback objects.
1485type SourceCallbackFuncs struct {
1486 _ structs.HostLayout
1487
1488 xRef uintptr
1489
1490 xUnref uintptr
1491
1492 xGet uintptr
1493}
1494
1495func (x *SourceCallbackFuncs) GoPointer() uintptr {
1496 return uintptr(unsafe.Pointer(x))
1497}
1498
1499// OverrideRef sets the "ref" callback function.
1500// Called when a reference is added to the callback object
1501func (x *SourceCallbackFuncs) OverrideRef(cb func(uintptr)) {
1502 if cb == nil {
1503 x.xRef = 0
1504 } else {
1505 x.xRef = purego.NewCallback(func(CbDataVarp uintptr) {
1506 cb(CbDataVarp)
1507 })
1508 }
1509}
1510
1511// GetRef gets the "ref" callback function.
1512// Called when a reference is added to the callback object
1513func (x *SourceCallbackFuncs) GetRef() func(uintptr) {
1514 if x.xRef == 0 {
1515 return nil
1516 }
1517 var rawCallback func(CbDataVarp uintptr)
1518 purego.RegisterFunc(&rawCallback, x.xRef)
1519 return func(CbDataVar uintptr) {
1520 rawCallback(CbDataVar)
1521 }
1522}
1523
1524// OverrideUnref sets the "unref" callback function.
1525// Called when a reference to the callback object is dropped
1526func (x *SourceCallbackFuncs) OverrideUnref(cb func(uintptr)) {
1527 if cb == nil {
1528 x.xUnref = 0
1529 } else {
1530 x.xUnref = purego.NewCallback(func(CbDataVarp uintptr) {
1531 cb(CbDataVarp)
1532 })
1533 }
1534}
1535
1536// GetUnref gets the "unref" callback function.
1537// Called when a reference to the callback object is dropped
1538func (x *SourceCallbackFuncs) GetUnref() func(uintptr) {
1539 if x.xUnref == 0 {
1540 return nil
1541 }
1542 var rawCallback func(CbDataVarp uintptr)
1543 purego.RegisterFunc(&rawCallback, x.xUnref)
1544 return func(CbDataVar uintptr) {
1545 rawCallback(CbDataVar)
1546 }
1547}
1548
1549// OverrideGet sets the "get" callback function.
1550// Called to extract the callback function and data from the
1551//
1552// callback object.
1553func (x *SourceCallbackFuncs) OverrideGet(cb func(uintptr, *Source, *SourceFunc, uintptr)) {
1554 if cb == nil {
1555 x.xGet = 0
1556 } else {
1557 x.xGet = purego.NewCallback(func(CbDataVarp uintptr, SourceVarp *Source, FuncVarp uintptr, DataVarp uintptr) {
1558 cb(CbDataVarp, SourceVarp, (*SourceFunc)(unsafe.Pointer(FuncVarp)), DataVarp)
1559 })
1560 }
1561}
1562
1563// GetGet gets the "get" callback function.
1564// Called to extract the callback function and data from the
1565//
1566// callback object.
1567func (x *SourceCallbackFuncs) GetGet() func(uintptr, *Source, *SourceFunc, uintptr) {
1568 if x.xGet == 0 {
1569 return nil
1570 }
1571 var rawCallback func(CbDataVarp uintptr, SourceVarp *Source, FuncVarp uintptr, DataVarp uintptr)
1572 purego.RegisterFunc(&rawCallback, x.xGet)
1573 return func(CbDataVar uintptr, SourceVar *Source, FuncVar *SourceFunc, DataVar uintptr) {
1574 rawCallback(CbDataVar, SourceVar, NewCallback(FuncVar), DataVar)
1575 }
1576}
1577
1578// The `GSourceFuncs` struct contains a table of
1579// functions used to handle event sources in a generic manner.
1580//
1581// For idle sources, the prepare and check functions always return %TRUE
1582// to indicate that the source is always ready to be processed. The prepare
1583// function also returns a timeout value of 0 to ensure that the poll() call
1584// doesn't block (since that would be time wasted which could have been spent
1585// running the idle function).
1586//
1587// For timeout sources, the prepare and check functions both return %TRUE
1588// if the timeout interval has expired. The prepare function also returns
1589// a timeout value to ensure that the poll() call doesn't block too long
1590// and miss the next timeout.
1591//
1592// For file descriptor sources, the prepare function typically returns %FALSE,
1593// since it must wait until poll() has been called before it knows whether
1594// any events need to be processed. It sets the returned timeout to -1 to
1595// indicate that it doesn't mind how long the poll() call blocks. In the
1596// check function, it tests the results of the poll() call to see if the
1597// required condition has been met, and returns %TRUE if so.
1598type SourceFuncs struct {
1599 _ structs.HostLayout
1600
1601 Prepare SourceFuncsPrepareFunc
1602
1603 Check SourceFuncsCheckFunc
1604
1605 Dispatch SourceFuncsDispatchFunc
1606
1607 Finalize SourceFuncsFinalizeFunc
1608
1609 ClosureCallback SourceFunc
1610
1611 ClosureMarshal SourceDummyMarshal
1612}
1613
1614func (x *SourceFuncs) GoPointer() uintptr {
1615 return uintptr(unsafe.Pointer(x))
1616}
1617
1618type SourcePrivate struct {
1619 _ structs.HostLayout
1620}
1621
1622func (x *SourcePrivate) GoPointer() uintptr {
1623 return uintptr(unsafe.Pointer(x))
1624}
1625
1626// Opaque type. See g_main_context_pusher_new() for details.
1627type MainContextPusher = uintptr
1628
1629const (
1630 // Use this for default priority event sources.
1631 //
1632 // In GLib this priority is used when adding timeout functions
1633 // with [func@GLib.timeout_add]. In GDK this priority is used for events
1634 // from the X server.
1635 PRIORITY_DEFAULT int = 0
1636 // Use this for default priority idle functions.
1637 //
1638 // In GLib this priority is used when adding idle functions with
1639 // [func@GLib.idle_add].
1640 PRIORITY_DEFAULT_IDLE int = 200
1641 // Use this for high priority event sources.
1642 //
1643 // It is not used within GLib or GTK.
1644 PRIORITY_HIGH int = -100
1645 // Use this for high priority idle functions.
1646 //
1647 // GTK uses %G_PRIORITY_HIGH_IDLE + 10 for resizing operations,
1648 // and %G_PRIORITY_HIGH_IDLE + 20 for redrawing operations. (This is
1649 // done to ensure that any pending resizes are processed before any
1650 // pending redraws, so that widgets are not redrawn twice unnecessarily.)
1651 PRIORITY_HIGH_IDLE int = 100
1652 // Use this for very low priority background tasks.
1653 //
1654 // It is not used within GLib or GTK.
1655 PRIORITY_LOW int = 300
1656 // Use this macro as the return value of a [callback@GLib.SourceFunc] to leave
1657 // the [struct@GLib.Source] in the main loop.
1658 SOURCE_CONTINUE bool = true
1659 // Use this macro as the return value of a [callback@GLib.SourceFunc] to remove
1660 // the [struct@GLib.Source] from the main loop.
1661 SOURCE_REMOVE bool = false
1662)
1663
1664// Flags to pass to [ctor@GLib.MainContext.new_with_flags] which affect the
1665// behaviour of a [struct@GLib.MainContext].
1666type MainContextFlags int
1667
1668const (
1669
1670 // Default behaviour.
1671 GMainContextFlagsNoneValue MainContextFlags = 0
1672 // Assume that polling for events will
1673 // free the thread to process other jobs. That's useful if you're using
1674 // `g_main_context_{prepare,query,check,dispatch}` to integrate GMainContext in
1675 // other event loops.
1676 GMainContextFlagsOwnerlessPollingValue MainContextFlags = 1
1677)
1678
1679var xChildWatchAdd func(Pid, uintptr, uintptr) uint
1680
1681// Sets a function to be called when the child indicated by @pid
1682// exits, at a default priority, [const@GLib.PRIORITY_DEFAULT].
1683//
1684// If you obtain @pid from [func@GLib.spawn_async] or
1685// [func@GLib.spawn_async_with_pipes] you will need to pass
1686// [flags@GLib.SpawnFlags.DO_NOT_REAP_CHILD] as a flag to the spawn function for
1687// the child watching to work.
1688//
1689// Note that on platforms where [type@GLib.Pid] must be explicitly closed
1690// (see [func@GLib.spawn_close_pid]) @pid must not be closed while the
1691// source is still active. Typically, you will want to call
1692// [func@GLib.spawn_close_pid] in the callback function for the source.
1693//
1694// GLib supports only a single callback per process ID.
1695// On POSIX platforms, the same restrictions mentioned for
1696// [func@GLib.child_watch_source_new] apply to this function.
1697//
1698// This internally creates a main loop source using
1699// [func@GLib.child_watch_source_new] and attaches it to the main loop context
1700// using [method@GLib.Source.attach]. You can do these steps manually if you
1701// need greater control.
1702func ChildWatchAdd(PidVar Pid, FunctionVar *ChildWatchFunc, DataVar uintptr) uint {
1703
1704 var FunctionVarRef uintptr
1705 if FunctionVar != nil {
1706 FunctionVarPtr := uintptr(unsafe.Pointer(FunctionVar))
1707 if cbRefPtr, ok := GetCallback(FunctionVarPtr); ok {
1708 FunctionVarRef = cbRefPtr
1709 } else {
1710 fcb := func(arg0 Pid, arg1 int, arg2 uintptr) {
1711 cbFn := *FunctionVar
1712 cbFn(arg0, arg1, arg2)
1713 }
1714 FunctionVarRef = purego.NewCallback(fcb)
1715 SaveCallbackWithClosure(FunctionVarPtr, FunctionVarRef, FunctionVar)
1716 }
1717 }
1718
1719 cret := xChildWatchAdd(PidVar, FunctionVarRef, DataVar)
1720
1721 return cret
1722}
1723
1724var xChildWatchAddFull func(int, Pid, uintptr, uintptr, uintptr) uint
1725
1726// Sets a function to be called when the child indicated by @pid
1727// exits, at the priority @priority.
1728//
1729// If you obtain @pid from [func@GLib.spawn_async] or
1730// [func@GLib.spawn_async_with_pipes] you will need to pass
1731// [flags@GLib.SpawnFlags.DO_NOT_REAP_CHILD] as a flag to the spawn function for
1732// the child watching to work.
1733//
1734// In many programs, you will want to call [func@GLib.spawn_check_wait_status]
1735// in the callback to determine whether or not the child exited
1736// successfully.
1737//
1738// Also, note that on platforms where [type@GLib.Pid] must be explicitly closed
1739// (see [func@GLib.spawn_close_pid]) @pid must not be closed while the source
1740// is still active. Typically, you should invoke [func@GLib.spawn_close_pid]
1741// in the callback function for the source.
1742//
1743// GLib supports only a single callback per process ID.
1744// On POSIX platforms, the same restrictions mentioned for
1745// [func@GLib.child_watch_source_new] apply to this function.
1746//
1747// This internally creates a main loop source using
1748// [func@GLib.child_watch_source_new] and attaches it to the main loop context
1749// using [method@GLib.Source.attach]. You can do these steps manually if you
1750// need greater control.
1751func ChildWatchAddFull(PriorityVar int, PidVar Pid, FunctionVar *ChildWatchFunc, DataVar uintptr, NotifyVar *DestroyNotify) uint {
1752
1753 var FunctionVarRef uintptr
1754 if FunctionVar != nil {
1755 FunctionVarPtr := uintptr(unsafe.Pointer(FunctionVar))
1756 if cbRefPtr, ok := GetCallback(FunctionVarPtr); ok {
1757 FunctionVarRef = cbRefPtr
1758 } else {
1759 fcb := func(arg0 Pid, arg1 int, arg2 uintptr) {
1760 cbFn := *FunctionVar
1761 cbFn(arg0, arg1, arg2)
1762 }
1763 FunctionVarRef = purego.NewCallback(fcb)
1764 SaveCallbackWithClosure(FunctionVarPtr, FunctionVarRef, FunctionVar)
1765 }
1766 }
1767
1768 var NotifyVarRef uintptr
1769 if NotifyVar != nil {
1770 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
1771 if cbRefPtr, ok := GetCallback(NotifyVarPtr); ok {
1772 NotifyVarRef = cbRefPtr
1773 } else {
1774 fcb := func(arg0 uintptr) {
1775 cbFn := *NotifyVar
1776 cbFn(arg0)
1777 }
1778 NotifyVarRef = purego.NewCallback(fcb)
1779 SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
1780 }
1781 }
1782
1783 cret := xChildWatchAddFull(PriorityVar, PidVar, FunctionVarRef, DataVar, NotifyVarRef)
1784
1785 return cret
1786}
1787
1788var xChildWatchSourceNew func(Pid) *Source
1789
1790// Creates a new child watch source.
1791//
1792// The source will not initially be associated with any
1793// [struct@GLib.MainContext] and must be added to one with
1794// [method@GLib.Source.attach] before it will be executed.
1795//
1796// Note that child watch sources can only be used in conjunction with
1797// `g_spawn...` when the [flags@GLib.SpawnFlags.DO_NOT_REAP_CHILD] flag is used.
1798//
1799// Note that on platforms where [type@GLib.Pid] must be explicitly closed
1800// (see [func@GLib.spawn_close_pid]) @pid must not be closed while the
1801// source is still active. Typically, you will want to call
1802// [func@GLib.spawn_close_pid] in the callback function for the source.
1803//
1804// On POSIX platforms, the following restrictions apply to this API
1805// due to limitations in POSIX process interfaces:
1806//
1807// - @pid must be a child of this process.
1808// - @pid must be positive.
1809// - The application must not call [`waitpid()`](man:waitpid(1)) with a
1810// non-positive first argument, for instance in another thread.
1811// - The application must not wait for @pid to exit by any other
1812// mechanism, including `waitpid(pid, ...)` or a second child-watch
1813// source for the same @pid.
1814// - The application must not ignore `SIGCHLD`.
1815// - Before 2.78, the application could not send a signal ([`kill()`](man:kill(2))) to the
1816// watched @pid in a race free manner. Since 2.78, you can do that while the
1817// associated [struct@GLib.MainContext] is acquired.
1818// - Before 2.78, even after destroying the [struct@GLib.Source], you could not
1819// be sure that @pid wasn’t already reaped. Hence, it was also not
1820// safe to `kill()` or `waitpid()` on the process ID after the child watch
1821// source was gone. Destroying the source before it fired made it
1822// impossible to reliably reap the process.
1823//
1824// If any of those conditions are not met, this and related APIs will
1825// not work correctly. This can often be diagnosed via a GLib warning
1826// stating that `ECHILD` was received by `waitpid()`.
1827//
1828// Calling [`waitpid()`](man:waitpid(2)) for specific processes other than @pid
1829// remains a valid thing to do.
1830func ChildWatchSourceNew(PidVar Pid) *Source {
1831
1832 cret := xChildWatchSourceNew(PidVar)
1833
1834 return cret
1835}
1836
1837var xClearHandleId func(uint, uintptr)
1838
1839// Clears a numeric handler, such as a [struct@GLib.Source] ID.
1840//
1841// The @tag_ptr must be a valid pointer to the variable holding the handler.
1842//
1843// If the ID is zero then this function does nothing.
1844// Otherwise, @clear_func is called with the ID as a parameter, and the tag is
1845// set to zero.
1846//
1847// A macro is also included that allows this function to be used without
1848// pointer casts.
1849func ClearHandleId(TagPtrVar uint, ClearFuncVar *ClearHandleFunc) {
1850
1851 var ClearFuncVarRef uintptr
1852 if ClearFuncVar != nil {
1853 ClearFuncVarPtr := uintptr(unsafe.Pointer(ClearFuncVar))
1854 if cbRefPtr, ok := GetCallback(ClearFuncVarPtr); ok {
1855 ClearFuncVarRef = cbRefPtr
1856 } else {
1857 fcb := func(arg0 uint) {
1858 cbFn := *ClearFuncVar
1859 cbFn(arg0)
1860 }
1861 ClearFuncVarRef = purego.NewCallback(fcb)
1862 SaveCallbackWithClosure(ClearFuncVarPtr, ClearFuncVarRef, ClearFuncVar)
1863 }
1864 }
1865
1866 xClearHandleId(TagPtrVar, ClearFuncVarRef)
1867
1868}
1869
1870var xGetCurrentTime func(*TimeVal)
1871
1872// Queries the system wall-clock time.
1873//
1874// This is equivalent to the UNIX [`gettimeofday()`](man:gettimeofday(2))
1875// function, but portable.
1876//
1877// You may find [func@GLib.get_real_time] to be more convenient.
1878func GetCurrentTime(ResultVar *TimeVal) {
1879
1880 xGetCurrentTime(ResultVar)
1881
1882}
1883
1884var xGetMonotonicTime func() int64
1885
1886// Queries the system monotonic time.
1887//
1888// The monotonic clock will always increase and doesn’t suffer
1889// discontinuities when the user (or NTP) changes the system time. It
1890// may or may not continue to tick during times where the machine is
1891// suspended.
1892//
1893// We try to use the clock that corresponds as closely as possible to
1894// the passage of time as measured by system calls such as
1895// [`poll()`](man:poll(2)) but it
1896// may not always be possible to do this.
1897func GetMonotonicTime() int64 {
1898
1899 cret := xGetMonotonicTime()
1900
1901 return cret
1902}
1903
1904var xGetRealTime func() int64
1905
1906// Queries the system wall-clock time.
1907//
1908// This is equivalent to the UNIX [`gettimeofday()`](man:gettimeofday(2))
1909// function, but portable.
1910//
1911// You should only use this call if you are actually interested in the real
1912// wall-clock time. [func@GLib.get_monotonic_time] is probably more useful for
1913// measuring intervals.
1914func GetRealTime() int64 {
1915
1916 cret := xGetRealTime()
1917
1918 return cret
1919}
1920
1921var xIdleAdd func(uintptr, uintptr) uint
1922
1923// Adds a function to be called whenever there are no higher priority
1924// events pending to the default main loop.
1925//
1926// The function is given the
1927// default idle priority, [const@GLib.PRIORITY_DEFAULT_IDLE]. If the function
1928// returns [const@GLib.SOURCE_REMOVE] it is automatically removed from the list
1929// of event sources and will not be called again.
1930//
1931// See [main loop memory management](main-loop.html#memory-management-of-sources) for details
1932// on how to handle the return value and memory management of @data.
1933//
1934// This internally creates a main loop source using [func@GLib.idle_source_new]
1935// and attaches it to the global [struct@GLib.MainContext] using
1936// [method@GLib.Source.attach], so the callback will be invoked in whichever
1937// thread is running that main context. You can do these steps manually if you
1938// need greater control or to use a custom main context.
1939func IdleAdd(FunctionVar *SourceFunc, DataVar uintptr) uint {
1940 trampolineCb, userData := registerSourceFunc(FunctionVar, false)
1941 cret := xIdleAdd(trampolineCb, userData)
1942 saveSourceTrampolineMapping(cret, userData)
1943 return cret
1944}
1945
1946var xIdleAddFull func(int, uintptr, uintptr, uintptr) uint
1947
1948// Adds a function to be called whenever there are no higher priority
1949// events pending.
1950//
1951// If the function returns [const@GLib.SOURCE_REMOVE] it is automatically
1952// removed from the list of event sources and will not be called again.
1953//
1954// See [main loop memory management](main-loop.html#memory-management-of-sources) for details
1955// on how to handle the return value and memory management of @data.
1956//
1957// This internally creates a main loop source using [func@GLib.idle_source_new]
1958// and attaches it to the global [struct@GLib.MainContext] using
1959// [method@GLib.Source.attach], so the callback will be invoked in whichever
1960// thread is running that main context. You can do these steps manually if you
1961// need greater control or to use a custom main context.
1962func IdleAddFull(PriorityVar int, FunctionVar *SourceFunc, DataVar uintptr, NotifyVar *DestroyNotify) uint {
1963 trampolineCb, userData := registerSourceFunc(FunctionVar, false)
1964 var NotifyVarRef uintptr
1965 if NotifyVar != nil {
1966 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
1967 if cbRefPtr, ok := GetCallback(NotifyVarPtr); ok {
1968 NotifyVarRef = cbRefPtr
1969 } else {
1970 fcb := func(arg0 uintptr) {
1971 cbFn := *NotifyVar
1972 cbFn(arg0)
1973 }
1974 NotifyVarRef = purego.NewCallback(fcb)
1975 SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
1976 }
1977 }
1978 cret := xIdleAddFull(PriorityVar, trampolineCb, userData, NotifyVarRef)
1979 saveSourceTrampolineMapping(cret, userData)
1980 return cret
1981}
1982
1983var xIdleAddOnce func(uintptr, uintptr) uint
1984
1985// Adds a function to be called whenever there are no higher priority
1986// events pending to the default main loop.
1987//
1988// The function is given the
1989// default idle priority, [const@GLib.PRIORITY_DEFAULT_IDLE].
1990//
1991// The function will only be called once and then the source will be
1992// automatically removed from the main context.
1993//
1994// This function otherwise behaves like [func@GLib.idle_add].
1995func IdleAddOnce(FunctionVar *SourceOnceFunc, DataVar uintptr) uint {
1996 trampolineCb, userData := registerSourceOnceFunc(FunctionVar)
1997 cret := xIdleAddOnce(trampolineCb, userData)
1998 saveSourceTrampolineMapping(cret, userData)
1999 return cret
2000}
2001
2002var xIdleRemoveByData func(uintptr) bool
2003
2004// Removes the idle function with the given data.
2005func IdleRemoveByData(DataVar uintptr) bool {
2006
2007 cret := xIdleRemoveByData(DataVar)
2008
2009 return cret
2010}
2011
2012var xIdleSourceNew func() *Source
2013
2014// Creates a new idle source.
2015//
2016// The source will not initially be associated with any
2017// [struct@GLib.MainContext] and must be added to one with
2018// [method@GLib.Source.attach] before it will be executed. Note that the
2019// default priority for idle sources is [const@GLib.PRIORITY_DEFAULT_IDLE], as
2020// compared to other sources which have a default priority of
2021// [const@GLib.PRIORITY_DEFAULT].
2022func IdleSourceNew() *Source {
2023
2024 cret := xIdleSourceNew()
2025
2026 return cret
2027}
2028
2029var xMainContextDefault func() *MainContext
2030
2031// Returns the global-default main context.
2032//
2033// This is the main context
2034// used for main loop functions when a main loop is not explicitly
2035// specified, and corresponds to the ‘main’ main loop. See also
2036// [func@GLib.MainContext.get_thread_default].
2037func MainContextDefault() *MainContext {
2038
2039 cret := xMainContextDefault()
2040
2041 return cret
2042}
2043
2044var xMainContextGetThreadDefault func() *MainContext
2045
2046// Gets the thread-default main context for this thread.
2047//
2048// Asynchronous operations that want to be able to be run in contexts other than
2049// the default one should call this method or
2050// [func@GLib.MainContext.ref_thread_default] to get a
2051// [struct@GLib.MainContext] to add their [struct@GLib.Source]s to. (Note that
2052// even in single-threaded programs applications may sometimes want to
2053// temporarily push a non-default context, so it is not safe to assume that
2054// this will always return `NULL` if you are running in the default thread.)
2055//
2056// If you need to hold a reference on the context, use
2057// [func@GLib.MainContext.ref_thread_default] instead.
2058func MainContextGetThreadDefault() *MainContext {
2059
2060 cret := xMainContextGetThreadDefault()
2061
2062 return cret
2063}
2064
2065var xMainContextRefThreadDefault func() *MainContext
2066
2067// Gets a reference to the thread-default [struct@GLib.MainContext] for this
2068// thread
2069//
2070// This is the same as [func@GLib.MainContext.get_thread_default], but it also
2071// adds a reference to the returned main context with [method@GLib.MainContext.ref].
2072// In addition, unlike
2073// [func@GLib.MainContext.get_thread_default], if the thread-default context
2074// is the global-default context, this will return that
2075// [struct@GLib.MainContext] (with a ref added to it) rather than returning
2076// `NULL`.
2077func MainContextRefThreadDefault() *MainContext {
2078
2079 cret := xMainContextRefThreadDefault()
2080
2081 return cret
2082}
2083
2084var xMainCurrentSource func() *Source
2085
2086// Returns the currently firing source for this thread.
2087func MainCurrentSource() *Source {
2088
2089 cret := xMainCurrentSource()
2090
2091 return cret
2092}
2093
2094var xMainDepth func() int
2095
2096// Returns the depth of the stack of calls to
2097// [method@GLib.MainContext.dispatch] on any #GMainContext in the current thread.
2098//
2099// That is, when called from the top level, it gives `0`. When
2100// called from within a callback from [method@GLib.MainContext.iteration]
2101// (or [method@GLib.MainLoop.run], etc.) it returns `1`. When called from within
2102// a callback to a recursive call to [method@GLib.MainContext.iteration],
2103// it returns `2`. And so forth.
2104//
2105// This function is useful in a situation like the following:
2106// Imagine an extremely simple ‘garbage collected’ system.
2107//
2108// ```c
2109// static GList *free_list;
2110//
2111// gpointer
2112// allocate_memory (gsize size)
2113//
2114// {
2115// gpointer result = g_malloc (size);
2116// free_list = g_list_prepend (free_list, result);
2117// return result;
2118// }
2119//
2120// void
2121// free_allocated_memory (void)
2122//
2123// {
2124// GList *l;
2125// for (l = free_list; l; l = l->next);
2126// g_free (l->data);
2127// g_list_free (free_list);
2128// free_list = NULL;
2129// }
2130//
2131// [...]
2132//
2133// while (TRUE);
2134//
2135// {
2136// g_main_context_iteration (NULL, TRUE);
2137// free_allocated_memory();
2138// }
2139//
2140// ```
2141//
2142// This works from an application, however, if you want to do the same
2143// thing from a library, it gets more difficult, since you no longer
2144// control the main loop. You might think you can simply use an idle
2145// function to make the call to `free_allocated_memory()`, but that
2146// doesn’t work, since the idle function could be called from a
2147// recursive callback. This can be fixed by using [func@GLib.main_depth]
2148//
2149// ```c
2150// gpointer
2151// allocate_memory (gsize size)
2152//
2153// {
2154// FreeListBlock *block = g_new (FreeListBlock, 1);
2155// block->mem = g_malloc (size);
2156// block->depth = g_main_depth ();
2157// free_list = g_list_prepend (free_list, block);
2158// return block->mem;
2159// }
2160//
2161// void
2162// free_allocated_memory (void)
2163//
2164// {
2165// GList *l;
2166//
2167// int depth = g_main_depth ();
2168// for (l = free_list; l; );
2169// {
2170// GList *next = l->next;
2171// FreeListBlock *block = l->data;
2172// if (block->depth > depth)
2173// {
2174// g_free (block->mem);
2175// g_free (block);
2176// free_list = g_list_delete_link (free_list, l);
2177// }
2178//
2179// l = next;
2180// }
2181// }
2182//
2183// ```
2184//
2185// There is a temptation to use [func@GLib.main_depth] to solve
2186// problems with reentrancy. For instance, while waiting for data
2187// to be received from the network in response to a menu item,
2188// the menu item might be selected again. It might seem that
2189// one could make the menu item’s callback return immediately
2190// and do nothing if [func@GLib.main_depth] returns a value greater than 1.
2191// However, this should be avoided since the user then sees selecting
2192// the menu item do nothing. Furthermore, you’ll find yourself adding
2193// these checks all over your code, since there are doubtless many,
2194// many things that the user could do. Instead, you can use the
2195// following techniques:
2196//
2197// 1. Use `gtk_widget_set_sensitive()` or modal dialogs to prevent
2198// the user from interacting with elements while the main
2199// loop is recursing.
2200//
2201// 2. Avoid main loop recursion in situations where you can’t handle
2202// arbitrary callbacks. Instead, structure your code so that you
2203// simply return to the main loop and then get called again when
2204// there is more work to do.
2205func MainDepth() int {
2206
2207 cret := xMainDepth()
2208
2209 return cret
2210}
2211
2212var xSourceRemove func(uint) bool
2213
2214// Removes the source with the given ID from the default main context.
2215//
2216// You must
2217// use [method@GLib.Source.destroy] for sources added to a non-default main context.
2218//
2219// The ID of a [struct@GLib.Source] is given by [method@GLib.Source.get_id], or will be
2220// returned by the functions [method@GLib.Source.attach], [func@GLib.idle_add],
2221// [func@GLib.idle_add_full], [func@GLib.timeout_add],
2222// [func@GLib.timeout_add_full], [func@GLib.child_watch_add],
2223// [func@GLib.child_watch_add_full], [func@GLib.io_add_watch], and
2224// [func@GLib.io_add_watch_full].
2225//
2226// It is a programmer error to attempt to remove a non-existent source.
2227//
2228// More specifically: source IDs can be reissued after a source has been
2229// destroyed and therefore it is never valid to use this function with a
2230// source ID which may have already been removed. An example is when
2231// scheduling an idle to run in another thread with [func@GLib.idle_add]: the
2232// idle may already have run and been removed by the time this function
2233// is called on its (now invalid) source ID. This source ID may have
2234// been reissued, leading to the operation being performed against the
2235// wrong source.
2236func SourceRemove(TagVar uint) bool {
2237
2238 cret := xSourceRemove(TagVar)
2239
2240 if cret {
2241 RemoveCallbackBySource(TagVar)
2242 removeSourceTrampolineBySourceID(TagVar)
2243 }
2244 return cret
2245}
2246
2247var xSourceRemoveByFuncsUserData func(*SourceFuncs, uintptr) bool
2248
2249// Removes a source from the default main loop context given the
2250// source functions and user data.
2251//
2252// If multiple sources exist with the same source functions and user data, only
2253// one will be destroyed.
2254func SourceRemoveByFuncsUserData(FuncsVar *SourceFuncs, UserDataVar uintptr) bool {
2255
2256 cret := xSourceRemoveByFuncsUserData(FuncsVar, UserDataVar)
2257
2258 return cret
2259}
2260
2261var xSourceRemoveByUserData func(uintptr) bool
2262
2263// Removes a source from the default main loop context given the user
2264// data for the callback.
2265//
2266// If multiple sources exist with the same user data, only one will be destroyed.
2267func SourceRemoveByUserData(UserDataVar uintptr) bool {
2268
2269 cret := xSourceRemoveByUserData(UserDataVar)
2270
2271 return cret
2272}
2273
2274var xSourceSetNameById func(uint, string)
2275
2276// Sets the name of a source using its ID.
2277//
2278// This is a convenience utility to set source names from the return
2279// value of [func@GLib.idle_add], [func@GLib.timeout_add], etc.
2280//
2281// It is a programmer error to attempt to set the name of a non-existent
2282// source.
2283//
2284// More specifically: source IDs can be reissued after a source has been
2285// destroyed and therefore it is never valid to use this function with a
2286// source ID which may have already been removed. An example is when
2287// scheduling an idle to run in another thread with [func@GLib.idle_add]: the
2288// idle may already have run and been removed by the time this function
2289// is called on its (now invalid) source ID. This source ID may have
2290// been reissued, leading to the operation being performed against the
2291// wrong source.
2292func SourceSetNameById(TagVar uint, NameVar string) {
2293
2294 xSourceSetNameById(TagVar, NameVar)
2295
2296}
2297
2298var xTimeoutAdd func(uint, uintptr, uintptr) uint
2299
2300// Sets a function to be called at regular intervals, with the default
2301// priority, [const@GLib.PRIORITY_DEFAULT].
2302//
2303// The given @function is called repeatedly until it returns
2304// [const@GLib.SOURCE_REMOVE], at which point the timeout is
2305// automatically destroyed and the function will not be called again. The first
2306// call to the function will be at the end of the first @interval.
2307//
2308// Note that timeout functions may be delayed, due to the processing of other
2309// event sources. Thus they should not be relied on for precise timing.
2310// After each call to the timeout function, the time of the next
2311// timeout is recalculated based on the current time and the given interval
2312// (it does not try to ‘catch up’ time lost in delays).
2313//
2314// See [main loop memory management](main-loop.html#memory-management-of-sources) for details
2315// on how to handle the return value and memory management of @data.
2316//
2317// If you want to have a timer in the ‘seconds’ range and do not care
2318// about the exact time of the first call of the timer, use the
2319// [func@GLib.timeout_add_seconds] function; this function allows for more
2320// optimizations and more efficient system power usage.
2321//
2322// This internally creates a main loop source using
2323// [func@GLib.timeout_source_new] and attaches it to the global
2324// [struct@GLib.MainContext] using [method@GLib.Source.attach], so the callback
2325// will be invoked in whichever thread is running that main context. You can do
2326// these steps manually if you need greater control or to use a custom main
2327// context.
2328//
2329// It is safe to call this function from any thread.
2330//
2331// The interval given is in terms of monotonic time, not wall clock
2332// time. See [func@GLib.get_monotonic_time].
2333func TimeoutAdd(IntervalVar uint, FunctionVar *SourceFunc, DataVar uintptr) uint {
2334 trampolineCb, userData := registerSourceFunc(FunctionVar, false)
2335 cret := xTimeoutAdd(IntervalVar, trampolineCb, userData)
2336 saveSourceTrampolineMapping(cret, userData)
2337 return cret
2338}
2339
2340var xTimeoutAddFull func(int, uint, uintptr, uintptr, uintptr) uint
2341
2342// Sets a function to be called at regular intervals, with the given
2343// priority.
2344//
2345// The function is called repeatedly until it returns
2346// [const@GLib.SOURCE_REMOVE], at which point the timeout is automatically
2347// destroyed and
2348// the function will not be called again. The @notify function is
2349// called when the timeout is destroyed. The first call to the
2350// function will be at the end of the first @interval.
2351//
2352// Note that timeout functions may be delayed, due to the processing of other
2353// event sources. Thus they should not be relied on for precise timing.
2354// After each call to the timeout function, the time of the next
2355// timeout is recalculated based on the current time and the given interval
2356// (it does not try to ‘catch up’ time lost in delays).
2357//
2358// See [main loop memory management](main-loop.html#memory-management-of-sources) for details
2359// on how to handle the return value and memory management of @data.
2360//
2361// This internally creates a main loop source using
2362// [func@GLib.timeout_source_new] and attaches it to the global
2363// [struct@GLib.MainContext] using [method@GLib.Source.attach], so the callback
2364// will be invoked in whichever thread is running that main context. You can do
2365// these steps manually if you need greater control or to use a custom main
2366// context.
2367//
2368// The interval given is in terms of monotonic time, not wall clock time.
2369// See [func@GLib.get_monotonic_time].
2370func TimeoutAddFull(PriorityVar int, IntervalVar uint, FunctionVar *SourceFunc, DataVar uintptr, NotifyVar *DestroyNotify) uint {
2371 trampolineCb, userData := registerSourceFunc(FunctionVar, false)
2372 var NotifyVarRef uintptr
2373 if NotifyVar != nil {
2374 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
2375 if cbRefPtr, ok := GetCallback(NotifyVarPtr); ok {
2376 NotifyVarRef = cbRefPtr
2377 } else {
2378 fcb := func(arg0 uintptr) {
2379 cbFn := *NotifyVar
2380 cbFn(arg0)
2381 }
2382 NotifyVarRef = purego.NewCallback(fcb)
2383 SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
2384 }
2385 }
2386 cret := xTimeoutAddFull(PriorityVar, IntervalVar, trampolineCb, userData, NotifyVarRef)
2387 saveSourceTrampolineMapping(cret, userData)
2388 return cret
2389}
2390
2391var xTimeoutAddOnce func(uint, uintptr, uintptr) uint
2392
2393// Sets a function to be called after @interval milliseconds have elapsed,
2394// with the default priority, [const@GLib.PRIORITY_DEFAULT].
2395//
2396// The given @function is called once and then the source will be automatically
2397// removed from the main context.
2398//
2399// This function otherwise behaves like [func@GLib.timeout_add].
2400func TimeoutAddOnce(IntervalVar uint, FunctionVar *SourceOnceFunc, DataVar uintptr) uint {
2401 trampolineCb, userData := registerSourceOnceFunc(FunctionVar)
2402 cret := xTimeoutAddOnce(IntervalVar, trampolineCb, userData)
2403 saveSourceTrampolineMapping(cret, userData)
2404 return cret
2405}
2406
2407var xTimeoutAddSeconds func(uint, uintptr, uintptr) uint
2408
2409// Sets a function to be called at regular intervals with the default
2410// priority, [const@GLib.PRIORITY_DEFAULT].
2411//
2412// The function is called repeatedly until it returns [const@GLib.SOURCE_REMOVE],
2413// at which point the timeout is automatically destroyed
2414// and the function will not be called again.
2415//
2416// This internally creates a main loop source using
2417// [func@GLib.timeout_source_new_seconds] and attaches it to the main loop context
2418// using [method@GLib.Source.attach]. You can do these steps manually if you need
2419// greater control. Also see [func@GLib.timeout_add_seconds_full].
2420//
2421// It is safe to call this function from any thread.
2422//
2423// Note that the first call of the timer may not be precise for timeouts
2424// of one second. If you need finer precision and have such a timeout,
2425// you may want to use [func@GLib.timeout_add] instead.
2426//
2427// See [main loop memory management](main-loop.html#memory-management-of-sources) for details
2428// on how to handle the return value and memory management of @data.
2429//
2430// The interval given is in terms of monotonic time, not wall clock
2431// time. See [func@GLib.get_monotonic_time].
2432func TimeoutAddSeconds(IntervalVar uint, FunctionVar *SourceFunc, DataVar uintptr) uint {
2433 trampolineCb, userData := registerSourceFunc(FunctionVar, false)
2434 cret := xTimeoutAddSeconds(IntervalVar, trampolineCb, userData)
2435 saveSourceTrampolineMapping(cret, userData)
2436 return cret
2437}
2438
2439var xTimeoutAddSecondsFull func(int, uint, uintptr, uintptr, uintptr) uint
2440
2441// Sets a function to be called at regular intervals, with @priority.
2442//
2443// The function is called repeatedly until it returns [const@GLib.SOURCE_REMOVE],
2444// at which point the timeout is automatically destroyed and
2445// the function will not be called again.
2446//
2447// Unlike [func@GLib.timeout_add], this function operates at whole second
2448// granularity. The initial starting point of the timer is determined by the
2449// implementation and the implementation is expected to group multiple timers
2450// together so that they fire all at the same time. To allow this grouping,
2451// the @interval to the first timer is rounded and can deviate up to one second
2452// from the specified interval. Subsequent timer iterations will generally run
2453// at the specified interval.
2454//
2455// Note that timeout functions may be delayed, due to the processing of other
2456// event sources. Thus they should not be relied on for precise timing.
2457// After each call to the timeout function, the time of the next
2458// timeout is recalculated based on the current time and the given @interval
2459//
2460// See [main loop memory management](main-loop.html#memory-management-of-sources) for details
2461// on how to handle the return value and memory management of @data.
2462//
2463// If you want timing more precise than whole seconds, use
2464// [func@GLib.timeout_add] instead.
2465//
2466// The grouping of timers to fire at the same time results in a more power
2467// and CPU efficient behavior so if your timer is in multiples of seconds
2468// and you don’t require the first timer exactly one second from now, the
2469// use of [func@GLib.timeout_add_seconds] is preferred over
2470// [func@GLib.timeout_add].
2471//
2472// This internally creates a main loop source using
2473// [func@GLib.timeout_source_new_seconds] and attaches it to the main loop
2474// context using [method@GLib.Source.attach]. You can do these steps manually
2475// if you need greater control.
2476//
2477// It is safe to call this function from any thread.
2478//
2479// The interval given is in terms of monotonic time, not wall clock
2480// time. See [func@GLib.get_monotonic_time].
2481func TimeoutAddSecondsFull(PriorityVar int, IntervalVar uint, FunctionVar *SourceFunc, DataVar uintptr, NotifyVar *DestroyNotify) uint {
2482 trampolineCb, userData := registerSourceFunc(FunctionVar, false)
2483 var NotifyVarRef uintptr
2484 if NotifyVar != nil {
2485 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
2486 if cbRefPtr, ok := GetCallback(NotifyVarPtr); ok {
2487 NotifyVarRef = cbRefPtr
2488 } else {
2489 fcb := func(arg0 uintptr) {
2490 cbFn := *NotifyVar
2491 cbFn(arg0)
2492 }
2493 NotifyVarRef = purego.NewCallback(fcb)
2494 SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
2495 }
2496 }
2497 cret := xTimeoutAddSecondsFull(PriorityVar, IntervalVar, trampolineCb, userData, NotifyVarRef)
2498 saveSourceTrampolineMapping(cret, userData)
2499 return cret
2500}
2501
2502var xTimeoutAddSecondsOnce func(uint, uintptr, uintptr) uint
2503
2504// This function behaves like [func@GLib.timeout_add_once] but with a range in
2505// seconds.
2506func TimeoutAddSecondsOnce(IntervalVar uint, FunctionVar *SourceOnceFunc, DataVar uintptr) uint {
2507 trampolineCb, userData := registerSourceOnceFunc(FunctionVar)
2508 cret := xTimeoutAddSecondsOnce(IntervalVar, trampolineCb, userData)
2509 saveSourceTrampolineMapping(cret, userData)
2510 return cret
2511}
2512
2513var xTimeoutSourceNew func(uint) *Source
2514
2515// Creates a new timeout source.
2516//
2517// The source will not initially be associated with any [struct@GLib.MainContext]
2518// and must be added to one with [method@GLib.Source.attach] before it will be
2519// executed.
2520//
2521// The interval given is in terms of monotonic time, not wall clock
2522// time. See [func@GLib.get_monotonic_time].
2523func TimeoutSourceNew(IntervalVar uint) *Source {
2524
2525 cret := xTimeoutSourceNew(IntervalVar)
2526
2527 return cret
2528}
2529
2530var xTimeoutSourceNewSeconds func(uint) *Source
2531
2532// Creates a new timeout source.
2533//
2534// The source will not initially be associated with any
2535// [struct@GLib.MainContext] and must be added to one with
2536// [method@GLib.Source.attach] before it will be executed.
2537//
2538// The scheduling granularity/accuracy of this timeout source will be
2539// in seconds.
2540//
2541// The interval given is in terms of monotonic time, not wall clock time.
2542// See [func@GLib.get_monotonic_time].
2543func TimeoutSourceNewSeconds(IntervalVar uint) *Source {
2544
2545 cret := xTimeoutSourceNewSeconds(IntervalVar)
2546
2547 return cret
2548}
2549
2550func init() {
2551 core.SetPackageName("GLIB", "glib-2.0")
2552 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
2553 var libs []uintptr
2554 for _, libPath := range core.GetPaths("GLIB") {
2555 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
2556 if err != nil {
2557 panic(err)
2558 }
2559 libs = append(libs, lib)
2560 }
2561
2562 core.PuregoSafeRegister(&xChildWatchAdd, libs, "g_child_watch_add")
2563 core.PuregoSafeRegister(&xChildWatchAddFull, libs, "g_child_watch_add_full")
2564 core.PuregoSafeRegister(&xChildWatchSourceNew, libs, "g_child_watch_source_new")
2565 core.PuregoSafeRegister(&xClearHandleId, libs, "g_clear_handle_id")
2566 core.PuregoSafeRegister(&xGetCurrentTime, libs, "g_get_current_time")
2567 core.PuregoSafeRegister(&xGetMonotonicTime, libs, "g_get_monotonic_time")
2568 core.PuregoSafeRegister(&xGetRealTime, libs, "g_get_real_time")
2569 core.PuregoSafeRegister(&xIdleAdd, libs, "g_idle_add")
2570 core.PuregoSafeRegister(&xIdleAddFull, libs, "g_idle_add_full")
2571 core.PuregoSafeRegister(&xIdleAddOnce, libs, "g_idle_add_once")
2572 core.PuregoSafeRegister(&xIdleRemoveByData, libs, "g_idle_remove_by_data")
2573 core.PuregoSafeRegister(&xIdleSourceNew, libs, "g_idle_source_new")
2574 core.PuregoSafeRegister(&xMainContextDefault, libs, "g_main_context_default")
2575 core.PuregoSafeRegister(&xMainContextGetThreadDefault, libs, "g_main_context_get_thread_default")
2576 core.PuregoSafeRegister(&xMainContextRefThreadDefault, libs, "g_main_context_ref_thread_default")
2577 core.PuregoSafeRegister(&xMainCurrentSource, libs, "g_main_current_source")
2578 core.PuregoSafeRegister(&xMainDepth, libs, "g_main_depth")
2579 core.PuregoSafeRegister(&xSourceRemove, libs, "g_source_remove")
2580 core.PuregoSafeRegister(&xSourceRemoveByFuncsUserData, libs, "g_source_remove_by_funcs_user_data")
2581 core.PuregoSafeRegister(&xSourceRemoveByUserData, libs, "g_source_remove_by_user_data")
2582 core.PuregoSafeRegister(&xSourceSetNameById, libs, "g_source_set_name_by_id")
2583 core.PuregoSafeRegister(&xTimeoutAdd, libs, "g_timeout_add")
2584 core.PuregoSafeRegister(&xTimeoutAddFull, libs, "g_timeout_add_full")
2585 core.PuregoSafeRegister(&xTimeoutAddOnce, libs, "g_timeout_add_once")
2586 core.PuregoSafeRegister(&xTimeoutAddSeconds, libs, "g_timeout_add_seconds")
2587 core.PuregoSafeRegister(&xTimeoutAddSecondsFull, libs, "g_timeout_add_seconds_full")
2588 core.PuregoSafeRegister(&xTimeoutAddSecondsOnce, libs, "g_timeout_add_seconds_once")
2589 core.PuregoSafeRegister(&xTimeoutSourceNew, libs, "g_timeout_source_new")
2590 core.PuregoSafeRegister(&xTimeoutSourceNewSeconds, libs, "g_timeout_source_new_seconds")
2591
2592 core.PuregoSafeRegister(&xMainContextGLibType, libs, "g_main_context_get_type")
2593
2594 core.PuregoSafeRegister(&xNewMainContext, libs, "g_main_context_new")
2595 core.PuregoSafeRegister(&xNewMainContextWithFlags, libs, "g_main_context_new_with_flags")
2596
2597 core.PuregoSafeRegister(&xMainContextAcquire, libs, "g_main_context_acquire")
2598 core.PuregoSafeRegister(&xMainContextAddPoll, libs, "g_main_context_add_poll")
2599 core.PuregoSafeRegister(&xMainContextCheck, libs, "g_main_context_check")
2600 core.PuregoSafeRegister(&xMainContextDispatch, libs, "g_main_context_dispatch")
2601 core.PuregoSafeRegister(&xMainContextFindSourceByFuncsUserData, libs, "g_main_context_find_source_by_funcs_user_data")
2602 core.PuregoSafeRegister(&xMainContextFindSourceById, libs, "g_main_context_find_source_by_id")
2603 core.PuregoSafeRegister(&xMainContextFindSourceByUserData, libs, "g_main_context_find_source_by_user_data")
2604 core.PuregoSafeRegister(&xMainContextGetPollFunc, libs, "g_main_context_get_poll_func")
2605 core.PuregoSafeRegister(&xMainContextInvoke, libs, "g_main_context_invoke")
2606 core.PuregoSafeRegister(&xMainContextInvokeFull, libs, "g_main_context_invoke_full")
2607 core.PuregoSafeRegister(&xMainContextIsOwner, libs, "g_main_context_is_owner")
2608 core.PuregoSafeRegister(&xMainContextIteration, libs, "g_main_context_iteration")
2609 core.PuregoSafeRegister(&xMainContextPending, libs, "g_main_context_pending")
2610 core.PuregoSafeRegister(&xMainContextPopThreadDefault, libs, "g_main_context_pop_thread_default")
2611 core.PuregoSafeRegister(&xMainContextPrepare, libs, "g_main_context_prepare")
2612 core.PuregoSafeRegister(&xMainContextPushThreadDefault, libs, "g_main_context_push_thread_default")
2613 core.PuregoSafeRegister(&xMainContextPusherNew, libs, "g_main_context_pusher_new")
2614 core.PuregoSafeRegister(&xMainContextQuery, libs, "g_main_context_query")
2615 core.PuregoSafeRegister(&xMainContextRef, libs, "g_main_context_ref")
2616 core.PuregoSafeRegister(&xMainContextRelease, libs, "g_main_context_release")
2617 core.PuregoSafeRegister(&xMainContextRemovePoll, libs, "g_main_context_remove_poll")
2618 core.PuregoSafeRegister(&xMainContextSetPollFunc, libs, "g_main_context_set_poll_func")
2619 core.PuregoSafeRegister(&xMainContextUnref, libs, "g_main_context_unref")
2620 core.PuregoSafeRegister(&xMainContextWait, libs, "g_main_context_wait")
2621 core.PuregoSafeRegister(&xMainContextWakeup, libs, "g_main_context_wakeup")
2622
2623 core.PuregoSafeRegister(&xMainLoopGLibType, libs, "g_main_loop_get_type")
2624
2625 core.PuregoSafeRegister(&xNewMainLoop, libs, "g_main_loop_new")
2626
2627 core.PuregoSafeRegister(&xMainLoopGetContext, libs, "g_main_loop_get_context")
2628 core.PuregoSafeRegister(&xMainLoopIsRunning, libs, "g_main_loop_is_running")
2629 core.PuregoSafeRegister(&xMainLoopQuit, libs, "g_main_loop_quit")
2630 core.PuregoSafeRegister(&xMainLoopRef, libs, "g_main_loop_ref")
2631 core.PuregoSafeRegister(&xMainLoopRun, libs, "g_main_loop_run")
2632 core.PuregoSafeRegister(&xMainLoopUnref, libs, "g_main_loop_unref")
2633
2634 core.PuregoSafeRegister(&xSourceGLibType, libs, "g_source_get_type")
2635
2636 core.PuregoSafeRegister(&xNewSource, libs, "g_source_new")
2637
2638 core.PuregoSafeRegister(&xSourceAddChildSource, libs, "g_source_add_child_source")
2639 core.PuregoSafeRegister(&xSourceAddPoll, libs, "g_source_add_poll")
2640 core.PuregoSafeRegister(&xSourceAddUnixFd, libs, "g_source_add_unix_fd")
2641 core.PuregoSafeRegister(&xSourceAttach, libs, "g_source_attach")
2642 core.PuregoSafeRegister(&xSourceDestroy, libs, "g_source_destroy")
2643 core.PuregoSafeRegister(&xSourceDupContext, libs, "g_source_dup_context")
2644 core.PuregoSafeRegister(&xSourceGetCanRecurse, libs, "g_source_get_can_recurse")
2645 core.PuregoSafeRegister(&xSourceGetContext, libs, "g_source_get_context")
2646 core.PuregoSafeRegister(&xSourceGetCurrentTime, libs, "g_source_get_current_time")
2647 core.PuregoSafeRegister(&xSourceGetId, libs, "g_source_get_id")
2648 core.PuregoSafeRegister(&xSourceGetName, libs, "g_source_get_name")
2649 core.PuregoSafeRegister(&xSourceGetPriority, libs, "g_source_get_priority")
2650 core.PuregoSafeRegister(&xSourceGetReadyTime, libs, "g_source_get_ready_time")
2651 core.PuregoSafeRegister(&xSourceGetTime, libs, "g_source_get_time")
2652 core.PuregoSafeRegister(&xSourceIsDestroyed, libs, "g_source_is_destroyed")
2653 core.PuregoSafeRegister(&xSourceModifyUnixFd, libs, "g_source_modify_unix_fd")
2654 core.PuregoSafeRegister(&xSourceQueryUnixFd, libs, "g_source_query_unix_fd")
2655 core.PuregoSafeRegister(&xSourceRef, libs, "g_source_ref")
2656 core.PuregoSafeRegister(&xSourceRemoveChildSource, libs, "g_source_remove_child_source")
2657 core.PuregoSafeRegister(&xSourceRemovePoll, libs, "g_source_remove_poll")
2658 core.PuregoSafeRegister(&xSourceRemoveUnixFd, libs, "g_source_remove_unix_fd")
2659 core.PuregoSafeRegister(&xSourceSetCallback, libs, "g_source_set_callback")
2660 core.PuregoSafeRegister(&xSourceSetCallbackIndirect, libs, "g_source_set_callback_indirect")
2661 core.PuregoSafeRegister(&xSourceSetCanRecurse, libs, "g_source_set_can_recurse")
2662 core.PuregoSafeRegister(&xSourceSetDisposeFunction, libs, "g_source_set_dispose_function")
2663 core.PuregoSafeRegister(&xSourceSetFuncs, libs, "g_source_set_funcs")
2664 core.PuregoSafeRegister(&xSourceSetName, libs, "g_source_set_name")
2665 core.PuregoSafeRegister(&xSourceSetPriority, libs, "g_source_set_priority")
2666 core.PuregoSafeRegister(&xSourceSetReadyTime, libs, "g_source_set_ready_time")
2667 core.PuregoSafeRegister(&xSourceSetStaticName, libs, "g_source_set_static_name")
2668 core.PuregoSafeRegister(&xSourceUnref, libs, "g_source_unref")
2669
2670}