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.NetworkMonitor;
30 public  import gio.NetworkMonitorIF;
31 public  import gio.SocketConnectableIF;
32 public  import glib.ErrorG;
33 public  import glib.GException;
34 public  import gobject.ObjectG;
35 public  import gobject.Signals;
36 public  import gtkc.gdktypes;
37 public  import gtkc.gio;
38 public  import gtkc.giotypes;
39 
40 
41 /**
42  * #GNetworkMonitor provides an easy-to-use cross-platform API
43  * for monitoring network connectivity. On Linux, the implementation
44  * is based on the kernel's netlink interface.
45  *
46  * Since: 2.32
47  */
48 public template NetworkMonitorT(TStruct)
49 {
50 	/** Get the main Gtk struct */
51 	public GNetworkMonitor* getNetworkMonitorStruct()
52 	{
53 		return cast(GNetworkMonitor*)getStruct();
54 	}
55 
56 	/**
57 	 */
58 
59 	/**
60 	 * Gets the default #GNetworkMonitor for the system.
61 	 *
62 	 * Return: a #GNetworkMonitor
63 	 *
64 	 * Since: 2.32
65 	 */
66 	public static NetworkMonitorIF getDefault()
67 	{
68 		auto p = g_network_monitor_get_default();
69 		
70 		if(p is null)
71 		{
72 			return null;
73 		}
74 		
75 		return ObjectG.getDObject!(NetworkMonitor, NetworkMonitorIF)(cast(GNetworkMonitor*) p);
76 	}
77 
78 	/**
79 	 * Attempts to determine whether or not the host pointed to by
80 	 * @connectable can be reached, without actually trying to connect to
81 	 * it.
82 	 *
83 	 * This may return %TRUE even when #GNetworkMonitor:network-available
84 	 * is %FALSE, if, for example, @monitor can determine that
85 	 * @connectable refers to a host on a local network.
86 	 *
87 	 * If @monitor believes that an attempt to connect to @connectable
88 	 * will succeed, it will return %TRUE. Otherwise, it will return
89 	 * %FALSE and set @error to an appropriate error (such as
90 	 * %G_IO_ERROR_HOST_UNREACHABLE).
91 	 *
92 	 * Note that although this does not attempt to connect to
93 	 * @connectable, it may still block for a brief period of time (eg,
94 	 * trying to do multicast DNS on the local network), so if you do not
95 	 * want to block, you should use g_network_monitor_can_reach_async().
96 	 *
97 	 * Params:
98 	 *     connectable = a #GSocketConnectable
99 	 *     cancellable = a #GCancellable, or %NULL
100 	 *
101 	 * Return: %TRUE if @connectable is reachable, %FALSE if not.
102 	 *
103 	 * Since: 2.32
104 	 *
105 	 * Throws: GException on failure.
106 	 */
107 	public bool canReach(SocketConnectableIF connectable, Cancellable cancellable)
108 	{
109 		GError* err = null;
110 		
111 		auto p = g_network_monitor_can_reach(getNetworkMonitorStruct(), (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
112 		
113 		if (err !is null)
114 		{
115 			throw new GException( new ErrorG(err) );
116 		}
117 		
118 		return p;
119 	}
120 
121 	/**
122 	 * Asynchronously attempts to determine whether or not the host
123 	 * pointed to by @connectable can be reached, without actually
124 	 * trying to connect to it.
125 	 *
126 	 * For more details, see g_network_monitor_can_reach().
127 	 *
128 	 * When the operation is finished, @callback will be called.
129 	 * You can then call g_network_monitor_can_reach_finish()
130 	 * to get the result of the operation.
131 	 *
132 	 * Params:
133 	 *     connectable = a #GSocketConnectable
134 	 *     cancellable = a #GCancellable, or %NULL
135 	 *     callback = a #GAsyncReadyCallback to call when the
136 	 *         request is satisfied
137 	 *     userData = the data to pass to callback function
138 	 */
139 	public void canReachAsync(SocketConnectableIF connectable, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
140 	{
141 		g_network_monitor_can_reach_async(getNetworkMonitorStruct(), (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
142 	}
143 
144 	/**
145 	 * Finishes an async network connectivity test.
146 	 * See g_network_monitor_can_reach_async().
147 	 *
148 	 * Params:
149 	 *     result = a #GAsyncResult
150 	 *
151 	 * Return: %TRUE if network is reachable, %FALSE if not.
152 	 *
153 	 * Throws: GException on failure.
154 	 */
155 	public bool canReachFinish(AsyncResultIF result)
156 	{
157 		GError* err = null;
158 		
159 		auto p = g_network_monitor_can_reach_finish(getNetworkMonitorStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
160 		
161 		if (err !is null)
162 		{
163 			throw new GException( new ErrorG(err) );
164 		}
165 		
166 		return p;
167 	}
168 
169 	/**
170 	 * Checks if the network is available. "Available" here means that the
171 	 * system has a default route available for at least one of IPv4 or
172 	 * IPv6. It does not necessarily imply that the public Internet is
173 	 * reachable. See #GNetworkMonitor:network-available for more details.
174 	 *
175 	 * Return: whether the network is available
176 	 *
177 	 * Since: 2.32
178 	 */
179 	public bool getNetworkAvailable()
180 	{
181 		return g_network_monitor_get_network_available(getNetworkMonitorStruct()) != 0;
182 	}
183 
184 	int[string] connectedSignals;
185 
186 	void delegate(bool, NetworkMonitorIF)[] _onNetworkChangedListeners;
187 	@property void delegate(bool, NetworkMonitorIF)[] onNetworkChangedListeners()
188 	{
189 		return _onNetworkChangedListeners;
190 	}
191 	/**
192 	 * Emitted when the network configuration changes. If @available is
193 	 * %TRUE, then some hosts may be reachable that were not reachable
194 	 * before, while others that were reachable before may no longer be
195 	 * reachable. If @available is %FALSE, then no remote hosts are
196 	 * reachable.
197 	 *
198 	 * Params:
199 	 *     available = the current value of #GNetworkMonitor:network-available
200 	 *
201 	 * Since: 2.32
202 	 */
203 	void addOnNetworkChanged(void delegate(bool, NetworkMonitorIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
204 	{
205 		if ( "network-changed" !in connectedSignals )
206 		{
207 			Signals.connectData(
208 				this,
209 				"network-changed",
210 				cast(GCallback)&callBackNetworkChanged,
211 				cast(void*)cast(NetworkMonitorIF)this,
212 				null,
213 				connectFlags);
214 			connectedSignals["network-changed"] = 1;
215 		}
216 		_onNetworkChangedListeners ~= dlg;
217 	}
218 	extern(C) static void callBackNetworkChanged(GNetworkMonitor* networkmonitorStruct, bool available, NetworkMonitorIF _networkmonitor)
219 	{
220 		foreach ( void delegate(bool, NetworkMonitorIF) dlg; _networkmonitor.onNetworkChangedListeners )
221 		{
222 			dlg(available, _networkmonitor);
223 		}
224 	}
225 }