summaryrefslogtreecommitdiff
path: root/src/devices/nm-device-generic.c
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-09-05 08:50:02 -0500
committerDan Williams <dcbw@redhat.com>2015-07-31 14:06:09 -0500
commite8139f56c26ae3bcc5e14abdb29970ae07e93299 (patch)
tree202fe6b86700440bae1d4161c3daf49c34d4dd09 /src/devices/nm-device-generic.c
parentcf455aa0e20f16b109a4cd4e76e26bb4f698d97e (diff)
downloadNetworkManager-e8139f56c26ae3bcc5e14abdb29970ae07e93299.tar.gz
core: split device creation and device setup (bgo #737458)
Future patches will create devices long before they are backed by kernel resources, so we need to split NMDevice object creation from actual setup based on the backing resources. This patch combines the NMDeviceFactory's new_link() and create_virtual_device_for_connection() class methods into a single create_device() method that simply creates an unrealized NMDevice object; this method is not expected to fail unless the device is supposed to be ignored. This also means that the NMDevice 'platform-device' property is removed, because a platform link object may not be available at NMDevice object creation time. After the device is created, it is then "realized" at some later time from a platform link (for existing/hardware devices via the realize() method) or from an NMConnection (for newly created software devices via the create_and_realize() NMDeviceClass methods). https://bugzilla.gnome.org/show_bug.cgi?id=737458
Diffstat (limited to 'src/devices/nm-device-generic.c')
-rw-r--r--src/devices/nm-device-generic.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/devices/nm-device-generic.c b/src/devices/nm-device-generic.c
index db5b2b6b4d..5d092b98f7 100644
--- a/src/devices/nm-device-generic.c
+++ b/src/devices/nm-device-generic.c
@@ -60,6 +60,21 @@ get_type_description (NMDevice *device)
return NM_DEVICE_CLASS (nm_device_generic_parent_class)->get_type_description (device);
}
+static void
+setup (NMDevice *device, NMPlatformLink *plink)
+{
+ NMDeviceGeneric *self = NM_DEVICE_GENERIC (device);
+ NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
+ int ifindex;
+
+ NM_DEVICE_CLASS (nm_device_generic_parent_class)->setup (device, plink);
+
+ g_clear_pointer (&priv->type_description, g_free);
+ ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self));
+ if (ifindex > 0)
+ priv->type_description = g_strdup (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex));
+}
+
static gboolean
check_connection_compatible (NMDevice *device, NMConnection *connection)
{
@@ -96,12 +111,12 @@ update_connection (NMDevice *device, NMConnection *connection)
/**************************************************************/
NMDevice *
-nm_device_generic_new (NMPlatformLink *platform_device)
+nm_device_generic_new (NMPlatformLink *plink)
{
- g_return_val_if_fail (platform_device != NULL, NULL);
+ g_return_val_if_fail (plink != NULL, NULL);
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GENERIC,
- NM_DEVICE_PLATFORM_DEVICE, platform_device,
+ NM_DEVICE_IFACE, plink->name,
NM_DEVICE_TYPE_DESC, "Generic",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
NULL);
@@ -114,22 +129,6 @@ nm_device_generic_init (NMDeviceGeneric *self)
}
static void
-constructed (GObject *object)
-{
- NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
- NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
-
- if (!priv->type_description) {
- int ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self));
-
- if (ifindex != 0)
- priv->type_description = g_strdup (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex));
- }
-
- G_OBJECT_CLASS (nm_device_generic_parent_class)->constructed (object);
-}
-
-static void
dispose (GObject *object)
{
NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
@@ -184,11 +183,11 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass)
parent_class->connection_type = NM_SETTING_GENERIC_SETTING_NAME;
- object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->get_property = get_property;
object_class->set_property = set_property;
+ parent_class->setup = setup;
parent_class->get_generic_capabilities = get_generic_capabilities;
parent_class->get_type_description = get_type_description;
parent_class->check_connection_compatible = check_connection_compatible;