// 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" ) // The virtual function table for #GNetworkMonitor. type NetworkMonitorInterface struct { _ structs.HostLayout GIface uintptr xNetworkChanged uintptr xCanReach uintptr xCanReachAsync uintptr xCanReachFinish uintptr } func (x *NetworkMonitorInterface) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideNetworkChanged sets the "network_changed" callback function. // the virtual function pointer for the // // GNetworkMonitor::network-changed signal. func (x *NetworkMonitorInterface) OverrideNetworkChanged(cb func(NetworkMonitor, bool)) { if cb == nil { x.xNetworkChanged = 0 } else { x.xNetworkChanged = purego.NewCallback(func(MonitorVarp uintptr, NetworkAvailableVarp bool) { cb(&NetworkMonitorBase{Ptr: MonitorVarp}, NetworkAvailableVarp) }) } } // GetNetworkChanged gets the "network_changed" callback function. // the virtual function pointer for the // // GNetworkMonitor::network-changed signal. func (x *NetworkMonitorInterface) GetNetworkChanged() func(NetworkMonitor, bool) { if x.xNetworkChanged == 0 { return nil } var rawCallback func(MonitorVarp uintptr, NetworkAvailableVarp bool) purego.RegisterFunc(&rawCallback, x.xNetworkChanged) return func(MonitorVar NetworkMonitor, NetworkAvailableVar bool) { rawCallback(MonitorVar.GoPointer(), NetworkAvailableVar) } } // OverrideCanReach sets the "can_reach" callback function. // the virtual function pointer for g_network_monitor_can_reach() func (x *NetworkMonitorInterface) OverrideCanReach(cb func(NetworkMonitor, SocketConnectable, *Cancellable) bool) { if cb == nil { x.xCanReach = 0 } else { x.xCanReach = purego.NewCallback(func(MonitorVarp uintptr, ConnectableVarp uintptr, CancellableVarp uintptr) bool { return cb(&NetworkMonitorBase{Ptr: MonitorVarp}, &SocketConnectableBase{Ptr: ConnectableVarp}, CancellableNewFromInternalPtr(CancellableVarp)) }) } } // GetCanReach gets the "can_reach" callback function. // the virtual function pointer for g_network_monitor_can_reach() func (x *NetworkMonitorInterface) GetCanReach() func(NetworkMonitor, SocketConnectable, *Cancellable) bool { if x.xCanReach == 0 { return nil } var rawCallback func(MonitorVarp uintptr, ConnectableVarp uintptr, CancellableVarp uintptr) bool purego.RegisterFunc(&rawCallback, x.xCanReach) return func(MonitorVar NetworkMonitor, ConnectableVar SocketConnectable, CancellableVar *Cancellable) bool { return rawCallback(MonitorVar.GoPointer(), ConnectableVar.GoPointer(), CancellableVar.GoPointer()) } } // OverrideCanReachAsync sets the "can_reach_async" callback function. // the virtual function pointer for // // g_network_monitor_can_reach_async() func (x *NetworkMonitorInterface) OverrideCanReachAsync(cb func(NetworkMonitor, SocketConnectable, *Cancellable, *AsyncReadyCallback, uintptr)) { if cb == nil { x.xCanReachAsync = 0 } else { x.xCanReachAsync = purego.NewCallback(func(MonitorVarp uintptr, ConnectableVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) { cb(&NetworkMonitorBase{Ptr: MonitorVarp}, &SocketConnectableBase{Ptr: ConnectableVarp}, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp) }) } } // GetCanReachAsync gets the "can_reach_async" callback function. // the virtual function pointer for // // g_network_monitor_can_reach_async() func (x *NetworkMonitorInterface) GetCanReachAsync() func(NetworkMonitor, SocketConnectable, *Cancellable, *AsyncReadyCallback, uintptr) { if x.xCanReachAsync == 0 { return nil } var rawCallback func(MonitorVarp uintptr, ConnectableVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) purego.RegisterFunc(&rawCallback, x.xCanReachAsync) return func(MonitorVar NetworkMonitor, ConnectableVar SocketConnectable, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) { rawCallback(MonitorVar.GoPointer(), ConnectableVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar) } } // OverrideCanReachFinish sets the "can_reach_finish" callback function. // the virtual function pointer for // // g_network_monitor_can_reach_finish() func (x *NetworkMonitorInterface) OverrideCanReachFinish(cb func(NetworkMonitor, AsyncResult) bool) { if cb == nil { x.xCanReachFinish = 0 } else { x.xCanReachFinish = purego.NewCallback(func(MonitorVarp uintptr, ResultVarp uintptr) bool { return cb(&NetworkMonitorBase{Ptr: MonitorVarp}, &AsyncResultBase{Ptr: ResultVarp}) }) } } // GetCanReachFinish gets the "can_reach_finish" callback function. // the virtual function pointer for // // g_network_monitor_can_reach_finish() func (x *NetworkMonitorInterface) GetCanReachFinish() func(NetworkMonitor, AsyncResult) bool { if x.xCanReachFinish == 0 { return nil } var rawCallback func(MonitorVarp uintptr, ResultVarp uintptr) bool purego.RegisterFunc(&rawCallback, x.xCanReachFinish) return func(MonitorVar NetworkMonitor, ResultVar AsyncResult) bool { return rawCallback(MonitorVar.GoPointer(), ResultVar.GoPointer()) } } // `GNetworkMonitor` provides an easy-to-use cross-platform API // for monitoring network connectivity. On Linux, the available // implementations are based on the kernel's netlink interface and // on NetworkManager. // // There is also an implementation for use inside Flatpak sandboxes. type NetworkMonitor interface { GoPointer() uintptr SetGoPointer(uintptr) CanReach(ConnectableVar SocketConnectable, CancellableVar *Cancellable) (bool, error) CanReachAsync(ConnectableVar SocketConnectable, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) CanReachFinish(ResultVar AsyncResult) (bool, error) GetConnectivity() NetworkConnectivity GetNetworkAvailable() bool GetNetworkMetered() bool } var xNetworkMonitorGLibType func() types.GType func NetworkMonitorGLibType() types.GType { return xNetworkMonitorGLibType() } type NetworkMonitorBase struct { Ptr uintptr } func (x *NetworkMonitorBase) GoPointer() uintptr { if x == nil { return 0 } return x.Ptr } func (x *NetworkMonitorBase) SetGoPointer(ptr uintptr) { x.Ptr = ptr } // Attempts to determine whether or not the host pointed to by // @connectable can be reached, without actually trying to connect to // it. // // This may return %TRUE even when #GNetworkMonitor:network-available // is %FALSE, if, for example, @monitor can determine that // @connectable refers to a host on a local network. // // If @monitor believes that an attempt to connect to @connectable // will succeed, it will return %TRUE. Otherwise, it will return // %FALSE and set @error to an appropriate error (such as // %G_IO_ERROR_HOST_UNREACHABLE). // // Note that although this does not attempt to connect to // @connectable, it may still block for a brief period of time (eg, // trying to do multicast DNS on the local network), so if you do not // want to block, you should use g_network_monitor_can_reach_async(). func (x *NetworkMonitorBase) CanReach(ConnectableVar SocketConnectable, CancellableVar *Cancellable) (bool, error) { var cerr *glib.Error cret := XGNetworkMonitorCanReach(x.GoPointer(), ConnectableVar.GoPointer(), CancellableVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } // Asynchronously attempts to determine whether or not the host // pointed to by @connectable can be reached, without actually // trying to connect to it. // // For more details, see g_network_monitor_can_reach(). // // When the operation is finished, @callback will be called. // You can then call g_network_monitor_can_reach_finish() // to get the result of the operation. func (x *NetworkMonitorBase) CanReachAsync(ConnectableVar SocketConnectable, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) { XGNetworkMonitorCanReachAsync(x.GoPointer(), ConnectableVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar) } // Finishes an async network connectivity test. // See g_network_monitor_can_reach_async(). func (x *NetworkMonitorBase) CanReachFinish(ResultVar AsyncResult) (bool, error) { var cerr *glib.Error cret := XGNetworkMonitorCanReachFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } // Gets a more detailed networking state than // g_network_monitor_get_network_available(). // // If #GNetworkMonitor:network-available is %FALSE, then the // connectivity state will be %G_NETWORK_CONNECTIVITY_LOCAL. // // If #GNetworkMonitor:network-available is %TRUE, then the // connectivity state will be %G_NETWORK_CONNECTIVITY_FULL (if there // is full Internet connectivity), %G_NETWORK_CONNECTIVITY_LIMITED (if // the host has a default route, but appears to be unable to actually // reach the full Internet), or %G_NETWORK_CONNECTIVITY_PORTAL (if the // host is trapped behind a "captive portal" that requires some sort // of login or acknowledgement before allowing full Internet access). // // Note that in the case of %G_NETWORK_CONNECTIVITY_LIMITED and // %G_NETWORK_CONNECTIVITY_PORTAL, it is possible that some sites are // reachable but others are not. In this case, applications can // attempt to connect to remote servers, but should gracefully fall // back to their "offline" behavior if the connection attempt fails. func (x *NetworkMonitorBase) GetConnectivity() NetworkConnectivity { cret := XGNetworkMonitorGetConnectivity(x.GoPointer()) return cret } // Checks if the network is available. "Available" here means that the // system has a default route available for at least one of IPv4 or // IPv6. It does not necessarily imply that the public Internet is // reachable. See #GNetworkMonitor:network-available for more details. func (x *NetworkMonitorBase) GetNetworkAvailable() bool { cret := XGNetworkMonitorGetNetworkAvailable(x.GoPointer()) return cret } // Checks if the network is metered. // See #GNetworkMonitor:network-metered for more details. func (x *NetworkMonitorBase) GetNetworkMetered() bool { cret := XGNetworkMonitorGetNetworkMetered(x.GoPointer()) return cret } // GetPropertyNetworkAvailable gets the "network-available" property. // Whether the network is considered available. That is, whether the // system has a default route for at least one of IPv4 or IPv6. // // Real-world networks are of course much more complicated than // this; the machine may be connected to a wifi hotspot that // requires payment before allowing traffic through, or may be // connected to a functioning router that has lost its own upstream // connectivity. Some hosts might only be accessible when a VPN is // active. Other hosts might only be accessible when the VPN is // not active. Thus, it is best to use g_network_monitor_can_reach() // or g_network_monitor_can_reach_async() to test for reachability // on a host-by-host basis. (On the other hand, when the property is // %FALSE, the application can reasonably expect that no remote // hosts at all are reachable, and should indicate this to the user // in its UI.) // // See also #GNetworkMonitor::network-changed. func (x *NetworkMonitorBase) GetPropertyNetworkAvailable() bool { obj := gobject.Object{} obj.Ptr = x.GoPointer() var v gobject.Value obj.GetProperty("network-available", &v) return v.GetBoolean() } // GetPropertyNetworkMetered gets the "network-metered" property. // Whether the network is considered metered. // // That is, whether the // system has traffic flowing through the default connection that is // subject to limitations set by service providers. For example, traffic // might be billed by the amount of data transmitted, or there might be a // quota on the amount of traffic per month. This is typical with tethered // connections (3G and 4G) and in such situations, bandwidth intensive // applications may wish to avoid network activity where possible if it will // cost the user money or use up their limited quota. Anything more than a // few hundreds of kilobytes of data usage per hour should be avoided without // asking permission from the user. // // If more information is required about specific devices then the // system network management API should be used instead (for example, // NetworkManager or ConnMan). // // If this information is not available then no networks will be // marked as metered. // // See also #GNetworkMonitor:network-available. func (x *NetworkMonitorBase) GetPropertyNetworkMetered() bool { obj := gobject.Object{} obj.Ptr = x.GoPointer() var v gobject.Value obj.GetProperty("network-metered", &v) return v.GetBoolean() } var XGNetworkMonitorCanReach func(uintptr, uintptr, uintptr, **glib.Error) bool var XGNetworkMonitorCanReachAsync func(uintptr, uintptr, uintptr, uintptr, uintptr) var XGNetworkMonitorCanReachFinish func(uintptr, uintptr, **glib.Error) bool var XGNetworkMonitorGetConnectivity func(uintptr) NetworkConnectivity var XGNetworkMonitorGetNetworkAvailable func(uintptr) bool var XGNetworkMonitorGetNetworkMetered func(uintptr) bool const ( // Extension point for network status monitoring functionality. // See [Extending GIO](overview.html#extending-gio). NETWORK_MONITOR_EXTENSION_POINT_NAME string = "gio-network-monitor" ) var xNetworkMonitorGetDefault func() uintptr // Gets the default #GNetworkMonitor for the system. func NetworkMonitorGetDefault() *NetworkMonitorBase { var cls *NetworkMonitorBase cret := xNetworkMonitorGetDefault() if cret == 0 { return nil } gobject.IncreaseRef(cret) cls = &NetworkMonitorBase{} cls.Ptr = cret return cls } 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(&xNetworkMonitorGetDefault, libs, "g_network_monitor_get_default") core.PuregoSafeRegister(&xNetworkMonitorGLibType, libs, "g_network_monitor_get_type") core.PuregoSafeRegister(&XGNetworkMonitorCanReach, libs, "g_network_monitor_can_reach") core.PuregoSafeRegister(&XGNetworkMonitorCanReachAsync, libs, "g_network_monitor_can_reach_async") core.PuregoSafeRegister(&XGNetworkMonitorCanReachFinish, libs, "g_network_monitor_can_reach_finish") core.PuregoSafeRegister(&XGNetworkMonitorGetConnectivity, libs, "g_network_monitor_get_connectivity") core.PuregoSafeRegister(&XGNetworkMonitorGetNetworkAvailable, libs, "g_network_monitor_get_network_available") core.PuregoSafeRegister(&XGNetworkMonitorGetNetworkMetered, libs, "g_network_monitor_get_network_metered") }