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
16// Interface definition for [iface@Gio.AsyncResult].
17type AsyncResultIface struct {
18 _ structs.HostLayout
19
20 GIface uintptr
21
22 xGetUserData uintptr
23
24 xGetSourceObject uintptr
25
26 xIsTagged uintptr
27}
28
29func (x *AsyncResultIface) GoPointer() uintptr {
30 return uintptr(unsafe.Pointer(x))
31}
32
33// OverrideGetUserData sets the "get_user_data" callback function.
34// Gets the user data passed to the callback.
35func (x *AsyncResultIface) OverrideGetUserData(cb func(AsyncResult) uintptr) {
36 if cb == nil {
37 x.xGetUserData = 0
38 } else {
39 x.xGetUserData = purego.NewCallback(func(ResVarp uintptr) uintptr {
40 return cb(&AsyncResultBase{Ptr: ResVarp})
41 })
42 }
43}
44
45// GetGetUserData gets the "get_user_data" callback function.
46// Gets the user data passed to the callback.
47func (x *AsyncResultIface) GetGetUserData() func(AsyncResult) uintptr {
48 if x.xGetUserData == 0 {
49 return nil
50 }
51 var rawCallback func(ResVarp uintptr) uintptr
52 purego.RegisterFunc(&rawCallback, x.xGetUserData)
53 return func(ResVar AsyncResult) uintptr {
54 return rawCallback(ResVar.GoPointer())
55 }
56}
57
58// OverrideGetSourceObject sets the "get_source_object" callback function.
59// Gets the source object that issued the asynchronous operation.
60func (x *AsyncResultIface) OverrideGetSourceObject(cb func(AsyncResult) *gobject.Object) {
61 if cb == nil {
62 x.xGetSourceObject = 0
63 } else {
64 x.xGetSourceObject = purego.NewCallback(func(ResVarp uintptr) uintptr {
65 ret := cb(&AsyncResultBase{Ptr: ResVarp})
66 if ret == nil {
67 return 0
68 }
69 return ret.GoPointer()
70 })
71 }
72}
73
74// GetGetSourceObject gets the "get_source_object" callback function.
75// Gets the source object that issued the asynchronous operation.
76func (x *AsyncResultIface) GetGetSourceObject() func(AsyncResult) *gobject.Object {
77 if x.xGetSourceObject == 0 {
78 return nil
79 }
80 var rawCallback func(ResVarp uintptr) uintptr
81 purego.RegisterFunc(&rawCallback, x.xGetSourceObject)
82 return func(ResVar AsyncResult) *gobject.Object {
83 rawRet := rawCallback(ResVar.GoPointer())
84 if rawRet == 0 {
85 return nil
86 }
87 ret := &gobject.Object{}
88 ret.Ptr = rawRet
89 return ret
90 }
91}
92
93// OverrideIsTagged sets the "is_tagged" callback function.
94// Checks if a result is tagged with a particular source.
95func (x *AsyncResultIface) OverrideIsTagged(cb func(AsyncResult, uintptr) bool) {
96 if cb == nil {
97 x.xIsTagged = 0
98 } else {
99 x.xIsTagged = purego.NewCallback(func(ResVarp uintptr, SourceTagVarp uintptr) bool {
100 return cb(&AsyncResultBase{Ptr: ResVarp}, SourceTagVarp)
101 })
102 }
103}
104
105// GetIsTagged gets the "is_tagged" callback function.
106// Checks if a result is tagged with a particular source.
107func (x *AsyncResultIface) GetIsTagged() func(AsyncResult, uintptr) bool {
108 if x.xIsTagged == 0 {
109 return nil
110 }
111 var rawCallback func(ResVarp uintptr, SourceTagVarp uintptr) bool
112 purego.RegisterFunc(&rawCallback, x.xIsTagged)
113 return func(ResVar AsyncResult, SourceTagVar uintptr) bool {
114 return rawCallback(ResVar.GoPointer(), SourceTagVar)
115 }
116}
117
118// `GAsyncResult` provides a base class for implementing asynchronous function results.
119//
120// Asynchronous operations are broken up into two separate operations
121// which are chained together by a `GAsyncReadyCallback`. To begin
122// an asynchronous operation, provide a `GAsyncReadyCallback` to the
123// asynchronous function. This callback will be triggered when the
124// operation has completed, and must be run in a later iteration of
125// the thread-default main context (see
126// [method@GLib.MainContext.push_thread_default]) from where the operation was
127// initiated. It will be passed a `GAsyncResult` instance filled with the
128// details of the operation's success or failure, the object the asynchronous
129// function was started for and any error codes returned. The asynchronous
130// callback function is then expected to call the corresponding `_finish()`
131// function, passing the object the function was called for, the
132// `GAsyncResult` instance, and (optionally) an @error to grab any
133// error conditions that may have occurred.
134//
135// The `_finish()` function for an operation takes the generic result
136// (of type `GAsyncResult`) and returns the specific result that the
137// operation in question yields (e.g. a [class@Gio.FileEnumerator] for a
138// "enumerate children" operation). If the result or error status of the
139// operation is not needed, there is no need to call the `_finish()`
140// function; GIO will take care of cleaning up the result and error
141// information after the `GAsyncReadyCallback` returns. You can pass
142// `NULL` for the `GAsyncReadyCallback` if you don't need to take any
143// action at all after the operation completes. Applications may also
144// take a reference to the `GAsyncResult` and call `_finish()` later;
145// however, the `_finish()` function may be called at most once.
146//
147// Example of a typical asynchronous operation flow:
148//
149// ```c
150// void _theoretical_frobnitz_async (Theoretical *t,
151//
152// GCancellable *c,
153// GAsyncReadyCallback cb,
154// gpointer u);
155//
156// gboolean _theoretical_frobnitz_finish (Theoretical *t,
157//
158// GAsyncResult *res,
159// GError **e);
160//
161// static void
162// frobnitz_result_func (GObject *source_object,
163//
164// GAsyncResult *res,
165// gpointer user_data)
166//
167// {
168// gboolean success = FALSE;
169//
170// success = _theoretical_frobnitz_finish (source_object, res, NULL);
171//
172// if (success)
173// g_printf ("Hurray!\n");
174// else
175// g_printf ("Uh oh!\n");
176//
177// ...
178//
179// }
180//
181// int main (int argc, void *argv[])
182//
183// {
184// ...
185//
186// _theoretical_frobnitz_async (theoretical_data,
187// NULL,
188// frobnitz_result_func,
189// NULL);
190//
191// ...
192// }
193//
194// ```
195//
196// The callback for an asynchronous operation is called only once, and is
197// always called, even in the case of a cancelled operation. On cancellation
198// the result is a `G_IO_ERROR_CANCELLED` error.
199//
200// ## I/O Priority
201//
202// Many I/O-related asynchronous operations have a priority parameter,
203// which is used in certain cases to determine the order in which
204// operations are executed. They are not used to determine system-wide
205// I/O scheduling. Priorities are integers, with lower numbers indicating
206// higher priority. It is recommended to choose priorities between
207// `G_PRIORITY_LOW` and `G_PRIORITY_HIGH`, with `G_PRIORITY_DEFAULT`
208// as a default.
209type AsyncResult interface {
210 GoPointer() uintptr
211 SetGoPointer(uintptr)
212 GetSourceObject() *gobject.Object
213 GetUserData() uintptr
214 IsTagged(SourceTagVar uintptr) bool
215 LegacyPropagateError() (bool, error)
216}
217
218var xAsyncResultGLibType func() types.GType
219
220func AsyncResultGLibType() types.GType {
221 return xAsyncResultGLibType()
222}
223
224type AsyncResultBase struct {
225 Ptr uintptr
226}
227
228func (x *AsyncResultBase) GoPointer() uintptr {
229 if x == nil {
230 return 0
231 }
232 return x.Ptr
233}
234
235func (x *AsyncResultBase) SetGoPointer(ptr uintptr) {
236 x.Ptr = ptr
237}
238
239// Gets the source object from a [iface@Gio.AsyncResult].
240func (x *AsyncResultBase) GetSourceObject() *gobject.Object {
241 var cls *gobject.Object
242
243 cret := XGAsyncResultGetSourceObject(x.GoPointer())
244
245 if cret == 0 {
246 return nil
247 }
248 cls = &gobject.Object{}
249 cls.Ptr = cret
250 return cls
251}
252
253// Gets the user data from a [iface@Gio.AsyncResult].
254func (x *AsyncResultBase) GetUserData() uintptr {
255
256 cret := XGAsyncResultGetUserData(x.GoPointer())
257 return cret
258}
259
260// Checks if @res has the given @source_tag (generally a function
261// pointer indicating the function @res was created by).
262func (x *AsyncResultBase) IsTagged(SourceTagVar uintptr) bool {
263
264 cret := XGAsyncResultIsTagged(x.GoPointer(), SourceTagVar)
265 return cret
266}
267
268// If @res is a [class@Gio.SimpleAsyncResult], this is equivalent to
269// [method@Gio.SimpleAsyncResult.propagate_error]. Otherwise it returns
270// `FALSE`.
271//
272// This can be used for legacy error handling in async `*_finish()`
273// wrapper functions that traditionally handled [class@Gio.SimpleAsyncResult]
274// error returns themselves rather than calling into the virtual method.
275// This should not be used in new code; [iface@Gio.AsyncResult] errors that are
276// set by virtual methods should also be extracted by virtual methods,
277// to enable subclasses to chain up correctly.
278func (x *AsyncResultBase) LegacyPropagateError() (bool, error) {
279 var cerr *glib.Error
280
281 cret := XGAsyncResultLegacyPropagateError(x.GoPointer())
282 if cerr == nil {
283 return cret, nil
284 }
285 return cret, cerr
286
287}
288
289var XGAsyncResultGetSourceObject func(uintptr) uintptr
290var XGAsyncResultGetUserData func(uintptr) uintptr
291var XGAsyncResultIsTagged func(uintptr, uintptr) bool
292var XGAsyncResultLegacyPropagateError func(uintptr) bool
293
294func init() {
295 core.SetPackageName("GIO", "gio-2.0")
296 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
297 var libs []uintptr
298 for _, libPath := range core.GetPaths("GIO") {
299 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
300 if err != nil {
301 panic(err)
302 }
303 libs = append(libs, lib)
304 }
305
306 core.PuregoSafeRegister(&xAsyncResultGLibType, libs, "g_async_result_get_type")
307
308 core.PuregoSafeRegister(&XGAsyncResultGetSourceObject, libs, "g_async_result_get_source_object")
309 core.PuregoSafeRegister(&XGAsyncResultGetUserData, libs, "g_async_result_get_user_data")
310 core.PuregoSafeRegister(&XGAsyncResultIsTagged, libs, "g_async_result_is_tagged")
311 core.PuregoSafeRegister(&XGAsyncResultLegacyPropagateError, libs, "g_async_result_legacy_propagate_error")
312
313}