summary refs log tree commit diff
path: root/src/devices/nm-device-generic.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2017-01-17 20:25:09 +0100
committerMichael Biebl <biebl@debian.org>2017-01-17 20:25:09 +0100
commit58f8be580039b0575b197b9573a1c92745d96d30 (patch)
tree2c226233f623a0dcb529be0eb8cdf97e4a2ae0c0 /src/devices/nm-device-generic.c
parent45cb5bb3c0e6edb887cf69b417fcaf7053814a9b (diff)
New upstream version 1.5.90 upstream/1.5.90
Diffstat (limited to 'src/devices/nm-device-generic.c')
-rw-r--r--src/devices/nm-device-generic.c139
1 files changed, 76 insertions, 63 deletions
diff --git a/src/devices/nm-device-generic.c b/src/devices/nm-device-generic.c
index d90840d2..2f51c69d 100644
--- a/src/devices/nm-device-generic.c
+++ b/src/devices/nm-device-generic.c
@@ -21,32 +21,44 @@
 #include "nm-default.h"
 
 #include "nm-device-generic.h"
+
 #include "nm-device-private.h"
-#include "nm-enum-types.h"
-#include "nm-platform.h"
+#include "platform/nm-platform.h"
 #include "nm-core-internal.h"
 
-#include "nmdbus-device-generic.h"
+#include "introspection/org.freedesktop.NetworkManager.Device.Generic.h"
 
-G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE)
+/*****************************************************************************/
 
-#define NM_DEVICE_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericPrivate))
+NM_GOBJECT_PROPERTIES_DEFINE_BASE (
+	PROP_TYPE_DESCRIPTION,
+);
 
 typedef struct {
 	char *type_description;
 } NMDeviceGenericPrivate;
 
-enum {
-	PROP_0,
-	PROP_TYPE_DESCRIPTION,
+struct _NMDeviceGeneric {
+	NMDevice parent;
+	NMDeviceGenericPrivate _priv;
+};
 
-	LAST_PROP
+struct _NMDeviceGenericClass {
+	NMDeviceClass parent;
 };
 
+G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_GENERIC_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceGeneric, NM_IS_DEVICE_GENERIC)
+
+/*****************************************************************************/
+
 static NMDeviceCapabilities
 get_generic_capabilities (NMDevice *dev)
 {
-	if (nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, nm_device_get_ifindex (dev)))
+	int ifindex = nm_device_get_ifindex (dev);
+
+	if (ifindex > 0 && nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, ifindex))
 		return NM_DEVICE_CAP_CARRIER_DETECT;
 	else
 		return NM_DEVICE_CAP_NONE;
@@ -55,8 +67,8 @@ get_generic_capabilities (NMDevice *dev)
 static const char *
 get_type_description (NMDevice *device)
 {
-	if (NM_DEVICE_GENERIC_GET_PRIVATE (device)->type_description)
-		return NM_DEVICE_GENERIC_GET_PRIVATE (device)->type_description;
+	if (NM_DEVICE_GENERIC_GET_PRIVATE ((NMDeviceGeneric *) device)->type_description)
+		return NM_DEVICE_GENERIC_GET_PRIVATE ((NMDeviceGeneric *) device)->type_description;
 	return NM_DEVICE_CLASS (nm_device_generic_parent_class)->get_type_description (device);
 }
 
@@ -108,21 +120,45 @@ update_connection (NMDevice *device, NMConnection *connection)
 	              NULL);
 }
 
-/**************************************************************/
+/*****************************************************************************/
 
-NMDevice *
-nm_device_generic_new (const NMPlatformLink *plink)
+static void
+get_property (GObject *object, guint prop_id,
+              GValue *value, GParamSpec *pspec)
 {
-	g_return_val_if_fail (plink != NULL, NULL);
+	NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
+	NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
 
-	return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GENERIC,
-	                                  NM_DEVICE_IFACE, plink->name,
-	                                  NM_DEVICE_TYPE_DESC, "Generic",
-	                                  NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
-	                                  NULL);
+	switch (prop_id) {
+	case PROP_TYPE_DESCRIPTION:
+		g_value_set_string (value, priv->type_description);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
 }
 
 static void
+set_property (GObject *object, guint prop_id,
+              const GValue *value, GParamSpec *pspec)
+{
+	NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
+	NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
+
+	switch (prop_id) {
+	case PROP_TYPE_DESCRIPTION:
+		priv->type_description = g_value_dup_string (value);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+/*****************************************************************************/
+
+static void
 nm_device_generic_init (NMDeviceGeneric *self)
 {
 }
@@ -143,49 +179,28 @@ constructor (GType type,
 	return object;
 }
 
-static void
-dispose (GObject *object)
+NMDevice *
+nm_device_generic_new (const NMPlatformLink *plink, gboolean nm_plugin_missing)
 {
-	NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
-	NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
-
-	g_clear_pointer (&priv->type_description, g_free);
+	g_return_val_if_fail (plink != NULL, NULL);
 
-	G_OBJECT_CLASS (nm_device_generic_parent_class)->dispose (object);
+	return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GENERIC,
+	                                  NM_DEVICE_IFACE, plink->name,
+	                                  NM_DEVICE_TYPE_DESC, "Generic",
+	                                  NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
+	                                  NM_DEVICE_NM_PLUGIN_MISSING, nm_plugin_missing,
+	                                  NULL);
 }
 
 static void
-get_property (GObject *object, guint prop_id,
-              GValue *value, GParamSpec *pspec)
+dispose (GObject *object)
 {
 	NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
 	NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
 
-	switch (prop_id) {
-	case PROP_TYPE_DESCRIPTION:
-		g_value_set_string (value, priv->type_description);
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-		break;
-	}
-}
-
-static void
-set_property (GObject *object, guint prop_id,
-              const GValue *value, GParamSpec *pspec)
-{
-	NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
-	NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
+	g_clear_pointer (&priv->type_description, g_free);
 
-	switch (prop_id) {
-	case PROP_TYPE_DESCRIPTION:
-		priv->type_description = g_value_dup_string (value);
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-		break;
-	}
+	G_OBJECT_CLASS (nm_device_generic_parent_class)->dispose (object);
 }
 
 static void
@@ -194,8 +209,6 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass)
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
 
-	g_type_class_add_private (klass, sizeof (NMDeviceGenericPrivate));
-
 	NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_GENERIC_SETTING_NAME, NM_LINK_TYPE_ANY)
 
 	object_class->constructor = constructor;
@@ -209,13 +222,13 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass)
 	parent_class->check_connection_compatible = check_connection_compatible;
 	parent_class->update_connection = update_connection;
 
-	/* properties */
-	g_object_class_install_property
-		(object_class, PROP_TYPE_DESCRIPTION,
-		 g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "",
-		                      NULL,
-		                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
-		                      G_PARAM_STATIC_STRINGS));
+	obj_properties[PROP_TYPE_DESCRIPTION] =
+	     g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "",
+	                          NULL,
+	                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+	                          G_PARAM_STATIC_STRINGS);
+
+	g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
 
 	nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
 	                                        NMDBUS_TYPE_DEVICE_GENERIC_SKELETON,