// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT package glib import ( "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/gobject/types" ) // Specifies the type of function passed to g_io_add_watch() or // g_io_add_watch_full(), which is called when the requested condition // on a #GIOChannel is satisfied. type IOFunc func(*IOChannel, IOCondition, uintptr) bool // The `GIOChannel` data type aims to provide a portable method for // using file descriptors, pipes, and sockets, and integrating them // into the main event loop (see [struct@GLib.MainContext]). Currently, // full support is available on UNIX platforms; support for Windows // is only partially complete. // // To create a new `GIOChannel` on UNIX systems use // [ctor@GLib.IOChannel.unix_new]. This works for plain file descriptors, // pipes and sockets. Alternatively, a channel can be created for a // file in a system independent manner using [ctor@GLib.IOChannel.new_file]. // // Once a `GIOChannel` has been created, it can be used in a generic // manner with the functions [method@GLib.IOChannel.read_chars], // [method@GLib.IOChannel.write_chars], [method@GLib.IOChannel.seek_position], // and [method@GLib.IOChannel.shutdown]. // // To add a `GIOChannel` to the main event loop, use [func@GLib.io_add_watch] or // [func@GLib.io_add_watch_full]. Here you specify which events you are // interested in on the `GIOChannel`, and provide a function to be called // whenever these events occur. // // `GIOChannel` instances are created with an initial reference count of 1. // [method@GLib.IOChannel.ref] and [method@GLib.IOChannel.unref] can be used to // increment or decrement the reference count respectively. When the // reference count falls to 0, the `GIOChannel` is freed. (Though it // isn’t closed automatically, unless it was created using // [ctor@GLib.IOChannel.new_file].) Using [func@GLib.io_add_watch] or // [func@GLib.io_add_watch_full] increments a channel’s reference count. // // The new functions [method@GLib.IOChannel.read_chars], // [method@GLib.IOChannel.read_line], [method@GLib.IOChannel.read_line_string], // [method@GLib.IOChannel.read_to_end], [method@GLib.IOChannel.write_chars], // [method@GLib.IOChannel.seek_position], and [method@GLib.IOChannel.flush] // should not be mixed with the deprecated functions // [method@GLib.IOChannel.read], [method@GLib.IOChannel.write], and // [method@GLib.IOChannel.seek] on the same channel. type IOChannel struct { _ structs.HostLayout RefCount int32 Funcs *IOFuncs Encoding uintptr ReadCd uintptr WriteCd uintptr LineTerm uintptr LineTermLen uint BufSize uint ReadBuf *String EncodedReadBuf *String WriteBuf *String PartialWriteBuf [6]byte UseBuffer uint DoEncode uint CloseOnUnref uint IsReadable uint IsWriteable uint IsSeekable uint Reserved1 uintptr Reserved2 uintptr } var xIOChannelGLibType func() types.GType func IOChannelGLibType() types.GType { return xIOChannelGLibType() } func (x *IOChannel) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } var xNewIOChannelFile func(string, string, **Error) *IOChannel // Open a file @filename as a #GIOChannel using mode @mode. This // channel will be closed when the last reference to it is dropped, // so there is no need to call g_io_channel_close() (though doing // so will not cause problems, as long as no attempt is made to // access the channel after it is closed). func NewIOChannelFile(FilenameVar string, ModeVar string) (*IOChannel, error) { var cerr *Error cret := xNewIOChannelFile(FilenameVar, ModeVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelUnixNew func(int) *IOChannel // Creates a new #GIOChannel given a file descriptor. On UNIX systems // this works for plain files, pipes, and sockets. // // The returned #GIOChannel has a reference count of 1. // // The default encoding for #GIOChannel is UTF-8. If your application // is reading output from a command using via pipe, you may need to set // the encoding to the encoding of the current locale (see // g_get_charset()) with the g_io_channel_set_encoding() function. // By default, the fd passed will not be closed when the final reference // to the #GIOChannel data structure is dropped. // // If you want to read raw binary data without interpretation, then // call the g_io_channel_set_encoding() function with %NULL for the // encoding argument. // // This function is available in GLib on Windows, too, but you should // avoid using it on Windows. The domain of file descriptors and // sockets overlap. There is no way for GLib to know which one you mean // in case the argument you pass to this function happens to be both a // valid file descriptor and socket. If that happens a warning is // issued, and GLib assumes that it is the file descriptor you mean. func IOChannelUnixNew(FdVar int) *IOChannel { cret := xIOChannelUnixNew(FdVar) return cret } var xIOChannelClose func(uintptr) // Close an IO channel. Any pending data to be written will be // flushed, ignoring errors. The channel will not be freed until the // last reference is dropped using g_io_channel_unref(). func (x *IOChannel) Close() { xIOChannelClose(x.GoPointer()) } var xIOChannelFlush func(uintptr) IOStatus // Flushes the write buffer for the GIOChannel. func (x *IOChannel) Flush() (IOStatus, error) { var cerr *Error cret := xIOChannelFlush(x.GoPointer()) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelGetBufferCondition func(uintptr) IOCondition // This function returns a #GIOCondition depending on whether there // is data to be read/space to write data in the internal buffers in // the #GIOChannel. Only the flags %G_IO_IN and %G_IO_OUT may be set. func (x *IOChannel) GetBufferCondition() IOCondition { cret := xIOChannelGetBufferCondition(x.GoPointer()) return cret } var xIOChannelGetBufferSize func(uintptr) uint // Gets the buffer size. func (x *IOChannel) GetBufferSize() uint { cret := xIOChannelGetBufferSize(x.GoPointer()) return cret } var xIOChannelGetBuffered func(uintptr) bool // Returns whether @channel is buffered. func (x *IOChannel) GetBuffered() bool { cret := xIOChannelGetBuffered(x.GoPointer()) return cret } var xIOChannelGetCloseOnUnref func(uintptr) bool // Returns whether the file/socket/whatever associated with @channel // will be closed when @channel receives its final unref and is // destroyed. The default value of this is %TRUE for channels created // by g_io_channel_new_file (), and %FALSE for all other channels. func (x *IOChannel) GetCloseOnUnref() bool { cret := xIOChannelGetCloseOnUnref(x.GoPointer()) return cret } var xIOChannelGetEncoding func(uintptr) string // Gets the encoding for the input/output of the channel. // The internal encoding is always UTF-8. The encoding %NULL // makes the channel safe for binary data. func (x *IOChannel) GetEncoding() string { cret := xIOChannelGetEncoding(x.GoPointer()) return cret } var xIOChannelGetFlags func(uintptr) IOFlags // Gets the current flags for a #GIOChannel, including read-only // flags such as %G_IO_FLAG_IS_READABLE. // // The values of the flags %G_IO_FLAG_IS_READABLE and %G_IO_FLAG_IS_WRITABLE // are cached for internal use by the channel when it is created. // If they should change at some later point (e.g. partial shutdown // of a socket with the UNIX shutdown() function), the user // should immediately call g_io_channel_get_flags() to update // the internal values of these flags. func (x *IOChannel) GetFlags() IOFlags { cret := xIOChannelGetFlags(x.GoPointer()) return cret } var xIOChannelGetLineTerm func(uintptr, *int) string // This returns the string that #GIOChannel uses to determine // where in the file a line break occurs. A value of %NULL // indicates autodetection. Since 2.84, the return value is always // nul-terminated. func (x *IOChannel) GetLineTerm(LengthVar *int) string { cret := xIOChannelGetLineTerm(x.GoPointer(), LengthVar) return cret } var xIOChannelInit func(uintptr) // Initializes a #GIOChannel struct. // // This is called by each of the above functions when creating a // #GIOChannel, and so is not often needed by the application // programmer (unless you are creating a new type of #GIOChannel). func (x *IOChannel) Init() { xIOChannelInit(x.GoPointer()) } var xIOChannelRead func(uintptr, string, uint, uint) IOError // Reads data from a #GIOChannel. func (x *IOChannel) Read(BufVar string, CountVar uint, BytesReadVar uint) IOError { cret := xIOChannelRead(x.GoPointer(), BufVar, CountVar, BytesReadVar) return cret } var xIOChannelReadChars func(uintptr, *[]byte, uint, *uint, **Error) IOStatus // Replacement for g_io_channel_read() with the new API. func (x *IOChannel) ReadChars(BufVar *[]byte, CountVar uint, BytesReadVar *uint) (IOStatus, error) { var cerr *Error cret := xIOChannelReadChars(x.GoPointer(), BufVar, CountVar, BytesReadVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelReadLine func(uintptr, *string, *uint, *uint, **Error) IOStatus // Reads a line, including the terminating character(s), // from a #GIOChannel into a newly-allocated string. // @str_return will contain allocated memory if the return // is %G_IO_STATUS_NORMAL. func (x *IOChannel) ReadLine(StrReturnVar *string, LengthVar *uint, TerminatorPosVar *uint) (IOStatus, error) { var cerr *Error cret := xIOChannelReadLine(x.GoPointer(), StrReturnVar, LengthVar, TerminatorPosVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelReadLineString func(uintptr, *String, uint, **Error) IOStatus // Reads a line from a #GIOChannel, using a #GString as a buffer. func (x *IOChannel) ReadLineString(BufferVar *String, TerminatorPosVar uint) (IOStatus, error) { var cerr *Error cret := xIOChannelReadLineString(x.GoPointer(), BufferVar, TerminatorPosVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelReadToEnd func(uintptr, *[]byte, *uint, **Error) IOStatus // Reads all the remaining data from the file. func (x *IOChannel) ReadToEnd(StrReturnVar *[]byte, LengthVar *uint) (IOStatus, error) { var cerr *Error cret := xIOChannelReadToEnd(x.GoPointer(), StrReturnVar, LengthVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelReadUnichar func(uintptr, *uint32, **Error) IOStatus // Reads a Unicode character from @channel. // This function cannot be called on a channel with %NULL encoding. func (x *IOChannel) ReadUnichar(ThecharVar *uint32) (IOStatus, error) { var cerr *Error cret := xIOChannelReadUnichar(x.GoPointer(), ThecharVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelRef func(uintptr) *IOChannel // Increments the reference count of a #GIOChannel. func (x *IOChannel) Ref() *IOChannel { cret := xIOChannelRef(x.GoPointer()) return cret } var xIOChannelSeek func(uintptr, int64, SeekType) IOError // Sets the current position in the #GIOChannel, similar to the standard // library function fseek(). func (x *IOChannel) Seek(OffsetVar int64, TypeVar SeekType) IOError { cret := xIOChannelSeek(x.GoPointer(), OffsetVar, TypeVar) return cret } var xIOChannelSeekPosition func(uintptr, int64, SeekType, **Error) IOStatus // Replacement for g_io_channel_seek() with the new API. func (x *IOChannel) SeekPosition(OffsetVar int64, TypeVar SeekType) (IOStatus, error) { var cerr *Error cret := xIOChannelSeekPosition(x.GoPointer(), OffsetVar, TypeVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelSetBufferSize func(uintptr, uint) // Sets the buffer size. func (x *IOChannel) SetBufferSize(SizeVar uint) { xIOChannelSetBufferSize(x.GoPointer(), SizeVar) } var xIOChannelSetBuffered func(uintptr, bool) // The buffering state can only be set if the channel's encoding // is %NULL. For any other encoding, the channel must be buffered. // // A buffered channel can only be set unbuffered if the channel's // internal buffers have been flushed. Newly created channels or // channels which have returned %G_IO_STATUS_EOF // not require such a flush. For write-only channels, a call to // g_io_channel_flush () is sufficient. For all other channels, // the buffers may be flushed by a call to g_io_channel_seek_position (). // This includes the possibility of seeking with seek type %G_SEEK_CUR // and an offset of zero. Note that this means that socket-based // channels cannot be set unbuffered once they have had data // read from them. // // On unbuffered channels, it is safe to mix read and write // calls from the new and old APIs, if this is necessary for // maintaining old code. // // The default state of the channel is buffered. func (x *IOChannel) SetBuffered(BufferedVar bool) { xIOChannelSetBuffered(x.GoPointer(), BufferedVar) } var xIOChannelSetCloseOnUnref func(uintptr, bool) // Whether to close the channel on the final unref of the #GIOChannel // data structure. The default value of this is %TRUE for channels // created by g_io_channel_new_file (), and %FALSE for all other channels. // // Setting this flag to %TRUE for a channel you have already closed // can cause problems when the final reference to the #GIOChannel is dropped. func (x *IOChannel) SetCloseOnUnref(DoCloseVar bool) { xIOChannelSetCloseOnUnref(x.GoPointer(), DoCloseVar) } var xIOChannelSetEncoding func(uintptr, uintptr, **Error) IOStatus // Sets the encoding for the input/output of the channel. // The internal encoding is always UTF-8. The default encoding // for the external file is UTF-8. // // The encoding %NULL is safe to use with binary data. // // The encoding can only be set if one of the following conditions // is true: // // - The channel was just created, and has not been written to or read from yet. // // - The channel is write-only. // // - The channel is a file, and the file pointer was just repositioned // by a call to g_io_channel_seek_position(). (This flushes all the // internal buffers.) // // - The current encoding is %NULL or UTF-8. // // - One of the (new API) read functions has just returned %G_IO_STATUS_EOF // (or, in the case of g_io_channel_read_to_end(), %G_IO_STATUS_NORMAL). // // - One of the functions g_io_channel_read_chars() or // g_io_channel_read_unichar() has returned %G_IO_STATUS_AGAIN or // %G_IO_STATUS_ERROR. This may be useful in the case of // %G_CONVERT_ERROR_ILLEGAL_SEQUENCE. // Returning one of these statuses from g_io_channel_read_line(), // g_io_channel_read_line_string(), or g_io_channel_read_to_end() // does not guarantee that the encoding can be changed. // // Channels which do not meet one of the above conditions cannot call // g_io_channel_seek_position() with an offset of %G_SEEK_CUR, and, if // they are "seekable", cannot call g_io_channel_write_chars() after // calling one of the API "read" functions. func (x *IOChannel) SetEncoding(EncodingVar *string) (IOStatus, error) { var cerr *Error EncodingVarPtr := core.GStrdupNullable(EncodingVar) defer core.GFreeNullable(EncodingVarPtr) cret := xIOChannelSetEncoding(x.GoPointer(), EncodingVarPtr, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelSetFlags func(uintptr, IOFlags, **Error) IOStatus // Sets the (writeable) flags in @channel to (@flags & %G_IO_FLAG_SET_MASK). func (x *IOChannel) SetFlags(FlagsVar IOFlags) (IOStatus, error) { var cerr *Error cret := xIOChannelSetFlags(x.GoPointer(), FlagsVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelSetLineTerm func(uintptr, uintptr, int) // This sets the string that #GIOChannel uses to determine // where in the file a line break occurs. func (x *IOChannel) SetLineTerm(LineTermVar *string, LengthVar int) { LineTermVarPtr := core.GStrdupNullable(LineTermVar) defer core.GFreeNullable(LineTermVarPtr) xIOChannelSetLineTerm(x.GoPointer(), LineTermVarPtr, LengthVar) } var xIOChannelShutdown func(uintptr, bool, **Error) IOStatus // Close an IO channel. Any pending data to be written will be // flushed if @flush is %TRUE. The channel will not be freed until the // last reference is dropped using g_io_channel_unref(). func (x *IOChannel) Shutdown(FlushVar bool) (IOStatus, error) { var cerr *Error cret := xIOChannelShutdown(x.GoPointer(), FlushVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelUnixGetFd func(uintptr) int // Returns the file descriptor of the #GIOChannel. // // On Windows this function returns the file descriptor or socket of // the #GIOChannel. func (x *IOChannel) UnixGetFd() int { cret := xIOChannelUnixGetFd(x.GoPointer()) return cret } var xIOChannelUnref func(uintptr) // Decrements the reference count of a #GIOChannel. func (x *IOChannel) Unref() { xIOChannelUnref(x.GoPointer()) } var xIOChannelWrite func(uintptr, string, uint, uint) IOError // Writes data to a #GIOChannel. func (x *IOChannel) Write(BufVar string, CountVar uint, BytesWrittenVar uint) IOError { cret := xIOChannelWrite(x.GoPointer(), BufVar, CountVar, BytesWrittenVar) return cret } var xIOChannelWriteChars func(uintptr, []byte, int, *uint, **Error) IOStatus // Replacement for g_io_channel_write() with the new API. // // On seekable channels with encodings other than %NULL or UTF-8, generic // mixing of reading and writing is not allowed. A call to g_io_channel_write_chars () // may only be made on a channel from which data has been read in the // cases described in the documentation for g_io_channel_set_encoding (). func (x *IOChannel) WriteChars(BufVar []byte, CountVar int, BytesWrittenVar *uint) (IOStatus, error) { var cerr *Error cret := xIOChannelWriteChars(x.GoPointer(), BufVar, CountVar, BytesWrittenVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xIOChannelWriteUnichar func(uintptr, uint32, **Error) IOStatus // Writes a Unicode character to @channel. // This function cannot be called on a channel with %NULL encoding. func (x *IOChannel) WriteUnichar(ThecharVar uint32) (IOStatus, error) { var cerr *Error cret := xIOChannelWriteUnichar(x.GoPointer(), ThecharVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } // A table of functions used to handle different types of #GIOChannel // in a generic way. type IOFuncs struct { _ structs.HostLayout xIoRead uintptr xIoWrite uintptr xIoSeek uintptr xIoClose uintptr xIoCreateWatch uintptr xIoFree uintptr xIoSetFlags uintptr xIoGetFlags uintptr } func (x *IOFuncs) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideIoRead sets the "io_read" callback function. // reads raw bytes from the channel. This is called from // // various functions such as g_io_channel_read_chars() to // read raw bytes from the channel. Encoding and buffering // issues are dealt with at a higher level. func (x *IOFuncs) OverrideIoRead(cb func(*IOChannel, string, uint, uint) IOStatus) { if cb == nil { x.xIoRead = 0 } else { x.xIoRead = purego.NewCallback(func(ChannelVarp *IOChannel, BufVarp string, CountVarp uint, BytesReadVarp uint) IOStatus { return cb(ChannelVarp, BufVarp, CountVarp, BytesReadVarp) }) } } // GetIoRead gets the "io_read" callback function. // reads raw bytes from the channel. This is called from // // various functions such as g_io_channel_read_chars() to // read raw bytes from the channel. Encoding and buffering // issues are dealt with at a higher level. func (x *IOFuncs) GetIoRead() func(*IOChannel, string, uint, uint) IOStatus { if x.xIoRead == 0 { return nil } var rawCallback func(ChannelVarp *IOChannel, BufVarp string, CountVarp uint, BytesReadVarp uint) IOStatus purego.RegisterFunc(&rawCallback, x.xIoRead) return func(ChannelVar *IOChannel, BufVar string, CountVar uint, BytesReadVar uint) IOStatus { return rawCallback(ChannelVar, BufVar, CountVar, BytesReadVar) } } // OverrideIoWrite sets the "io_write" callback function. // writes raw bytes to the channel. This is called from // // various functions such as g_io_channel_write_chars() to // write raw bytes to the channel. Encoding and buffering // issues are dealt with at a higher level. func (x *IOFuncs) OverrideIoWrite(cb func(*IOChannel, string, uint, uint) IOStatus) { if cb == nil { x.xIoWrite = 0 } else { x.xIoWrite = purego.NewCallback(func(ChannelVarp *IOChannel, BufVarp string, CountVarp uint, BytesWrittenVarp uint) IOStatus { return cb(ChannelVarp, BufVarp, CountVarp, BytesWrittenVarp) }) } } // GetIoWrite gets the "io_write" callback function. // writes raw bytes to the channel. This is called from // // various functions such as g_io_channel_write_chars() to // write raw bytes to the channel. Encoding and buffering // issues are dealt with at a higher level. func (x *IOFuncs) GetIoWrite() func(*IOChannel, string, uint, uint) IOStatus { if x.xIoWrite == 0 { return nil } var rawCallback func(ChannelVarp *IOChannel, BufVarp string, CountVarp uint, BytesWrittenVarp uint) IOStatus purego.RegisterFunc(&rawCallback, x.xIoWrite) return func(ChannelVar *IOChannel, BufVar string, CountVar uint, BytesWrittenVar uint) IOStatus { return rawCallback(ChannelVar, BufVar, CountVar, BytesWrittenVar) } } // OverrideIoSeek sets the "io_seek" callback function. // seeks the channel. This is called from // // g_io_channel_seek() on channels that support it. func (x *IOFuncs) OverrideIoSeek(cb func(*IOChannel, int64, SeekType) IOStatus) { if cb == nil { x.xIoSeek = 0 } else { x.xIoSeek = purego.NewCallback(func(ChannelVarp *IOChannel, OffsetVarp int64, TypeVarp SeekType) IOStatus { return cb(ChannelVarp, OffsetVarp, TypeVarp) }) } } // GetIoSeek gets the "io_seek" callback function. // seeks the channel. This is called from // // g_io_channel_seek() on channels that support it. func (x *IOFuncs) GetIoSeek() func(*IOChannel, int64, SeekType) IOStatus { if x.xIoSeek == 0 { return nil } var rawCallback func(ChannelVarp *IOChannel, OffsetVarp int64, TypeVarp SeekType) IOStatus purego.RegisterFunc(&rawCallback, x.xIoSeek) return func(ChannelVar *IOChannel, OffsetVar int64, TypeVar SeekType) IOStatus { return rawCallback(ChannelVar, OffsetVar, TypeVar) } } // OverrideIoClose sets the "io_close" callback function. // closes the channel. This is called from // // g_io_channel_close() after flushing the buffers. func (x *IOFuncs) OverrideIoClose(cb func(*IOChannel) IOStatus) { if cb == nil { x.xIoClose = 0 } else { x.xIoClose = purego.NewCallback(func(ChannelVarp *IOChannel) IOStatus { return cb(ChannelVarp) }) } } // GetIoClose gets the "io_close" callback function. // closes the channel. This is called from // // g_io_channel_close() after flushing the buffers. func (x *IOFuncs) GetIoClose() func(*IOChannel) IOStatus { if x.xIoClose == 0 { return nil } var rawCallback func(ChannelVarp *IOChannel) IOStatus purego.RegisterFunc(&rawCallback, x.xIoClose) return func(ChannelVar *IOChannel) IOStatus { return rawCallback(ChannelVar) } } // OverrideIoCreateWatch sets the "io_create_watch" callback function. // creates a watch on the channel. This call // // corresponds directly to g_io_create_watch(). func (x *IOFuncs) OverrideIoCreateWatch(cb func(*IOChannel, IOCondition) *Source) { if cb == nil { x.xIoCreateWatch = 0 } else { x.xIoCreateWatch = purego.NewCallback(func(ChannelVarp *IOChannel, ConditionVarp IOCondition) *Source { return cb(ChannelVarp, ConditionVarp) }) } } // GetIoCreateWatch gets the "io_create_watch" callback function. // creates a watch on the channel. This call // // corresponds directly to g_io_create_watch(). func (x *IOFuncs) GetIoCreateWatch() func(*IOChannel, IOCondition) *Source { if x.xIoCreateWatch == 0 { return nil } var rawCallback func(ChannelVarp *IOChannel, ConditionVarp IOCondition) *Source purego.RegisterFunc(&rawCallback, x.xIoCreateWatch) return func(ChannelVar *IOChannel, ConditionVar IOCondition) *Source { return rawCallback(ChannelVar, ConditionVar) } } // OverrideIoFree sets the "io_free" callback function. // called from g_io_channel_unref() when the channel needs to // // be freed. This function must free the memory associated // with the channel, including freeing the #GIOChannel // structure itself. The channel buffers have been flushed // and possibly @io_close has been called by the time this // function is called. func (x *IOFuncs) OverrideIoFree(cb func(*IOChannel)) { if cb == nil { x.xIoFree = 0 } else { x.xIoFree = purego.NewCallback(func(ChannelVarp *IOChannel) { cb(ChannelVarp) }) } } // GetIoFree gets the "io_free" callback function. // called from g_io_channel_unref() when the channel needs to // // be freed. This function must free the memory associated // with the channel, including freeing the #GIOChannel // structure itself. The channel buffers have been flushed // and possibly @io_close has been called by the time this // function is called. func (x *IOFuncs) GetIoFree() func(*IOChannel) { if x.xIoFree == 0 { return nil } var rawCallback func(ChannelVarp *IOChannel) purego.RegisterFunc(&rawCallback, x.xIoFree) return func(ChannelVar *IOChannel) { rawCallback(ChannelVar) } } // OverrideIoSetFlags sets the "io_set_flags" callback function. // sets the #GIOFlags on the channel. This is called // // from g_io_channel_set_flags() with all flags except // for %G_IO_FLAG_APPEND and %G_IO_FLAG_NONBLOCK masked // out. func (x *IOFuncs) OverrideIoSetFlags(cb func(*IOChannel, IOFlags) IOStatus) { if cb == nil { x.xIoSetFlags = 0 } else { x.xIoSetFlags = purego.NewCallback(func(ChannelVarp *IOChannel, FlagsVarp IOFlags) IOStatus { return cb(ChannelVarp, FlagsVarp) }) } } // GetIoSetFlags gets the "io_set_flags" callback function. // sets the #GIOFlags on the channel. This is called // // from g_io_channel_set_flags() with all flags except // for %G_IO_FLAG_APPEND and %G_IO_FLAG_NONBLOCK masked // out. func (x *IOFuncs) GetIoSetFlags() func(*IOChannel, IOFlags) IOStatus { if x.xIoSetFlags == 0 { return nil } var rawCallback func(ChannelVarp *IOChannel, FlagsVarp IOFlags) IOStatus purego.RegisterFunc(&rawCallback, x.xIoSetFlags) return func(ChannelVar *IOChannel, FlagsVar IOFlags) IOStatus { return rawCallback(ChannelVar, FlagsVar) } } // OverrideIoGetFlags sets the "io_get_flags" callback function. // gets the #GIOFlags for the channel. This function // // need only return the %G_IO_FLAG_APPEND and // %G_IO_FLAG_NONBLOCK flags; g_io_channel_get_flags() // automatically adds the others as appropriate. func (x *IOFuncs) OverrideIoGetFlags(cb func(*IOChannel) IOFlags) { if cb == nil { x.xIoGetFlags = 0 } else { x.xIoGetFlags = purego.NewCallback(func(ChannelVarp *IOChannel) IOFlags { return cb(ChannelVarp) }) } } // GetIoGetFlags gets the "io_get_flags" callback function. // gets the #GIOFlags for the channel. This function // // need only return the %G_IO_FLAG_APPEND and // %G_IO_FLAG_NONBLOCK flags; g_io_channel_get_flags() // automatically adds the others as appropriate. func (x *IOFuncs) GetIoGetFlags() func(*IOChannel) IOFlags { if x.xIoGetFlags == 0 { return nil } var rawCallback func(ChannelVarp *IOChannel) IOFlags purego.RegisterFunc(&rawCallback, x.xIoGetFlags) return func(ChannelVar *IOChannel) IOFlags { return rawCallback(ChannelVar) } } const ( WIN32_MSG_HANDLE int = 19981206 ) // A bitwise combination representing a condition to watch for on an // event source. type IOCondition int var xIOConditionGLibType func() types.GType func IOConditionGLibType() types.GType { return xIOConditionGLibType() } const ( // There is data to read. GIoInValue IOCondition = 1 // Data can be written (without blocking). GIoOutValue IOCondition = 4 // There is urgent data to read. GIoPriValue IOCondition = 2 // Error condition. GIoErrValue IOCondition = 8 // Hung up (the connection has been broken, usually for // pipes and sockets). GIoHupValue IOCondition = 16 // Invalid request. The file descriptor is not open. GIoNvalValue IOCondition = 32 ) // Specifies properties of a #GIOChannel. Some of the flags can only be // read with g_io_channel_get_flags(), but not changed with // g_io_channel_set_flags(). type IOFlags int const ( // no special flags set. Since: 2.74 GIoFlagNoneValue IOFlags = 0 // turns on append mode, corresponds to %O_APPEND // (see the documentation of the UNIX open() syscall) GIoFlagAppendValue IOFlags = 1 // turns on nonblocking mode, corresponds to // %O_NONBLOCK/%O_NDELAY (see the documentation of the UNIX open() // syscall) GIoFlagNonblockValue IOFlags = 2 // indicates that the io channel is readable. // This flag cannot be changed. GIoFlagIsReadableValue IOFlags = 4 // indicates that the io channel is writable. // This flag cannot be changed. GIoFlagIsWritableValue IOFlags = 8 // a misspelled version of @G_IO_FLAG_IS_WRITABLE // that existed before the spelling was fixed in GLib 2.30. It is kept // here for compatibility reasons. Deprecated since 2.30 GIoFlagIsWriteableValue IOFlags = 8 // indicates that the io channel is seekable, // i.e. that g_io_channel_seek_position() can be used on it. // This flag cannot be changed. GIoFlagIsSeekableValue IOFlags = 16 // the mask that specifies all the valid flags. GIoFlagMaskValue IOFlags = 31 // the mask of the flags that are returned from // g_io_channel_get_flags() GIoFlagGetMaskValue IOFlags = 31 // the mask of the flags that the user can modify // with g_io_channel_set_flags() GIoFlagSetMaskValue IOFlags = 3 ) // Error codes returned by #GIOChannel operations. type IOChannelError int const ( // File too large. GIoChannelErrorFbigValue IOChannelError = 0 // Invalid argument. GIoChannelErrorInvalValue IOChannelError = 1 // IO error. GIoChannelErrorIoValue IOChannelError = 2 // File is a directory. GIoChannelErrorIsdirValue IOChannelError = 3 // No space left on device. GIoChannelErrorNospcValue IOChannelError = 4 // No such device or address. GIoChannelErrorNxioValue IOChannelError = 5 // Value too large for defined datatype. GIoChannelErrorOverflowValue IOChannelError = 6 // Broken pipe. GIoChannelErrorPipeValue IOChannelError = 7 // Some other error. GIoChannelErrorFailedValue IOChannelError = 8 ) // #GIOError is only used by the deprecated functions // g_io_channel_read(), g_io_channel_write(), and g_io_channel_seek(). type IOError int const ( // no error GIoErrorNoneValue IOError = 0 // an EAGAIN error occurred GIoErrorAgainValue IOError = 1 // an EINVAL error occurred GIoErrorInvalValue IOError = 2 // another error occurred GIoErrorUnknownValue IOError = 3 ) // Statuses returned by most of the #GIOFuncs functions. type IOStatus int const ( // An error occurred. GIoStatusErrorValue IOStatus = 0 // Success. GIoStatusNormalValue IOStatus = 1 // End of file. GIoStatusEofValue IOStatus = 2 // Resource temporarily unavailable. GIoStatusAgainValue IOStatus = 3 ) // An enumeration specifying the base position for a // g_io_channel_seek_position() operation. type SeekType int const ( // the current position in the file. GSeekCurValue SeekType = 0 // the start of the file. GSeekSetValue SeekType = 1 // the end of the file. GSeekEndValue SeekType = 2 ) var xIoAddWatch func(*IOChannel, IOCondition, uintptr, uintptr) uint // Adds the #GIOChannel into the default main loop context // with the default priority. func IoAddWatch(ChannelVar *IOChannel, ConditionVar IOCondition, FuncVar *IOFunc, UserDataVar uintptr) uint { var FuncVarRef uintptr if FuncVar != nil { FuncVarPtr := uintptr(unsafe.Pointer(FuncVar)) if cbRefPtr, ok := GetCallback(FuncVarPtr); ok { FuncVarRef = cbRefPtr } else { fcb := func(arg0 *IOChannel, arg1 IOCondition, arg2 uintptr) bool { cbFn := *FuncVar return cbFn(arg0, arg1, arg2) } FuncVarRef = purego.NewCallback(fcb) SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar) } } cret := xIoAddWatch(ChannelVar, ConditionVar, FuncVarRef, UserDataVar) return cret } var xIoAddWatchFull func(*IOChannel, int, IOCondition, uintptr, uintptr, uintptr) uint // Adds the #GIOChannel into the default main loop context // with the given priority. // // This internally creates a main loop source using g_io_create_watch() // and attaches it to the main loop context with g_source_attach(). // You can do these steps manually if you need greater control. func IoAddWatchFull(ChannelVar *IOChannel, PriorityVar int, ConditionVar IOCondition, FuncVar *IOFunc, UserDataVar uintptr, NotifyVar *DestroyNotify) uint { var FuncVarRef uintptr if FuncVar != nil { FuncVarPtr := uintptr(unsafe.Pointer(FuncVar)) if cbRefPtr, ok := GetCallback(FuncVarPtr); ok { FuncVarRef = cbRefPtr } else { fcb := func(arg0 *IOChannel, arg1 IOCondition, arg2 uintptr) bool { cbFn := *FuncVar return cbFn(arg0, arg1, arg2) } FuncVarRef = purego.NewCallback(fcb) SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar) } } var NotifyVarRef uintptr if NotifyVar != nil { NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar)) if cbRefPtr, ok := GetCallback(NotifyVarPtr); ok { NotifyVarRef = cbRefPtr } else { fcb := func(arg0 uintptr) { cbFn := *NotifyVar cbFn(arg0) } NotifyVarRef = purego.NewCallback(fcb) SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar) } } cret := xIoAddWatchFull(ChannelVar, PriorityVar, ConditionVar, FuncVarRef, UserDataVar, NotifyVarRef) return cret } var xIoChannelErrorFromErrno func(int) IOChannelError // Converts an `errno` error number to a #GIOChannelError. func IoChannelErrorFromErrno(EnVar int) IOChannelError { cret := xIoChannelErrorFromErrno(EnVar) return cret } var xIoCreateWatch func(*IOChannel, IOCondition) *Source // Creates a #GSource that's dispatched when @condition is met for the // given @channel. For example, if condition is %G_IO_IN, the source will // be dispatched when there's data available for reading. // // The callback function invoked by the #GSource should be added with // g_source_set_callback(), but it has type #GIOFunc (not #GSourceFunc). // // g_io_add_watch() is a simpler interface to this same functionality, for // the case where you want to add the source to the default main loop context // at the default priority. // // On Windows, polling a #GSource created to watch a channel for a socket // puts the socket in non-blocking mode. This is a side-effect of the // implementation and unavoidable. func IoCreateWatch(ChannelVar *IOChannel, ConditionVar IOCondition) *Source { cret := xIoCreateWatch(ChannelVar, ConditionVar) return cret } func init() { core.SetPackageName("GLIB", "glib-2.0") core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"}) var libs []uintptr for _, libPath := range core.GetPaths("GLIB") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xIOConditionGLibType, libs, "g_io_condition_get_type") core.PuregoSafeRegister(&xIoAddWatch, libs, "g_io_add_watch") core.PuregoSafeRegister(&xIoAddWatchFull, libs, "g_io_add_watch_full") core.PuregoSafeRegister(&xIoChannelErrorFromErrno, libs, "g_io_channel_error_from_errno") core.PuregoSafeRegister(&xIoCreateWatch, libs, "g_io_create_watch") core.PuregoSafeRegister(&xIOChannelGLibType, libs, "g_io_channel_get_type") core.PuregoSafeRegister(&xNewIOChannelFile, libs, "g_io_channel_new_file") core.PuregoSafeRegister(&xIOChannelUnixNew, libs, "g_io_channel_unix_new") core.PuregoSafeRegister(&xIOChannelClose, libs, "g_io_channel_close") core.PuregoSafeRegister(&xIOChannelFlush, libs, "g_io_channel_flush") core.PuregoSafeRegister(&xIOChannelGetBufferCondition, libs, "g_io_channel_get_buffer_condition") core.PuregoSafeRegister(&xIOChannelGetBufferSize, libs, "g_io_channel_get_buffer_size") core.PuregoSafeRegister(&xIOChannelGetBuffered, libs, "g_io_channel_get_buffered") core.PuregoSafeRegister(&xIOChannelGetCloseOnUnref, libs, "g_io_channel_get_close_on_unref") core.PuregoSafeRegister(&xIOChannelGetEncoding, libs, "g_io_channel_get_encoding") core.PuregoSafeRegister(&xIOChannelGetFlags, libs, "g_io_channel_get_flags") core.PuregoSafeRegister(&xIOChannelGetLineTerm, libs, "g_io_channel_get_line_term") core.PuregoSafeRegister(&xIOChannelInit, libs, "g_io_channel_init") core.PuregoSafeRegister(&xIOChannelRead, libs, "g_io_channel_read") core.PuregoSafeRegister(&xIOChannelReadChars, libs, "g_io_channel_read_chars") core.PuregoSafeRegister(&xIOChannelReadLine, libs, "g_io_channel_read_line") core.PuregoSafeRegister(&xIOChannelReadLineString, libs, "g_io_channel_read_line_string") core.PuregoSafeRegister(&xIOChannelReadToEnd, libs, "g_io_channel_read_to_end") core.PuregoSafeRegister(&xIOChannelReadUnichar, libs, "g_io_channel_read_unichar") core.PuregoSafeRegister(&xIOChannelRef, libs, "g_io_channel_ref") core.PuregoSafeRegister(&xIOChannelSeek, libs, "g_io_channel_seek") core.PuregoSafeRegister(&xIOChannelSeekPosition, libs, "g_io_channel_seek_position") core.PuregoSafeRegister(&xIOChannelSetBufferSize, libs, "g_io_channel_set_buffer_size") core.PuregoSafeRegister(&xIOChannelSetBuffered, libs, "g_io_channel_set_buffered") core.PuregoSafeRegister(&xIOChannelSetCloseOnUnref, libs, "g_io_channel_set_close_on_unref") core.PuregoSafeRegister(&xIOChannelSetEncoding, libs, "g_io_channel_set_encoding") core.PuregoSafeRegister(&xIOChannelSetFlags, libs, "g_io_channel_set_flags") core.PuregoSafeRegister(&xIOChannelSetLineTerm, libs, "g_io_channel_set_line_term") core.PuregoSafeRegister(&xIOChannelShutdown, libs, "g_io_channel_shutdown") core.PuregoSafeRegister(&xIOChannelUnixGetFd, libs, "g_io_channel_unix_get_fd") core.PuregoSafeRegister(&xIOChannelUnref, libs, "g_io_channel_unref") core.PuregoSafeRegister(&xIOChannelWrite, libs, "g_io_channel_write") core.PuregoSafeRegister(&xIOChannelWriteChars, libs, "g_io_channel_write_chars") core.PuregoSafeRegister(&xIOChannelWriteUnichar, libs, "g_io_channel_write_unichar") }