// 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" "github.com/bnema/puregotk/v4/gobject/types" ) // Class structure for #GSocketService. type SocketServiceClass struct { _ structs.HostLayout ParentClass SocketListenerClass xIncoming uintptr xGReserved1 uintptr xGReserved2 uintptr xGReserved3 uintptr xGReserved4 uintptr xGReserved5 uintptr xGReserved6 uintptr } func (x *SocketServiceClass) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideIncoming sets the "incoming" callback function. // signal emitted when new connections are accepted func (x *SocketServiceClass) OverrideIncoming(cb func(*SocketService, *SocketConnection, *gobject.Object) bool) { if cb == nil { x.xIncoming = 0 } else { x.xIncoming = purego.NewCallback(func(ServiceVarp uintptr, ConnectionVarp uintptr, SourceObjectVarp uintptr) bool { return cb(SocketServiceNewFromInternalPtr(ServiceVarp), SocketConnectionNewFromInternalPtr(ConnectionVarp), gobject.ObjectNewFromInternalPtr(SourceObjectVarp)) }) } } // GetIncoming gets the "incoming" callback function. // signal emitted when new connections are accepted func (x *SocketServiceClass) GetIncoming() func(*SocketService, *SocketConnection, *gobject.Object) bool { if x.xIncoming == 0 { return nil } var rawCallback func(ServiceVarp uintptr, ConnectionVarp uintptr, SourceObjectVarp uintptr) bool purego.RegisterFunc(&rawCallback, x.xIncoming) return func(ServiceVar *SocketService, ConnectionVar *SocketConnection, SourceObjectVar *gobject.Object) bool { return rawCallback(ServiceVar.GoPointer(), ConnectionVar.GoPointer(), SourceObjectVar.GoPointer()) } } // OverrideGReserved1 sets the "_g_reserved1" callback function. func (x *SocketServiceClass) OverrideGReserved1(cb func()) { if cb == nil { x.xGReserved1 = 0 } else { x.xGReserved1 = purego.NewCallback(func() { cb() }) } } // GetGReserved1 gets the "_g_reserved1" callback function. func (x *SocketServiceClass) GetGReserved1() func() { if x.xGReserved1 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved1) return func() { rawCallback() } } // OverrideGReserved2 sets the "_g_reserved2" callback function. func (x *SocketServiceClass) OverrideGReserved2(cb func()) { if cb == nil { x.xGReserved2 = 0 } else { x.xGReserved2 = purego.NewCallback(func() { cb() }) } } // GetGReserved2 gets the "_g_reserved2" callback function. func (x *SocketServiceClass) GetGReserved2() func() { if x.xGReserved2 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved2) return func() { rawCallback() } } // OverrideGReserved3 sets the "_g_reserved3" callback function. func (x *SocketServiceClass) OverrideGReserved3(cb func()) { if cb == nil { x.xGReserved3 = 0 } else { x.xGReserved3 = purego.NewCallback(func() { cb() }) } } // GetGReserved3 gets the "_g_reserved3" callback function. func (x *SocketServiceClass) GetGReserved3() func() { if x.xGReserved3 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved3) return func() { rawCallback() } } // OverrideGReserved4 sets the "_g_reserved4" callback function. func (x *SocketServiceClass) OverrideGReserved4(cb func()) { if cb == nil { x.xGReserved4 = 0 } else { x.xGReserved4 = purego.NewCallback(func() { cb() }) } } // GetGReserved4 gets the "_g_reserved4" callback function. func (x *SocketServiceClass) GetGReserved4() func() { if x.xGReserved4 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved4) return func() { rawCallback() } } // OverrideGReserved5 sets the "_g_reserved5" callback function. func (x *SocketServiceClass) OverrideGReserved5(cb func()) { if cb == nil { x.xGReserved5 = 0 } else { x.xGReserved5 = purego.NewCallback(func() { cb() }) } } // GetGReserved5 gets the "_g_reserved5" callback function. func (x *SocketServiceClass) GetGReserved5() func() { if x.xGReserved5 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved5) return func() { rawCallback() } } // OverrideGReserved6 sets the "_g_reserved6" callback function. func (x *SocketServiceClass) OverrideGReserved6(cb func()) { if cb == nil { x.xGReserved6 = 0 } else { x.xGReserved6 = purego.NewCallback(func() { cb() }) } } // GetGReserved6 gets the "_g_reserved6" callback function. func (x *SocketServiceClass) GetGReserved6() func() { if x.xGReserved6 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved6) return func() { rawCallback() } } type SocketServicePrivate struct { _ structs.HostLayout } func (x *SocketServicePrivate) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // A `GSocketService` is an object that represents a service that // is provided to the network or over local sockets. When a new // connection is made to the service the [signal@Gio.SocketService::incoming] // signal is emitted. // // A `GSocketService` is a subclass of [class@Gio.SocketListener] and you need // to add the addresses you want to accept connections on with the // [class@Gio.SocketListener] APIs. // // There are two options for implementing a network service based on // `GSocketService`. The first is to create the service using // [ctor@Gio.SocketService.new] and to connect to the // [signal@Gio.SocketService::incoming] signal. The second is to subclass // `GSocketService` and override the default signal handler implementation. // // In either case, the handler must immediately return, or else it // will block additional incoming connections from being serviced. // If you are interested in writing connection handlers that contain // blocking code then see [class@Gio.ThreadedSocketService]. // // The socket service runs on the main loop of the // thread-default context (see // [method@GLib.MainContext.push_thread_default]) of the thread it is // created in, and is not threadsafe in general. However, the calls to start and // stop the service are thread-safe so these can be used from threads that // handle incoming clients. type SocketService struct { SocketListener } var xSocketServiceGLibType func() types.GType func SocketServiceGLibType() types.GType { return xSocketServiceGLibType() } func SocketServiceNewFromInternalPtr(ptr uintptr) *SocketService { cls := &SocketService{} cls.Ptr = ptr return cls } var xNewSocketService func() uintptr // Creates a new #GSocketService with no sockets to listen for. // New listeners can be added with e.g. g_socket_listener_add_address() // or g_socket_listener_add_inet_port(). // // New services are created active, there is no need to call // g_socket_service_start(), unless g_socket_service_stop() has been // called before. func NewSocketService() *SocketService { var cls *SocketService cret := xNewSocketService() if cret == 0 { return nil } cls = &SocketService{} cls.Ptr = cret return cls } var xSocketServiceIsActive func(uintptr) bool // Check whether the service is active or not. An active // service will accept new clients that connect, while // a non-active service will let connecting clients queue // up until the service is started. func (x *SocketService) IsActive() bool { cret := xSocketServiceIsActive(x.GoPointer()) return cret } var xSocketServiceStart func(uintptr) // Restarts the service, i.e. start accepting connections // from the added sockets when the mainloop runs. This only needs // to be called after the service has been stopped from // g_socket_service_stop(). // // This call is thread-safe, so it may be called from a thread // handling an incoming client request. func (x *SocketService) Start() { xSocketServiceStart(x.GoPointer()) } var xSocketServiceStop func(uintptr) // Stops the service, i.e. stops accepting connections // from the added sockets when the mainloop runs. // // This call is thread-safe, so it may be called from a thread // handling an incoming client request. // // Note that this only stops accepting new connections; it does not // close the listening sockets, and you can call // g_socket_service_start() again later to begin listening again. To // close the listening sockets, call g_socket_listener_close(). (This // will happen automatically when the #GSocketService is finalized.) // // This must be called before calling g_socket_listener_close() as // the socket service will start accepting connections immediately // when a new socket is added. func (x *SocketService) Stop() { xSocketServiceStop(x.GoPointer()) } func (c *SocketService) GoPointer() uintptr { if c == nil { return 0 } return c.Ptr } func (c *SocketService) SetGoPointer(ptr uintptr) { c.Ptr = ptr } // SetPropertyActive sets the "active" property. // Whether the service is currently accepting connections. func (x *SocketService) SetPropertyActive(value bool) { var v gobject.Value v.Init(gobject.TypeBooleanVal) v.SetBoolean(value) x.SetProperty("active", &v) } // GetPropertyActive gets the "active" property. // Whether the service is currently accepting connections. func (x *SocketService) GetPropertyActive() bool { var v gobject.Value x.GetProperty("active", &v) return v.GetBoolean() } // The ::incoming signal is emitted when a new incoming connection // to @service needs to be handled. The handler must initiate the // handling of @connection, but may not block; in essence, // asynchronous operations must be used. // // @connection will be unreffed once the signal handler returns, // so you need to ref it yourself if you are planning to use it. func (x *SocketService) ConnectIncoming(cb *func(SocketService, uintptr, uintptr) bool) uint { cbPtr := uintptr(unsafe.Pointer(cb)) if cbRefPtr, ok := glib.GetCallback(cbPtr); ok { handlerID := gobject.SignalConnect(x.GoPointer(), "incoming", cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } fcb := func(clsPtr uintptr, ConnectionVarp uintptr, SourceObjectVarp uintptr) bool { fa := SocketService{} fa.Ptr = clsPtr cbFn := *cb return cbFn(fa, ConnectionVarp, SourceObjectVarp) } cbRefPtr := purego.NewCallback(fcb) glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb) handlerID := gobject.SignalConnect(x.GoPointer(), "incoming", cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } 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(&xSocketServiceGLibType, libs, "g_socket_service_get_type") core.PuregoSafeRegister(&xNewSocketService, libs, "g_socket_service_new") core.PuregoSafeRegister(&xSocketServiceIsActive, libs, "g_socket_service_is_active") core.PuregoSafeRegister(&xSocketServiceStart, libs, "g_socket_service_start") core.PuregoSafeRegister(&xSocketServiceStop, libs, "g_socket_service_stop") }