| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  | /* GIO - GLib Input, Output and Streaming Library
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright 2014 Red Hat, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-05-18 09:12:45 +01:00
										 |  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							| 
									
										
										
										
											2017-05-27 18:21:30 +02:00
										 |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General | 
					
						
							|  |  |  |  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "config.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <errno.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "gnetworkmonitornm.h"
 | 
					
						
							|  |  |  | #include "gioerror.h"
 | 
					
						
							|  |  |  | #include "ginitable.h"
 | 
					
						
							|  |  |  | #include "giomodule-priv.h"
 | 
					
						
							|  |  |  | #include "glibintl.h"
 | 
					
						
							|  |  |  | #include "glib/gstdio.h"
 | 
					
						
							|  |  |  | #include "gnetworkingprivate.h"
 | 
					
						
							|  |  |  | #include "gnetworkmonitor.h"
 | 
					
						
							|  |  |  | #include "gdbusproxy.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void g_network_monitor_nm_iface_init (GNetworkMonitorInterface *iface); | 
					
						
							|  |  |  | static void g_network_monitor_nm_initable_iface_init (GInitableIface *iface); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PROP_0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PROP_NETWORK_AVAILABLE, | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |   PROP_NETWORK_METERED, | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   PROP_CONNECTIVITY | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef enum { | 
					
						
							|  |  |  |   NM_CONNECTIVITY_UNKNOWN, | 
					
						
							|  |  |  |   NM_CONNECTIVITY_NONE, | 
					
						
							|  |  |  |   NM_CONNECTIVITY_PORTAL, | 
					
						
							|  |  |  |   NM_CONNECTIVITY_LIMITED, | 
					
						
							|  |  |  |   NM_CONNECTIVITY_FULL | 
					
						
							|  |  |  | } NMConnectivityState; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-29 12:05:54 +00:00
										 |  |  | /* Copied from https://developer.gnome.org/libnm-util/stable/libnm-util-NetworkManager.html#NMState;
 | 
					
						
							|  |  |  |  * used inline to avoid a NetworkManager dependency from GLib. */ | 
					
						
							|  |  |  | typedef enum { | 
					
						
							|  |  |  |   NM_STATE_UNKNOWN          = 0, | 
					
						
							|  |  |  |   NM_STATE_ASLEEP           = 10, | 
					
						
							|  |  |  |   NM_STATE_DISCONNECTED     = 20, | 
					
						
							|  |  |  |   NM_STATE_DISCONNECTING    = 30, | 
					
						
							|  |  |  |   NM_STATE_CONNECTING       = 40, | 
					
						
							|  |  |  |   NM_STATE_CONNECTED_LOCAL  = 50, | 
					
						
							|  |  |  |   NM_STATE_CONNECTED_SITE   = 60, | 
					
						
							|  |  |  |   NM_STATE_CONNECTED_GLOBAL = 70, | 
					
						
							|  |  |  | } NMState; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  | struct _GNetworkMonitorNMPrivate | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GDBusProxy *proxy; | 
					
						
							| 
									
										
										
										
											2019-07-29 17:25:21 +02:00
										 |  |  |   guint signal_id; | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   GNetworkConnectivity connectivity; | 
					
						
							|  |  |  |   gboolean network_available; | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |   gboolean network_metered; | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define g_network_monitor_nm_get_type _g_network_monitor_nm_get_type
 | 
					
						
							|  |  |  | G_DEFINE_TYPE_WITH_CODE (GNetworkMonitorNM, g_network_monitor_nm, G_TYPE_NETWORK_MONITOR_NETLINK, | 
					
						
							|  |  |  |                          G_ADD_PRIVATE (GNetworkMonitorNM) | 
					
						
							|  |  |  |                          G_IMPLEMENT_INTERFACE (G_TYPE_NETWORK_MONITOR, | 
					
						
							|  |  |  |                                                 g_network_monitor_nm_iface_init) | 
					
						
							|  |  |  |                          G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, | 
					
						
							|  |  |  |                                                 g_network_monitor_nm_initable_iface_init) | 
					
						
							|  |  |  |                          _g_io_modules_ensure_extension_points_registered (); | 
					
						
							|  |  |  |                          g_io_extension_point_implement (G_NETWORK_MONITOR_EXTENSION_POINT_NAME, | 
					
						
							|  |  |  |                                                          g_define_type_id, | 
					
						
							|  |  |  |                                                          "networkmanager", | 
					
						
							|  |  |  |                                                          30)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_network_monitor_nm_init (GNetworkMonitorNM *nm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   nm->priv = g_network_monitor_nm_get_instance_private (nm); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_network_monitor_nm_get_property (GObject    *object, | 
					
						
							|  |  |  |                                    guint       prop_id, | 
					
						
							|  |  |  |                                    GValue     *value, | 
					
						
							|  |  |  |                                    GParamSpec *pspec) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GNetworkMonitorNM *nm = G_NETWORK_MONITOR_NM (object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (prop_id) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     case PROP_NETWORK_AVAILABLE: | 
					
						
							|  |  |  |       g_value_set_boolean (value, nm->priv->network_available); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |     case PROP_NETWORK_METERED: | 
					
						
							|  |  |  |       g_value_set_boolean (value, nm->priv->network_metered); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |     case PROP_CONNECTIVITY: | 
					
						
							|  |  |  |       g_value_set_enum (value, nm->priv->connectivity); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static GNetworkConnectivity | 
					
						
							|  |  |  | nm_conn_to_g_conn (int nm_state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (nm_state) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       case NM_CONNECTIVITY_UNKNOWN: | 
					
						
							|  |  |  |         return G_NETWORK_CONNECTIVITY_LOCAL; | 
					
						
							|  |  |  |       case NM_CONNECTIVITY_NONE: | 
					
						
							|  |  |  |         return G_NETWORK_CONNECTIVITY_LOCAL; | 
					
						
							|  |  |  |       case NM_CONNECTIVITY_PORTAL: | 
					
						
							|  |  |  |         return G_NETWORK_CONNECTIVITY_PORTAL; | 
					
						
							|  |  |  |       case NM_CONNECTIVITY_LIMITED: | 
					
						
							|  |  |  |         return G_NETWORK_CONNECTIVITY_LIMITED; | 
					
						
							|  |  |  |       case NM_CONNECTIVITY_FULL: | 
					
						
							|  |  |  |         return G_NETWORK_CONNECTIVITY_FULL; | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         g_warning ("Unknown NM connectivity state %d", nm_state); | 
					
						
							|  |  |  |         return G_NETWORK_CONNECTIVITY_LOCAL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  | static gboolean | 
					
						
							|  |  |  | nm_metered_to_bool (guint nm_metered) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (nm_metered) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       case 1: /* yes */ | 
					
						
							|  |  |  |       case 3: /* guess-yes */ | 
					
						
							|  |  |  |         return TRUE; | 
					
						
							| 
									
										
										
										
											2015-07-29 11:56:41 +01:00
										 |  |  |       case 0: /* unknown */ | 
					
						
							|  |  |  |         /* We default to FALSE in the unknown-because-you're-not-running-NM
 | 
					
						
							|  |  |  |          * case, so we should return FALSE in the | 
					
						
							|  |  |  |          * unknown-when-you-are-running-NM case too. */ | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |       case 2: /* no */ | 
					
						
							|  |  |  |       case 4: /* guess-no */ | 
					
						
							|  |  |  |         return FALSE; | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         g_warning ("Unknown NM metered state %d", nm_metered); | 
					
						
							|  |  |  |         return FALSE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  | static void | 
					
						
							|  |  |  | sync_properties (GNetworkMonitorNM *nm, | 
					
						
							|  |  |  |                  gboolean           emit_signals) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GVariant *v; | 
					
						
							| 
									
										
										
										
											2019-04-29 12:05:54 +00:00
										 |  |  |   NMState nm_state; | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   NMConnectivityState nm_connectivity; | 
					
						
							|  |  |  |   gboolean new_network_available; | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |   gboolean new_network_metered; | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   GNetworkConnectivity new_connectivity; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-29 12:05:54 +00:00
										 |  |  |   v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "State"); | 
					
						
							|  |  |  |   if (!v) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   nm_state = g_variant_get_uint32 (v); | 
					
						
							|  |  |  |   g_variant_unref (v); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "Connectivity"); | 
					
						
							| 
									
										
										
										
											2014-12-07 22:41:57 +00:00
										 |  |  |   if (!v) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   nm_connectivity = g_variant_get_uint32 (v); | 
					
						
							|  |  |  |   g_variant_unref (v); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-29 12:05:54 +00:00
										 |  |  |   if (nm_state <= NM_STATE_CONNECTED_LOCAL) | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |       new_network_available = FALSE; | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |       new_network_metered = FALSE; | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |       new_connectivity = G_NETWORK_CONNECTIVITY_LOCAL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-29 12:05:54 +00:00
										 |  |  |   else if (nm_state <= NM_STATE_CONNECTED_SITE) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-31 11:19:07 +01:00
										 |  |  |       new_network_available = TRUE; | 
					
						
							| 
									
										
										
										
											2019-04-29 12:05:54 +00:00
										 |  |  |       new_network_metered = FALSE; | 
					
						
							|  |  |  |       if (nm_connectivity == NM_CONNECTIVITY_PORTAL) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           new_connectivity = G_NETWORK_CONNECTIVITY_PORTAL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           new_connectivity = G_NETWORK_CONNECTIVITY_LIMITED; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else /* nm_state == NM_STATE_CONNECTED_FULL */ | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-29 11:56:41 +01:00
										 |  |  |       /* this is only available post NM 1.0 */ | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |       v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "Metered"); | 
					
						
							|  |  |  |       if (v == NULL) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           new_network_metered = FALSE; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           new_network_metered = nm_metered_to_bool (g_variant_get_uint32 (v)); | 
					
						
							|  |  |  |           g_variant_unref (v); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |       new_network_available = TRUE; | 
					
						
							|  |  |  |       new_connectivity = nm_conn_to_g_conn (nm_connectivity); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!emit_signals) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |       nm->priv->network_metered = new_network_metered; | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |       nm->priv->network_available = new_network_available; | 
					
						
							|  |  |  |       nm->priv->connectivity = new_connectivity; | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (new_network_available != nm->priv->network_available) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       nm->priv->network_available = new_network_available; | 
					
						
							|  |  |  |       g_object_notify (G_OBJECT (nm), "network-available"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |   if (new_network_metered != nm->priv->network_metered) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       nm->priv->network_metered = new_network_metered; | 
					
						
							| 
									
										
										
										
											2015-07-29 11:56:41 +01:00
										 |  |  |       g_object_notify (G_OBJECT (nm), "network-metered"); | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   if (new_connectivity != nm->priv->connectivity) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       nm->priv->connectivity = new_connectivity; | 
					
						
							|  |  |  |       g_object_notify (G_OBJECT (nm), "connectivity"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2021-10-12 12:01:50 +02:00
										 |  |  | proxy_properties_changed_cb (GDBusProxy        *proxy, | 
					
						
							|  |  |  |                              GVariant          *changed_properties, | 
					
						
							|  |  |  |                              GStrv              invalidated_properties, | 
					
						
							|  |  |  |                              GNetworkMonitorNM *nm) | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  | { | 
					
						
							|  |  |  |   sync_properties (nm, TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static gboolean | 
					
						
							|  |  |  | has_property (GDBusProxy *proxy, | 
					
						
							|  |  |  |               const char *property_name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char **props; | 
					
						
							|  |  |  |   gboolean prop_found = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   props = g_dbus_proxy_get_cached_property_names (proxy); | 
					
						
							| 
									
										
										
										
											2015-01-05 11:51:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!props) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 12:54:38 +00:00
										 |  |  |   prop_found = g_strv_contains ((const gchar * const *) props, property_name); | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   g_strfreev (props); | 
					
						
							|  |  |  |   return prop_found; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static gboolean | 
					
						
							|  |  |  | g_network_monitor_nm_initable_init (GInitable     *initable, | 
					
						
							|  |  |  |                                     GCancellable  *cancellable, | 
					
						
							|  |  |  |                                     GError       **error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GNetworkMonitorNM *nm = G_NETWORK_MONITOR_NM (initable); | 
					
						
							|  |  |  |   GDBusProxy *proxy; | 
					
						
							|  |  |  |   GInitableIface *parent_iface; | 
					
						
							| 
									
										
										
										
											2015-01-12 10:03:18 +00:00
										 |  |  |   gchar *name_owner = NULL; | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   parent_iface = g_type_interface_peek_parent (G_NETWORK_MONITOR_NM_GET_INITABLE_IFACE (initable)); | 
					
						
							|  |  |  |   if (!parent_iface->init (initable, cancellable, error)) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, | 
					
						
							|  |  |  |                                          G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START | G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, | 
					
						
							|  |  |  |                                          NULL, | 
					
						
							|  |  |  |                                          "org.freedesktop.NetworkManager", | 
					
						
							|  |  |  |                                          "/org/freedesktop/NetworkManager", | 
					
						
							|  |  |  |                                          "org.freedesktop.NetworkManager", | 
					
						
							|  |  |  |                                          cancellable, | 
					
						
							|  |  |  |                                          error); | 
					
						
							|  |  |  |   if (!proxy) | 
					
						
							|  |  |  |     return FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-12 10:03:18 +00:00
										 |  |  |   name_owner = g_dbus_proxy_get_name_owner (proxy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!name_owner) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-09-13 10:25:05 +01:00
										 |  |  |       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, | 
					
						
							|  |  |  |                    _("NetworkManager not running")); | 
					
						
							| 
									
										
										
										
											2015-01-12 10:03:18 +00:00
										 |  |  |       g_object_unref (proxy); | 
					
						
							|  |  |  |       return FALSE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_free (name_owner); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   /* Verify it has the PrimaryConnection and Connectivity properties */ | 
					
						
							|  |  |  |   if (!has_property (proxy, "Connectivity")) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, | 
					
						
							|  |  |  |                    _("NetworkManager version too old")); | 
					
						
							|  |  |  |       g_object_unref (proxy); | 
					
						
							|  |  |  |       return FALSE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 12:01:50 +02:00
										 |  |  |   nm->priv->signal_id = g_signal_connect (G_OBJECT (proxy), "g-properties-changed", | 
					
						
							|  |  |  |                                           G_CALLBACK (proxy_properties_changed_cb), nm); | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   nm->priv->proxy = proxy; | 
					
						
							|  |  |  |   sync_properties (nm, FALSE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return TRUE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_network_monitor_nm_finalize (GObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GNetworkMonitorNM *nm = G_NETWORK_MONITOR_NM (object); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-29 17:25:21 +02:00
										 |  |  |   if (nm->priv->proxy != NULL && | 
					
						
							|  |  |  |       nm->priv->signal_id != 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       g_signal_handler_disconnect (nm->priv->proxy, | 
					
						
							|  |  |  |                                    nm->priv->signal_id); | 
					
						
							|  |  |  |       nm->priv->signal_id = 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   g_clear_object (&nm->priv->proxy); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   G_OBJECT_CLASS (g_network_monitor_nm_parent_class)->finalize (object); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_network_monitor_nm_class_init (GNetworkMonitorNMClass *nl_class) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   GObjectClass *gobject_class = G_OBJECT_CLASS (nl_class); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-29 17:26:47 +02:00
										 |  |  |   gobject_class->finalize = g_network_monitor_nm_finalize; | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   gobject_class->get_property = g_network_monitor_nm_get_property; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_object_class_override_property (gobject_class, PROP_NETWORK_AVAILABLE, "network-available"); | 
					
						
							| 
									
										
										
										
											2015-06-02 15:41:48 +01:00
										 |  |  |   g_object_class_override_property (gobject_class, PROP_NETWORK_METERED, "network-metered"); | 
					
						
							| 
									
										
										
										
											2014-12-03 18:36:25 +01:00
										 |  |  |   g_object_class_override_property (gobject_class, PROP_CONNECTIVITY, "connectivity"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_network_monitor_nm_iface_init (GNetworkMonitorInterface *monitor_iface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | g_network_monitor_nm_initable_iface_init (GInitableIface *iface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   iface->init = g_network_monitor_nm_initable_init; | 
					
						
							|  |  |  | } |