mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-07 00:30:32 +01:00
device: split new_device_added() out of component_added()
Commit cd3df12c8f reused the
virtual function component_added() to notify the vlan device
about a possibly new parent.
This reuse of the virtual function for another purpose is confusing.
Clean that up by splitting the implementation and add a new
virtual function nm_device_notify_new_device_added() which gets
(only implemented by NMDeviceVlan).
This commit is contained in:
parent
d681cbfd3d
commit
9e36ccbe28
4 changed files with 55 additions and 32 deletions
|
|
@ -290,36 +290,28 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
|||
return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->is_available (device, flags);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
component_added (NMDevice *device, GObject *component)
|
||||
static void
|
||||
notify_new_device_added (NMDevice *device, NMDevice *new_device)
|
||||
{
|
||||
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
|
||||
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
||||
NMDevice *added_device;
|
||||
const NMPlatformLink *plink;
|
||||
const NMPlatformLnkVlan *plnk;
|
||||
|
||||
if (priv->parent)
|
||||
return FALSE;
|
||||
|
||||
if (!NM_IS_DEVICE (component))
|
||||
return FALSE;
|
||||
added_device = NM_DEVICE (component);
|
||||
return;
|
||||
|
||||
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink);
|
||||
if (!plnk) {
|
||||
_LOGW (LOGD_VLAN, "failed to get VLAN interface info while checking added component.");
|
||||
return FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( plink->parent <= 0
|
||||
|| nm_device_get_ifindex (added_device) != plink->parent)
|
||||
return FALSE;
|
||||
|| nm_device_get_ifindex (new_device) != plink->parent)
|
||||
return;
|
||||
|
||||
nm_device_vlan_set_parent (self, added_device);
|
||||
|
||||
/* Don't claim parent exclusively */
|
||||
return FALSE;
|
||||
nm_device_vlan_set_parent (self, new_device);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
|
@ -677,7 +669,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
|
|||
parent_class->ip4_config_pre_commit = ip4_config_pre_commit;
|
||||
parent_class->deactivate = deactivate;
|
||||
parent_class->is_available = is_available;
|
||||
parent_class->component_added = component_added;
|
||||
parent_class->notify_new_device_added = notify_new_device_added;
|
||||
|
||||
parent_class->check_connection_compatible = check_connection_compatible;
|
||||
parent_class->complete_connection = complete_connection;
|
||||
|
|
|
|||
|
|
@ -1832,6 +1832,27 @@ setup (NMDevice *self, NMPlatformLink *plink)
|
|||
g_object_thaw_notify (G_OBJECT (self));
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_device_notify_new_device_added():
|
||||
* @self: the #NMDevice
|
||||
* @device: the newly added device
|
||||
*
|
||||
* Called by the manager to notify the device that a new device has
|
||||
* been found and added.
|
||||
*/
|
||||
void
|
||||
nm_device_notify_new_device_added (NMDevice *self, NMDevice *device)
|
||||
{
|
||||
NMDeviceClass *klass;
|
||||
|
||||
g_return_if_fail (NM_IS_DEVICE (self));
|
||||
g_return_if_fail (NM_IS_DEVICE (device));
|
||||
|
||||
klass = NM_DEVICE_GET_CLASS (self);
|
||||
if (klass->notify_new_device_added)
|
||||
klass->notify_new_device_added (self, device);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_device_notify_component_added():
|
||||
* @self: the #NMDevice
|
||||
|
|
@ -1847,8 +1868,14 @@ setup (NMDevice *self, NMPlatformLink *plink)
|
|||
gboolean
|
||||
nm_device_notify_component_added (NMDevice *self, GObject *component)
|
||||
{
|
||||
if (NM_DEVICE_GET_CLASS (self)->component_added)
|
||||
return NM_DEVICE_GET_CLASS (self)->component_added (self, component);
|
||||
NMDeviceClass *klass;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
|
||||
g_return_val_if_fail (G_IS_OBJECT (component), FALSE);
|
||||
|
||||
klass = NM_DEVICE_GET_CLASS (self);
|
||||
if (klass->component_added)
|
||||
return klass->component_added (self, component);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -288,6 +288,8 @@ typedef struct {
|
|||
gboolean (* have_any_ready_slaves) (NMDevice *self,
|
||||
const GSList *slaves);
|
||||
|
||||
void (* notify_new_device_added) (NMDevice *self, NMDevice *new_device);
|
||||
|
||||
/**
|
||||
* component_added:
|
||||
* @self: the #NMDevice
|
||||
|
|
@ -496,6 +498,7 @@ gboolean nm_device_check_connection_available (NMDevice *device,
|
|||
NMDeviceCheckConAvailableFlags flags,
|
||||
const char *specific_object);
|
||||
|
||||
void nm_device_notify_new_device_added (NMDevice *self, NMDevice *new_device);
|
||||
gboolean nm_device_notify_component_added (NMDevice *device, GObject *component);
|
||||
|
||||
gboolean nm_device_owns_iface (NMDevice *device, const char *iface);
|
||||
|
|
|
|||
|
|
@ -1671,18 +1671,6 @@ device_ip_iface_changed (NMDevice *device,
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
notify_component_added (NMManager *self, GObject *component)
|
||||
{
|
||||
GSList *iter;
|
||||
|
||||
for (iter = NM_MANAGER_GET_PRIVATE (self)->devices; iter; iter = iter->next) {
|
||||
if (nm_device_notify_component_added (NM_DEVICE (iter->data), component))
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_device:
|
||||
* @self: the #NMManager
|
||||
|
|
@ -1814,7 +1802,12 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume)
|
|||
g_signal_emit (self, signals[DEVICE_ADDED], 0, device);
|
||||
g_object_notify (G_OBJECT (self), NM_MANAGER_DEVICES);
|
||||
|
||||
notify_component_added (self, G_OBJECT (device));
|
||||
for (iter = priv->devices; iter; iter = iter->next) {
|
||||
NMDevice *d = iter->data;
|
||||
|
||||
if (d != device)
|
||||
nm_device_notify_new_device_added (d, device);
|
||||
}
|
||||
|
||||
/* New devices might be master interfaces for virtual interfaces; so we may
|
||||
* need to create new virtual interfaces now.
|
||||
|
|
@ -1845,7 +1838,15 @@ factory_component_added_cb (NMDeviceFactory *factory,
|
|||
GObject *component,
|
||||
gpointer user_data)
|
||||
{
|
||||
return notify_component_added (NM_MANAGER (user_data), component);
|
||||
GSList *iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_MANAGER (user_data), FALSE);
|
||||
|
||||
for (iter = NM_MANAGER_GET_PRIVATE (user_data)->devices; iter; iter = iter->next) {
|
||||
if (nm_device_notify_component_added ((NMDevice *) iter->data, component))
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue