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// Class structure for #GSocketAddressEnumerator.
17type SocketAddressEnumeratorClass struct {
18 _ structs.HostLayout
19
20 ParentClass gobject.ObjectClass
21
22 xNext uintptr
23
24 xNextAsync uintptr
25
26 xNextFinish uintptr
27}
28
29func (x *SocketAddressEnumeratorClass) GoPointer() uintptr {
30 return uintptr(unsafe.Pointer(x))
31}
32
33// OverrideNext sets the "next" callback function.
34// Virtual method for g_socket_address_enumerator_next().
35func (x *SocketAddressEnumeratorClass) OverrideNext(cb func(*SocketAddressEnumerator, *Cancellable) *SocketAddress) {
36 if cb == nil {
37 x.xNext = 0
38 } else {
39 x.xNext = purego.NewCallback(func(EnumeratorVarp uintptr, CancellableVarp uintptr) uintptr {
40 ret := cb(SocketAddressEnumeratorNewFromInternalPtr(EnumeratorVarp), CancellableNewFromInternalPtr(CancellableVarp))
41 if ret == nil {
42 return 0
43 }
44 return ret.GoPointer()
45 })
46 }
47}
48
49// GetNext gets the "next" callback function.
50// Virtual method for g_socket_address_enumerator_next().
51func (x *SocketAddressEnumeratorClass) GetNext() func(*SocketAddressEnumerator, *Cancellable) *SocketAddress {
52 if x.xNext == 0 {
53 return nil
54 }
55 var rawCallback func(EnumeratorVarp uintptr, CancellableVarp uintptr) uintptr
56 purego.RegisterFunc(&rawCallback, x.xNext)
57 return func(EnumeratorVar *SocketAddressEnumerator, CancellableVar *Cancellable) *SocketAddress {
58 rawRet := rawCallback(EnumeratorVar.GoPointer(), CancellableVar.GoPointer())
59 if rawRet == 0 {
60 return nil
61 }
62 ret := &SocketAddress{}
63 ret.Ptr = rawRet
64 return ret
65 }
66}
67
68// OverrideNextAsync sets the "next_async" callback function.
69// Virtual method for g_socket_address_enumerator_next_async().
70func (x *SocketAddressEnumeratorClass) OverrideNextAsync(cb func(*SocketAddressEnumerator, *Cancellable, *AsyncReadyCallback, uintptr)) {
71 if cb == nil {
72 x.xNextAsync = 0
73 } else {
74 x.xNextAsync = purego.NewCallback(func(EnumeratorVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
75 cb(SocketAddressEnumeratorNewFromInternalPtr(EnumeratorVarp), CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
76 })
77 }
78}
79
80// GetNextAsync gets the "next_async" callback function.
81// Virtual method for g_socket_address_enumerator_next_async().
82func (x *SocketAddressEnumeratorClass) GetNextAsync() func(*SocketAddressEnumerator, *Cancellable, *AsyncReadyCallback, uintptr) {
83 if x.xNextAsync == 0 {
84 return nil
85 }
86 var rawCallback func(EnumeratorVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
87 purego.RegisterFunc(&rawCallback, x.xNextAsync)
88 return func(EnumeratorVar *SocketAddressEnumerator, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
89 rawCallback(EnumeratorVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
90 }
91}
92
93// OverrideNextFinish sets the "next_finish" callback function.
94// Virtual method for g_socket_address_enumerator_next_finish().
95func (x *SocketAddressEnumeratorClass) OverrideNextFinish(cb func(*SocketAddressEnumerator, AsyncResult) *SocketAddress) {
96 if cb == nil {
97 x.xNextFinish = 0
98 } else {
99 x.xNextFinish = purego.NewCallback(func(EnumeratorVarp uintptr, ResultVarp uintptr) uintptr {
100 ret := cb(SocketAddressEnumeratorNewFromInternalPtr(EnumeratorVarp), &AsyncResultBase{Ptr: ResultVarp})
101 if ret == nil {
102 return 0
103 }
104 return ret.GoPointer()
105 })
106 }
107}
108
109// GetNextFinish gets the "next_finish" callback function.
110// Virtual method for g_socket_address_enumerator_next_finish().
111func (x *SocketAddressEnumeratorClass) GetNextFinish() func(*SocketAddressEnumerator, AsyncResult) *SocketAddress {
112 if x.xNextFinish == 0 {
113 return nil
114 }
115 var rawCallback func(EnumeratorVarp uintptr, ResultVarp uintptr) uintptr
116 purego.RegisterFunc(&rawCallback, x.xNextFinish)
117 return func(EnumeratorVar *SocketAddressEnumerator, ResultVar AsyncResult) *SocketAddress {
118 rawRet := rawCallback(EnumeratorVar.GoPointer(), ResultVar.GoPointer())
119 if rawRet == 0 {
120 return nil
121 }
122 ret := &SocketAddress{}
123 ret.Ptr = rawRet
124 return ret
125 }
126}
127
128// `GSocketAddressEnumerator` is an enumerator type for
129// [class@Gio.SocketAddress] instances. It is returned by enumeration functions
130// such as [method@Gio.SocketConnectable.enumerate], which returns a
131// `GSocketAddressEnumerator` to list each [class@Gio.SocketAddress] which could
132// be used to connect to that [iface@Gio.SocketConnectable].
133//
134// Enumeration is typically a blocking operation, so the asynchronous methods
135// [method@Gio.SocketAddressEnumerator.next_async] and
136// [method@Gio.SocketAddressEnumerator.next_finish] should be used where
137// possible.
138//
139// Each `GSocketAddressEnumerator` can only be enumerated once. Once
140// [method@Gio.SocketAddressEnumerator.next] has returned `NULL`, further
141// enumeration with that `GSocketAddressEnumerator` is not possible, and it can
142// be unreffed.
143type SocketAddressEnumerator struct {
144 gobject.Object
145}
146
147var xSocketAddressEnumeratorGLibType func() types.GType
148
149func SocketAddressEnumeratorGLibType() types.GType {
150 return xSocketAddressEnumeratorGLibType()
151}
152
153func SocketAddressEnumeratorNewFromInternalPtr(ptr uintptr) *SocketAddressEnumerator {
154 cls := &SocketAddressEnumerator{}
155 cls.Ptr = ptr
156 return cls
157}
158
159var xSocketAddressEnumeratorNext func(uintptr, uintptr, **glib.Error) uintptr
160
161// Retrieves the next #GSocketAddress from @enumerator. Note that this
162// may block for some amount of time. (Eg, a #GNetworkAddress may need
163// to do a DNS lookup before it can return an address.) Use
164// g_socket_address_enumerator_next_async() if you need to avoid
165// blocking.
166//
167// If @enumerator is expected to yield addresses, but for some reason
168// is unable to (eg, because of a DNS error), then the first call to
169// g_socket_address_enumerator_next() will return an appropriate error
170// in `*error`. However, if the first call to
171// g_socket_address_enumerator_next() succeeds, then any further
172// internal errors (other than @cancellable being triggered) will be
173// ignored.
174func (x *SocketAddressEnumerator) Next(CancellableVar *Cancellable) (*SocketAddress, error) {
175 var cls *SocketAddress
176 var cerr *glib.Error
177
178 cret := xSocketAddressEnumeratorNext(x.GoPointer(), CancellableVar.GoPointer(), &cerr)
179
180 if cret == 0 {
181 return nil, cerr
182 }
183 cls = &SocketAddress{}
184 cls.Ptr = cret
185 if cerr == nil {
186 return cls, nil
187 }
188 return cls, cerr
189
190}
191
192var xSocketAddressEnumeratorNextAsync func(uintptr, uintptr, uintptr, uintptr)
193
194// Asynchronously retrieves the next #GSocketAddress from @enumerator
195// and then calls @callback, which must call
196// g_socket_address_enumerator_next_finish() to get the result.
197//
198// It is an error to call this multiple times before the previous callback has finished.
199func (x *SocketAddressEnumerator) NextAsync(CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
200
201 var CallbackVarRef uintptr
202 if CallbackVar != nil {
203 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
204 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
205 CallbackVarRef = cbRefPtr
206 } else {
207 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
208 cbFn := *CallbackVar
209 cbFn(arg0, arg1, arg2)
210 }
211 CallbackVarRef = purego.NewCallback(fcb)
212 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
213 }
214 }
215
216 xSocketAddressEnumeratorNextAsync(x.GoPointer(), CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
217
218}
219
220var xSocketAddressEnumeratorNextFinish func(uintptr, uintptr, **glib.Error) uintptr
221
222// Retrieves the result of a completed call to
223// g_socket_address_enumerator_next_async(). See
224// g_socket_address_enumerator_next() for more information about
225// error handling.
226func (x *SocketAddressEnumerator) NextFinish(ResultVar AsyncResult) (*SocketAddress, error) {
227 var cls *SocketAddress
228 var cerr *glib.Error
229
230 cret := xSocketAddressEnumeratorNextFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
231
232 if cret == 0 {
233 return nil, cerr
234 }
235 cls = &SocketAddress{}
236 cls.Ptr = cret
237 if cerr == nil {
238 return cls, nil
239 }
240 return cls, cerr
241
242}
243
244func (c *SocketAddressEnumerator) GoPointer() uintptr {
245 if c == nil {
246 return 0
247 }
248 return c.Ptr
249}
250
251func (c *SocketAddressEnumerator) SetGoPointer(ptr uintptr) {
252 c.Ptr = ptr
253}
254
255func init() {
256 core.SetPackageName("GIO", "gio-2.0")
257 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
258 var libs []uintptr
259 for _, libPath := range core.GetPaths("GIO") {
260 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
261 if err != nil {
262 panic(err)
263 }
264 libs = append(libs, lib)
265 }
266
267 core.PuregoSafeRegister(&xSocketAddressEnumeratorGLibType, libs, "g_socket_address_enumerator_get_type")
268
269 core.PuregoSafeRegister(&xSocketAddressEnumeratorNext, libs, "g_socket_address_enumerator_next")
270 core.PuregoSafeRegister(&xSocketAddressEnumeratorNextAsync, libs, "g_socket_address_enumerator_next_async")
271 core.PuregoSafeRegister(&xSocketAddressEnumeratorNextFinish, libs, "g_socket_address_enumerator_next_finish")
272
273}