source: appstream-generator/build/girepo/gio/NetworkMonitorT.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 8.6 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.NetworkMonitorT;
22
23public  import gi.gio;
24public  import gi.giotypes;
25public  import gio.AsyncResultIF;
26public  import gio.Cancellable;
27public  import gio.NetworkMonitor;
28public  import gio.NetworkMonitorIF;
29public  import gio.SocketConnectableIF;
30public  import glib.ErrorG;
31public  import glib.GException;
32public  import gobject.ObjectG;
33public  import gobject.Signals;
34public  import std.algorithm;
35
36
37/**
38 * #GNetworkMonitor provides an easy-to-use cross-platform API
39 * for monitoring network connectivity. On Linux, the implementation
40 * is based on the kernel's netlink interface.
41 *
42 * Since: 2.32
43 */
44public template NetworkMonitorT(TStruct)
45{
46        /** Get the main Gtk struct */
47        public GNetworkMonitor* getNetworkMonitorStruct()
48        {
49                return cast(GNetworkMonitor*)getStruct();
50        }
51
52
53        /**
54         * Gets the default #GNetworkMonitor for the system.
55         *
56         * Returns: a #GNetworkMonitor
57         *
58         * Since: 2.32
59         */
60        public static NetworkMonitorIF getDefault()
61        {
62                auto p = g_network_monitor_get_default();
63               
64                if(p is null)
65                {
66                        return null;
67                }
68               
69                return ObjectG.getDObject!(NetworkMonitor, NetworkMonitorIF)(cast(GNetworkMonitor*) p);
70        }
71
72        /**
73         * Attempts to determine whether or not the host pointed to by
74         * @connectable can be reached, without actually trying to connect to
75         * it.
76         *
77         * This may return %TRUE even when #GNetworkMonitor:network-available
78         * is %FALSE, if, for example, @monitor can determine that
79         * @connectable refers to a host on a local network.
80         *
81         * If @monitor believes that an attempt to connect to @connectable
82         * will succeed, it will return %TRUE. Otherwise, it will return
83         * %FALSE and set @error to an appropriate error (such as
84         * %G_IO_ERROR_HOST_UNREACHABLE).
85         *
86         * Note that although this does not attempt to connect to
87         * @connectable, it may still block for a brief period of time (eg,
88         * trying to do multicast DNS on the local network), so if you do not
89         * want to block, you should use g_network_monitor_can_reach_async().
90         *
91         * Params:
92         *     connectable = a #GSocketConnectable
93         *     cancellable = a #GCancellable, or %NULL
94         *
95         * Returns: %TRUE if @connectable is reachable, %FALSE if not.
96         *
97         * Since: 2.32
98         *
99         * Throws: GException on failure.
100         */
101        public bool canReach(SocketConnectableIF connectable, Cancellable cancellable)
102        {
103                GError* err = null;
104               
105                auto p = g_network_monitor_can_reach(getNetworkMonitorStruct(), (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
106               
107                if (err !is null)
108                {
109                        throw new GException( new ErrorG(err) );
110                }
111               
112                return p;
113        }
114
115        /**
116         * Asynchronously attempts to determine whether or not the host
117         * pointed to by @connectable can be reached, without actually
118         * trying to connect to it.
119         *
120         * For more details, see g_network_monitor_can_reach().
121         *
122         * When the operation is finished, @callback will be called.
123         * You can then call g_network_monitor_can_reach_finish()
124         * to get the result of the operation.
125         *
126         * Params:
127         *     connectable = a #GSocketConnectable
128         *     cancellable = a #GCancellable, or %NULL
129         *     callback = a #GAsyncReadyCallback to call when the
130         *         request is satisfied
131         *     userData = the data to pass to callback function
132         */
133        public void canReachAsync(SocketConnectableIF connectable, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
134        {
135                g_network_monitor_can_reach_async(getNetworkMonitorStruct(), (connectable is null) ? null : connectable.getSocketConnectableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
136        }
137
138        /**
139         * Finishes an async network connectivity test.
140         * See g_network_monitor_can_reach_async().
141         *
142         * Params:
143         *     result = a #GAsyncResult
144         *
145         * Returns: %TRUE if network is reachable, %FALSE if not.
146         *
147         * Throws: GException on failure.
148         */
149        public bool canReachFinish(AsyncResultIF result)
150        {
151                GError* err = null;
152               
153                auto p = g_network_monitor_can_reach_finish(getNetworkMonitorStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0;
154               
155                if (err !is null)
156                {
157                        throw new GException( new ErrorG(err) );
158                }
159               
160                return p;
161        }
162
163        /**
164         * Gets a more detailed networking state than
165         * g_network_monitor_get_network_available().
166         *
167         * If #GNetworkMonitor:network-available is %FALSE, then the
168         * connectivity state will be %G_NETWORK_CONNECTIVITY_LOCAL.
169         *
170         * If #GNetworkMonitor:network-available is %TRUE, then the
171         * connectivity state will be %G_NETWORK_CONNECTIVITY_FULL (if there
172         * is full Internet connectivity), %G_NETWORK_CONNECTIVITY_LIMITED (if
173         * the host has a default route, but appears to be unable to actually
174         * reach the full Internet), or %G_NETWORK_CONNECTIVITY_PORTAL (if the
175         * host is trapped behind a "captive portal" that requires some sort
176         * of login or acknowledgement before allowing full Internet access).
177         *
178         * Note that in the case of %G_NETWORK_CONNECTIVITY_LIMITED and
179         * %G_NETWORK_CONNECTIVITY_PORTAL, it is possible that some sites are
180         * reachable but others are not. In this case, applications can
181         * attempt to connect to remote servers, but should gracefully fall
182         * back to their "offline" behavior if the connection attempt fails.
183         *
184         * Returns: the network connectivity state
185         *
186         * Since: 2.44
187         */
188        public GNetworkConnectivity getConnectivity()
189        {
190                return g_network_monitor_get_connectivity(getNetworkMonitorStruct());
191        }
192
193        /**
194         * Checks if the network is available. "Available" here means that the
195         * system has a default route available for at least one of IPv4 or
196         * IPv6. It does not necessarily imply that the public Internet is
197         * reachable. See #GNetworkMonitor:network-available for more details.
198         *
199         * Returns: whether the network is available
200         *
201         * Since: 2.32
202         */
203        public bool getNetworkAvailable()
204        {
205                return g_network_monitor_get_network_available(getNetworkMonitorStruct()) != 0;
206        }
207
208        /**
209         * Checks if the network is metered.
210         * See #GNetworkMonitor:network-metered for more details.
211         *
212         * Returns: whether the connection is metered
213         *
214         * Since: 2.46
215         */
216        public bool getNetworkMetered()
217        {
218                return g_network_monitor_get_network_metered(getNetworkMonitorStruct()) != 0;
219        }
220
221        protected class OnNetworkChangedDelegateWrapper
222        {
223                static OnNetworkChangedDelegateWrapper[] listeners;
224                void delegate(bool, NetworkMonitorIF) dlg;
225                gulong handlerId;
226               
227                this(void delegate(bool, NetworkMonitorIF) dlg)
228                {
229                        this.dlg = dlg;
230                        this.listeners ~= this;
231                }
232               
233                void remove(OnNetworkChangedDelegateWrapper source)
234                {
235                        foreach(index, wrapper; listeners)
236                        {
237                                if (wrapper.handlerId == source.handlerId)
238                                {
239                                        listeners[index] = null;
240                                        listeners = std.algorithm.remove(listeners, index);
241                                        break;
242                                }
243                        }
244                }
245        }
246
247        /**
248         * Emitted when the network configuration changes. If @available is
249         * %TRUE, then some hosts may be reachable that were not reachable
250         * before, while others that were reachable before may no longer be
251         * reachable. If @available is %FALSE, then no remote hosts are
252         * reachable.
253         *
254         * Params:
255         *     available = the current value of #GNetworkMonitor:network-available
256         *
257         * Since: 2.32
258         */
259        gulong addOnNetworkChanged(void delegate(bool, NetworkMonitorIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
260        {
261                auto wrapper = new OnNetworkChangedDelegateWrapper(dlg);
262                wrapper.handlerId = Signals.connectData(
263                        this,
264                        "network-changed",
265                        cast(GCallback)&callBackNetworkChanged,
266                        cast(void*)wrapper,
267                        cast(GClosureNotify)&callBackNetworkChangedDestroy,
268                        connectFlags);
269                return wrapper.handlerId;
270        }
271       
272        extern(C) static void callBackNetworkChanged(GNetworkMonitor* networkmonitorStruct, bool available, OnNetworkChangedDelegateWrapper wrapper)
273        {
274                wrapper.dlg(available, wrapper.outer);
275        }
276       
277        extern(C) static void callBackNetworkChangedDestroy(OnNetworkChangedDelegateWrapper wrapper, GClosure* closure)
278        {
279                wrapper.remove(wrapper);
280        }
281}
Note: See TracBrowser for help on using the repository browser.