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