diff options
author | Thomas Haller <thaller@redhat.com> | 2015-11-24 16:43:18 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-12-04 12:15:12 +0100 |
commit | 9e36ccbe284aa4352296b21e5cd087edc6155820 (patch) | |
tree | 2a6af472b9b46b7b190fa18760f291977493c324 | |
parent | d681cbfd3daeec38934bf1e3b73a571b3fef5f2f (diff) | |
download | NetworkManager-9e36ccbe284aa4352296b21e5cd087edc6155820.tar.gz |
device: split new_device_added() out of component_added()
Commit cd3df12c8f8ed6c868c12bc4e7fe6ba162dafc5b 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).
-rw-r--r-- | src/devices/nm-device-vlan.c | 24 | ||||
-rw-r--r-- | src/devices/nm-device.c | 31 | ||||
-rw-r--r-- | src/devices/nm-device.h | 3 | ||||
-rw-r--r-- | src/nm-manager.c | 29 |
4 files changed, 55 insertions, 32 deletions
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 55790a9273..1712a81385 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -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_vlan_set_parent (self, added_device); + || nm_device_get_ifindex (new_device) != plink->parent) + return; - /* 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; diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3318e2ef4c..77f3e2031b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1833,6 +1833,27 @@ setup (NMDevice *self, NMPlatformLink *plink) } /** + * 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 * @component: the component being added by a plugin @@ -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; } diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 6a5cd46f29..704ef6e9a9 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -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); diff --git a/src/nm-manager.c b/src/nm-manager.c index 72d9144d84..0ccd3f7c1f 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -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 |