1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
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/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16// The virtual function table for #GNetworkMonitor.
17type NetworkMonitorInterface struct {
18 _ structs.HostLayout
19
20 GIface uintptr
21
22 xNetworkChanged uintptr
23
24 xCanReach uintptr
25
26 xCanReachAsync uintptr
27
28 xCanReachFinish uintptr
29}
30
31func (x *NetworkMonitorInterface) GoPointer() uintptr {
32 return uintptr(unsafe.Pointer(x))
33}
34
35// OverrideNetworkChanged sets the "network_changed" callback function.
36// the virtual function pointer for the
37//
38// GNetworkMonitor::network-changed signal.
39func (x *NetworkMonitorInterface) OverrideNetworkChanged(cb func(NetworkMonitor, bool)) {
40 if cb == nil {
41 x.xNetworkChanged = 0
42 } else {
43 x.xNetworkChanged = purego.NewCallback(func(MonitorVarp uintptr, NetworkAvailableVarp bool) {
44 cb(&NetworkMonitorBase{Ptr: MonitorVarp}, NetworkAvailableVarp)
45 })
46 }
47}
48
49// GetNetworkChanged gets the "network_changed" callback function.
50// the virtual function pointer for the
51//
52// GNetworkMonitor::network-changed signal.
53func (x *NetworkMonitorInterface) GetNetworkChanged() func(NetworkMonitor, bool) {
54 if x.xNetworkChanged == 0 {
55 return nil
56 }
57 var rawCallback func(MonitorVarp uintptr, NetworkAvailableVarp bool)
58 purego.RegisterFunc(&rawCallback, x.xNetworkChanged)
59 return func(MonitorVar NetworkMonitor, NetworkAvailableVar bool) {
60 rawCallback(MonitorVar.GoPointer(), NetworkAvailableVar)
61 }
62}
63
64// OverrideCanReach sets the "can_reach" callback function.
65// the virtual function pointer for g_network_monitor_can_reach()
66func (x *NetworkMonitorInterface) OverrideCanReach(cb func(NetworkMonitor, SocketConnectable, *Cancellable) bool) {
67 if cb == nil {
68 x.xCanReach = 0
69 } else {
70 x.xCanReach = purego.NewCallback(func(MonitorVarp uintptr, ConnectableVarp uintptr, CancellableVarp uintptr) bool {
71 return cb(&NetworkMonitorBase{Ptr: MonitorVarp}, &SocketConnectableBase{Ptr: ConnectableVarp}, CancellableNewFromInternalPtr(CancellableVarp))
72 })
73 }
74}
75
76// GetCanReach gets the "can_reach" callback function.
77// the virtual function pointer for g_network_monitor_can_reach()
78func (x *NetworkMonitorInterface) GetCanReach() func(NetworkMonitor, SocketConnectable, *Cancellable) bool {
79 if x.xCanReach == 0 {
80 return nil
81 }
82 var rawCallback func(MonitorVarp uintptr, ConnectableVarp uintptr, CancellableVarp uintptr) bool
83 purego.RegisterFunc(&rawCallback, x.xCanReach)
84 return func(MonitorVar NetworkMonitor, ConnectableVar SocketConnectable, CancellableVar *Cancellable) bool {
85 return rawCallback(MonitorVar.GoPointer(), ConnectableVar.GoPointer(), CancellableVar.GoPointer())
86 }
87}
88
89// OverrideCanReachAsync sets the "can_reach_async" callback function.
90// the virtual function pointer for
91//
92// g_network_monitor_can_reach_async()
93func (x *NetworkMonitorInterface) OverrideCanReachAsync(cb func(NetworkMonitor, SocketConnectable, *Cancellable, *AsyncReadyCallback, uintptr)) {
94 if cb == nil {
95 x.xCanReachAsync = 0
96 } else {
97 x.xCanReachAsync = purego.NewCallback(func(MonitorVarp uintptr, ConnectableVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr) {
98 cb(&NetworkMonitorBase{Ptr: MonitorVarp}, &SocketConnectableBase{Ptr: ConnectableVarp}, CancellableNewFromInternalPtr(CancellableVarp), (*AsyncReadyCallback)(unsafe.Pointer(CallbackVarp)), UserDataVarp)
99 })
100 }
101}
102
103// GetCanReachAsync gets the "can_reach_async" callback function.
104// the virtual function pointer for
105//
106// g_network_monitor_can_reach_async()
107func (x *NetworkMonitorInterface) GetCanReachAsync() func(NetworkMonitor, SocketConnectable, *Cancellable, *AsyncReadyCallback, uintptr) {
108 if x.xCanReachAsync == 0 {
109 return nil
110 }
111 var rawCallback func(MonitorVarp uintptr, ConnectableVarp uintptr, CancellableVarp uintptr, CallbackVarp uintptr, UserDataVarp uintptr)
112 purego.RegisterFunc(&rawCallback, x.xCanReachAsync)
113 return func(MonitorVar NetworkMonitor, ConnectableVar SocketConnectable, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
114 rawCallback(MonitorVar.GoPointer(), ConnectableVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
115 }
116}
117
118// OverrideCanReachFinish sets the "can_reach_finish" callback function.
119// the virtual function pointer for
120//
121// g_network_monitor_can_reach_finish()
122func (x *NetworkMonitorInterface) OverrideCanReachFinish(cb func(NetworkMonitor, AsyncResult) bool) {
123 if cb == nil {
124 x.xCanReachFinish = 0
125 } else {
126 x.xCanReachFinish = purego.NewCallback(func(MonitorVarp uintptr, ResultVarp uintptr) bool {
127 return cb(&NetworkMonitorBase{Ptr: MonitorVarp}, &AsyncResultBase{Ptr: ResultVarp})
128 })
129 }
130}
131
132// GetCanReachFinish gets the "can_reach_finish" callback function.
133// the virtual function pointer for
134//
135// g_network_monitor_can_reach_finish()
136func (x *NetworkMonitorInterface) GetCanReachFinish() func(NetworkMonitor, AsyncResult) bool {
137 if x.xCanReachFinish == 0 {
138 return nil
139 }
140 var rawCallback func(MonitorVarp uintptr, ResultVarp uintptr) bool
141 purego.RegisterFunc(&rawCallback, x.xCanReachFinish)
142 return func(MonitorVar NetworkMonitor, ResultVar AsyncResult) bool {
143 return rawCallback(MonitorVar.GoPointer(), ResultVar.GoPointer())
144 }
145}
146
147// `GNetworkMonitor` provides an easy-to-use cross-platform API
148// for monitoring network connectivity. On Linux, the available
149// implementations are based on the kernel's netlink interface and
150// on NetworkManager.
151//
152// There is also an implementation for use inside Flatpak sandboxes.
153type NetworkMonitor interface {
154 GoPointer() uintptr
155 SetGoPointer(uintptr)
156 CanReach(ConnectableVar SocketConnectable, CancellableVar *Cancellable) (bool, error)
157 CanReachAsync(ConnectableVar SocketConnectable, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr)
158 CanReachFinish(ResultVar AsyncResult) (bool, error)
159 GetConnectivity() NetworkConnectivity
160 GetNetworkAvailable() bool
161 GetNetworkMetered() bool
162}
163
164var xNetworkMonitorGLibType func() types.GType
165
166func NetworkMonitorGLibType() types.GType {
167 return xNetworkMonitorGLibType()
168}
169
170type NetworkMonitorBase struct {
171 Ptr uintptr
172}
173
174func (x *NetworkMonitorBase) GoPointer() uintptr {
175 if x == nil {
176 return 0
177 }
178 return x.Ptr
179}
180
181func (x *NetworkMonitorBase) SetGoPointer(ptr uintptr) {
182 x.Ptr = ptr
183}
184
185// Attempts to determine whether or not the host pointed to by
186// @connectable can be reached, without actually trying to connect to
187// it.
188//
189// This may return %TRUE even when #GNetworkMonitor:network-available
190// is %FALSE, if, for example, @monitor can determine that
191// @connectable refers to a host on a local network.
192//
193// If @monitor believes that an attempt to connect to @connectable
194// will succeed, it will return %TRUE. Otherwise, it will return
195// %FALSE and set @error to an appropriate error (such as
196// %G_IO_ERROR_HOST_UNREACHABLE).
197//
198// Note that although this does not attempt to connect to
199// @connectable, it may still block for a brief period of time (eg,
200// trying to do multicast DNS on the local network), so if you do not
201// want to block, you should use g_network_monitor_can_reach_async().
202func (x *NetworkMonitorBase) CanReach(ConnectableVar SocketConnectable, CancellableVar *Cancellable) (bool, error) {
203 var cerr *glib.Error
204
205 cret := XGNetworkMonitorCanReach(x.GoPointer(), ConnectableVar.GoPointer(), CancellableVar.GoPointer(), &cerr)
206 if cerr == nil {
207 return cret, nil
208 }
209 return cret, cerr
210
211}
212
213// Asynchronously attempts to determine whether or not the host
214// pointed to by @connectable can be reached, without actually
215// trying to connect to it.
216//
217// For more details, see g_network_monitor_can_reach().
218//
219// When the operation is finished, @callback will be called.
220// You can then call g_network_monitor_can_reach_finish()
221// to get the result of the operation.
222func (x *NetworkMonitorBase) CanReachAsync(ConnectableVar SocketConnectable, CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) {
223
224 XGNetworkMonitorCanReachAsync(x.GoPointer(), ConnectableVar.GoPointer(), CancellableVar.GoPointer(), glib.NewCallbackNullable(CallbackVar), UserDataVar)
225
226}
227
228// Finishes an async network connectivity test.
229// See g_network_monitor_can_reach_async().
230func (x *NetworkMonitorBase) CanReachFinish(ResultVar AsyncResult) (bool, error) {
231 var cerr *glib.Error
232
233 cret := XGNetworkMonitorCanReachFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
234 if cerr == nil {
235 return cret, nil
236 }
237 return cret, cerr
238
239}
240
241// Gets a more detailed networking state than
242// g_network_monitor_get_network_available().
243//
244// If #GNetworkMonitor:network-available is %FALSE, then the
245// connectivity state will be %G_NETWORK_CONNECTIVITY_LOCAL.
246//
247// If #GNetworkMonitor:network-available is %TRUE, then the
248// connectivity state will be %G_NETWORK_CONNECTIVITY_FULL (if there
249// is full Internet connectivity), %G_NETWORK_CONNECTIVITY_LIMITED (if
250// the host has a default route, but appears to be unable to actually
251// reach the full Internet), or %G_NETWORK_CONNECTIVITY_PORTAL (if the
252// host is trapped behind a "captive portal" that requires some sort
253// of login or acknowledgement before allowing full Internet access).
254//
255// Note that in the case of %G_NETWORK_CONNECTIVITY_LIMITED and
256// %G_NETWORK_CONNECTIVITY_PORTAL, it is possible that some sites are
257// reachable but others are not. In this case, applications can
258// attempt to connect to remote servers, but should gracefully fall
259// back to their "offline" behavior if the connection attempt fails.
260func (x *NetworkMonitorBase) GetConnectivity() NetworkConnectivity {
261
262 cret := XGNetworkMonitorGetConnectivity(x.GoPointer())
263 return cret
264}
265
266// Checks if the network is available. "Available" here means that the
267// system has a default route available for at least one of IPv4 or
268// IPv6. It does not necessarily imply that the public Internet is
269// reachable. See #GNetworkMonitor:network-available for more details.
270func (x *NetworkMonitorBase) GetNetworkAvailable() bool {
271
272 cret := XGNetworkMonitorGetNetworkAvailable(x.GoPointer())
273 return cret
274}
275
276// Checks if the network is metered.
277// See #GNetworkMonitor:network-metered for more details.
278func (x *NetworkMonitorBase) GetNetworkMetered() bool {
279
280 cret := XGNetworkMonitorGetNetworkMetered(x.GoPointer())
281 return cret
282}
283
284// GetPropertyNetworkAvailable gets the "network-available" property.
285// Whether the network is considered available. That is, whether the
286// system has a default route for at least one of IPv4 or IPv6.
287//
288// Real-world networks are of course much more complicated than
289// this; the machine may be connected to a wifi hotspot that
290// requires payment before allowing traffic through, or may be
291// connected to a functioning router that has lost its own upstream
292// connectivity. Some hosts might only be accessible when a VPN is
293// active. Other hosts might only be accessible when the VPN is
294// not active. Thus, it is best to use g_network_monitor_can_reach()
295// or g_network_monitor_can_reach_async() to test for reachability
296// on a host-by-host basis. (On the other hand, when the property is
297// %FALSE, the application can reasonably expect that no remote
298// hosts at all are reachable, and should indicate this to the user
299// in its UI.)
300//
301// See also #GNetworkMonitor::network-changed.
302func (x *NetworkMonitorBase) GetPropertyNetworkAvailable() bool {
303 obj := gobject.Object{}
304 obj.Ptr = x.GoPointer()
305 var v gobject.Value
306 obj.GetProperty("network-available", &v)
307 return v.GetBoolean()
308}
309
310// GetPropertyNetworkMetered gets the "network-metered" property.
311// Whether the network is considered metered.
312//
313// That is, whether the
314// system has traffic flowing through the default connection that is
315// subject to limitations set by service providers. For example, traffic
316// might be billed by the amount of data transmitted, or there might be a
317// quota on the amount of traffic per month. This is typical with tethered
318// connections (3G and 4G) and in such situations, bandwidth intensive
319// applications may wish to avoid network activity where possible if it will
320// cost the user money or use up their limited quota. Anything more than a
321// few hundreds of kilobytes of data usage per hour should be avoided without
322// asking permission from the user.
323//
324// If more information is required about specific devices then the
325// system network management API should be used instead (for example,
326// NetworkManager or ConnMan).
327//
328// If this information is not available then no networks will be
329// marked as metered.
330//
331// See also #GNetworkMonitor:network-available.
332func (x *NetworkMonitorBase) GetPropertyNetworkMetered() bool {
333 obj := gobject.Object{}
334 obj.Ptr = x.GoPointer()
335 var v gobject.Value
336 obj.GetProperty("network-metered", &v)
337 return v.GetBoolean()
338}
339
340var XGNetworkMonitorCanReach func(uintptr, uintptr, uintptr, **glib.Error) bool
341var XGNetworkMonitorCanReachAsync func(uintptr, uintptr, uintptr, uintptr, uintptr)
342var XGNetworkMonitorCanReachFinish func(uintptr, uintptr, **glib.Error) bool
343var XGNetworkMonitorGetConnectivity func(uintptr) NetworkConnectivity
344var XGNetworkMonitorGetNetworkAvailable func(uintptr) bool
345var XGNetworkMonitorGetNetworkMetered func(uintptr) bool
346
347const (
348 // Extension point for network status monitoring functionality.
349 // See [Extending GIO](overview.html#extending-gio).
350 NETWORK_MONITOR_EXTENSION_POINT_NAME string = "gio-network-monitor"
351)
352
353var xNetworkMonitorGetDefault func() uintptr
354
355// Gets the default #GNetworkMonitor for the system.
356func NetworkMonitorGetDefault() *NetworkMonitorBase {
357 var cls *NetworkMonitorBase
358
359 cret := xNetworkMonitorGetDefault()
360
361 if cret == 0 {
362 return nil
363 }
364 gobject.IncreaseRef(cret)
365 cls = &NetworkMonitorBase{}
366 cls.Ptr = cret
367 return cls
368}
369
370func init() {
371 core.SetPackageName("GIO", "gio-2.0")
372 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
373 var libs []uintptr
374 for _, libPath := range core.GetPaths("GIO") {
375 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
376 if err != nil {
377 panic(err)
378 }
379 libs = append(libs, lib)
380 }
381
382 core.PuregoSafeRegister(&xNetworkMonitorGetDefault, libs, "g_network_monitor_get_default")
383
384 core.PuregoSafeRegister(&xNetworkMonitorGLibType, libs, "g_network_monitor_get_type")
385
386 core.PuregoSafeRegister(&XGNetworkMonitorCanReach, libs, "g_network_monitor_can_reach")
387 core.PuregoSafeRegister(&XGNetworkMonitorCanReachAsync, libs, "g_network_monitor_can_reach_async")
388 core.PuregoSafeRegister(&XGNetworkMonitorCanReachFinish, libs, "g_network_monitor_can_reach_finish")
389 core.PuregoSafeRegister(&XGNetworkMonitorGetConnectivity, libs, "g_network_monitor_get_connectivity")
390 core.PuregoSafeRegister(&XGNetworkMonitorGetNetworkAvailable, libs, "g_network_monitor_get_network_available")
391 core.PuregoSafeRegister(&XGNetworkMonitorGetNetworkMetered, libs, "g_network_monitor_get_network_metered")
392
393}