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// Provides an interface for initializing object such that initialization
17// may fail.
18type InitableIface struct {
19 _ structs.HostLayout
20
21 GIface uintptr
22
23 xInit uintptr
24}
25
26func (x *InitableIface) GoPointer() uintptr {
27 return uintptr(unsafe.Pointer(x))
28}
29
30// OverrideInit sets the "init" callback function.
31// Initializes the object.
32func (x *InitableIface) OverrideInit(cb func(Initable, *Cancellable) bool) {
33 if cb == nil {
34 x.xInit = 0
35 } else {
36 x.xInit = purego.NewCallback(func(InitableVarp uintptr, CancellableVarp uintptr) bool {
37 return cb(&InitableBase{Ptr: InitableVarp}, CancellableNewFromInternalPtr(CancellableVarp))
38 })
39 }
40}
41
42// GetInit gets the "init" callback function.
43// Initializes the object.
44func (x *InitableIface) GetInit() func(Initable, *Cancellable) bool {
45 if x.xInit == 0 {
46 return nil
47 }
48 var rawCallback func(InitableVarp uintptr, CancellableVarp uintptr) bool
49 purego.RegisterFunc(&rawCallback, x.xInit)
50 return func(InitableVar Initable, CancellableVar *Cancellable) bool {
51 return rawCallback(InitableVar.GoPointer(), CancellableVar.GoPointer())
52 }
53}
54
55// `GInitable` is implemented by objects that can fail during
56// initialization. If an object implements this interface then
57// it must be initialized as the first thing after construction,
58// either via [method@Gio.Initable.init] or [method@Gio.AsyncInitable.init_async]
59// (the latter is only available if it also implements [iface@Gio.AsyncInitable]).
60//
61// If the object is not initialized, or initialization returns with an
62// error, then all operations on the object except `g_object_ref()` and
63// `g_object_unref()` are considered to be invalid, and have undefined
64// behaviour. They will often fail with [func@GLib.critical] or
65// [func@GLib.warning], but this must not be relied on.
66//
67// Users of objects implementing this are not intended to use
68// the interface method directly, instead it will be used automatically
69// in various ways. For C applications you generally just call
70// [func@Gio.Initable.new] directly, or indirectly via a `foo_thing_new()` wrapper.
71// This will call [method@Gio.Initable.init] under the cover, returning `NULL`
72// and setting a `GError` on failure (at which point the instance is
73// unreferenced).
74//
75// For bindings in languages where the native constructor supports
76// exceptions the binding could check for objects implementing `GInitable`
77// during normal construction and automatically initialize them, throwing
78// an exception on failure.
79type Initable interface {
80 GoPointer() uintptr
81 SetGoPointer(uintptr)
82 Init(CancellableVar *Cancellable) (bool, error)
83}
84
85var xInitableGLibType func() types.GType
86
87func InitableGLibType() types.GType {
88 return xInitableGLibType()
89}
90
91type InitableBase struct {
92 Ptr uintptr
93}
94
95func (x *InitableBase) GoPointer() uintptr {
96 if x == nil {
97 return 0
98 }
99 return x.Ptr
100}
101
102func (x *InitableBase) SetGoPointer(ptr uintptr) {
103 x.Ptr = ptr
104}
105
106// Initializes the object implementing the interface.
107//
108// This method is intended for language bindings. If writing in C,
109// g_initable_new() should typically be used instead.
110//
111// The object must be initialized before any real use after initial
112// construction, either with this function or g_async_initable_init_async().
113//
114// Implementations may also support cancellation. If @cancellable is not %NULL,
115// then initialization can be cancelled by triggering the cancellable object
116// from another thread. If the operation was cancelled, the error
117// %G_IO_ERROR_CANCELLED will be returned. If @cancellable is not %NULL and
118// the object doesn't support cancellable initialization the error
119// %G_IO_ERROR_NOT_SUPPORTED will be returned.
120//
121// If the object is not initialized, or initialization returns with an
122// error, then all operations on the object except g_object_ref() and
123// g_object_unref() are considered to be invalid, and have undefined
124// behaviour. See the [description][iface@Gio.Initable#description] for more details.
125//
126// Callers should not assume that a class which implements #GInitable can be
127// initialized multiple times, unless the class explicitly documents itself as
128// supporting this. Generally, a class’ implementation of init() can assume
129// (and assert) that it will only be called once. Previously, this documentation
130// recommended all #GInitable implementations should be idempotent; that
131// recommendation was relaxed in GLib 2.54.
132//
133// If a class explicitly supports being initialized multiple times, it is
134// recommended that the method is idempotent: multiple calls with the same
135// arguments should return the same results. Only the first call initializes
136// the object; further calls return the result of the first call.
137//
138// One reason why a class might need to support idempotent initialization is if
139// it is designed to be used via the singleton pattern, with a
140// #GObjectClass.constructor that sometimes returns an existing instance.
141// In this pattern, a caller would expect to be able to call g_initable_init()
142// on the result of g_object_new(), regardless of whether it is in fact a new
143// instance.
144func (x *InitableBase) Init(CancellableVar *Cancellable) (bool, error) {
145 var cerr *glib.Error
146
147 cret := XGInitableInit(x.GoPointer(), CancellableVar.GoPointer(), &cerr)
148 if cerr == nil {
149 return cret, nil
150 }
151 return cret, cerr
152
153}
154
155var XGInitableInit func(uintptr, uintptr, **glib.Error) bool
156
157var xInitableNewv func(types.GType, uint, []gobject.Parameter, uintptr, **glib.Error) uintptr
158
159// Helper function for constructing #GInitable object. This is
160// similar to g_object_newv() but also initializes the object
161// and returns %NULL, setting an error on failure.
162func InitableNewv(ObjectTypeVar types.GType, NParametersVar uint, ParametersVar []gobject.Parameter, CancellableVar *Cancellable) (*gobject.Object, error) {
163 var cls *gobject.Object
164 var cerr *glib.Error
165
166 cret := xInitableNewv(ObjectTypeVar, NParametersVar, ParametersVar, CancellableVar.GoPointer(), &cerr)
167
168 if cret == 0 {
169 return nil, cerr
170 }
171 cls = &gobject.Object{}
172 cls.Ptr = cret
173 if cerr == nil {
174 return cls, nil
175 }
176 return cls, cerr
177
178}
179
180func init() {
181 core.SetPackageName("GIO", "gio-2.0")
182 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
183 var libs []uintptr
184 for _, libPath := range core.GetPaths("GIO") {
185 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
186 if err != nil {
187 panic(err)
188 }
189 libs = append(libs, lib)
190 }
191
192 core.PuregoSafeRegister(&xInitableNewv, libs, "g_initable_newv")
193
194 core.PuregoSafeRegister(&xInitableGLibType, libs, "g_initable_get_type")
195
196 core.PuregoSafeRegister(&XGInitableInit, libs, "g_initable_init")
197
198}