1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gio.NetworkMonitorT;
26 
27 public  import gio.AsyncResultIF;
28 public  import gio.Cancellable;
29 public  import gio.NetworkMonitorIF;
30 public  import gio.SocketConnectableIF;
31 public  import gio.c.functions;
32 public  import gio.c.types;
33 public  import glib.ErrorG;
34 public  import glib.GException;
35 public  import gobject.ObjectG;
36 public  import gobject.Signals;
37 public  import std.algorithm;
38 
39 
40 /**
41  * #GNetworkMonitor provides an easy-to-use cross-platform API
42  * for monitoring network connectivity. On Linux, the available
43  * implementations are based on the kernel's netlink interface and
44  * on NetworkManager.
45  * 
46  * There is also an implementation for use inside Flatpak sandboxes.
47  *
48  * Since: 2.32
49  */
50 public template NetworkMonitorT(TStruct)
51 {
52 	/** Get the main Gtk struct */
53 	public GNetworkMonitor* getNetworkMonitorStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return cast(GNetworkMonitor*)getStruct();
58 	}
59 
60 
61 	/**
62 	 * Attempts to determine whether or not the host pointed to by
63 	 * @connectable can be reached, without actually trying to connect to
64 	 * it.
65 	 *
66 	 * This may return %TRUE even when #GNetworkMonitor:network-available
67 	 * is %FALSE, if, for example, @monitor can determine that
68 	 * @connectable refers to a host on a local network.
69 	 *
70 	 * If @monitor believes that an attempt to connect to @connectable
71 	 * will succeed, it will return %TRUE. Otherwise, it will return
72 	 * %FALSE and set @error to an appropriate error (such as
73 	 * %G_IO_ERROR_HOST_UNREACHABLE).
74 	 *
75 	 * Note that although this does not attempt to connect to
76 	 * @connectable, it may still block for a brief period of time (eg,
77 	 * trying to do multicast DNS on the local network), so if you do not
78 	 * want to block, you should use g_network_monitor_can_reach_async().
79 	 *
80 	 * Params:
81 	 *     connectable = a #GSocketConnectable
82 	 *     cancellable = a #GCancellable, or %NULL
83 	 *
84 	 * Returns: %TRUE if @connectable is reachable, %FALSE if not.
85 	 *
86 	 * Since: 2.32
87 	 *
88 	 * Throws: GException on failure.
89 	 */
90 	public bool canReach(SocketConnectableIF connectable, Cancellable cancellable)
91 	{
92 		GError* err = null;
93 
94 		auto __p = g_network_monitor_can_reach(getNetworkMonitorStruct(), (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
95 
96 		if (err !is null)
97 		{
98 			throw new GException( new ErrorG(err) );
99 		}
100 
101 		return __p;
102 	}
103 
104 	/**
105 	 * Asynchronously attempts to determine whether or not the host
106 	 * pointed to by @connectable can be reached, without actually
107 	 * trying to connect to it.
108 	 *
109 	 * For more details, see g_network_monitor_can_reach().
110 	 *
111 	 * When the operation is finished, @callback will be called.
112 	 * You can then call g_network_monitor_can_reach_finish()
113 	 * to get the result of the operation.
114 	 *
115 	 * Params:
116 	 *     connectable = a #GSocketConnectable
117 	 *     cancellable = a #GCancellable, or %NULL
118 	 *     callback = a #GAsyncReadyCallback to call when the
119 	 *         request is satisfied
120 	 *     userData = the data to pass to callback function
121 	 */
122 	public void canReachAsync(SocketConnectableIF connectable, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
123 	{
124 		g_network_monitor_can_reach_async(getNetworkMonitorStruct(), (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
125 	}
126 
127 	/**
128 	 * Finishes an async network connectivity test.
129 	 * See g_network_monitor_can_reach_async().
130 	 *
131 	 * Params:
132 	 *     result = a #GAsyncResult
133 	 *
134 	 * Returns: %TRUE if network is reachable, %FALSE if not.
135 	 *
136 	 * Throws: GException on failure.
137 	 */
138 	public bool canReachFinish(AsyncResultIF result)
139 	{
140 		GError* err = null;
141 
142 		auto __p = g_network_monitor_can_reach_finish(getNetworkMonitorStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
143 
144 		if (err !is null)
145 		{
146 			throw new GException( new ErrorG(err) );
147 		}
148 
149 		return __p;
150 	}
151 
152 	/**
153 	 * Gets a more detailed networking state than
154 	 * g_network_monitor_get_network_available().
155 	 *
156 	 * If #GNetworkMonitor:network-available is %FALSE, then the
157 	 * connectivity state will be %G_NETWORK_CONNECTIVITY_LOCAL.
158 	 *
159 	 * If #GNetworkMonitor:network-available is %TRUE, then the
160 	 * connectivity state will be %G_NETWORK_CONNECTIVITY_FULL (if there
161 	 * is full Internet connectivity), %G_NETWORK_CONNECTIVITY_LIMITED (if
162 	 * the host has a default route, but appears to be unable to actually
163 	 * reach the full Internet), or %G_NETWORK_CONNECTIVITY_PORTAL (if the
164 	 * host is trapped behind a "captive portal" that requires some sort
165 	 * of login or acknowledgement before allowing full Internet access).
166 	 *
167 	 * Note that in the case of %G_NETWORK_CONNECTIVITY_LIMITED and
168 	 * %G_NETWORK_CONNECTIVITY_PORTAL, it is possible that some sites are
169 	 * reachable but others are not. In this case, applications can
170 	 * attempt to connect to remote servers, but should gracefully fall
171 	 * back to their "offline" behavior if the connection attempt fails.
172 	 *
173 	 * Returns: the network connectivity state
174 	 *
175 	 * Since: 2.44
176 	 */
177 	public GNetworkConnectivity getConnectivity()
178 	{
179 		return g_network_monitor_get_connectivity(getNetworkMonitorStruct());
180 	}
181 
182 	/**
183 	 * Checks if the network is available. "Available" here means that the
184 	 * system has a default route available for at least one of IPv4 or
185 	 * IPv6. It does not necessarily imply that the public Internet is
186 	 * reachable. See #GNetworkMonitor:network-available for more details.
187 	 *
188 	 * Returns: whether the network is available
189 	 *
190 	 * Since: 2.32
191 	 */
192 	public bool getNetworkAvailable()
193 	{
194 		return g_network_monitor_get_network_available(getNetworkMonitorStruct()) != 0;
195 	}
196 
197 	/**
198 	 * Checks if the network is metered.
199 	 * See #GNetworkMonitor:network-metered for more details.
200 	 *
201 	 * Returns: whether the connection is metered
202 	 *
203 	 * Since: 2.46
204 	 */
205 	public bool getNetworkMetered()
206 	{
207 		return g_network_monitor_get_network_metered(getNetworkMonitorStruct()) != 0;
208 	}
209 
210 	/**
211 	 * Emitted when the network configuration changes.
212 	 *
213 	 * Params:
214 	 *     networkAvailable = the current value of #GNetworkMonitor:network-available
215 	 *
216 	 * Since: 2.32
217 	 */
218 	gulong addOnNetworkChanged(void delegate(bool, NetworkMonitorIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
219 	{
220 		return Signals.connect(this, "network-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
221 	}
222 }