Package ch.bailu.gtk.gio
Class NetworkMonitor
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.type.Interface
ch.bailu.gtk.gio.NetworkMonitor
- All Implemented Interfaces:
PointerInterface
#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.
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canReach
(SocketConnectable connectable, Cancellable cancellable) Attempts to determine whether or not the host pointed to by
@connectable can be reached, without actually trying to connect to
it.void
canReachAsync
(SocketConnectable connectable, Cancellable cancellable, NetworkMonitor.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously attempts to determine whether or not the host
pointed to by @connectable can be reached, without actually
trying to connect to it.boolean
canReachFinish
(AsyncResult result) Finishes an async network connectivity test.static ClassHandler
int
Gets a more detailed networking state than
g_network_monitor_get_network_available().static NetworkMonitor
Gets the default #GNetworkMonitor for the system.static int
boolean
Checks if the network is available.boolean
Checks if the network is metered.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
Connect to signal "network-changed".Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_NETWORK_CHANGED
- See Also:
-
-
Constructor Details
-
NetworkMonitor
-
-
Method Details
-
getClassHandler
-
canReach
public boolean canReach(@Nonnull SocketConnectable connectable, @Nullable Cancellable cancellable) throws AllocationError 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().- Parameters:
connectable
- a #GSocketConnectablecancellable
- a #GCancellable, or %NULL- Returns:
- %TRUE if @connectable is reachable, %FALSE if not.
- Throws:
AllocationError
-
canReachAsync
public void canReachAsync(@Nonnull SocketConnectable connectable, @Nullable Cancellable cancellable, NetworkMonitor.OnAsyncReadyCallback callback, @Nullable Pointer user_data) 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.- Parameters:
connectable
- a #GSocketConnectablecancellable
- a #GCancellable, or %NULLcallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
canReachFinish
Finishes an async network connectivity test.
See g_network_monitor_can_reach_async().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if network is reachable, %FALSE if not.
- Throws:
AllocationError
-
getConnectivity
public int getConnectivity()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.- Returns:
- the network connectivity state
-
getNetworkAvailable
public boolean getNetworkAvailable()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.- Returns:
- whether the network is available
-
getNetworkMetered
public boolean getNetworkMetered()Checks if the network is metered.
See #GNetworkMonitor:network-metered for more details.- Returns:
- whether the connection is metered
-
onNetworkChanged
Connect to signal "network-changed".
SeeNetworkMonitor.OnNetworkChanged.onNetworkChanged(boolean)
for signal description.
FieldSIGNAL_ON_NETWORK_CHANGED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
getDefault
Gets the default #GNetworkMonitor for the system.- Returns:
- a #GNetworkMonitor, which will be a dummy object if no network monitor is available
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-