1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
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/gobject/types"
12)
13
14// Specifies the type of function passed to g_io_add_watch() or
15// g_io_add_watch_full(), which is called when the requested condition
16// on a #GIOChannel is satisfied.
17type IOFunc func(*IOChannel, IOCondition, uintptr) bool
18
19// The `GIOChannel` data type aims to provide a portable method for
20// using file descriptors, pipes, and sockets, and integrating them
21// into the main event loop (see [struct@GLib.MainContext]). Currently,
22// full support is available on UNIX platforms; support for Windows
23// is only partially complete.
24//
25// To create a new `GIOChannel` on UNIX systems use
26// [ctor@GLib.IOChannel.unix_new]. This works for plain file descriptors,
27// pipes and sockets. Alternatively, a channel can be created for a
28// file in a system independent manner using [ctor@GLib.IOChannel.new_file].
29//
30// Once a `GIOChannel` has been created, it can be used in a generic
31// manner with the functions [method@GLib.IOChannel.read_chars],
32// [method@GLib.IOChannel.write_chars], [method@GLib.IOChannel.seek_position],
33// and [method@GLib.IOChannel.shutdown].
34//
35// To add a `GIOChannel` to the main event loop, use [func@GLib.io_add_watch] or
36// [func@GLib.io_add_watch_full]. Here you specify which events you are
37// interested in on the `GIOChannel`, and provide a function to be called
38// whenever these events occur.
39//
40// `GIOChannel` instances are created with an initial reference count of 1.
41// [method@GLib.IOChannel.ref] and [method@GLib.IOChannel.unref] can be used to
42// increment or decrement the reference count respectively. When the
43// reference count falls to 0, the `GIOChannel` is freed. (Though it
44// isn’t closed automatically, unless it was created using
45// [ctor@GLib.IOChannel.new_file].) Using [func@GLib.io_add_watch] or
46// [func@GLib.io_add_watch_full] increments a channel’s reference count.
47//
48// The new functions [method@GLib.IOChannel.read_chars],
49// [method@GLib.IOChannel.read_line], [method@GLib.IOChannel.read_line_string],
50// [method@GLib.IOChannel.read_to_end], [method@GLib.IOChannel.write_chars],
51// [method@GLib.IOChannel.seek_position], and [method@GLib.IOChannel.flush]
52// should not be mixed with the deprecated functions
53// [method@GLib.IOChannel.read], [method@GLib.IOChannel.write], and
54// [method@GLib.IOChannel.seek] on the same channel.
55type IOChannel struct {
56 _ structs.HostLayout
57
58 RefCount int32
59
60 Funcs *IOFuncs
61
62 Encoding uintptr
63
64 ReadCd uintptr
65
66 WriteCd uintptr
67
68 LineTerm uintptr
69
70 LineTermLen uint
71
72 BufSize uint
73
74 ReadBuf *String
75
76 EncodedReadBuf *String
77
78 WriteBuf *String
79
80 PartialWriteBuf [6]byte
81
82 UseBuffer uint
83
84 DoEncode uint
85
86 CloseOnUnref uint
87
88 IsReadable uint
89
90 IsWriteable uint
91
92 IsSeekable uint
93
94 Reserved1 uintptr
95
96 Reserved2 uintptr
97}
98
99var xIOChannelGLibType func() types.GType
100
101func IOChannelGLibType() types.GType {
102 return xIOChannelGLibType()
103}
104
105func (x *IOChannel) GoPointer() uintptr {
106 return uintptr(unsafe.Pointer(x))
107}
108
109var xNewIOChannelFile func(string, string, **Error) *IOChannel
110
111// Open a file @filename as a #GIOChannel using mode @mode. This
112// channel will be closed when the last reference to it is dropped,
113// so there is no need to call g_io_channel_close() (though doing
114// so will not cause problems, as long as no attempt is made to
115// access the channel after it is closed).
116func NewIOChannelFile(FilenameVar string, ModeVar string) (*IOChannel, error) {
117 var cerr *Error
118
119 cret := xNewIOChannelFile(FilenameVar, ModeVar, &cerr)
120 if cerr == nil {
121 return cret, nil
122 }
123 return cret, cerr
124
125}
126
127var xIOChannelUnixNew func(int) *IOChannel
128
129// Creates a new #GIOChannel given a file descriptor. On UNIX systems
130// this works for plain files, pipes, and sockets.
131//
132// The returned #GIOChannel has a reference count of 1.
133//
134// The default encoding for #GIOChannel is UTF-8. If your application
135// is reading output from a command using via pipe, you may need to set
136// the encoding to the encoding of the current locale (see
137// g_get_charset()) with the g_io_channel_set_encoding() function.
138// By default, the fd passed will not be closed when the final reference
139// to the #GIOChannel data structure is dropped.
140//
141// If you want to read raw binary data without interpretation, then
142// call the g_io_channel_set_encoding() function with %NULL for the
143// encoding argument.
144//
145// This function is available in GLib on Windows, too, but you should
146// avoid using it on Windows. The domain of file descriptors and
147// sockets overlap. There is no way for GLib to know which one you mean
148// in case the argument you pass to this function happens to be both a
149// valid file descriptor and socket. If that happens a warning is
150// issued, and GLib assumes that it is the file descriptor you mean.
151func IOChannelUnixNew(FdVar int) *IOChannel {
152
153 cret := xIOChannelUnixNew(FdVar)
154 return cret
155}
156
157var xIOChannelClose func(uintptr)
158
159// Close an IO channel. Any pending data to be written will be
160// flushed, ignoring errors. The channel will not be freed until the
161// last reference is dropped using g_io_channel_unref().
162func (x *IOChannel) Close() {
163
164 xIOChannelClose(x.GoPointer())
165
166}
167
168var xIOChannelFlush func(uintptr) IOStatus
169
170// Flushes the write buffer for the GIOChannel.
171func (x *IOChannel) Flush() (IOStatus, error) {
172 var cerr *Error
173
174 cret := xIOChannelFlush(x.GoPointer())
175 if cerr == nil {
176 return cret, nil
177 }
178 return cret, cerr
179
180}
181
182var xIOChannelGetBufferCondition func(uintptr) IOCondition
183
184// This function returns a #GIOCondition depending on whether there
185// is data to be read/space to write data in the internal buffers in
186// the #GIOChannel. Only the flags %G_IO_IN and %G_IO_OUT may be set.
187func (x *IOChannel) GetBufferCondition() IOCondition {
188
189 cret := xIOChannelGetBufferCondition(x.GoPointer())
190 return cret
191}
192
193var xIOChannelGetBufferSize func(uintptr) uint
194
195// Gets the buffer size.
196func (x *IOChannel) GetBufferSize() uint {
197
198 cret := xIOChannelGetBufferSize(x.GoPointer())
199 return cret
200}
201
202var xIOChannelGetBuffered func(uintptr) bool
203
204// Returns whether @channel is buffered.
205func (x *IOChannel) GetBuffered() bool {
206
207 cret := xIOChannelGetBuffered(x.GoPointer())
208 return cret
209}
210
211var xIOChannelGetCloseOnUnref func(uintptr) bool
212
213// Returns whether the file/socket/whatever associated with @channel
214// will be closed when @channel receives its final unref and is
215// destroyed. The default value of this is %TRUE for channels created
216// by g_io_channel_new_file (), and %FALSE for all other channels.
217func (x *IOChannel) GetCloseOnUnref() bool {
218
219 cret := xIOChannelGetCloseOnUnref(x.GoPointer())
220 return cret
221}
222
223var xIOChannelGetEncoding func(uintptr) string
224
225// Gets the encoding for the input/output of the channel.
226// The internal encoding is always UTF-8. The encoding %NULL
227// makes the channel safe for binary data.
228func (x *IOChannel) GetEncoding() string {
229
230 cret := xIOChannelGetEncoding(x.GoPointer())
231 return cret
232}
233
234var xIOChannelGetFlags func(uintptr) IOFlags
235
236// Gets the current flags for a #GIOChannel, including read-only
237// flags such as %G_IO_FLAG_IS_READABLE.
238//
239// The values of the flags %G_IO_FLAG_IS_READABLE and %G_IO_FLAG_IS_WRITABLE
240// are cached for internal use by the channel when it is created.
241// If they should change at some later point (e.g. partial shutdown
242// of a socket with the UNIX shutdown() function), the user
243// should immediately call g_io_channel_get_flags() to update
244// the internal values of these flags.
245func (x *IOChannel) GetFlags() IOFlags {
246
247 cret := xIOChannelGetFlags(x.GoPointer())
248 return cret
249}
250
251var xIOChannelGetLineTerm func(uintptr, *int) string
252
253// This returns the string that #GIOChannel uses to determine
254// where in the file a line break occurs. A value of %NULL
255// indicates autodetection. Since 2.84, the return value is always
256// nul-terminated.
257func (x *IOChannel) GetLineTerm(LengthVar *int) string {
258
259 cret := xIOChannelGetLineTerm(x.GoPointer(), LengthVar)
260 return cret
261}
262
263var xIOChannelInit func(uintptr)
264
265// Initializes a #GIOChannel struct.
266//
267// This is called by each of the above functions when creating a
268// #GIOChannel, and so is not often needed by the application
269// programmer (unless you are creating a new type of #GIOChannel).
270func (x *IOChannel) Init() {
271
272 xIOChannelInit(x.GoPointer())
273
274}
275
276var xIOChannelRead func(uintptr, string, uint, uint) IOError
277
278// Reads data from a #GIOChannel.
279func (x *IOChannel) Read(BufVar string, CountVar uint, BytesReadVar uint) IOError {
280
281 cret := xIOChannelRead(x.GoPointer(), BufVar, CountVar, BytesReadVar)
282 return cret
283}
284
285var xIOChannelReadChars func(uintptr, *[]byte, uint, *uint, **Error) IOStatus
286
287// Replacement for g_io_channel_read() with the new API.
288func (x *IOChannel) ReadChars(BufVar *[]byte, CountVar uint, BytesReadVar *uint) (IOStatus, error) {
289 var cerr *Error
290
291 cret := xIOChannelReadChars(x.GoPointer(), BufVar, CountVar, BytesReadVar, &cerr)
292 if cerr == nil {
293 return cret, nil
294 }
295 return cret, cerr
296
297}
298
299var xIOChannelReadLine func(uintptr, *string, *uint, *uint, **Error) IOStatus
300
301// Reads a line, including the terminating character(s),
302// from a #GIOChannel into a newly-allocated string.
303// @str_return will contain allocated memory if the return
304// is %G_IO_STATUS_NORMAL.
305func (x *IOChannel) ReadLine(StrReturnVar *string, LengthVar *uint, TerminatorPosVar *uint) (IOStatus, error) {
306 var cerr *Error
307
308 cret := xIOChannelReadLine(x.GoPointer(), StrReturnVar, LengthVar, TerminatorPosVar, &cerr)
309 if cerr == nil {
310 return cret, nil
311 }
312 return cret, cerr
313
314}
315
316var xIOChannelReadLineString func(uintptr, *String, uint, **Error) IOStatus
317
318// Reads a line from a #GIOChannel, using a #GString as a buffer.
319func (x *IOChannel) ReadLineString(BufferVar *String, TerminatorPosVar uint) (IOStatus, error) {
320 var cerr *Error
321
322 cret := xIOChannelReadLineString(x.GoPointer(), BufferVar, TerminatorPosVar, &cerr)
323 if cerr == nil {
324 return cret, nil
325 }
326 return cret, cerr
327
328}
329
330var xIOChannelReadToEnd func(uintptr, *[]byte, *uint, **Error) IOStatus
331
332// Reads all the remaining data from the file.
333func (x *IOChannel) ReadToEnd(StrReturnVar *[]byte, LengthVar *uint) (IOStatus, error) {
334 var cerr *Error
335
336 cret := xIOChannelReadToEnd(x.GoPointer(), StrReturnVar, LengthVar, &cerr)
337 if cerr == nil {
338 return cret, nil
339 }
340 return cret, cerr
341
342}
343
344var xIOChannelReadUnichar func(uintptr, *uint32, **Error) IOStatus
345
346// Reads a Unicode character from @channel.
347// This function cannot be called on a channel with %NULL encoding.
348func (x *IOChannel) ReadUnichar(ThecharVar *uint32) (IOStatus, error) {
349 var cerr *Error
350
351 cret := xIOChannelReadUnichar(x.GoPointer(), ThecharVar, &cerr)
352 if cerr == nil {
353 return cret, nil
354 }
355 return cret, cerr
356
357}
358
359var xIOChannelRef func(uintptr) *IOChannel
360
361// Increments the reference count of a #GIOChannel.
362func (x *IOChannel) Ref() *IOChannel {
363
364 cret := xIOChannelRef(x.GoPointer())
365 return cret
366}
367
368var xIOChannelSeek func(uintptr, int64, SeekType) IOError
369
370// Sets the current position in the #GIOChannel, similar to the standard
371// library function fseek().
372func (x *IOChannel) Seek(OffsetVar int64, TypeVar SeekType) IOError {
373
374 cret := xIOChannelSeek(x.GoPointer(), OffsetVar, TypeVar)
375 return cret
376}
377
378var xIOChannelSeekPosition func(uintptr, int64, SeekType, **Error) IOStatus
379
380// Replacement for g_io_channel_seek() with the new API.
381func (x *IOChannel) SeekPosition(OffsetVar int64, TypeVar SeekType) (IOStatus, error) {
382 var cerr *Error
383
384 cret := xIOChannelSeekPosition(x.GoPointer(), OffsetVar, TypeVar, &cerr)
385 if cerr == nil {
386 return cret, nil
387 }
388 return cret, cerr
389
390}
391
392var xIOChannelSetBufferSize func(uintptr, uint)
393
394// Sets the buffer size.
395func (x *IOChannel) SetBufferSize(SizeVar uint) {
396
397 xIOChannelSetBufferSize(x.GoPointer(), SizeVar)
398
399}
400
401var xIOChannelSetBuffered func(uintptr, bool)
402
403// The buffering state can only be set if the channel's encoding
404// is %NULL. For any other encoding, the channel must be buffered.
405//
406// A buffered channel can only be set unbuffered if the channel's
407// internal buffers have been flushed. Newly created channels or
408// channels which have returned %G_IO_STATUS_EOF
409// not require such a flush. For write-only channels, a call to
410// g_io_channel_flush () is sufficient. For all other channels,
411// the buffers may be flushed by a call to g_io_channel_seek_position ().
412// This includes the possibility of seeking with seek type %G_SEEK_CUR
413// and an offset of zero. Note that this means that socket-based
414// channels cannot be set unbuffered once they have had data
415// read from them.
416//
417// On unbuffered channels, it is safe to mix read and write
418// calls from the new and old APIs, if this is necessary for
419// maintaining old code.
420//
421// The default state of the channel is buffered.
422func (x *IOChannel) SetBuffered(BufferedVar bool) {
423
424 xIOChannelSetBuffered(x.GoPointer(), BufferedVar)
425
426}
427
428var xIOChannelSetCloseOnUnref func(uintptr, bool)
429
430// Whether to close the channel on the final unref of the #GIOChannel
431// data structure. The default value of this is %TRUE for channels
432// created by g_io_channel_new_file (), and %FALSE for all other channels.
433//
434// Setting this flag to %TRUE for a channel you have already closed
435// can cause problems when the final reference to the #GIOChannel is dropped.
436func (x *IOChannel) SetCloseOnUnref(DoCloseVar bool) {
437
438 xIOChannelSetCloseOnUnref(x.GoPointer(), DoCloseVar)
439
440}
441
442var xIOChannelSetEncoding func(uintptr, uintptr, **Error) IOStatus
443
444// Sets the encoding for the input/output of the channel.
445// The internal encoding is always UTF-8. The default encoding
446// for the external file is UTF-8.
447//
448// The encoding %NULL is safe to use with binary data.
449//
450// The encoding can only be set if one of the following conditions
451// is true:
452//
453// - The channel was just created, and has not been written to or read from yet.
454//
455// - The channel is write-only.
456//
457// - The channel is a file, and the file pointer was just repositioned
458// by a call to g_io_channel_seek_position(). (This flushes all the
459// internal buffers.)
460//
461// - The current encoding is %NULL or UTF-8.
462//
463// - One of the (new API) read functions has just returned %G_IO_STATUS_EOF
464// (or, in the case of g_io_channel_read_to_end(), %G_IO_STATUS_NORMAL).
465//
466// - One of the functions g_io_channel_read_chars() or
467// g_io_channel_read_unichar() has returned %G_IO_STATUS_AGAIN or
468// %G_IO_STATUS_ERROR. This may be useful in the case of
469// %G_CONVERT_ERROR_ILLEGAL_SEQUENCE.
470// Returning one of these statuses from g_io_channel_read_line(),
471// g_io_channel_read_line_string(), or g_io_channel_read_to_end()
472// does not guarantee that the encoding can be changed.
473//
474// Channels which do not meet one of the above conditions cannot call
475// g_io_channel_seek_position() with an offset of %G_SEEK_CUR, and, if
476// they are "seekable", cannot call g_io_channel_write_chars() after
477// calling one of the API "read" functions.
478func (x *IOChannel) SetEncoding(EncodingVar *string) (IOStatus, error) {
479 var cerr *Error
480
481 EncodingVarPtr := core.GStrdupNullable(EncodingVar)
482 defer core.GFreeNullable(EncodingVarPtr)
483
484 cret := xIOChannelSetEncoding(x.GoPointer(), EncodingVarPtr, &cerr)
485 if cerr == nil {
486 return cret, nil
487 }
488 return cret, cerr
489
490}
491
492var xIOChannelSetFlags func(uintptr, IOFlags, **Error) IOStatus
493
494// Sets the (writeable) flags in @channel to (@flags & %G_IO_FLAG_SET_MASK).
495func (x *IOChannel) SetFlags(FlagsVar IOFlags) (IOStatus, error) {
496 var cerr *Error
497
498 cret := xIOChannelSetFlags(x.GoPointer(), FlagsVar, &cerr)
499 if cerr == nil {
500 return cret, nil
501 }
502 return cret, cerr
503
504}
505
506var xIOChannelSetLineTerm func(uintptr, uintptr, int)
507
508// This sets the string that #GIOChannel uses to determine
509// where in the file a line break occurs.
510func (x *IOChannel) SetLineTerm(LineTermVar *string, LengthVar int) {
511
512 LineTermVarPtr := core.GStrdupNullable(LineTermVar)
513 defer core.GFreeNullable(LineTermVarPtr)
514
515 xIOChannelSetLineTerm(x.GoPointer(), LineTermVarPtr, LengthVar)
516
517}
518
519var xIOChannelShutdown func(uintptr, bool, **Error) IOStatus
520
521// Close an IO channel. Any pending data to be written will be
522// flushed if @flush is %TRUE. The channel will not be freed until the
523// last reference is dropped using g_io_channel_unref().
524func (x *IOChannel) Shutdown(FlushVar bool) (IOStatus, error) {
525 var cerr *Error
526
527 cret := xIOChannelShutdown(x.GoPointer(), FlushVar, &cerr)
528 if cerr == nil {
529 return cret, nil
530 }
531 return cret, cerr
532
533}
534
535var xIOChannelUnixGetFd func(uintptr) int
536
537// Returns the file descriptor of the #GIOChannel.
538//
539// On Windows this function returns the file descriptor or socket of
540// the #GIOChannel.
541func (x *IOChannel) UnixGetFd() int {
542
543 cret := xIOChannelUnixGetFd(x.GoPointer())
544 return cret
545}
546
547var xIOChannelUnref func(uintptr)
548
549// Decrements the reference count of a #GIOChannel.
550func (x *IOChannel) Unref() {
551
552 xIOChannelUnref(x.GoPointer())
553
554}
555
556var xIOChannelWrite func(uintptr, string, uint, uint) IOError
557
558// Writes data to a #GIOChannel.
559func (x *IOChannel) Write(BufVar string, CountVar uint, BytesWrittenVar uint) IOError {
560
561 cret := xIOChannelWrite(x.GoPointer(), BufVar, CountVar, BytesWrittenVar)
562 return cret
563}
564
565var xIOChannelWriteChars func(uintptr, []byte, int, *uint, **Error) IOStatus
566
567// Replacement for g_io_channel_write() with the new API.
568//
569// On seekable channels with encodings other than %NULL or UTF-8, generic
570// mixing of reading and writing is not allowed. A call to g_io_channel_write_chars ()
571// may only be made on a channel from which data has been read in the
572// cases described in the documentation for g_io_channel_set_encoding ().
573func (x *IOChannel) WriteChars(BufVar []byte, CountVar int, BytesWrittenVar *uint) (IOStatus, error) {
574 var cerr *Error
575
576 cret := xIOChannelWriteChars(x.GoPointer(), BufVar, CountVar, BytesWrittenVar, &cerr)
577 if cerr == nil {
578 return cret, nil
579 }
580 return cret, cerr
581
582}
583
584var xIOChannelWriteUnichar func(uintptr, uint32, **Error) IOStatus
585
586// Writes a Unicode character to @channel.
587// This function cannot be called on a channel with %NULL encoding.
588func (x *IOChannel) WriteUnichar(ThecharVar uint32) (IOStatus, error) {
589 var cerr *Error
590
591 cret := xIOChannelWriteUnichar(x.GoPointer(), ThecharVar, &cerr)
592 if cerr == nil {
593 return cret, nil
594 }
595 return cret, cerr
596
597}
598
599// A table of functions used to handle different types of #GIOChannel
600// in a generic way.
601type IOFuncs struct {
602 _ structs.HostLayout
603
604 xIoRead uintptr
605
606 xIoWrite uintptr
607
608 xIoSeek uintptr
609
610 xIoClose uintptr
611
612 xIoCreateWatch uintptr
613
614 xIoFree uintptr
615
616 xIoSetFlags uintptr
617
618 xIoGetFlags uintptr
619}
620
621func (x *IOFuncs) GoPointer() uintptr {
622 return uintptr(unsafe.Pointer(x))
623}
624
625// OverrideIoRead sets the "io_read" callback function.
626// reads raw bytes from the channel. This is called from
627//
628// various functions such as g_io_channel_read_chars() to
629// read raw bytes from the channel. Encoding and buffering
630// issues are dealt with at a higher level.
631func (x *IOFuncs) OverrideIoRead(cb func(*IOChannel, string, uint, uint) IOStatus) {
632 if cb == nil {
633 x.xIoRead = 0
634 } else {
635 x.xIoRead = purego.NewCallback(func(ChannelVarp *IOChannel, BufVarp string, CountVarp uint, BytesReadVarp uint) IOStatus {
636 return cb(ChannelVarp, BufVarp, CountVarp, BytesReadVarp)
637 })
638 }
639}
640
641// GetIoRead gets the "io_read" callback function.
642// reads raw bytes from the channel. This is called from
643//
644// various functions such as g_io_channel_read_chars() to
645// read raw bytes from the channel. Encoding and buffering
646// issues are dealt with at a higher level.
647func (x *IOFuncs) GetIoRead() func(*IOChannel, string, uint, uint) IOStatus {
648 if x.xIoRead == 0 {
649 return nil
650 }
651 var rawCallback func(ChannelVarp *IOChannel, BufVarp string, CountVarp uint, BytesReadVarp uint) IOStatus
652 purego.RegisterFunc(&rawCallback, x.xIoRead)
653 return func(ChannelVar *IOChannel, BufVar string, CountVar uint, BytesReadVar uint) IOStatus {
654 return rawCallback(ChannelVar, BufVar, CountVar, BytesReadVar)
655 }
656}
657
658// OverrideIoWrite sets the "io_write" callback function.
659// writes raw bytes to the channel. This is called from
660//
661// various functions such as g_io_channel_write_chars() to
662// write raw bytes to the channel. Encoding and buffering
663// issues are dealt with at a higher level.
664func (x *IOFuncs) OverrideIoWrite(cb func(*IOChannel, string, uint, uint) IOStatus) {
665 if cb == nil {
666 x.xIoWrite = 0
667 } else {
668 x.xIoWrite = purego.NewCallback(func(ChannelVarp *IOChannel, BufVarp string, CountVarp uint, BytesWrittenVarp uint) IOStatus {
669 return cb(ChannelVarp, BufVarp, CountVarp, BytesWrittenVarp)
670 })
671 }
672}
673
674// GetIoWrite gets the "io_write" callback function.
675// writes raw bytes to the channel. This is called from
676//
677// various functions such as g_io_channel_write_chars() to
678// write raw bytes to the channel. Encoding and buffering
679// issues are dealt with at a higher level.
680func (x *IOFuncs) GetIoWrite() func(*IOChannel, string, uint, uint) IOStatus {
681 if x.xIoWrite == 0 {
682 return nil
683 }
684 var rawCallback func(ChannelVarp *IOChannel, BufVarp string, CountVarp uint, BytesWrittenVarp uint) IOStatus
685 purego.RegisterFunc(&rawCallback, x.xIoWrite)
686 return func(ChannelVar *IOChannel, BufVar string, CountVar uint, BytesWrittenVar uint) IOStatus {
687 return rawCallback(ChannelVar, BufVar, CountVar, BytesWrittenVar)
688 }
689}
690
691// OverrideIoSeek sets the "io_seek" callback function.
692// seeks the channel. This is called from
693//
694// g_io_channel_seek() on channels that support it.
695func (x *IOFuncs) OverrideIoSeek(cb func(*IOChannel, int64, SeekType) IOStatus) {
696 if cb == nil {
697 x.xIoSeek = 0
698 } else {
699 x.xIoSeek = purego.NewCallback(func(ChannelVarp *IOChannel, OffsetVarp int64, TypeVarp SeekType) IOStatus {
700 return cb(ChannelVarp, OffsetVarp, TypeVarp)
701 })
702 }
703}
704
705// GetIoSeek gets the "io_seek" callback function.
706// seeks the channel. This is called from
707//
708// g_io_channel_seek() on channels that support it.
709func (x *IOFuncs) GetIoSeek() func(*IOChannel, int64, SeekType) IOStatus {
710 if x.xIoSeek == 0 {
711 return nil
712 }
713 var rawCallback func(ChannelVarp *IOChannel, OffsetVarp int64, TypeVarp SeekType) IOStatus
714 purego.RegisterFunc(&rawCallback, x.xIoSeek)
715 return func(ChannelVar *IOChannel, OffsetVar int64, TypeVar SeekType) IOStatus {
716 return rawCallback(ChannelVar, OffsetVar, TypeVar)
717 }
718}
719
720// OverrideIoClose sets the "io_close" callback function.
721// closes the channel. This is called from
722//
723// g_io_channel_close() after flushing the buffers.
724func (x *IOFuncs) OverrideIoClose(cb func(*IOChannel) IOStatus) {
725 if cb == nil {
726 x.xIoClose = 0
727 } else {
728 x.xIoClose = purego.NewCallback(func(ChannelVarp *IOChannel) IOStatus {
729 return cb(ChannelVarp)
730 })
731 }
732}
733
734// GetIoClose gets the "io_close" callback function.
735// closes the channel. This is called from
736//
737// g_io_channel_close() after flushing the buffers.
738func (x *IOFuncs) GetIoClose() func(*IOChannel) IOStatus {
739 if x.xIoClose == 0 {
740 return nil
741 }
742 var rawCallback func(ChannelVarp *IOChannel) IOStatus
743 purego.RegisterFunc(&rawCallback, x.xIoClose)
744 return func(ChannelVar *IOChannel) IOStatus {
745 return rawCallback(ChannelVar)
746 }
747}
748
749// OverrideIoCreateWatch sets the "io_create_watch" callback function.
750// creates a watch on the channel. This call
751//
752// corresponds directly to g_io_create_watch().
753func (x *IOFuncs) OverrideIoCreateWatch(cb func(*IOChannel, IOCondition) *Source) {
754 if cb == nil {
755 x.xIoCreateWatch = 0
756 } else {
757 x.xIoCreateWatch = purego.NewCallback(func(ChannelVarp *IOChannel, ConditionVarp IOCondition) *Source {
758 return cb(ChannelVarp, ConditionVarp)
759 })
760 }
761}
762
763// GetIoCreateWatch gets the "io_create_watch" callback function.
764// creates a watch on the channel. This call
765//
766// corresponds directly to g_io_create_watch().
767func (x *IOFuncs) GetIoCreateWatch() func(*IOChannel, IOCondition) *Source {
768 if x.xIoCreateWatch == 0 {
769 return nil
770 }
771 var rawCallback func(ChannelVarp *IOChannel, ConditionVarp IOCondition) *Source
772 purego.RegisterFunc(&rawCallback, x.xIoCreateWatch)
773 return func(ChannelVar *IOChannel, ConditionVar IOCondition) *Source {
774 return rawCallback(ChannelVar, ConditionVar)
775 }
776}
777
778// OverrideIoFree sets the "io_free" callback function.
779// called from g_io_channel_unref() when the channel needs to
780//
781// be freed. This function must free the memory associated
782// with the channel, including freeing the #GIOChannel
783// structure itself. The channel buffers have been flushed
784// and possibly @io_close has been called by the time this
785// function is called.
786func (x *IOFuncs) OverrideIoFree(cb func(*IOChannel)) {
787 if cb == nil {
788 x.xIoFree = 0
789 } else {
790 x.xIoFree = purego.NewCallback(func(ChannelVarp *IOChannel) {
791 cb(ChannelVarp)
792 })
793 }
794}
795
796// GetIoFree gets the "io_free" callback function.
797// called from g_io_channel_unref() when the channel needs to
798//
799// be freed. This function must free the memory associated
800// with the channel, including freeing the #GIOChannel
801// structure itself. The channel buffers have been flushed
802// and possibly @io_close has been called by the time this
803// function is called.
804func (x *IOFuncs) GetIoFree() func(*IOChannel) {
805 if x.xIoFree == 0 {
806 return nil
807 }
808 var rawCallback func(ChannelVarp *IOChannel)
809 purego.RegisterFunc(&rawCallback, x.xIoFree)
810 return func(ChannelVar *IOChannel) {
811 rawCallback(ChannelVar)
812 }
813}
814
815// OverrideIoSetFlags sets the "io_set_flags" callback function.
816// sets the #GIOFlags on the channel. This is called
817//
818// from g_io_channel_set_flags() with all flags except
819// for %G_IO_FLAG_APPEND and %G_IO_FLAG_NONBLOCK masked
820// out.
821func (x *IOFuncs) OverrideIoSetFlags(cb func(*IOChannel, IOFlags) IOStatus) {
822 if cb == nil {
823 x.xIoSetFlags = 0
824 } else {
825 x.xIoSetFlags = purego.NewCallback(func(ChannelVarp *IOChannel, FlagsVarp IOFlags) IOStatus {
826 return cb(ChannelVarp, FlagsVarp)
827 })
828 }
829}
830
831// GetIoSetFlags gets the "io_set_flags" callback function.
832// sets the #GIOFlags on the channel. This is called
833//
834// from g_io_channel_set_flags() with all flags except
835// for %G_IO_FLAG_APPEND and %G_IO_FLAG_NONBLOCK masked
836// out.
837func (x *IOFuncs) GetIoSetFlags() func(*IOChannel, IOFlags) IOStatus {
838 if x.xIoSetFlags == 0 {
839 return nil
840 }
841 var rawCallback func(ChannelVarp *IOChannel, FlagsVarp IOFlags) IOStatus
842 purego.RegisterFunc(&rawCallback, x.xIoSetFlags)
843 return func(ChannelVar *IOChannel, FlagsVar IOFlags) IOStatus {
844 return rawCallback(ChannelVar, FlagsVar)
845 }
846}
847
848// OverrideIoGetFlags sets the "io_get_flags" callback function.
849// gets the #GIOFlags for the channel. This function
850//
851// need only return the %G_IO_FLAG_APPEND and
852// %G_IO_FLAG_NONBLOCK flags; g_io_channel_get_flags()
853// automatically adds the others as appropriate.
854func (x *IOFuncs) OverrideIoGetFlags(cb func(*IOChannel) IOFlags) {
855 if cb == nil {
856 x.xIoGetFlags = 0
857 } else {
858 x.xIoGetFlags = purego.NewCallback(func(ChannelVarp *IOChannel) IOFlags {
859 return cb(ChannelVarp)
860 })
861 }
862}
863
864// GetIoGetFlags gets the "io_get_flags" callback function.
865// gets the #GIOFlags for the channel. This function
866//
867// need only return the %G_IO_FLAG_APPEND and
868// %G_IO_FLAG_NONBLOCK flags; g_io_channel_get_flags()
869// automatically adds the others as appropriate.
870func (x *IOFuncs) GetIoGetFlags() func(*IOChannel) IOFlags {
871 if x.xIoGetFlags == 0 {
872 return nil
873 }
874 var rawCallback func(ChannelVarp *IOChannel) IOFlags
875 purego.RegisterFunc(&rawCallback, x.xIoGetFlags)
876 return func(ChannelVar *IOChannel) IOFlags {
877 return rawCallback(ChannelVar)
878 }
879}
880
881const (
882 WIN32_MSG_HANDLE int = 19981206
883)
884
885// A bitwise combination representing a condition to watch for on an
886// event source.
887type IOCondition int
888
889var xIOConditionGLibType func() types.GType
890
891func IOConditionGLibType() types.GType {
892 return xIOConditionGLibType()
893}
894
895const (
896
897 // There is data to read.
898 GIoInValue IOCondition = 1
899 // Data can be written (without blocking).
900 GIoOutValue IOCondition = 4
901 // There is urgent data to read.
902 GIoPriValue IOCondition = 2
903 // Error condition.
904 GIoErrValue IOCondition = 8
905 // Hung up (the connection has been broken, usually for
906 // pipes and sockets).
907 GIoHupValue IOCondition = 16
908 // Invalid request. The file descriptor is not open.
909 GIoNvalValue IOCondition = 32
910)
911
912// Specifies properties of a #GIOChannel. Some of the flags can only be
913// read with g_io_channel_get_flags(), but not changed with
914// g_io_channel_set_flags().
915type IOFlags int
916
917const (
918
919 // no special flags set. Since: 2.74
920 GIoFlagNoneValue IOFlags = 0
921 // turns on append mode, corresponds to %O_APPEND
922 // (see the documentation of the UNIX open() syscall)
923 GIoFlagAppendValue IOFlags = 1
924 // turns on nonblocking mode, corresponds to
925 // %O_NONBLOCK/%O_NDELAY (see the documentation of the UNIX open()
926 // syscall)
927 GIoFlagNonblockValue IOFlags = 2
928 // indicates that the io channel is readable.
929 // This flag cannot be changed.
930 GIoFlagIsReadableValue IOFlags = 4
931 // indicates that the io channel is writable.
932 // This flag cannot be changed.
933 GIoFlagIsWritableValue IOFlags = 8
934 // a misspelled version of @G_IO_FLAG_IS_WRITABLE
935 // that existed before the spelling was fixed in GLib 2.30. It is kept
936 // here for compatibility reasons. Deprecated since 2.30
937 GIoFlagIsWriteableValue IOFlags = 8
938 // indicates that the io channel is seekable,
939 // i.e. that g_io_channel_seek_position() can be used on it.
940 // This flag cannot be changed.
941 GIoFlagIsSeekableValue IOFlags = 16
942 // the mask that specifies all the valid flags.
943 GIoFlagMaskValue IOFlags = 31
944 // the mask of the flags that are returned from
945 // g_io_channel_get_flags()
946 GIoFlagGetMaskValue IOFlags = 31
947 // the mask of the flags that the user can modify
948 // with g_io_channel_set_flags()
949 GIoFlagSetMaskValue IOFlags = 3
950)
951
952// Error codes returned by #GIOChannel operations.
953type IOChannelError int
954
955const (
956
957 // File too large.
958 GIoChannelErrorFbigValue IOChannelError = 0
959 // Invalid argument.
960 GIoChannelErrorInvalValue IOChannelError = 1
961 // IO error.
962 GIoChannelErrorIoValue IOChannelError = 2
963 // File is a directory.
964 GIoChannelErrorIsdirValue IOChannelError = 3
965 // No space left on device.
966 GIoChannelErrorNospcValue IOChannelError = 4
967 // No such device or address.
968 GIoChannelErrorNxioValue IOChannelError = 5
969 // Value too large for defined datatype.
970 GIoChannelErrorOverflowValue IOChannelError = 6
971 // Broken pipe.
972 GIoChannelErrorPipeValue IOChannelError = 7
973 // Some other error.
974 GIoChannelErrorFailedValue IOChannelError = 8
975)
976
977// #GIOError is only used by the deprecated functions
978// g_io_channel_read(), g_io_channel_write(), and g_io_channel_seek().
979type IOError int
980
981const (
982
983 // no error
984 GIoErrorNoneValue IOError = 0
985 // an EAGAIN error occurred
986 GIoErrorAgainValue IOError = 1
987 // an EINVAL error occurred
988 GIoErrorInvalValue IOError = 2
989 // another error occurred
990 GIoErrorUnknownValue IOError = 3
991)
992
993// Statuses returned by most of the #GIOFuncs functions.
994type IOStatus int
995
996const (
997
998 // An error occurred.
999 GIoStatusErrorValue IOStatus = 0
1000 // Success.
1001 GIoStatusNormalValue IOStatus = 1
1002 // End of file.
1003 GIoStatusEofValue IOStatus = 2
1004 // Resource temporarily unavailable.
1005 GIoStatusAgainValue IOStatus = 3
1006)
1007
1008// An enumeration specifying the base position for a
1009// g_io_channel_seek_position() operation.
1010type SeekType int
1011
1012const (
1013
1014 // the current position in the file.
1015 GSeekCurValue SeekType = 0
1016 // the start of the file.
1017 GSeekSetValue SeekType = 1
1018 // the end of the file.
1019 GSeekEndValue SeekType = 2
1020)
1021
1022var xIoAddWatch func(*IOChannel, IOCondition, uintptr, uintptr) uint
1023
1024// Adds the #GIOChannel into the default main loop context
1025// with the default priority.
1026func IoAddWatch(ChannelVar *IOChannel, ConditionVar IOCondition, FuncVar *IOFunc, UserDataVar uintptr) uint {
1027
1028 var FuncVarRef uintptr
1029 if FuncVar != nil {
1030 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
1031 if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
1032 FuncVarRef = cbRefPtr
1033 } else {
1034 fcb := func(arg0 *IOChannel, arg1 IOCondition, arg2 uintptr) bool {
1035 cbFn := *FuncVar
1036 return cbFn(arg0, arg1, arg2)
1037 }
1038 FuncVarRef = purego.NewCallback(fcb)
1039 SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
1040 }
1041 }
1042
1043 cret := xIoAddWatch(ChannelVar, ConditionVar, FuncVarRef, UserDataVar)
1044
1045 return cret
1046}
1047
1048var xIoAddWatchFull func(*IOChannel, int, IOCondition, uintptr, uintptr, uintptr) uint
1049
1050// Adds the #GIOChannel into the default main loop context
1051// with the given priority.
1052//
1053// This internally creates a main loop source using g_io_create_watch()
1054// and attaches it to the main loop context with g_source_attach().
1055// You can do these steps manually if you need greater control.
1056func IoAddWatchFull(ChannelVar *IOChannel, PriorityVar int, ConditionVar IOCondition, FuncVar *IOFunc, UserDataVar uintptr, NotifyVar *DestroyNotify) uint {
1057
1058 var FuncVarRef uintptr
1059 if FuncVar != nil {
1060 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
1061 if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
1062 FuncVarRef = cbRefPtr
1063 } else {
1064 fcb := func(arg0 *IOChannel, arg1 IOCondition, arg2 uintptr) bool {
1065 cbFn := *FuncVar
1066 return cbFn(arg0, arg1, arg2)
1067 }
1068 FuncVarRef = purego.NewCallback(fcb)
1069 SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
1070 }
1071 }
1072
1073 var NotifyVarRef uintptr
1074 if NotifyVar != nil {
1075 NotifyVarPtr := uintptr(unsafe.Pointer(NotifyVar))
1076 if cbRefPtr, ok := GetCallback(NotifyVarPtr); ok {
1077 NotifyVarRef = cbRefPtr
1078 } else {
1079 fcb := func(arg0 uintptr) {
1080 cbFn := *NotifyVar
1081 cbFn(arg0)
1082 }
1083 NotifyVarRef = purego.NewCallback(fcb)
1084 SaveCallbackWithClosure(NotifyVarPtr, NotifyVarRef, NotifyVar)
1085 }
1086 }
1087
1088 cret := xIoAddWatchFull(ChannelVar, PriorityVar, ConditionVar, FuncVarRef, UserDataVar, NotifyVarRef)
1089
1090 return cret
1091}
1092
1093var xIoChannelErrorFromErrno func(int) IOChannelError
1094
1095// Converts an `errno` error number to a #GIOChannelError.
1096func IoChannelErrorFromErrno(EnVar int) IOChannelError {
1097
1098 cret := xIoChannelErrorFromErrno(EnVar)
1099
1100 return cret
1101}
1102
1103var xIoCreateWatch func(*IOChannel, IOCondition) *Source
1104
1105// Creates a #GSource that's dispatched when @condition is met for the
1106// given @channel. For example, if condition is %G_IO_IN, the source will
1107// be dispatched when there's data available for reading.
1108//
1109// The callback function invoked by the #GSource should be added with
1110// g_source_set_callback(), but it has type #GIOFunc (not #GSourceFunc).
1111//
1112// g_io_add_watch() is a simpler interface to this same functionality, for
1113// the case where you want to add the source to the default main loop context
1114// at the default priority.
1115//
1116// On Windows, polling a #GSource created to watch a channel for a socket
1117// puts the socket in non-blocking mode. This is a side-effect of the
1118// implementation and unavoidable.
1119func IoCreateWatch(ChannelVar *IOChannel, ConditionVar IOCondition) *Source {
1120
1121 cret := xIoCreateWatch(ChannelVar, ConditionVar)
1122
1123 return cret
1124}
1125
1126func init() {
1127 core.SetPackageName("GLIB", "glib-2.0")
1128 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
1129 var libs []uintptr
1130 for _, libPath := range core.GetPaths("GLIB") {
1131 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
1132 if err != nil {
1133 panic(err)
1134 }
1135 libs = append(libs, lib)
1136 }
1137
1138 core.PuregoSafeRegister(&xIOConditionGLibType, libs, "g_io_condition_get_type")
1139
1140 core.PuregoSafeRegister(&xIoAddWatch, libs, "g_io_add_watch")
1141 core.PuregoSafeRegister(&xIoAddWatchFull, libs, "g_io_add_watch_full")
1142 core.PuregoSafeRegister(&xIoChannelErrorFromErrno, libs, "g_io_channel_error_from_errno")
1143 core.PuregoSafeRegister(&xIoCreateWatch, libs, "g_io_create_watch")
1144
1145 core.PuregoSafeRegister(&xIOChannelGLibType, libs, "g_io_channel_get_type")
1146
1147 core.PuregoSafeRegister(&xNewIOChannelFile, libs, "g_io_channel_new_file")
1148 core.PuregoSafeRegister(&xIOChannelUnixNew, libs, "g_io_channel_unix_new")
1149
1150 core.PuregoSafeRegister(&xIOChannelClose, libs, "g_io_channel_close")
1151 core.PuregoSafeRegister(&xIOChannelFlush, libs, "g_io_channel_flush")
1152 core.PuregoSafeRegister(&xIOChannelGetBufferCondition, libs, "g_io_channel_get_buffer_condition")
1153 core.PuregoSafeRegister(&xIOChannelGetBufferSize, libs, "g_io_channel_get_buffer_size")
1154 core.PuregoSafeRegister(&xIOChannelGetBuffered, libs, "g_io_channel_get_buffered")
1155 core.PuregoSafeRegister(&xIOChannelGetCloseOnUnref, libs, "g_io_channel_get_close_on_unref")
1156 core.PuregoSafeRegister(&xIOChannelGetEncoding, libs, "g_io_channel_get_encoding")
1157 core.PuregoSafeRegister(&xIOChannelGetFlags, libs, "g_io_channel_get_flags")
1158 core.PuregoSafeRegister(&xIOChannelGetLineTerm, libs, "g_io_channel_get_line_term")
1159 core.PuregoSafeRegister(&xIOChannelInit, libs, "g_io_channel_init")
1160 core.PuregoSafeRegister(&xIOChannelRead, libs, "g_io_channel_read")
1161 core.PuregoSafeRegister(&xIOChannelReadChars, libs, "g_io_channel_read_chars")
1162 core.PuregoSafeRegister(&xIOChannelReadLine, libs, "g_io_channel_read_line")
1163 core.PuregoSafeRegister(&xIOChannelReadLineString, libs, "g_io_channel_read_line_string")
1164 core.PuregoSafeRegister(&xIOChannelReadToEnd, libs, "g_io_channel_read_to_end")
1165 core.PuregoSafeRegister(&xIOChannelReadUnichar, libs, "g_io_channel_read_unichar")
1166 core.PuregoSafeRegister(&xIOChannelRef, libs, "g_io_channel_ref")
1167 core.PuregoSafeRegister(&xIOChannelSeek, libs, "g_io_channel_seek")
1168 core.PuregoSafeRegister(&xIOChannelSeekPosition, libs, "g_io_channel_seek_position")
1169 core.PuregoSafeRegister(&xIOChannelSetBufferSize, libs, "g_io_channel_set_buffer_size")
1170 core.PuregoSafeRegister(&xIOChannelSetBuffered, libs, "g_io_channel_set_buffered")
1171 core.PuregoSafeRegister(&xIOChannelSetCloseOnUnref, libs, "g_io_channel_set_close_on_unref")
1172 core.PuregoSafeRegister(&xIOChannelSetEncoding, libs, "g_io_channel_set_encoding")
1173 core.PuregoSafeRegister(&xIOChannelSetFlags, libs, "g_io_channel_set_flags")
1174 core.PuregoSafeRegister(&xIOChannelSetLineTerm, libs, "g_io_channel_set_line_term")
1175 core.PuregoSafeRegister(&xIOChannelShutdown, libs, "g_io_channel_shutdown")
1176 core.PuregoSafeRegister(&xIOChannelUnixGetFd, libs, "g_io_channel_unix_get_fd")
1177 core.PuregoSafeRegister(&xIOChannelUnref, libs, "g_io_channel_unref")
1178 core.PuregoSafeRegister(&xIOChannelWrite, libs, "g_io_channel_write")
1179 core.PuregoSafeRegister(&xIOChannelWriteChars, libs, "g_io_channel_write_chars")
1180 core.PuregoSafeRegister(&xIOChannelWriteUnichar, libs, "g_io_channel_write_unichar")
1181
1182}