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
16type InputStreamClass struct {
17 _ structs.HostLayout
18
19 ParentClass gobject.ObjectClass
20
21 xReadFn uintptr
22
23 xSkip uintptr
24
25 xCloseFn uintptr
26
27 xReadAsync uintptr
28
29 xReadFinish uintptr
30
31 xSkipAsync uintptr
32
33 xSkipFinish uintptr
34
35 xCloseAsync uintptr
36
37 xCloseFinish uintptr
38
39 xGReserved1 uintptr
40
41 xGReserved2 uintptr
42
43 xGReserved3 uintptr
44
45 xGReserved4 uintptr
46
47 xGReserved5 uintptr
48}
49
50func (x *InputStreamClass) GoPointer() uintptr {
51 return uintptr(unsafe.Pointer(x))
52}
53
54// OverrideReadFn sets the "read_fn" callback function.
55func (x *InputStreamClass) OverrideReadFn(cb func(*InputStream, uintptr, uint, *Cancellable) int) {
56 if cb == nil {
57 x.xReadFn = 0
58 } else {
59 x.xReadFn = purego.NewCallback(func(StreamVarp uintptr, BufferVarp uintptr, CountVarp uint, CancellableVarp uintptr) int {
60 return cb(InputStreamNewFromInternalPtr(StreamVarp), BufferVarp, CountVarp, CancellableNewFromInternalPtr(CancellableVarp))
61 })
62 }
63}
64
65// GetReadFn gets the "read_fn" callback function.
66func (x *InputStreamClass) GetReadFn() func(*InputStream, uintptr, uint, *Cancellable) int {
67 if x.xReadFn == 0 {
68 return nil
69 }
70 var rawCallback func(StreamVarp uintptr, BufferVarp uintptr, CountVarp uint, CancellableVarp uintptr) int
71 purego.RegisterFunc(&rawCallback, x.xReadFn)
72 return func(StreamVar *InputStream, BufferVar uintptr, CountVar uint, CancellableVar *Cancellable) int {
73 return rawCallback(StreamVar.GoPointer(), BufferVar, CountVar, CancellableVar.GoPointer())
74 }
75}
76
77// OverrideSkip sets the "skip" callback function.
78func (x *InputStreamClass) OverrideSkip(cb func(*InputStream, uint, *Cancellable) int) {
79 if cb == nil {
80 x.xSkip = 0
81 } else {
82 x.xSkip = purego.NewCallback(func(StreamVarp uintptr, CountVarp uint, CancellableVarp uintptr) int {
83 return cb(InputStreamNewFromInternalPtr(StreamVarp), CountVarp, CancellableNewFromInternalPtr(CancellableVarp))
84 })
85 }
86}
87
88// GetSkip gets the "skip" callback function.
89func (x *InputStreamClass) GetSkip() func(*InputStream, uint, *Cancellable) int {
90 if x.xSkip == 0 {
91 return nil
92 }
93 var rawCallback func(StreamVarp uintptr, CountVarp uint, CancellableVarp uintptr) int
94 purego.RegisterFunc(&rawCallback, x.xSkip)
95 return func(StreamVar *InputStream, CountVar uint, CancellableVar *Cancellable) int {
96 return rawCallback(StreamVar.GoPointer(), CountVar, CancellableVar.GoPointer())
97 }
98}
99
100// OverrideCloseFn sets the "close_fn" callback function.
101func (x *InputStreamClass) OverrideCloseFn(cb func(*InputStream, *Cancellable) bool) {
102 if cb == nil {
103 x.xCloseFn = 0
104 } else {
105 x.xCloseFn = purego.NewCallback(func(StreamVarp uintptr, CancellableVarp uintptr) bool {
106 return cb(InputStreamNewFromInternalPtr(StreamVarp), CancellableNewFromInternalPtr(CancellableVarp))
107 })
108 }
109}
110
111// GetCloseFn gets the "close_fn" callback function.
112func (x *InputStreamClass) GetCloseFn() func(*InputStream, *Cancellable) bool {
113 if x.xCloseFn == 0 {
114 return nil
115 }
116 var rawCallback func(StreamVarp uintptr, CancellableVarp uintptr) bool
117 purego.RegisterFunc(&rawCallback, x.xCloseFn)
118 return func(StreamVar *InputStream, CancellableVar *Cancellable) bool {
119 return rawCallback(StreamVar.GoPointer(), CancellableVar.GoPointer())
120 }
121}
122
123// OverrideReadAsync sets the "read_async" callback function.
124func (x *InputStreamClass) OverrideReadAsync(cb func(*InputStream, *[]byte, uint, int, *Cancellable, *AsyncReadyCallback, uintptr)) {
125 if cb == nil {
126 x.xReadAsync = 0
127 } else {
128 x.xReadAsync = purego.NewCallback(func(StreamVarp uintptr, BufferVarp *[]byte, CountVarp uint, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
129 cb(InputStreamNewFromInternalPtr(StreamVarp), BufferVarp, CountVarp, IoPriorityVarp, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
130 })
131 }
132}
133
134// GetReadAsync gets the "read_async" callback function.
135func (x *InputStreamClass) GetReadAsync() func(*InputStream, *[]byte, uint, int, *Cancellable, *AsyncReadyCallback, uintptr) {
136 if x.xReadAsync == 0 {
137 return nil
138 }
139 var rawCallback func(StreamVarp uintptr, BufferVarp *[]byte, CountVarp uint, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
140 purego.RegisterFunc(&rawCallback, x.xReadAsync)
141 return func(StreamVar *InputStream, BufferVar *[]byte, CountVar uint, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
142 rawCallback(StreamVar.GoPointer(), BufferVar, CountVar, IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
143 }
144}
145
146// OverrideReadFinish sets the "read_finish" callback function.
147func (x *InputStreamClass) OverrideReadFinish(cb func(*InputStream, AsyncResult) int) {
148 if cb == nil {
149 x.xReadFinish = 0
150 } else {
151 x.xReadFinish = purego.NewCallback(func(StreamVarp uintptr, ResultVarp uintptr) int {
152 return cb(InputStreamNewFromInternalPtr(StreamVarp), &AsyncResultBase{Ptr: ResultVarp})
153 })
154 }
155}
156
157// GetReadFinish gets the "read_finish" callback function.
158func (x *InputStreamClass) GetReadFinish() func(*InputStream, AsyncResult) int {
159 if x.xReadFinish == 0 {
160 return nil
161 }
162 var rawCallback func(StreamVarp uintptr, ResultVarp uintptr) int
163 purego.RegisterFunc(&rawCallback, x.xReadFinish)
164 return func(StreamVar *InputStream, ResultVar AsyncResult) int {
165 return rawCallback(StreamVar.GoPointer(), ResultVar.GoPointer())
166 }
167}
168
169// OverrideSkipAsync sets the "skip_async" callback function.
170func (x *InputStreamClass) OverrideSkipAsync(cb func(*InputStream, uint, int, *Cancellable, *AsyncReadyCallback, uintptr)) {
171 if cb == nil {
172 x.xSkipAsync = 0
173 } else {
174 x.xSkipAsync = purego.NewCallback(func(StreamVarp uintptr, CountVarp uint, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
175 cb(InputStreamNewFromInternalPtr(StreamVarp), CountVarp, IoPriorityVarp, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
176 })
177 }
178}
179
180// GetSkipAsync gets the "skip_async" callback function.
181func (x *InputStreamClass) GetSkipAsync() func(*InputStream, uint, int, *Cancellable, *AsyncReadyCallback, uintptr) {
182 if x.xSkipAsync == 0 {
183 return nil
184 }
185 var rawCallback func(StreamVarp uintptr, CountVarp uint, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
186 purego.RegisterFunc(&rawCallback, x.xSkipAsync)
187 return func(StreamVar *InputStream, CountVar uint, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
188 rawCallback(StreamVar.GoPointer(), CountVar, IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
189 }
190}
191
192// OverrideSkipFinish sets the "skip_finish" callback function.
193func (x *InputStreamClass) OverrideSkipFinish(cb func(*InputStream, AsyncResult) int) {
194 if cb == nil {
195 x.xSkipFinish = 0
196 } else {
197 x.xSkipFinish = purego.NewCallback(func(StreamVarp uintptr, ResultVarp uintptr) int {
198 return cb(InputStreamNewFromInternalPtr(StreamVarp), &AsyncResultBase{Ptr: ResultVarp})
199 })
200 }
201}
202
203// GetSkipFinish gets the "skip_finish" callback function.
204func (x *InputStreamClass) GetSkipFinish() func(*InputStream, AsyncResult) int {
205 if x.xSkipFinish == 0 {
206 return nil
207 }
208 var rawCallback func(StreamVarp uintptr, ResultVarp uintptr) int
209 purego.RegisterFunc(&rawCallback, x.xSkipFinish)
210 return func(StreamVar *InputStream, ResultVar AsyncResult) int {
211 return rawCallback(StreamVar.GoPointer(), ResultVar.GoPointer())
212 }
213}
214
215// OverrideCloseAsync sets the "close_async" callback function.
216func (x *InputStreamClass) OverrideCloseAsync(cb func(*InputStream, int, *Cancellable, *AsyncReadyCallback, uintptr)) {
217 if cb == nil {
218 x.xCloseAsync = 0
219 } else {
220 x.xCloseAsync = purego.NewCallback(func(StreamVarp uintptr, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
221 cb(InputStreamNewFromInternalPtr(StreamVarp), IoPriorityVarp, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
222 })
223 }
224}
225
226// GetCloseAsync gets the "close_async" callback function.
227func (x *InputStreamClass) GetCloseAsync() func(*InputStream, int, *Cancellable, *AsyncReadyCallback, uintptr) {
228 if x.xCloseAsync == 0 {
229 return nil
230 }
231 var rawCallback func(StreamVarp uintptr, IoPriorityVarp int, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
232 purego.RegisterFunc(&rawCallback, x.xCloseAsync)
233 return func(StreamVar *InputStream, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
234 rawCallback(StreamVar.GoPointer(), IoPriorityVar, CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
235 }
236}
237
238// OverrideCloseFinish sets the "close_finish" callback function.
239func (x *InputStreamClass) OverrideCloseFinish(cb func(*InputStream, AsyncResult) bool) {
240 if cb == nil {
241 x.xCloseFinish = 0
242 } else {
243 x.xCloseFinish = purego.NewCallback(func(StreamVarp uintptr, ResultVarp uintptr) bool {
244 return cb(InputStreamNewFromInternalPtr(StreamVarp), &AsyncResultBase{Ptr: ResultVarp})
245 })
246 }
247}
248
249// GetCloseFinish gets the "close_finish" callback function.
250func (x *InputStreamClass) GetCloseFinish() func(*InputStream, AsyncResult) bool {
251 if x.xCloseFinish == 0 {
252 return nil
253 }
254 var rawCallback func(StreamVarp uintptr, ResultVarp uintptr) bool
255 purego.RegisterFunc(&rawCallback, x.xCloseFinish)
256 return func(StreamVar *InputStream, ResultVar AsyncResult) bool {
257 return rawCallback(StreamVar.GoPointer(), ResultVar.GoPointer())
258 }
259}
260
261// OverrideGReserved1 sets the "_g_reserved1" callback function.
262func (x *InputStreamClass) OverrideGReserved1(cb func()) {
263 if cb == nil {
264 x.xGReserved1 = 0
265 } else {
266 x.xGReserved1 = purego.NewCallback(func() {
267 cb()
268 })
269 }
270}
271
272// GetGReserved1 gets the "_g_reserved1" callback function.
273func (x *InputStreamClass) GetGReserved1() func() {
274 if x.xGReserved1 == 0 {
275 return nil
276 }
277 var rawCallback func()
278 purego.RegisterFunc(&rawCallback, x.xGReserved1)
279 return func() {
280 rawCallback()
281 }
282}
283
284// OverrideGReserved2 sets the "_g_reserved2" callback function.
285func (x *InputStreamClass) OverrideGReserved2(cb func()) {
286 if cb == nil {
287 x.xGReserved2 = 0
288 } else {
289 x.xGReserved2 = purego.NewCallback(func() {
290 cb()
291 })
292 }
293}
294
295// GetGReserved2 gets the "_g_reserved2" callback function.
296func (x *InputStreamClass) GetGReserved2() func() {
297 if x.xGReserved2 == 0 {
298 return nil
299 }
300 var rawCallback func()
301 purego.RegisterFunc(&rawCallback, x.xGReserved2)
302 return func() {
303 rawCallback()
304 }
305}
306
307// OverrideGReserved3 sets the "_g_reserved3" callback function.
308func (x *InputStreamClass) OverrideGReserved3(cb func()) {
309 if cb == nil {
310 x.xGReserved3 = 0
311 } else {
312 x.xGReserved3 = purego.NewCallback(func() {
313 cb()
314 })
315 }
316}
317
318// GetGReserved3 gets the "_g_reserved3" callback function.
319func (x *InputStreamClass) GetGReserved3() func() {
320 if x.xGReserved3 == 0 {
321 return nil
322 }
323 var rawCallback func()
324 purego.RegisterFunc(&rawCallback, x.xGReserved3)
325 return func() {
326 rawCallback()
327 }
328}
329
330// OverrideGReserved4 sets the "_g_reserved4" callback function.
331func (x *InputStreamClass) OverrideGReserved4(cb func()) {
332 if cb == nil {
333 x.xGReserved4 = 0
334 } else {
335 x.xGReserved4 = purego.NewCallback(func() {
336 cb()
337 })
338 }
339}
340
341// GetGReserved4 gets the "_g_reserved4" callback function.
342func (x *InputStreamClass) GetGReserved4() func() {
343 if x.xGReserved4 == 0 {
344 return nil
345 }
346 var rawCallback func()
347 purego.RegisterFunc(&rawCallback, x.xGReserved4)
348 return func() {
349 rawCallback()
350 }
351}
352
353// OverrideGReserved5 sets the "_g_reserved5" callback function.
354func (x *InputStreamClass) OverrideGReserved5(cb func()) {
355 if cb == nil {
356 x.xGReserved5 = 0
357 } else {
358 x.xGReserved5 = purego.NewCallback(func() {
359 cb()
360 })
361 }
362}
363
364// GetGReserved5 gets the "_g_reserved5" callback function.
365func (x *InputStreamClass) GetGReserved5() func() {
366 if x.xGReserved5 == 0 {
367 return nil
368 }
369 var rawCallback func()
370 purego.RegisterFunc(&rawCallback, x.xGReserved5)
371 return func() {
372 rawCallback()
373 }
374}
375
376type InputStreamPrivate struct {
377 _ structs.HostLayout
378}
379
380func (x *InputStreamPrivate) GoPointer() uintptr {
381 return uintptr(unsafe.Pointer(x))
382}
383
384// `GInputStream` is a base class for implementing streaming input.
385//
386// It has functions to read from a stream ([method@Gio.InputStream.read]),
387// to close a stream ([method@Gio.InputStream.close]) and to skip some content
388// ([method@Gio.InputStream.skip]).
389//
390// To copy the content of an input stream to an output stream without
391// manually handling the reads and writes, use [method@Gio.OutputStream.splice].
392//
393// See the documentation for [class@Gio.IOStream] for details of thread safety
394// of streaming APIs.
395//
396// All of these functions have async variants too.
397type InputStream struct {
398 gobject.Object
399}
400
401var xInputStreamGLibType func() types.GType
402
403func InputStreamGLibType() types.GType {
404 return xInputStreamGLibType()
405}
406
407func InputStreamNewFromInternalPtr(ptr uintptr) *InputStream {
408 cls := &InputStream{}
409 cls.Ptr = ptr
410 return cls
411}
412
413var xInputStreamClearPending func(uintptr)
414
415// Clears the pending flag on @stream.
416func (x *InputStream) ClearPending() {
417
418 xInputStreamClearPending(x.GoPointer())
419
420}
421
422var xInputStreamClose func(uintptr, uintptr, **glib.Error) bool
423
424// Closes the stream, releasing resources related to it.
425//
426// Once the stream is closed, all other operations will return %G_IO_ERROR_CLOSED.
427// Closing a stream multiple times will not return an error.
428//
429// Streams will be automatically closed when the last reference
430// is dropped, but you might want to call this function to make sure
431// resources are released as early as possible.
432//
433// Some streams might keep the backing store of the stream (e.g. a file descriptor)
434// open after the stream is closed. See the documentation for the individual
435// stream for details.
436//
437// On failure the first error that happened will be reported, but the close
438// operation will finish as much as possible. A stream that failed to
439// close will still return %G_IO_ERROR_CLOSED for all operations. Still, it
440// is important to check and report the error to the user.
441//
442// If @cancellable is not %NULL, then the operation can be cancelled by
443// triggering the cancellable object from another thread. If the operation
444// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
445// Cancelling a close will still leave the stream closed, but some streams
446// can use a faster close that doesn't block to e.g. check errors.
447func (x *InputStream) Close(CancellableVar *Cancellable) (bool, error) {
448 var cerr *glib.Error
449
450 cret := xInputStreamClose(x.GoPointer(), CancellableVar.GoPointer(), &cerr)
451 if cerr == nil {
452 return cret, nil
453 }
454 return cret, cerr
455
456}
457
458var xInputStreamCloseAsync func(uintptr, int, uintptr, uintptr, uintptr)
459
460// Requests an asynchronous closes of the stream, releasing resources related to it.
461// When the operation is finished @callback will be called.
462// You can then call g_input_stream_close_finish() to get the result of the
463// operation.
464//
465// For behaviour details see g_input_stream_close().
466//
467// The asynchronous methods have a default fallback that uses threads to implement
468// asynchronicity, so they are optional for inheriting classes. However, if you
469// override one you must override all.
470func (x *InputStream) CloseAsync(IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
471
472 var CallbackVarRef uintptr
473 if CallbackVar != nil {
474 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
475 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
476 CallbackVarRef = cbRefPtr
477 } else {
478 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
479 cbFn := *CallbackVar
480 cbFn(arg0, arg1, arg2)
481 }
482 CallbackVarRef = purego.NewCallback(fcb)
483 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
484 }
485 }
486
487 xInputStreamCloseAsync(x.GoPointer(), IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
488
489}
490
491var xInputStreamCloseFinish func(uintptr, uintptr, **glib.Error) bool
492
493// Finishes closing a stream asynchronously, started from g_input_stream_close_async().
494func (x *InputStream) CloseFinish(ResultVar AsyncResult) (bool, error) {
495 var cerr *glib.Error
496
497 cret := xInputStreamCloseFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
498 if cerr == nil {
499 return cret, nil
500 }
501 return cret, cerr
502
503}
504
505var xInputStreamHasPending func(uintptr) bool
506
507// Checks if an input stream has pending actions.
508func (x *InputStream) HasPending() bool {
509
510 cret := xInputStreamHasPending(x.GoPointer())
511 return cret
512}
513
514var xInputStreamIsClosed func(uintptr) bool
515
516// Checks if an input stream is closed.
517func (x *InputStream) IsClosed() bool {
518
519 cret := xInputStreamIsClosed(x.GoPointer())
520 return cret
521}
522
523var xInputStreamRead func(uintptr, *[]byte, uint, uintptr, **glib.Error) int
524
525// Tries to read @count bytes from the stream into the buffer starting at
526// @buffer. Will block during this read.
527//
528// If count is zero returns zero and does nothing. A value of @count
529// larger than %G_MAXSSIZE will cause a %G_IO_ERROR_INVALID_ARGUMENT error.
530//
531// On success, the number of bytes read into the buffer is returned.
532// It is not an error if this is not the same as the requested size, as it
533// can happen e.g. near the end of a file. Zero is returned on end of file
534// (or if @count is zero), but never otherwise.
535//
536// The returned @buffer is not a nul-terminated string, it can contain nul bytes
537// at any position, and this function doesn't nul-terminate the @buffer.
538//
539// If @cancellable is not %NULL, then the operation can be cancelled by
540// triggering the cancellable object from another thread. If the operation
541// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
542// operation was partially finished when the operation was cancelled the
543// partial result will be returned, without an error.
544//
545// On error -1 is returned and @error is set accordingly.
546func (x *InputStream) Read(BufferVar *[]byte, CountVar uint, CancellableVar *Cancellable) (int, error) {
547 var cerr *glib.Error
548
549 cret := xInputStreamRead(x.GoPointer(), BufferVar, CountVar, CancellableVar.GoPointer(), &cerr)
550 if cerr == nil {
551 return cret, nil
552 }
553 return cret, cerr
554
555}
556
557var xInputStreamReadAll func(uintptr, *[]byte, uint, *uint, uintptr, **glib.Error) bool
558
559// Tries to read @count bytes from the stream into the buffer starting at
560// @buffer. Will block during this read.
561//
562// This function is similar to g_input_stream_read(), except it tries to
563// read as many bytes as requested, only stopping on an error or end of stream.
564//
565// On a successful read of @count bytes, or if we reached the end of the
566// stream, %TRUE is returned, and @bytes_read is set to the number of bytes
567// read into @buffer.
568//
569// If there is an error during the operation %FALSE is returned and @error
570// is set to indicate the error status.
571//
572// As a special exception to the normal conventions for functions that
573// use #GError, if this function returns %FALSE (and sets @error) then
574// @bytes_read will be set to the number of bytes that were successfully
575// read before the error was encountered. This functionality is only
576// available from C. If you need it from another language then you must
577// write your own loop around g_input_stream_read().
578func (x *InputStream) ReadAll(BufferVar *[]byte, CountVar uint, BytesReadVar *uint, CancellableVar *Cancellable) (bool, error) {
579 var cerr *glib.Error
580
581 cret := xInputStreamReadAll(x.GoPointer(), BufferVar, CountVar, BytesReadVar, CancellableVar.GoPointer(), &cerr)
582 if cerr == nil {
583 return cret, nil
584 }
585 return cret, cerr
586
587}
588
589var xInputStreamReadAllAsync func(uintptr, *[]byte, uint, int, uintptr, uintptr, uintptr)
590
591// Request an asynchronous read of @count bytes from the stream into the
592// buffer starting at @buffer.
593//
594// This is the asynchronous equivalent of [method@InputStream.read_all].
595//
596// Call [method@InputStream.read_all_finish] to collect the result.
597//
598// Any outstanding I/O request with higher priority (lower numerical
599// value) will be executed before an outstanding request with lower
600// priority. Default priority is %G_PRIORITY_DEFAULT.
601func (x *InputStream) ReadAllAsync(BufferVar *[]byte, CountVar uint, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
602
603 var CallbackVarRef uintptr
604 if CallbackVar != nil {
605 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
606 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
607 CallbackVarRef = cbRefPtr
608 } else {
609 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
610 cbFn := *CallbackVar
611 cbFn(arg0, arg1, arg2)
612 }
613 CallbackVarRef = purego.NewCallback(fcb)
614 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
615 }
616 }
617
618 xInputStreamReadAllAsync(x.GoPointer(), BufferVar, CountVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
619
620}
621
622var xInputStreamReadAllFinish func(uintptr, uintptr, *uint, **glib.Error) bool
623
624// Finishes an asynchronous stream read operation started with
625// [method@InputStream.read_all_async].
626//
627// As a special exception to the normal conventions for functions that
628// use #GError, if this function returns %FALSE (and sets @error) then
629// @bytes_read will be set to the number of bytes that were successfully
630// read before the error was encountered. This functionality is only
631// available from C. If you need it from another language then you must
632// write your own loop around g_input_stream_read_async().
633func (x *InputStream) ReadAllFinish(ResultVar AsyncResult, BytesReadVar *uint) (bool, error) {
634 var cerr *glib.Error
635
636 cret := xInputStreamReadAllFinish(x.GoPointer(), ResultVar.GoPointer(), BytesReadVar, &cerr)
637 if cerr == nil {
638 return cret, nil
639 }
640 return cret, cerr
641
642}
643
644var xInputStreamReadAsync func(uintptr, *[]byte, uint, int, uintptr, uintptr, uintptr)
645
646// Request an asynchronous read of @count bytes from the stream into the buffer
647// starting at @buffer. When the operation is finished @callback will be called.
648// You can then call g_input_stream_read_finish() to get the result of the
649// operation.
650//
651// During an async request no other sync and async calls are allowed on @stream, and will
652// result in %G_IO_ERROR_PENDING errors.
653//
654// A value of @count larger than %G_MAXSSIZE will cause a %G_IO_ERROR_INVALID_ARGUMENT error.
655//
656// On success, the number of bytes read into the buffer will be passed to the
657// callback. It is not an error if this is not the same as the requested size, as it
658// can happen e.g. near the end of a file, but generally we try to read
659// as many bytes as requested. Zero is returned on end of file
660// (or if @count is zero), but never otherwise.
661//
662// Any outstanding i/o request with higher priority (lower numerical value) will
663// be executed before an outstanding request with lower priority. Default
664// priority is %G_PRIORITY_DEFAULT.
665//
666// The asynchronous methods have a default fallback that uses threads to implement
667// asynchronicity, so they are optional for inheriting classes. However, if you
668// override one you must override all.
669func (x *InputStream) ReadAsync(BufferVar *[]byte, CountVar uint, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
670
671 var CallbackVarRef uintptr
672 if CallbackVar != nil {
673 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
674 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
675 CallbackVarRef = cbRefPtr
676 } else {
677 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
678 cbFn := *CallbackVar
679 cbFn(arg0, arg1, arg2)
680 }
681 CallbackVarRef = purego.NewCallback(fcb)
682 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
683 }
684 }
685
686 xInputStreamReadAsync(x.GoPointer(), BufferVar, CountVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
687
688}
689
690var xInputStreamReadBytes func(uintptr, uint, uintptr, **glib.Error) *glib.Bytes
691
692// Like g_input_stream_read(), this tries to read @count bytes from
693// the stream in a blocking fashion. However, rather than reading into
694// a user-supplied buffer, this will create a new #GBytes containing
695// the data that was read. This may be easier to use from language
696// bindings.
697//
698// If count is zero, returns a zero-length #GBytes and does nothing. A
699// value of @count larger than %G_MAXSSIZE will cause a
700// %G_IO_ERROR_INVALID_ARGUMENT error.
701//
702// On success, a new #GBytes is returned. It is not an error if the
703// size of this object is not the same as the requested size, as it
704// can happen e.g. near the end of a file. A zero-length #GBytes is
705// returned on end of file (or if @count is zero), but never
706// otherwise.
707//
708// If @cancellable is not %NULL, then the operation can be cancelled by
709// triggering the cancellable object from another thread. If the operation
710// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
711// operation was partially finished when the operation was cancelled the
712// partial result will be returned, without an error.
713//
714// On error %NULL is returned and @error is set accordingly.
715func (x *InputStream) ReadBytes(CountVar uint, CancellableVar *Cancellable) (*glib.Bytes, error) {
716 var cerr *glib.Error
717
718 cret := xInputStreamReadBytes(x.GoPointer(), CountVar, CancellableVar.GoPointer(), &cerr)
719 if cerr == nil {
720 return cret, nil
721 }
722 return cret, cerr
723
724}
725
726var xInputStreamReadBytesAsync func(uintptr, uint, int, uintptr, uintptr, uintptr)
727
728// Request an asynchronous read of @count bytes from the stream into a
729// new #GBytes. When the operation is finished @callback will be
730// called. You can then call g_input_stream_read_bytes_finish() to get the
731// result of the operation.
732//
733// During an async request no other sync and async calls are allowed
734// on @stream, and will result in %G_IO_ERROR_PENDING errors.
735//
736// A value of @count larger than %G_MAXSSIZE will cause a
737// %G_IO_ERROR_INVALID_ARGUMENT error.
738//
739// On success, the new #GBytes will be passed to the callback. It is
740// not an error if this is smaller than the requested size, as it can
741// happen e.g. near the end of a file, but generally we try to read as
742// many bytes as requested. Zero is returned on end of file (or if
743// @count is zero), but never otherwise.
744//
745// Any outstanding I/O request with higher priority (lower numerical
746// value) will be executed before an outstanding request with lower
747// priority. Default priority is %G_PRIORITY_DEFAULT.
748func (x *InputStream) ReadBytesAsync(CountVar uint, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
749
750 var CallbackVarRef uintptr
751 if CallbackVar != nil {
752 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
753 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
754 CallbackVarRef = cbRefPtr
755 } else {
756 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
757 cbFn := *CallbackVar
758 cbFn(arg0, arg1, arg2)
759 }
760 CallbackVarRef = purego.NewCallback(fcb)
761 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
762 }
763 }
764
765 xInputStreamReadBytesAsync(x.GoPointer(), CountVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
766
767}
768
769var xInputStreamReadBytesFinish func(uintptr, uintptr, **glib.Error) *glib.Bytes
770
771// Finishes an asynchronous stream read-into-#GBytes operation.
772func (x *InputStream) ReadBytesFinish(ResultVar AsyncResult) (*glib.Bytes, error) {
773 var cerr *glib.Error
774
775 cret := xInputStreamReadBytesFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
776 if cerr == nil {
777 return cret, nil
778 }
779 return cret, cerr
780
781}
782
783var xInputStreamReadFinish func(uintptr, uintptr, **glib.Error) int
784
785// Finishes an asynchronous stream read operation.
786func (x *InputStream) ReadFinish(ResultVar AsyncResult) (int, error) {
787 var cerr *glib.Error
788
789 cret := xInputStreamReadFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
790 if cerr == nil {
791 return cret, nil
792 }
793 return cret, cerr
794
795}
796
797var xInputStreamSetPending func(uintptr) bool
798
799// Sets @stream to have actions pending. If the pending flag is
800// already set or @stream is closed, it will return %FALSE and set
801// @error.
802func (x *InputStream) SetPending() (bool, error) {
803 var cerr *glib.Error
804
805 cret := xInputStreamSetPending(x.GoPointer())
806 if cerr == nil {
807 return cret, nil
808 }
809 return cret, cerr
810
811}
812
813var xInputStreamSkip func(uintptr, uint, uintptr, **glib.Error) int
814
815// Tries to skip @count bytes from the stream. Will block during the operation.
816//
817// This is identical to g_input_stream_read(), from a behaviour standpoint,
818// but the bytes that are skipped are not returned to the user. Some
819// streams have an implementation that is more efficient than reading the data.
820//
821// This function is optional for inherited classes, as the default implementation
822// emulates it using read.
823//
824// If @cancellable is not %NULL, then the operation can be cancelled by
825// triggering the cancellable object from another thread. If the operation
826// was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
827// operation was partially finished when the operation was cancelled the
828// partial result will be returned, without an error.
829func (x *InputStream) Skip(CountVar uint, CancellableVar *Cancellable) (int, error) {
830 var cerr *glib.Error
831
832 cret := xInputStreamSkip(x.GoPointer(), CountVar, CancellableVar.GoPointer(), &cerr)
833 if cerr == nil {
834 return cret, nil
835 }
836 return cret, cerr
837
838}
839
840var xInputStreamSkipAsync func(uintptr, uint, int, uintptr, uintptr, uintptr)
841
842// Request an asynchronous skip of @count bytes from the stream.
843// When the operation is finished @callback will be called.
844// You can then call g_input_stream_skip_finish() to get the result
845// of the operation.
846//
847// During an async request no other sync and async calls are allowed,
848// and will result in %G_IO_ERROR_PENDING errors.
849//
850// A value of @count larger than %G_MAXSSIZE will cause a %G_IO_ERROR_INVALID_ARGUMENT error.
851//
852// On success, the number of bytes skipped will be passed to the callback.
853// It is not an error if this is not the same as the requested size, as it
854// can happen e.g. near the end of a file, but generally we try to skip
855// as many bytes as requested. Zero is returned on end of file
856// (or if @count is zero), but never otherwise.
857//
858// Any outstanding i/o request with higher priority (lower numerical value)
859// will be executed before an outstanding request with lower priority.
860// Default priority is %G_PRIORITY_DEFAULT.
861//
862// The asynchronous methods have a default fallback that uses threads to
863// implement asynchronicity, so they are optional for inheriting classes.
864// However, if you override one, you must override all.
865func (x *InputStream) SkipAsync(CountVar uint, IoPriorityVar int, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
866
867 var CallbackVarRef uintptr
868 if CallbackVar != nil {
869 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
870 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
871 CallbackVarRef = cbRefPtr
872 } else {
873 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
874 cbFn := *CallbackVar
875 cbFn(arg0, arg1, arg2)
876 }
877 CallbackVarRef = purego.NewCallback(fcb)
878 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
879 }
880 }
881
882 xInputStreamSkipAsync(x.GoPointer(), CountVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
883
884}
885
886var xInputStreamSkipFinish func(uintptr, uintptr, **glib.Error) int
887
888// Finishes a stream skip operation.
889func (x *InputStream) SkipFinish(ResultVar AsyncResult) (int, error) {
890 var cerr *glib.Error
891
892 cret := xInputStreamSkipFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
893 if cerr == nil {
894 return cret, nil
895 }
896 return cret, cerr
897
898}
899
900func (c *InputStream) GoPointer() uintptr {
901 if c == nil {
902 return 0
903 }
904 return c.Ptr
905}
906
907func (c *InputStream) SetGoPointer(ptr uintptr) {
908 c.Ptr = ptr
909}
910
911func init() {
912 core.SetPackageName("GIO", "gio-2.0")
913 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
914 var libs []uintptr
915 for _, libPath := range core.GetPaths("GIO") {
916 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
917 if err != nil {
918 panic(err)
919 }
920 libs = append(libs, lib)
921 }
922
923 core.PuregoSafeRegister(&xInputStreamGLibType, libs, "g_input_stream_get_type")
924
925 core.PuregoSafeRegister(&xInputStreamClearPending, libs, "g_input_stream_clear_pending")
926 core.PuregoSafeRegister(&xInputStreamClose, libs, "g_input_stream_close")
927 core.PuregoSafeRegister(&xInputStreamCloseAsync, libs, "g_input_stream_close_async")
928 core.PuregoSafeRegister(&xInputStreamCloseFinish, libs, "g_input_stream_close_finish")
929 core.PuregoSafeRegister(&xInputStreamHasPending, libs, "g_input_stream_has_pending")
930 core.PuregoSafeRegister(&xInputStreamIsClosed, libs, "g_input_stream_is_closed")
931 core.PuregoSafeRegister(&xInputStreamRead, libs, "g_input_stream_read")
932 core.PuregoSafeRegister(&xInputStreamReadAll, libs, "g_input_stream_read_all")
933 core.PuregoSafeRegister(&xInputStreamReadAllAsync, libs, "g_input_stream_read_all_async")
934 core.PuregoSafeRegister(&xInputStreamReadAllFinish, libs, "g_input_stream_read_all_finish")
935 core.PuregoSafeRegister(&xInputStreamReadAsync, libs, "g_input_stream_read_async")
936 core.PuregoSafeRegister(&xInputStreamReadBytes, libs, "g_input_stream_read_bytes")
937 core.PuregoSafeRegister(&xInputStreamReadBytesAsync, libs, "g_input_stream_read_bytes_async")
938 core.PuregoSafeRegister(&xInputStreamReadBytesFinish, libs, "g_input_stream_read_bytes_finish")
939 core.PuregoSafeRegister(&xInputStreamReadFinish, libs, "g_input_stream_read_finish")
940 core.PuregoSafeRegister(&xInputStreamSetPending, libs, "g_input_stream_set_pending")
941 core.PuregoSafeRegister(&xInputStreamSkip, libs, "g_input_stream_skip")
942 core.PuregoSafeRegister(&xInputStreamSkipAsync, libs, "g_input_stream_skip_async")
943 core.PuregoSafeRegister(&xInputStreamSkipFinish, libs, "g_input_stream_skip_finish")
944
945}