v0.2.1 c0399be

gcancellable.go RawHistoryFolder

1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
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/glib"
12	"github.com/bnema/puregotk/v4/gobject"
13	"github.com/bnema/puregotk/v4/gobject/types"
14)
15
16type CancellableClass struct {
17	_ structs.HostLayout
18
19	ParentClass gobject.ObjectClass
20
21	xCancelled uintptr
22
23	xGReserved1 uintptr
24
25	xGReserved2 uintptr
26
27	xGReserved3 uintptr
28
29	xGReserved4 uintptr
30
31	xGReserved5 uintptr
32}
33
34func (x *CancellableClass) GoPointer() uintptr {
35	return uintptr(unsafe.Pointer(x))
36}
37
38// OverrideCancelled sets the "cancelled" callback function.
39func (x *CancellableClass) OverrideCancelled(cb func(*Cancellable)) {
40	if cb == nil {
41		x.xCancelled = 0
42	} else {
43		x.xCancelled = purego.NewCallback(func(CancellableVarp uintptr) {
44			cb(CancellableNewFromInternalPtr(CancellableVarp))
45		})
46	}
47}
48
49// GetCancelled gets the "cancelled" callback function.
50func (x *CancellableClass) GetCancelled() func(*Cancellable) {
51	if x.xCancelled == 0 {
52		return nil
53	}
54	var rawCallback func(CancellableVarp uintptr)
55	purego.RegisterFunc(&rawCallback, x.xCancelled)
56	return func(CancellableVar *Cancellable) {
57		rawCallback(CancellableVar.GoPointer())
58	}
59}
60
61// OverrideGReserved1 sets the "_g_reserved1" callback function.
62func (x *CancellableClass) OverrideGReserved1(cb func()) {
63	if cb == nil {
64		x.xGReserved1 = 0
65	} else {
66		x.xGReserved1 = purego.NewCallback(func() {
67			cb()
68		})
69	}
70}
71
72// GetGReserved1 gets the "_g_reserved1" callback function.
73func (x *CancellableClass) GetGReserved1() func() {
74	if x.xGReserved1 == 0 {
75		return nil
76	}
77	var rawCallback func()
78	purego.RegisterFunc(&rawCallback, x.xGReserved1)
79	return func() {
80		rawCallback()
81	}
82}
83
84// OverrideGReserved2 sets the "_g_reserved2" callback function.
85func (x *CancellableClass) OverrideGReserved2(cb func()) {
86	if cb == nil {
87		x.xGReserved2 = 0
88	} else {
89		x.xGReserved2 = purego.NewCallback(func() {
90			cb()
91		})
92	}
93}
94
95// GetGReserved2 gets the "_g_reserved2" callback function.
96func (x *CancellableClass) GetGReserved2() func() {
97	if x.xGReserved2 == 0 {
98		return nil
99	}
100	var rawCallback func()
101	purego.RegisterFunc(&rawCallback, x.xGReserved2)
102	return func() {
103		rawCallback()
104	}
105}
106
107// OverrideGReserved3 sets the "_g_reserved3" callback function.
108func (x *CancellableClass) OverrideGReserved3(cb func()) {
109	if cb == nil {
110		x.xGReserved3 = 0
111	} else {
112		x.xGReserved3 = purego.NewCallback(func() {
113			cb()
114		})
115	}
116}
117
118// GetGReserved3 gets the "_g_reserved3" callback function.
119func (x *CancellableClass) GetGReserved3() func() {
120	if x.xGReserved3 == 0 {
121		return nil
122	}
123	var rawCallback func()
124	purego.RegisterFunc(&rawCallback, x.xGReserved3)
125	return func() {
126		rawCallback()
127	}
128}
129
130// OverrideGReserved4 sets the "_g_reserved4" callback function.
131func (x *CancellableClass) OverrideGReserved4(cb func()) {
132	if cb == nil {
133		x.xGReserved4 = 0
134	} else {
135		x.xGReserved4 = purego.NewCallback(func() {
136			cb()
137		})
138	}
139}
140
141// GetGReserved4 gets the "_g_reserved4" callback function.
142func (x *CancellableClass) GetGReserved4() func() {
143	if x.xGReserved4 == 0 {
144		return nil
145	}
146	var rawCallback func()
147	purego.RegisterFunc(&rawCallback, x.xGReserved4)
148	return func() {
149		rawCallback()
150	}
151}
152
153// OverrideGReserved5 sets the "_g_reserved5" callback function.
154func (x *CancellableClass) OverrideGReserved5(cb func()) {
155	if cb == nil {
156		x.xGReserved5 = 0
157	} else {
158		x.xGReserved5 = purego.NewCallback(func() {
159			cb()
160		})
161	}
162}
163
164// GetGReserved5 gets the "_g_reserved5" callback function.
165func (x *CancellableClass) GetGReserved5() func() {
166	if x.xGReserved5 == 0 {
167		return nil
168	}
169	var rawCallback func()
170	purego.RegisterFunc(&rawCallback, x.xGReserved5)
171	return func() {
172		rawCallback()
173	}
174}
175
176type CancellablePrivate struct {
177	_ structs.HostLayout
178}
179
180func (x *CancellablePrivate) GoPointer() uintptr {
181	return uintptr(unsafe.Pointer(x))
182}
183
184// `GCancellable` allows operations to be cancelled.
185//
186// `GCancellable` is a thread-safe operation cancellation stack used
187// throughout GIO to allow for cancellation of synchronous and
188// asynchronous operations.
189type Cancellable struct {
190	gobject.Object
191}
192
193var xCancellableGLibType func() types.GType
194
195func CancellableGLibType() types.GType {
196	return xCancellableGLibType()
197}
198
199func CancellableNewFromInternalPtr(ptr uintptr) *Cancellable {
200	cls := &Cancellable{}
201	cls.Ptr = ptr
202	return cls
203}
204
205var xNewCancellable func() uintptr
206
207// Creates a new #GCancellable object.
208//
209// Applications that want to start one or more operations
210// that should be cancellable should create a #GCancellable
211// and pass it to the operations.
212//
213// One #GCancellable can be used in multiple consecutive
214// operations or in multiple concurrent operations.
215func NewCancellable() *Cancellable {
216	var cls *Cancellable
217
218	cret := xNewCancellable()
219
220	if cret == 0 {
221		return nil
222	}
223	cls = &Cancellable{}
224	cls.Ptr = cret
225	return cls
226}
227
228var xCancellableCancel func(uintptr)
229
230// Will set @cancellable to cancelled, and will emit the
231// #GCancellable::cancelled signal. (However, see the warning about
232// race conditions in the documentation for that signal if you are
233// planning to connect to it.)
234//
235// This function is thread-safe. In other words, you can safely call
236// it from a thread other than the one running the operation that was
237// passed the @cancellable.
238//
239// If @cancellable is %NULL, this function returns immediately for convenience.
240//
241// The convention within GIO is that cancelling an asynchronous
242// operation causes it to complete asynchronously. That is, if you
243// cancel the operation from the same thread in which it is running,
244// then the operation's #GAsyncReadyCallback will not be invoked until
245// the application returns to the main loop.
246//
247// It is safe (although useless, since it will be a no-op) to call
248// this function from a [signal@Gio.Cancellable::cancelled] signal handler.
249func (x *Cancellable) Cancel() {
250
251	xCancellableCancel(x.GoPointer())
252
253}
254
255var xCancellableConnect func(uintptr, uintptr, uintptr, uintptr) uint
256
257// Convenience function to connect to the #GCancellable::cancelled
258// signal. Also handles the race condition that may happen
259// if the cancellable is cancelled right before connecting.
260//
261// @callback is called exactly once each time @cancellable is cancelled,
262// either directly at the time of the connect if @cancellable is already
263// cancelled, or when @cancellable is cancelled in some thread.
264// In case the cancellable is reset via [method@Gio.Cancellable.reset]
265// then the callback can be called again if the @cancellable is cancelled and
266// if it had not been previously cancelled at the time
267// [method@Gio.Cancellable.connect] was called (e.g. if the connection actually
268// took place, returning a non-zero value).
269//
270// @data_destroy_func will be called when the handler is
271// disconnected, or immediately if the cancellable is already
272// cancelled.
273//
274// See #GCancellable::cancelled for details on how to use this.
275//
276// Since GLib 2.40, the lock protecting @cancellable is not held when
277// @callback is invoked. This lifts a restriction in place for
278// earlier GLib versions which now makes it easier to write cleanup
279// code that unconditionally invokes e.g. [method@Gio.Cancellable.cancel].
280// Note that since 2.82 GLib still holds a lock during the callback but it’s
281// designed in a way that most of the [class@Gio.Cancellable] methods can be
282// called, including [method@Gio.Cancellable.cancel] or
283// [method@GObject.Object.unref].
284//
285// There are still some methods that will deadlock (by design) when
286// called from the [signal@Gio.Cancellable::cancelled] callbacks:
287//   - [method@Gio.Cancellable.connect]
288//   - [method@Gio.Cancellable.disconnect]
289//   - [method@Gio.Cancellable.reset]
290//   - [method@Gio.Cancellable.make_pollfd]
291//   - [method@Gio.Cancellable.release_fd]
292func (x *Cancellable) Connect(CallbackVar *gobject.Callback, DataVar uintptr, DataDestroyFuncVar *glib.DestroyNotify) uint {
293
294	var CallbackVarRef uintptr
295	if CallbackVar != nil {
296		CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
297		if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
298			CallbackVarRef = cbRefPtr
299		} else {
300			fcb := func() {
301				cbFn := *CallbackVar
302				cbFn()
303			}
304			CallbackVarRef = purego.NewCallback(fcb)
305			glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
306		}
307	}
308
309	var DataDestroyFuncVarRef uintptr
310	if DataDestroyFuncVar != nil {
311		DataDestroyFuncVarPtr := uintptr(unsafe.Pointer(DataDestroyFuncVar))
312		if cbRefPtr, ok := glib.GetCallback(DataDestroyFuncVarPtr); ok {
313			DataDestroyFuncVarRef = cbRefPtr
314		} else {
315			fcb := func(arg0 uintptr) {
316				cbFn := *DataDestroyFuncVar
317				cbFn(arg0)
318			}
319			DataDestroyFuncVarRef = purego.NewCallback(fcb)
320			glib.SaveCallbackWithClosure(DataDestroyFuncVarPtr, DataDestroyFuncVarRef, DataDestroyFuncVar)
321		}
322	}
323
324	cret := xCancellableConnect(x.GoPointer(), CallbackVarRef, DataVar, DataDestroyFuncVarRef)
325	return cret
326}
327
328var xCancellableDisconnect func(uintptr, uint)
329
330// Disconnects a handler from a cancellable instance similar to
331// g_signal_handler_disconnect().  Additionally, in the event that a
332// signal handler is currently running, this call will block until the
333// handler has finished.  Calling this function from a
334// #GCancellable::cancelled signal handler will therefore result in a
335// deadlock.
336//
337// This avoids a race condition where a thread cancels at the
338// same time as the cancellable operation is finished and the
339// signal handler is removed. See #GCancellable::cancelled for
340// details on how to use this.
341//
342// If @cancellable is %NULL or @handler_id is `0` this function does
343// nothing.
344func (x *Cancellable) Disconnect(HandlerIdVar uint) {
345
346	xCancellableDisconnect(x.GoPointer(), HandlerIdVar)
347
348}
349
350var xCancellableGetFd func(uintptr) int
351
352// Gets the file descriptor for a cancellable job. This can be used to
353// implement cancellable operations on Unix systems. The returned fd will
354// turn readable when @cancellable is cancelled.
355//
356// You are not supposed to read from the fd yourself, just check for
357// readable status. Reading to unset the readable status is done
358// with g_cancellable_reset().
359//
360// After a successful return from this function, you should use
361// g_cancellable_release_fd() to free up resources allocated for
362// the returned file descriptor.
363//
364// See also g_cancellable_make_pollfd().
365func (x *Cancellable) GetFd() int {
366
367	cret := xCancellableGetFd(x.GoPointer())
368	return cret
369}
370
371var xCancellableIsCancelled func(uintptr) bool
372
373// Checks if a cancellable job has been cancelled.
374func (x *Cancellable) IsCancelled() bool {
375
376	cret := xCancellableIsCancelled(x.GoPointer())
377	return cret
378}
379
380var xCancellableMakePollfd func(uintptr, *glib.PollFD) bool
381
382// Creates a #GPollFD corresponding to @cancellable; this can be passed
383// to g_poll() and used to poll for cancellation. This is useful both
384// for unix systems without a native poll and for portability to
385// windows.
386//
387// When this function returns %TRUE, you should use
388// g_cancellable_release_fd() to free up resources allocated for the
389// @pollfd. After a %FALSE return, do not call g_cancellable_release_fd().
390//
391// If this function returns %FALSE, either no @cancellable was given or
392// resource limits prevent this function from allocating the necessary
393// structures for polling. (On Linux, you will likely have reached
394// the maximum number of file descriptors.) The suggested way to handle
395// these cases is to ignore the @cancellable.
396//
397// You are not supposed to read from the fd yourself, just check for
398// readable status. Reading to unset the readable status is done
399// with g_cancellable_reset().
400//
401// Note that in the event that a [signal@Gio.Cancellable::cancelled] signal handler is
402// currently running, this call will block until the handler has finished.
403// Calling this function from a signal handler will therefore result in a
404// deadlock.
405func (x *Cancellable) MakePollfd(PollfdVar *glib.PollFD) bool {
406
407	cret := xCancellableMakePollfd(x.GoPointer(), PollfdVar)
408	return cret
409}
410
411var xCancellablePopCurrent func(uintptr)
412
413// Pops @cancellable off the cancellable stack (verifying that @cancellable
414// is on the top of the stack).
415func (x *Cancellable) PopCurrent() {
416
417	xCancellablePopCurrent(x.GoPointer())
418
419}
420
421var xCancellablePushCurrent func(uintptr)
422
423// Pushes @cancellable onto the cancellable stack. The current
424// cancellable can then be received using g_cancellable_get_current().
425//
426// This is useful when implementing cancellable operations in
427// code that does not allow you to pass down the cancellable object.
428//
429// This is typically called automatically by e.g. #GFile operations,
430// so you rarely have to call this yourself.
431func (x *Cancellable) PushCurrent() {
432
433	xCancellablePushCurrent(x.GoPointer())
434
435}
436
437var xCancellableReleaseFd func(uintptr)
438
439// Releases a resources previously allocated by g_cancellable_get_fd()
440// or g_cancellable_make_pollfd().
441//
442// For compatibility reasons with older releases, calling this function
443// is not strictly required, the resources will be automatically freed
444// when the @cancellable is finalized. However, the @cancellable will
445// block scarce file descriptors until it is finalized if this function
446// is not called. This can cause the application to run out of file
447// descriptors when many #GCancellables are used at the same time.
448//
449// Note that in the event that a [signal@Gio.Cancellable::cancelled] signal handler is
450// currently running, this call will block until the handler has finished.
451// Calling this function from a signal handler will therefore result in a
452// deadlock.
453func (x *Cancellable) ReleaseFd() {
454
455	xCancellableReleaseFd(x.GoPointer())
456
457}
458
459var xCancellableReset func(uintptr)
460
461// Resets @cancellable to its uncancelled state.
462//
463// If cancellable is currently in use by any cancellable operation
464// then the behavior of this function is undefined.
465//
466// Note that it is generally not a good idea to reuse an existing
467// cancellable for more operations after it has been cancelled once,
468// as this function might tempt you to do. The recommended practice
469// is to drop the reference to a cancellable after cancelling it,
470// and let it die with the outstanding async operations. You should
471// create a fresh cancellable for further async operations.
472//
473// In the event that a [signal@Gio.Cancellable::cancelled] signal handler is currently
474// running, this call will block until the handler has finished.
475// Calling this function from a signal handler will therefore result in a
476// deadlock.
477func (x *Cancellable) Reset() {
478
479	xCancellableReset(x.GoPointer())
480
481}
482
483var xCancellableSetErrorIfCancelled func(uintptr) bool
484
485// If the @cancellable is cancelled, sets the error to notify
486// that the operation was cancelled.
487func (x *Cancellable) SetErrorIfCancelled() (bool, error) {
488	var cerr *glib.Error
489
490	cret := xCancellableSetErrorIfCancelled(x.GoPointer())
491	if cerr == nil {
492		return cret, nil
493	}
494	return cret, cerr
495
496}
497
498var xCancellableSourceNew func(uintptr) *glib.Source
499
500// Creates a source that triggers if @cancellable is cancelled and
501// calls its callback of type #GCancellableSourceFunc. This is
502// primarily useful for attaching to another (non-cancellable) source
503// with g_source_add_child_source() to add cancellability to it.
504//
505// For convenience, you can call this with a %NULL #GCancellable,
506// in which case the source will never trigger.
507//
508// The new #GSource will hold a reference to the #GCancellable.
509func (x *Cancellable) SourceNew() *glib.Source {
510
511	cret := xCancellableSourceNew(x.GoPointer())
512	return cret
513}
514
515func (c *Cancellable) GoPointer() uintptr {
516	if c == nil {
517		return 0
518	}
519	return c.Ptr
520}
521
522func (c *Cancellable) SetGoPointer(ptr uintptr) {
523	c.Ptr = ptr
524}
525
526// Emitted when the operation has been cancelled.
527//
528// Can be used by implementations of cancellable operations. If the
529// operation is cancelled from another thread, the signal will be
530// emitted in the thread that cancelled the operation, not the
531// thread that is running the operation.
532//
533// Note that disconnecting from this signal (or any signal) in a
534// multi-threaded program is prone to race conditions. For instance
535// it is possible that a signal handler may be invoked even after
536// a call to g_signal_handler_disconnect() for that handler has
537// already returned.
538//
539// There is also a problem when cancellation happens right before
540// connecting to the signal. If this happens the signal will
541// unexpectedly not be emitted, and checking before connecting to
542// the signal leaves a race condition where this is still happening.
543//
544// In order to make it safe and easy to connect handlers there
545// are two helper functions: g_cancellable_connect() and
546// g_cancellable_disconnect() which protect against problems
547// like this.
548//
549// An example of how to us this:
550// |[<!-- language="C" -->
551//
552//	// Make sure we don't do unnecessary work if already cancelled
553//	if (g_cancellable_set_error_if_cancelled (cancellable, error))
554//	  return;
555//
556//	// Set up all the data needed to be able to handle cancellation
557//	// of the operation
558//	my_data = my_data_new (...);
559//
560//	id = 0;
561//	if (cancellable)
562//	  id = g_cancellable_connect (cancellable,
563//				      G_CALLBACK (cancelled_handler)
564//				      data, NULL);
565//
566//	// cancellable operation here...
567//
568//	g_cancellable_disconnect (cancellable, id);
569//
570//	// cancelled_handler is never called after this, it is now safe
571//	// to free the data
572//	my_data_free (my_data);
573//
574// ]|
575//
576// Note that the cancelled signal is emitted in the thread that
577// the user cancelled from, which may be the main thread. So, the
578// cancellable signal should not do something that can block.
579func (x *Cancellable) ConnectCancelled(cb *func(Cancellable)) uint {
580	cbPtr := uintptr(unsafe.Pointer(cb))
581	if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
582		handlerID := gobject.SignalConnect(x.GoPointer(), "cancelled", cbRefPtr)
583		glib.SaveHandlerMapping(handlerID, cbPtr)
584		return handlerID
585	}
586
587	fcb := func(clsPtr uintptr) {
588		fa := Cancellable{}
589		fa.Ptr = clsPtr
590		cbFn := *cb
591
592		cbFn(fa)
593
594	}
595	cbRefPtr := purego.NewCallback(fcb)
596	glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
597	handlerID := gobject.SignalConnect(x.GoPointer(), "cancelled", cbRefPtr)
598	glib.SaveHandlerMapping(handlerID, cbPtr)
599	return handlerID
600}
601
602var xCancellableGetCurrent func() uintptr
603
604// Gets the top cancellable from the stack.
605func CancellableGetCurrent() *Cancellable {
606	var cls *Cancellable
607
608	cret := xCancellableGetCurrent()
609
610	if cret == 0 {
611		return nil
612	}
613	gobject.IncreaseRef(cret)
614	cls = &Cancellable{}
615	cls.Ptr = cret
616	return cls
617}
618
619func init() {
620	core.SetPackageName("GIO", "gio-2.0")
621	core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
622	var libs []uintptr
623	for _, libPath := range core.GetPaths("GIO") {
624		lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
625		if err != nil {
626			panic(err)
627		}
628		libs = append(libs, lib)
629	}
630
631	core.PuregoSafeRegister(&xCancellableGLibType, libs, "g_cancellable_get_type")
632
633	core.PuregoSafeRegister(&xNewCancellable, libs, "g_cancellable_new")
634
635	core.PuregoSafeRegister(&xCancellableCancel, libs, "g_cancellable_cancel")
636	core.PuregoSafeRegister(&xCancellableConnect, libs, "g_cancellable_connect")
637	core.PuregoSafeRegister(&xCancellableDisconnect, libs, "g_cancellable_disconnect")
638	core.PuregoSafeRegister(&xCancellableGetFd, libs, "g_cancellable_get_fd")
639	core.PuregoSafeRegister(&xCancellableIsCancelled, libs, "g_cancellable_is_cancelled")
640	core.PuregoSafeRegister(&xCancellableMakePollfd, libs, "g_cancellable_make_pollfd")
641	core.PuregoSafeRegister(&xCancellablePopCurrent, libs, "g_cancellable_pop_current")
642	core.PuregoSafeRegister(&xCancellablePushCurrent, libs, "g_cancellable_push_current")
643	core.PuregoSafeRegister(&xCancellableReleaseFd, libs, "g_cancellable_release_fd")
644	core.PuregoSafeRegister(&xCancellableReset, libs, "g_cancellable_reset")
645	core.PuregoSafeRegister(&xCancellableSetErrorIfCancelled, libs, "g_cancellable_set_error_if_cancelled")
646	core.PuregoSafeRegister(&xCancellableSourceNew, libs, "g_cancellable_source_new")
647
648	core.PuregoSafeRegister(&xCancellableGetCurrent, libs, "g_cancellable_get_current")
649
650}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close