// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT package gio import ( "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/glib" "github.com/bnema/puregotk/v4/gobject/types" ) // The interface for pollable output streams. // // The default implementation of @can_poll always returns %TRUE. // // The default implementation of @write_nonblocking calls // g_pollable_output_stream_is_writable(), and then calls // g_output_stream_write() if it returns %TRUE. This means you only // need to override it if it is possible that your @is_writable // implementation may return %TRUE when the stream is not actually // writable. // // The default implementation of @writev_nonblocking calls // g_pollable_output_stream_write_nonblocking() for each vector, and converts // its return value and error (if set) to a #GPollableReturn. You should // override this where possible to avoid having to allocate a #GError to return // %G_IO_ERROR_WOULD_BLOCK. type PollableOutputStreamInterface struct { _ structs.HostLayout GIface uintptr xCanPoll uintptr xIsWritable uintptr xCreateSource uintptr xWriteNonblocking uintptr xWritevNonblocking uintptr } func (x *PollableOutputStreamInterface) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideCanPoll sets the "can_poll" callback function. // Checks if the #GPollableOutputStream instance is actually pollable func (x *PollableOutputStreamInterface) OverrideCanPoll(cb func(PollableOutputStream) bool) { if cb == nil { x.xCanPoll = 0 } else { x.xCanPoll = purego.NewCallback(func(StreamVarp uintptr) bool { return cb(&PollableOutputStreamBase{Ptr: StreamVarp}) }) } } // GetCanPoll gets the "can_poll" callback function. // Checks if the #GPollableOutputStream instance is actually pollable func (x *PollableOutputStreamInterface) GetCanPoll() func(PollableOutputStream) bool { if x.xCanPoll == 0 { return nil } var rawCallback func(StreamVarp uintptr) bool purego.RegisterFunc(&rawCallback, x.xCanPoll) return func(StreamVar PollableOutputStream) bool { return rawCallback(StreamVar.GoPointer()) } } // OverrideIsWritable sets the "is_writable" callback function. // Checks if the stream is writable func (x *PollableOutputStreamInterface) OverrideIsWritable(cb func(PollableOutputStream) bool) { if cb == nil { x.xIsWritable = 0 } else { x.xIsWritable = purego.NewCallback(func(StreamVarp uintptr) bool { return cb(&PollableOutputStreamBase{Ptr: StreamVarp}) }) } } // GetIsWritable gets the "is_writable" callback function. // Checks if the stream is writable func (x *PollableOutputStreamInterface) GetIsWritable() func(PollableOutputStream) bool { if x.xIsWritable == 0 { return nil } var rawCallback func(StreamVarp uintptr) bool purego.RegisterFunc(&rawCallback, x.xIsWritable) return func(StreamVar PollableOutputStream) bool { return rawCallback(StreamVar.GoPointer()) } } // OverrideCreateSource sets the "create_source" callback function. // Creates a #GSource to poll the stream func (x *PollableOutputStreamInterface) OverrideCreateSource(cb func(PollableOutputStream, *Cancellable) *glib.Source) { if cb == nil { x.xCreateSource = 0 } else { x.xCreateSource = purego.NewCallback(func(StreamVarp uintptr, CancellableVarp uintptr) *glib.Source { return cb(&PollableOutputStreamBase{Ptr: StreamVarp}, CancellableNewFromInternalPtr(CancellableVarp)) }) } } // GetCreateSource gets the "create_source" callback function. // Creates a #GSource to poll the stream func (x *PollableOutputStreamInterface) GetCreateSource() func(PollableOutputStream, *Cancellable) *glib.Source { if x.xCreateSource == 0 { return nil } var rawCallback func(StreamVarp uintptr, CancellableVarp uintptr) *glib.Source purego.RegisterFunc(&rawCallback, x.xCreateSource) return func(StreamVar PollableOutputStream, CancellableVar *Cancellable) *glib.Source { return rawCallback(StreamVar.GoPointer(), CancellableVar.GoPointer()) } } // OverrideWriteNonblocking sets the "write_nonblocking" callback function. // Does a non-blocking write or returns // // %G_IO_ERROR_WOULD_BLOCK func (x *PollableOutputStreamInterface) OverrideWriteNonblocking(cb func(PollableOutputStream, []byte, uint) int) { if cb == nil { x.xWriteNonblocking = 0 } else { x.xWriteNonblocking = purego.NewCallback(func(StreamVarp uintptr, BufferVarp []byte, CountVarp uint) int { return cb(&PollableOutputStreamBase{Ptr: StreamVarp}, BufferVarp, CountVarp) }) } } // GetWriteNonblocking gets the "write_nonblocking" callback function. // Does a non-blocking write or returns // // %G_IO_ERROR_WOULD_BLOCK func (x *PollableOutputStreamInterface) GetWriteNonblocking() func(PollableOutputStream, []byte, uint) int { if x.xWriteNonblocking == 0 { return nil } var rawCallback func(StreamVarp uintptr, BufferVarp []byte, CountVarp uint) int purego.RegisterFunc(&rawCallback, x.xWriteNonblocking) return func(StreamVar PollableOutputStream, BufferVar []byte, CountVar uint) int { return rawCallback(StreamVar.GoPointer(), BufferVar, CountVar) } } // OverrideWritevNonblocking sets the "writev_nonblocking" callback function. // Does a vectored non-blocking write, or returns // // %G_POLLABLE_RETURN_WOULD_BLOCK func (x *PollableOutputStreamInterface) OverrideWritevNonblocking(cb func(PollableOutputStream, []OutputVector, uint, *uint) PollableReturn) { if cb == nil { x.xWritevNonblocking = 0 } else { x.xWritevNonblocking = purego.NewCallback(func(StreamVarp uintptr, VectorsVarp []OutputVector, NVectorsVarp uint, BytesWrittenVarp *uint) PollableReturn { return cb(&PollableOutputStreamBase{Ptr: StreamVarp}, VectorsVarp, NVectorsVarp, BytesWrittenVarp) }) } } // GetWritevNonblocking gets the "writev_nonblocking" callback function. // Does a vectored non-blocking write, or returns // // %G_POLLABLE_RETURN_WOULD_BLOCK func (x *PollableOutputStreamInterface) GetWritevNonblocking() func(PollableOutputStream, []OutputVector, uint, *uint) PollableReturn { if x.xWritevNonblocking == 0 { return nil } var rawCallback func(StreamVarp uintptr, VectorsVarp []OutputVector, NVectorsVarp uint, BytesWrittenVarp *uint) PollableReturn purego.RegisterFunc(&rawCallback, x.xWritevNonblocking) return func(StreamVar PollableOutputStream, VectorsVar []OutputVector, NVectorsVar uint, BytesWrittenVar *uint) PollableReturn { return rawCallback(StreamVar.GoPointer(), VectorsVar, NVectorsVar, BytesWrittenVar) } } // `GPollableOutputStream` is implemented by [class@Gio.OutputStream]s that // can be polled for readiness to write. This can be used when // interfacing with a non-GIO API that expects // UNIX-file-descriptor-style asynchronous I/O rather than GIO-style. // // Some classes may implement `GPollableOutputStream` but have only certain // instances of that class be pollable. If [method@Gio.PollableOutputStream.can_poll] // returns false, then the behavior of other `GPollableOutputStream` methods is // undefined. type PollableOutputStream interface { GoPointer() uintptr SetGoPointer(uintptr) CanPoll() bool CreateSource(CancellableVar *Cancellable) *glib.Source IsWritable() bool WriteNonblocking(BufferVar []byte, CountVar uint, CancellableVar *Cancellable) (int, error) WritevNonblocking(VectorsVar []OutputVector, NVectorsVar uint, BytesWrittenVar *uint, CancellableVar *Cancellable) (PollableReturn, error) } var xPollableOutputStreamGLibType func() types.GType func PollableOutputStreamGLibType() types.GType { return xPollableOutputStreamGLibType() } type PollableOutputStreamBase struct { Ptr uintptr } func (x *PollableOutputStreamBase) GoPointer() uintptr { if x == nil { return 0 } return x.Ptr } func (x *PollableOutputStreamBase) SetGoPointer(ptr uintptr) { x.Ptr = ptr } // Checks if @stream is actually pollable. Some classes may implement // #GPollableOutputStream but have only certain instances of that // class be pollable. If this method returns %FALSE, then the behavior // of other #GPollableOutputStream methods is undefined. // // For any given stream, the value returned by this method is constant; // a stream cannot switch from pollable to non-pollable or vice versa. func (x *PollableOutputStreamBase) CanPoll() bool { cret := XGPollableOutputStreamCanPoll(x.GoPointer()) return cret } // Creates a #GSource that triggers when @stream can be written, or // @cancellable is triggered or an error occurs. The callback on the // source is of the #GPollableSourceFunc type. // // As with g_pollable_output_stream_is_writable(), it is possible that // the stream may not actually be writable even after the source // triggers, so you should use g_pollable_output_stream_write_nonblocking() // rather than g_output_stream_write() from the callback. // // The behaviour of this method is undefined if // g_pollable_output_stream_can_poll() returns %FALSE for @stream. func (x *PollableOutputStreamBase) CreateSource(CancellableVar *Cancellable) *glib.Source { cret := XGPollableOutputStreamCreateSource(x.GoPointer(), CancellableVar.GoPointer()) return cret } // Checks if @stream can be written. // // Note that some stream types may not be able to implement this 100% // reliably, and it is possible that a call to g_output_stream_write() // after this returns %TRUE would still block. To guarantee // non-blocking behavior, you should always use // g_pollable_output_stream_write_nonblocking(), which will return a // %G_IO_ERROR_WOULD_BLOCK error rather than blocking. // // The behaviour of this method is undefined if // g_pollable_output_stream_can_poll() returns %FALSE for @stream. func (x *PollableOutputStreamBase) IsWritable() bool { cret := XGPollableOutputStreamIsWritable(x.GoPointer()) return cret } // Attempts to write up to @count bytes from @buffer to @stream, as // with g_output_stream_write(). If @stream is not currently writable, // this will immediately return %G_IO_ERROR_WOULD_BLOCK, and you can // use g_pollable_output_stream_create_source() to create a #GSource // that will be triggered when @stream is writable. // // Note that since this method never blocks, you cannot actually // use @cancellable to cancel it. However, it will return an error // if @cancellable has already been cancelled when you call, which // may happen if you call this method after a source triggers due // to having been cancelled. // // Also note that if %G_IO_ERROR_WOULD_BLOCK is returned some underlying // transports like D/TLS require that you re-send the same @buffer and // @count in the next write call. // // The behaviour of this method is undefined if // g_pollable_output_stream_can_poll() returns %FALSE for @stream. func (x *PollableOutputStreamBase) WriteNonblocking(BufferVar []byte, CountVar uint, CancellableVar *Cancellable) (int, error) { var cerr *glib.Error cret := XGPollableOutputStreamWriteNonblocking(x.GoPointer(), BufferVar, CountVar, CancellableVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } // Attempts to write the bytes contained in the @n_vectors @vectors to @stream, // as with g_output_stream_writev(). If @stream is not currently writable, // this will immediately return %@G_POLLABLE_RETURN_WOULD_BLOCK, and you can // use g_pollable_output_stream_create_source() to create a #GSource // that will be triggered when @stream is writable. @error will *not* be // set in that case. // // Note that since this method never blocks, you cannot actually // use @cancellable to cancel it. However, it will return an error // if @cancellable has already been cancelled when you call, which // may happen if you call this method after a source triggers due // to having been cancelled. // // Also note that if %G_POLLABLE_RETURN_WOULD_BLOCK is returned some underlying // transports like D/TLS require that you re-send the same @vectors and // @n_vectors in the next write call. // // The behaviour of this method is undefined if // g_pollable_output_stream_can_poll() returns %FALSE for @stream. func (x *PollableOutputStreamBase) WritevNonblocking(VectorsVar []OutputVector, NVectorsVar uint, BytesWrittenVar *uint, CancellableVar *Cancellable) (PollableReturn, error) { var cerr *glib.Error cret := XGPollableOutputStreamWritevNonblocking(x.GoPointer(), VectorsVar, NVectorsVar, BytesWrittenVar, CancellableVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } var XGPollableOutputStreamCanPoll func(uintptr) bool var XGPollableOutputStreamCreateSource func(uintptr, uintptr) *glib.Source var XGPollableOutputStreamIsWritable func(uintptr) bool var XGPollableOutputStreamWriteNonblocking func(uintptr, []byte, uint, uintptr, **glib.Error) int var XGPollableOutputStreamWritevNonblocking func(uintptr, []OutputVector, uint, *uint, uintptr, **glib.Error) PollableReturn func init() { core.SetPackageName("GIO", "gio-2.0") core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"}) var libs []uintptr for _, libPath := range core.GetPaths("GIO") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xPollableOutputStreamGLibType, libs, "g_pollable_output_stream_get_type") core.PuregoSafeRegister(&XGPollableOutputStreamCanPoll, libs, "g_pollable_output_stream_can_poll") core.PuregoSafeRegister(&XGPollableOutputStreamCreateSource, libs, "g_pollable_output_stream_create_source") core.PuregoSafeRegister(&XGPollableOutputStreamIsWritable, libs, "g_pollable_output_stream_is_writable") core.PuregoSafeRegister(&XGPollableOutputStreamWriteNonblocking, libs, "g_pollable_output_stream_write_nonblocking") core.PuregoSafeRegister(&XGPollableOutputStreamWritevNonblocking, libs, "g_pollable_output_stream_writev_nonblocking") }