From 6db85c56dc90cd76f5799bffeadf9e437a11f485 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 26 Apr 2020 14:44:41 +0200 Subject: [PATCH] device: add nm_device_get_manager() NMDevice already has access to the NMSettings singleton. It is permissible that NMDevice *knows* about NMManager. The current alternative is emitting GObject signals like NM_DEVICE_AUTH_REQUEST, pretending that NMDevice and NMManager would be completely independent, or that there could be anybody else handling the request aside NMManager. No, NMManager and NMDevice may know each other and refer to each other. Just like NMDevice also knows and refers to NMSettings. (cherry picked from commit 800ac28ccab6fad6278c5455d45a8ec950319e80) --- src/devices/nm-device-private.h | 2 ++ src/devices/nm-device.c | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 8d539026e7..f9bc4125b8 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -46,6 +46,8 @@ void nm_device_arp_announce (NMDevice *self); NMSettings *nm_device_get_settings (NMDevice *self); +NMManager *nm_device_get_manager (NMDevice *self); + gboolean nm_device_set_ip_ifindex (NMDevice *self, int ifindex); gboolean nm_device_set_ip_iface (NMDevice *self, const char *iface); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index f4f359a14c..d919705976 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -577,6 +577,7 @@ typedef struct _NMDevicePrivate { NMMetered metered; NMSettings *settings; + NMManager *manager; NMNetns *netns; @@ -912,6 +913,12 @@ nm_device_get_settings (NMDevice *self) return NM_DEVICE_GET_PRIVATE (self)->settings; } +NMManager * +nm_device_get_manager (NMDevice *self) +{ + return NM_DEVICE_GET_PRIVATE (self)->manager; +} + NMNetns * nm_device_get_netns (NMDevice *self) { @@ -17409,8 +17416,8 @@ constructed (GObject *object) g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (device_ipx_changed), self); g_signal_connect (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (link_changed_cb), self); + priv->manager = g_object_ref (NM_MANAGER_GET); priv->settings = g_object_ref (NM_SETTINGS_GET); - g_assert (priv->settings); g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_ADDED, @@ -17567,6 +17574,7 @@ finalize (GObject *object) /* for testing, NMDeviceTest does not invoke NMDevice::constructed, * and thus @settings might be unset. */ nm_g_object_unref (priv->settings); + nm_g_object_unref (priv->manager); nm_g_object_unref (priv->concheck_mgr);