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.
This commit is contained in:
Thomas Haller 2020-04-26 14:44:41 +02:00
parent ee7fbc954e
commit 800ac28cca
2 changed files with 11 additions and 1 deletions

View file

@ -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);

View file

@ -578,6 +578,7 @@ typedef struct _NMDevicePrivate {
NMMetered metered;
NMSettings *settings;
NMManager *manager;
NMNetns *netns;
@ -913,6 +914,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)
{
@ -17452,8 +17459,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,
@ -17610,6 +17617,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);