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