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// Specifies the type of function which is called when an extended
15// error instance is freed. It is passed the error pointer about to be
16// freed, and should free the error's private data fields.
17//
18// Normally, it is better to use G_DEFINE_EXTENDED_ERROR(), as it
19// already takes care of getting the private data from @error.
20type ErrorClearFunc func(*Error)
21
22// Specifies the type of function which is called when an extended
23// error instance is copied. It is passed the pointer to the
24// destination error and source error, and should copy only the fields
25// of the private data from @src_error to @dest_error.
26//
27// Normally, it is better to use G_DEFINE_EXTENDED_ERROR(), as it
28// already takes care of getting the private data from @src_error and
29// @dest_error.
30type ErrorCopyFunc func(*Error, *Error)
31
32// Specifies the type of function which is called just after an
33// extended error instance is created and its fields filled. It should
34// only initialize the fields in the private data, which can be
35// received with the generated `*_get_private()` function.
36//
37// Normally, it is better to use G_DEFINE_EXTENDED_ERROR(), as it
38// already takes care of getting the private data from @error.
39type ErrorInitFunc func(*Error)
40
41// The `GError` structure contains information about
42// an error that has occurred.
43type Error struct {
44 _ structs.HostLayout
45
46 Domain Quark
47
48 Code int32
49
50 Message uintptr
51}
52
53var xErrorGLibType func() types.GType
54
55func ErrorGLibType() types.GType {
56 return xErrorGLibType()
57}
58
59func (x *Error) GoPointer() uintptr {
60 return uintptr(unsafe.Pointer(x))
61}
62
63var xNewError func(Quark, int, string, ...interface{}) *Error
64
65// Creates a new #GError with the given @domain and @code,
66// and a message formatted with @format.
67func NewError(DomainVar Quark, CodeVar int, FormatVar string, varArgs ...interface{}) *Error {
68
69 cret := xNewError(DomainVar, CodeVar, FormatVar, varArgs...)
70 return cret
71}
72
73var xNewErrorLiteral func(Quark, int, string) *Error
74
75// Creates a new #GError; unlike g_error_new(), @message is
76// not a printf()-style format string. Use this function if
77// @message contains text you don't have control over,
78// that could include printf() escape sequences.
79func NewErrorLiteral(DomainVar Quark, CodeVar int, MessageVar string) *Error {
80
81 cret := xNewErrorLiteral(DomainVar, CodeVar, MessageVar)
82 return cret
83}
84
85var xNewErrorValist func(Quark, int, string, []interface{}) *Error
86
87// Creates a new #GError with the given @domain and @code,
88// and a message formatted with @format.
89func NewErrorValist(DomainVar Quark, CodeVar int, FormatVar string, ArgsVar []interface{}) *Error {
90
91 cret := xNewErrorValist(DomainVar, CodeVar, FormatVar, ArgsVar)
92 return cret
93}
94
95var xErrorCopy func(uintptr) *Error
96
97// Makes a copy of @error.
98func (x *Error) Copy() *Error {
99
100 cret := xErrorCopy(x.GoPointer())
101 return cret
102}
103
104var xErrorFree func(uintptr)
105
106// Frees a #GError and associated resources.
107func (x *Error) Free() {
108
109 xErrorFree(x.GoPointer())
110
111}
112
113var xErrorMatches func(uintptr, Quark, int) bool
114
115// Returns %TRUE if @error matches @domain and @code, %FALSE
116// otherwise. In particular, when @error is %NULL, %FALSE will
117// be returned.
118//
119// If @domain contains a `FAILED` (or otherwise generic) error code,
120// you should generally not check for it explicitly, but should
121// instead treat any not-explicitly-recognized error code as being
122// equivalent to the `FAILED` code. This way, if the domain is
123// extended in the future to provide a more specific error code for
124// a certain case, your code will still work.
125func (x *Error) Matches(DomainVar Quark, CodeVar int) bool {
126
127 cret := xErrorMatches(x.GoPointer(), DomainVar, CodeVar)
128 return cret
129}
130
131var xClearError func()
132
133// If @err or `*err` is %NULL, does nothing. Otherwise,
134// calls g_error_free() on `*err` and sets `*err` to %NULL.
135func ClearError() error {
136 var cerr *Error
137
138 xClearError()
139
140 if cerr == nil {
141 return nil
142 }
143 return cerr
144
145}
146
147var xErrorDomainRegister func(string, uint, uintptr, uintptr, uintptr) Quark
148
149// This function registers an extended #GError domain.
150// @error_type_name will be duplicated. Otherwise does the same as
151// g_error_domain_register_static().
152func ErrorDomainRegister(ErrorTypeNameVar string, ErrorTypePrivateSizeVar uint, ErrorTypeInitVar *ErrorInitFunc, ErrorTypeCopyVar *ErrorCopyFunc, ErrorTypeClearVar *ErrorClearFunc) Quark {
153
154 var ErrorTypeInitVarRef uintptr
155 if ErrorTypeInitVar != nil {
156 ErrorTypeInitVarPtr := uintptr(unsafe.Pointer(ErrorTypeInitVar))
157 if cbRefPtr, ok := GetCallback(ErrorTypeInitVarPtr); ok {
158 ErrorTypeInitVarRef = cbRefPtr
159 } else {
160 fcb := func(arg0 *Error) {
161 cbFn := *ErrorTypeInitVar
162 cbFn(arg0)
163 }
164 ErrorTypeInitVarRef = purego.NewCallback(fcb)
165 SaveCallbackWithClosure(ErrorTypeInitVarPtr, ErrorTypeInitVarRef, ErrorTypeInitVar)
166 }
167 }
168
169 var ErrorTypeCopyVarRef uintptr
170 if ErrorTypeCopyVar != nil {
171 ErrorTypeCopyVarPtr := uintptr(unsafe.Pointer(ErrorTypeCopyVar))
172 if cbRefPtr, ok := GetCallback(ErrorTypeCopyVarPtr); ok {
173 ErrorTypeCopyVarRef = cbRefPtr
174 } else {
175 fcb := func(arg0 *Error, arg1 *Error) {
176 cbFn := *ErrorTypeCopyVar
177 cbFn(arg0, arg1)
178 }
179 ErrorTypeCopyVarRef = purego.NewCallback(fcb)
180 SaveCallbackWithClosure(ErrorTypeCopyVarPtr, ErrorTypeCopyVarRef, ErrorTypeCopyVar)
181 }
182 }
183
184 var ErrorTypeClearVarRef uintptr
185 if ErrorTypeClearVar != nil {
186 ErrorTypeClearVarPtr := uintptr(unsafe.Pointer(ErrorTypeClearVar))
187 if cbRefPtr, ok := GetCallback(ErrorTypeClearVarPtr); ok {
188 ErrorTypeClearVarRef = cbRefPtr
189 } else {
190 fcb := func(arg0 *Error) {
191 cbFn := *ErrorTypeClearVar
192 cbFn(arg0)
193 }
194 ErrorTypeClearVarRef = purego.NewCallback(fcb)
195 SaveCallbackWithClosure(ErrorTypeClearVarPtr, ErrorTypeClearVarRef, ErrorTypeClearVar)
196 }
197 }
198
199 cret := xErrorDomainRegister(ErrorTypeNameVar, ErrorTypePrivateSizeVar, ErrorTypeInitVarRef, ErrorTypeCopyVarRef, ErrorTypeClearVarRef)
200
201 return cret
202}
203
204var xErrorDomainRegisterStatic func(string, uint, uintptr, uintptr, uintptr) Quark
205
206// This function registers an extended #GError domain.
207//
208// @error_type_name should not be freed. @error_type_private_size must
209// be greater than 0.
210//
211// @error_type_init receives an initialized #GError and should then initialize
212// the private data.
213//
214// @error_type_copy is a function that receives both original and a copy
215// #GError and should copy the fields of the private error data. The standard
216// #GError fields are already handled.
217//
218// @error_type_clear receives the pointer to the error, and it should free the
219// fields of the private error data. It should not free the struct itself though.
220//
221// Normally, it is better to use G_DEFINE_EXTENDED_ERROR(), as it
222// already takes care of passing valid information to this function.
223func ErrorDomainRegisterStatic(ErrorTypeNameVar string, ErrorTypePrivateSizeVar uint, ErrorTypeInitVar *ErrorInitFunc, ErrorTypeCopyVar *ErrorCopyFunc, ErrorTypeClearVar *ErrorClearFunc) Quark {
224
225 var ErrorTypeInitVarRef uintptr
226 if ErrorTypeInitVar != nil {
227 ErrorTypeInitVarPtr := uintptr(unsafe.Pointer(ErrorTypeInitVar))
228 if cbRefPtr, ok := GetCallback(ErrorTypeInitVarPtr); ok {
229 ErrorTypeInitVarRef = cbRefPtr
230 } else {
231 fcb := func(arg0 *Error) {
232 cbFn := *ErrorTypeInitVar
233 cbFn(arg0)
234 }
235 ErrorTypeInitVarRef = purego.NewCallback(fcb)
236 SaveCallbackWithClosure(ErrorTypeInitVarPtr, ErrorTypeInitVarRef, ErrorTypeInitVar)
237 }
238 }
239
240 var ErrorTypeCopyVarRef uintptr
241 if ErrorTypeCopyVar != nil {
242 ErrorTypeCopyVarPtr := uintptr(unsafe.Pointer(ErrorTypeCopyVar))
243 if cbRefPtr, ok := GetCallback(ErrorTypeCopyVarPtr); ok {
244 ErrorTypeCopyVarRef = cbRefPtr
245 } else {
246 fcb := func(arg0 *Error, arg1 *Error) {
247 cbFn := *ErrorTypeCopyVar
248 cbFn(arg0, arg1)
249 }
250 ErrorTypeCopyVarRef = purego.NewCallback(fcb)
251 SaveCallbackWithClosure(ErrorTypeCopyVarPtr, ErrorTypeCopyVarRef, ErrorTypeCopyVar)
252 }
253 }
254
255 var ErrorTypeClearVarRef uintptr
256 if ErrorTypeClearVar != nil {
257 ErrorTypeClearVarPtr := uintptr(unsafe.Pointer(ErrorTypeClearVar))
258 if cbRefPtr, ok := GetCallback(ErrorTypeClearVarPtr); ok {
259 ErrorTypeClearVarRef = cbRefPtr
260 } else {
261 fcb := func(arg0 *Error) {
262 cbFn := *ErrorTypeClearVar
263 cbFn(arg0)
264 }
265 ErrorTypeClearVarRef = purego.NewCallback(fcb)
266 SaveCallbackWithClosure(ErrorTypeClearVarPtr, ErrorTypeClearVarRef, ErrorTypeClearVar)
267 }
268 }
269
270 cret := xErrorDomainRegisterStatic(ErrorTypeNameVar, ErrorTypePrivateSizeVar, ErrorTypeInitVarRef, ErrorTypeCopyVarRef, ErrorTypeClearVarRef)
271
272 return cret
273}
274
275var xPrefixError func(**Error, string, ...interface{})
276
277// Formats a string according to @format and prefix it to an existing
278// error message. If @err is %NULL (ie: no error variable) then do
279// nothing.
280//
281// If `*err` is %NULL (ie: an error variable is present but there is no
282// error condition) then also do nothing.
283func PrefixError(ErrVar **Error, FormatVar string, varArgs ...interface{}) {
284
285 xPrefixError(ErrVar, FormatVar, varArgs...)
286
287}
288
289var xPrefixErrorLiteral func(**Error, string)
290
291// Prefixes @prefix to an existing error message. If @err or `*err` is
292// %NULL (i.e.: no error variable) then do nothing.
293func PrefixErrorLiteral(ErrVar **Error, PrefixVar string) {
294
295 xPrefixErrorLiteral(ErrVar, PrefixVar)
296
297}
298
299var xPropagateError func(**Error, *Error)
300
301// If @dest is %NULL, free @src; otherwise, moves @src into `*dest`.
302// The error variable @dest points to must be %NULL.
303//
304// @src must be non-%NULL.
305//
306// Note that @src is no longer valid after this call. If you want
307// to keep using the same GError*, you need to set it to %NULL
308// after calling this function on it.
309func PropagateError(DestVar **Error, SrcVar *Error) {
310
311 xPropagateError(DestVar, SrcVar)
312
313}
314
315var xPropagatePrefixedError func(**Error, *Error, string, ...interface{})
316
317// If @dest is %NULL, free @src; otherwise, moves @src into `*dest`.
318// `*dest` must be %NULL. After the move, add a prefix as with
319// g_prefix_error().
320func PropagatePrefixedError(DestVar **Error, SrcVar *Error, FormatVar string, varArgs ...interface{}) {
321
322 xPropagatePrefixedError(DestVar, SrcVar, FormatVar, varArgs...)
323
324}
325
326var xSetError func(**Error, Quark, int, string, ...interface{})
327
328// Does nothing if @err is %NULL; if @err is non-%NULL, then `*err`
329// must be %NULL. A new #GError is created and assigned to `*err`.
330func SetError(ErrVar **Error, DomainVar Quark, CodeVar int, FormatVar string, varArgs ...interface{}) {
331
332 xSetError(ErrVar, DomainVar, CodeVar, FormatVar, varArgs...)
333
334}
335
336var xSetErrorLiteral func(**Error, Quark, int, string)
337
338// Does nothing if @err is %NULL; if @err is non-%NULL, then `*err`
339// must be %NULL. A new #GError is created and assigned to `*err`.
340// Unlike g_set_error(), @message is not a printf()-style format string.
341// Use this function if @message contains text you don't have control over,
342// that could include printf() escape sequences.
343func SetErrorLiteral(ErrVar **Error, DomainVar Quark, CodeVar int, MessageVar string) {
344
345 xSetErrorLiteral(ErrVar, DomainVar, CodeVar, MessageVar)
346
347}
348
349func init() {
350 core.SetPackageName("GLIB", "glib-2.0")
351 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
352 var libs []uintptr
353 for _, libPath := range core.GetPaths("GLIB") {
354 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
355 if err != nil {
356 panic(err)
357 }
358 libs = append(libs, lib)
359 }
360
361 core.PuregoSafeRegister(&xClearError, libs, "g_clear_error")
362 core.PuregoSafeRegister(&xErrorDomainRegister, libs, "g_error_domain_register")
363 core.PuregoSafeRegister(&xErrorDomainRegisterStatic, libs, "g_error_domain_register_static")
364 core.PuregoSafeRegister(&xPrefixError, libs, "g_prefix_error")
365 core.PuregoSafeRegister(&xPrefixErrorLiteral, libs, "g_prefix_error_literal")
366 core.PuregoSafeRegister(&xPropagateError, libs, "g_propagate_error")
367 core.PuregoSafeRegister(&xPropagatePrefixedError, libs, "g_propagate_prefixed_error")
368 core.PuregoSafeRegister(&xSetError, libs, "g_set_error")
369 core.PuregoSafeRegister(&xSetErrorLiteral, libs, "g_set_error_literal")
370
371 core.PuregoSafeRegister(&xErrorGLibType, libs, "g_error_get_type")
372
373 core.PuregoSafeRegister(&xNewError, libs, "g_error_new")
374 core.PuregoSafeRegister(&xNewErrorLiteral, libs, "g_error_new_literal")
375 core.PuregoSafeRegister(&xNewErrorValist, libs, "g_error_new_valist")
376
377 core.PuregoSafeRegister(&xErrorCopy, libs, "g_error_copy")
378 core.PuregoSafeRegister(&xErrorFree, libs, "g_error_free")
379 core.PuregoSafeRegister(&xErrorMatches, libs, "g_error_matches")
380
381}