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/types"
13)
14
15// The interface for pollable output streams.
16//
17// The default implementation of @can_poll always returns %TRUE.
18//
19// The default implementation of @write_nonblocking calls
20// g_pollable_output_stream_is_writable(), and then calls
21// g_output_stream_write() if it returns %TRUE. This means you only
22// need to override it if it is possible that your @is_writable
23// implementation may return %TRUE when the stream is not actually
24// writable.
25//
26// The default implementation of @writev_nonblocking calls
27// g_pollable_output_stream_write_nonblocking() for each vector, and converts
28// its return value and error (if set) to a #GPollableReturn. You should
29// override this where possible to avoid having to allocate a #GError to return
30// %G_IO_ERROR_WOULD_BLOCK.
31type PollableOutputStreamInterface struct {
32 _ structs.HostLayout
33
34 GIface uintptr
35
36 xCanPoll uintptr
37
38 xIsWritable uintptr
39
40 xCreateSource uintptr
41
42 xWriteNonblocking uintptr
43
44 xWritevNonblocking uintptr
45}
46
47func (x *PollableOutputStreamInterface) GoPointer() uintptr {
48 return uintptr(unsafe.Pointer(x))
49}
50
51// OverrideCanPoll sets the "can_poll" callback function.
52// Checks if the #GPollableOutputStream instance is actually pollable
53func (x *PollableOutputStreamInterface) OverrideCanPoll(cb func(PollableOutputStream) bool) {
54 if cb == nil {
55 x.xCanPoll = 0
56 } else {
57 x.xCanPoll = purego.NewCallback(func(StreamVarp uintptr) bool {
58 return cb(&PollableOutputStreamBase{Ptr: StreamVarp})
59 })
60 }
61}
62
63// GetCanPoll gets the "can_poll" callback function.
64// Checks if the #GPollableOutputStream instance is actually pollable
65func (x *PollableOutputStreamInterface) GetCanPoll() func(PollableOutputStream) bool {
66 if x.xCanPoll == 0 {
67 return nil
68 }
69 var rawCallback func(StreamVarp uintptr) bool
70 purego.RegisterFunc(&rawCallback, x.xCanPoll)
71 return func(StreamVar PollableOutputStream) bool {
72 return rawCallback(StreamVar.GoPointer())
73 }
74}
75
76// OverrideIsWritable sets the "is_writable" callback function.
77// Checks if the stream is writable
78func (x *PollableOutputStreamInterface) OverrideIsWritable(cb func(PollableOutputStream) bool) {
79 if cb == nil {
80 x.xIsWritable = 0
81 } else {
82 x.xIsWritable = purego.NewCallback(func(StreamVarp uintptr) bool {
83 return cb(&PollableOutputStreamBase{Ptr: StreamVarp})
84 })
85 }
86}
87
88// GetIsWritable gets the "is_writable" callback function.
89// Checks if the stream is writable
90func (x *PollableOutputStreamInterface) GetIsWritable() func(PollableOutputStream) bool {
91 if x.xIsWritable == 0 {
92 return nil
93 }
94 var rawCallback func(StreamVarp uintptr) bool
95 purego.RegisterFunc(&rawCallback, x.xIsWritable)
96 return func(StreamVar PollableOutputStream) bool {
97 return rawCallback(StreamVar.GoPointer())
98 }
99}
100
101// OverrideCreateSource sets the "create_source" callback function.
102// Creates a #GSource to poll the stream
103func (x *PollableOutputStreamInterface) OverrideCreateSource(cb func(PollableOutputStream, *Cancellable) *glib.Source) {
104 if cb == nil {
105 x.xCreateSource = 0
106 } else {
107 x.xCreateSource = purego.NewCallback(func(StreamVarp uintptr, CancellableVarp uintptr) *glib.Source {
108 return cb(&PollableOutputStreamBase{Ptr: StreamVarp}, CancellableNewFromInternalPtr(CancellableVarp))
109 })
110 }
111}
112
113// GetCreateSource gets the "create_source" callback function.
114// Creates a #GSource to poll the stream
115func (x *PollableOutputStreamInterface) GetCreateSource() func(PollableOutputStream, *Cancellable) *glib.Source {
116 if x.xCreateSource == 0 {
117 return nil
118 }
119 var rawCallback func(StreamVarp uintptr, CancellableVarp uintptr) *glib.Source
120 purego.RegisterFunc(&rawCallback, x.xCreateSource)
121 return func(StreamVar PollableOutputStream, CancellableVar *Cancellable) *glib.Source {
122 return rawCallback(StreamVar.GoPointer(), CancellableVar.GoPointer())
123 }
124}
125
126// OverrideWriteNonblocking sets the "write_nonblocking" callback function.
127// Does a non-blocking write or returns
128//
129// %G_IO_ERROR_WOULD_BLOCK
130func (x *PollableOutputStreamInterface) OverrideWriteNonblocking(cb func(PollableOutputStream, []byte, uint) int) {
131 if cb == nil {
132 x.xWriteNonblocking = 0
133 } else {
134 x.xWriteNonblocking = purego.NewCallback(func(StreamVarp uintptr, BufferVarp []byte, CountVarp uint) int {
135 return cb(&PollableOutputStreamBase{Ptr: StreamVarp}, BufferVarp, CountVarp)
136 })
137 }
138}
139
140// GetWriteNonblocking gets the "write_nonblocking" callback function.
141// Does a non-blocking write or returns
142//
143// %G_IO_ERROR_WOULD_BLOCK
144func (x *PollableOutputStreamInterface) GetWriteNonblocking() func(PollableOutputStream, []byte, uint) int {
145 if x.xWriteNonblocking == 0 {
146 return nil
147 }
148 var rawCallback func(StreamVarp uintptr, BufferVarp []byte, CountVarp uint) int
149 purego.RegisterFunc(&rawCallback, x.xWriteNonblocking)
150 return func(StreamVar PollableOutputStream, BufferVar []byte, CountVar uint) int {
151 return rawCallback(StreamVar.GoPointer(), BufferVar, CountVar)
152 }
153}
154
155// OverrideWritevNonblocking sets the "writev_nonblocking" callback function.
156// Does a vectored non-blocking write, or returns
157//
158// %G_POLLABLE_RETURN_WOULD_BLOCK
159func (x *PollableOutputStreamInterface) OverrideWritevNonblocking(cb func(PollableOutputStream, []OutputVector, uint, *uint) PollableReturn) {
160 if cb == nil {
161 x.xWritevNonblocking = 0
162 } else {
163 x.xWritevNonblocking = purego.NewCallback(func(StreamVarp uintptr, VectorsVarp []OutputVector, NVectorsVarp uint, BytesWrittenVarp *uint) PollableReturn {
164 return cb(&PollableOutputStreamBase{Ptr: StreamVarp}, VectorsVarp, NVectorsVarp, BytesWrittenVarp)
165 })
166 }
167}
168
169// GetWritevNonblocking gets the "writev_nonblocking" callback function.
170// Does a vectored non-blocking write, or returns
171//
172// %G_POLLABLE_RETURN_WOULD_BLOCK
173func (x *PollableOutputStreamInterface) GetWritevNonblocking() func(PollableOutputStream, []OutputVector, uint, *uint) PollableReturn {
174 if x.xWritevNonblocking == 0 {
175 return nil
176 }
177 var rawCallback func(StreamVarp uintptr, VectorsVarp []OutputVector, NVectorsVarp uint, BytesWrittenVarp *uint) PollableReturn
178 purego.RegisterFunc(&rawCallback, x.xWritevNonblocking)
179 return func(StreamVar PollableOutputStream, VectorsVar []OutputVector, NVectorsVar uint, BytesWrittenVar *uint) PollableReturn {
180 return rawCallback(StreamVar.GoPointer(), VectorsVar, NVectorsVar, BytesWrittenVar)
181 }
182}
183
184// `GPollableOutputStream` is implemented by [class@Gio.OutputStream]s that
185// can be polled for readiness to write. This can be used when
186// interfacing with a non-GIO API that expects
187// UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.
188//
189// Some classes may implement `GPollableOutputStream` but have only certain
190// instances of that class be pollable. If [method@Gio.PollableOutputStream.can_poll]
191// returns false, then the behavior of other `GPollableOutputStream` methods is
192// undefined.
193type PollableOutputStream interface {
194 GoPointer() uintptr
195 SetGoPointer(uintptr)
196 CanPoll() bool
197 CreateSource(CancellableVar *Cancellable) *glib.Source
198 IsWritable() bool
199 WriteNonblocking(BufferVar []byte, CountVar uint, CancellableVar *Cancellable) (int, error)
200 WritevNonblocking(VectorsVar []OutputVector, NVectorsVar uint, BytesWrittenVar *uint, CancellableVar *Cancellable) (PollableReturn, error)
201}
202
203var xPollableOutputStreamGLibType func() types.GType
204
205func PollableOutputStreamGLibType() types.GType {
206 return xPollableOutputStreamGLibType()
207}
208
209type PollableOutputStreamBase struct {
210 Ptr uintptr
211}
212
213func (x *PollableOutputStreamBase) GoPointer() uintptr {
214 if x == nil {
215 return 0
216 }
217 return x.Ptr
218}
219
220func (x *PollableOutputStreamBase) SetGoPointer(ptr uintptr) {
221 x.Ptr = ptr
222}
223
224// Checks if @stream is actually pollable. Some classes may implement
225// #GPollableOutputStream but have only certain instances of that
226// class be pollable. If this method returns %FALSE, then the behavior
227// of other #GPollableOutputStream methods is undefined.
228//
229// For any given stream, the value returned by this method is constant;
230// a stream cannot switch from pollable to non-pollable or vice versa.
231func (x *PollableOutputStreamBase) CanPoll() bool {
232
233 cret := XGPollableOutputStreamCanPoll(x.GoPointer())
234 return cret
235}
236
237// Creates a #GSource that triggers when @stream can be written, or
238// @cancellable is triggered or an error occurs. The callback on the
239// source is of the #GPollableSourceFunc type.
240//
241// As with g_pollable_output_stream_is_writable(), it is possible that
242// the stream may not actually be writable even after the source
243// triggers, so you should use g_pollable_output_stream_write_nonblocking()
244// rather than g_output_stream_write() from the callback.
245//
246// The behaviour of this method is undefined if
247// g_pollable_output_stream_can_poll() returns %FALSE for @stream.
248func (x *PollableOutputStreamBase) CreateSource(CancellableVar *Cancellable) *glib.Source {
249
250 cret := XGPollableOutputStreamCreateSource(x.GoPointer(), CancellableVar.GoPointer())
251 return cret
252}
253
254// Checks if @stream can be written.
255//
256// Note that some stream types may not be able to implement this 100%
257// reliably, and it is possible that a call to g_output_stream_write()
258// after this returns %TRUE would still block. To guarantee
259// non-blocking behavior, you should always use
260// g_pollable_output_stream_write_nonblocking(), which will return a
261// %G_IO_ERROR_WOULD_BLOCK error rather than blocking.
262//
263// The behaviour of this method is undefined if
264// g_pollable_output_stream_can_poll() returns %FALSE for @stream.
265func (x *PollableOutputStreamBase) IsWritable() bool {
266
267 cret := XGPollableOutputStreamIsWritable(x.GoPointer())
268 return cret
269}
270
271// Attempts to write up to @count bytes from @buffer to @stream, as
272// with g_output_stream_write(). If @stream is not currently writable,
273// this will immediately return %G_IO_ERROR_WOULD_BLOCK, and you can
274// use g_pollable_output_stream_create_source() to create a #GSource
275// that will be triggered when @stream is writable.
276//
277// Note that since this method never blocks, you cannot actually
278// use @cancellable to cancel it. However, it will return an error
279// if @cancellable has already been cancelled when you call, which
280// may happen if you call this method after a source triggers due
281// to having been cancelled.
282//
283// Also note that if %G_IO_ERROR_WOULD_BLOCK is returned some underlying
284// transports like D/TLS require that you re-send the same @buffer and
285// @count in the next write call.
286//
287// The behaviour of this method is undefined if
288// g_pollable_output_stream_can_poll() returns %FALSE for @stream.
289func (x *PollableOutputStreamBase) WriteNonblocking(BufferVar []byte, CountVar uint, CancellableVar *Cancellable) (int, error) {
290 var cerr *glib.Error
291
292 cret := XGPollableOutputStreamWriteNonblocking(x.GoPointer(), BufferVar, CountVar, CancellableVar.GoPointer(), &cerr)
293 if cerr == nil {
294 return cret, nil
295 }
296 return cret, cerr
297
298}
299
300// Attempts to write the bytes contained in the @n_vectors @vectors to @stream,
301// as with g_output_stream_writev(). If @stream is not currently writable,
302// this will immediately return %@G_POLLABLE_RETURN_WOULD_BLOCK, and you can
303// use g_pollable_output_stream_create_source() to create a #GSource
304// that will be triggered when @stream is writable. @error will *not* be
305// set in that case.
306//
307// Note that since this method never blocks, you cannot actually
308// use @cancellable to cancel it. However, it will return an error
309// if @cancellable has already been cancelled when you call, which
310// may happen if you call this method after a source triggers due
311// to having been cancelled.
312//
313// Also note that if %G_POLLABLE_RETURN_WOULD_BLOCK is returned some underlying
314// transports like D/TLS require that you re-send the same @vectors and
315// @n_vectors in the next write call.
316//
317// The behaviour of this method is undefined if
318// g_pollable_output_stream_can_poll() returns %FALSE for @stream.
319func (x *PollableOutputStreamBase) WritevNonblocking(VectorsVar []OutputVector, NVectorsVar uint, BytesWrittenVar *uint, CancellableVar *Cancellable) (PollableReturn, error) {
320 var cerr *glib.Error
321
322 cret := XGPollableOutputStreamWritevNonblocking(x.GoPointer(), VectorsVar, NVectorsVar, BytesWrittenVar, CancellableVar.GoPointer(), &cerr)
323 if cerr == nil {
324 return cret, nil
325 }
326 return cret, cerr
327
328}
329
330var XGPollableOutputStreamCanPoll func(uintptr) bool
331var XGPollableOutputStreamCreateSource func(uintptr, uintptr) *glib.Source
332var XGPollableOutputStreamIsWritable func(uintptr) bool
333var XGPollableOutputStreamWriteNonblocking func(uintptr, []byte, uint, uintptr, **glib.Error) int
334var XGPollableOutputStreamWritevNonblocking func(uintptr, []OutputVector, uint, *uint, uintptr, **glib.Error) PollableReturn
335
336func init() {
337 core.SetPackageName("GIO", "gio-2.0")
338 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
339 var libs []uintptr
340 for _, libPath := range core.GetPaths("GIO") {
341 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
342 if err != nil {
343 panic(err)
344 }
345 libs = append(libs, lib)
346 }
347
348 core.PuregoSafeRegister(&xPollableOutputStreamGLibType, libs, "g_pollable_output_stream_get_type")
349
350 core.PuregoSafeRegister(&XGPollableOutputStreamCanPoll, libs, "g_pollable_output_stream_can_poll")
351 core.PuregoSafeRegister(&XGPollableOutputStreamCreateSource, libs, "g_pollable_output_stream_create_source")
352 core.PuregoSafeRegister(&XGPollableOutputStreamIsWritable, libs, "g_pollable_output_stream_is_writable")
353 core.PuregoSafeRegister(&XGPollableOutputStreamWriteNonblocking, libs, "g_pollable_output_stream_write_nonblocking")
354 core.PuregoSafeRegister(&XGPollableOutputStreamWritevNonblocking, libs, "g_pollable_output_stream_writev_nonblocking")
355
356}