From 4819df28b4006b203471969252a61ae0cfce112b Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 26 Apr 2013 12:06:15 -0400 Subject: [PATCH] core: add NMDeviceGeneric:type-description Use nm_platform_link_get_type_name() to get information about the generic device, and export that via D-Bus --- introspection/nm-device-generic.xml | 6 ++ libnm-glib/nm-device-generic.c | 21 +++++++ libnm-glib/nm-device-generic.h | 1 + src/nm-device-generic.c | 86 ++++++++++++++++++++++++++++- src/nm-device-generic.h | 1 + 5 files changed, 114 insertions(+), 1 deletion(-) diff --git a/introspection/nm-device-generic.xml b/introspection/nm-device-generic.xml index 7cd3d1afc3..79d1989968 100644 --- a/introspection/nm-device-generic.xml +++ b/introspection/nm-device-generic.xml @@ -9,6 +9,12 @@ + + + A (non-localized) description of the interface type, if known. + + + diff --git a/libnm-glib/nm-device-generic.c b/libnm-glib/nm-device-generic.c index 170b9b8fd8..b69070fdd2 100644 --- a/libnm-glib/nm-device-generic.c +++ b/libnm-glib/nm-device-generic.c @@ -37,16 +37,19 @@ typedef struct { DBusGProxy *proxy; char *hw_address; + char *type_description; } NMDeviceGenericPrivate; enum { PROP_0, PROP_HW_ADDRESS, + PROP_TYPE_DESCRIPTION, LAST_PROP }; #define DBUS_PROP_HW_ADDRESS "HwAddress" +#define DBUS_PROP_TYPE_DESCRIPTION "TypeDescription" /** * nm_device_generic_error_quark: @@ -156,6 +159,7 @@ register_properties (NMDeviceGeneric *device) NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device); const NMPropertiesInfo property_info[] = { { NM_DEVICE_GENERIC_HW_ADDRESS, &priv->hw_address }, + { NM_DEVICE_GENERIC_TYPE_DESCRIPTION, &priv->type_description }, { NULL }, }; @@ -209,6 +213,9 @@ get_property (GObject *object, case PROP_HW_ADDRESS: g_value_set_string (value, priv->hw_address); break; + 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; @@ -242,5 +249,19 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass) "Hardware address", NULL, G_PARAM_READABLE)); + + /** + * NMDeviceGeneric:type-description: + * + * A description of the specific type of device this is, or %NULL + * if not known. + **/ + g_object_class_install_property + (object_class, PROP_TYPE_DESCRIPTION, + g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, + "Type Description", + "Type description", + NULL, + G_PARAM_READABLE)); } diff --git a/libnm-glib/nm-device-generic.h b/libnm-glib/nm-device-generic.h index 492e3c598f..bdc301fcd0 100644 --- a/libnm-glib/nm-device-generic.h +++ b/libnm-glib/nm-device-generic.h @@ -50,6 +50,7 @@ typedef enum { GQuark nm_device_generic_error_quark (void); #define NM_DEVICE_GENERIC_HW_ADDRESS "hw-address" +#define NM_DEVICE_GENERIC_TYPE_DESCRIPTION "type-description" typedef struct { NMDevice parent; diff --git a/src/nm-device-generic.c b/src/nm-device-generic.c index 043de7eaf8..7a04efe98f 100644 --- a/src/nm-device-generic.c +++ b/src/nm-device-generic.c @@ -23,8 +23,10 @@ #include "nm-device-generic.h" #include "nm-device-private.h" #include "nm-enum-types.h" +#include "nm-platform.h" #include "nm-properties-changed-signal.h" #include "nm-utils.h" +#include "nm-glib-compat.h" #include "nm-device-generic-glue.h" @@ -33,7 +35,7 @@ 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)) typedef struct { - int dummy; + char *type_description; } NMDeviceGenericPrivate; enum { @@ -44,6 +46,13 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; +enum { + PROP_0, + PROP_TYPE_DESCRIPTION, + + LAST_PROP +}; + #define NM_DEVICE_GENERIC_ERROR (nm_device_generic_error_quark ()) static GQuark @@ -121,6 +130,67 @@ nm_device_generic_init (NMDeviceGeneric *self) nm_device_set_default_unmanaged (NM_DEVICE (self), TRUE); } +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 (ifindex)); + } + + G_OBJECT_CLASS (nm_device_generic_parent_class)->constructed (object); +} + +static void +dispose (GObject *object) +{ + NMDeviceGeneric *self = NM_DEVICE_GENERIC (object); + NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self); + + g_clear_pointer (&priv->type_description, g_free); + + G_OBJECT_CLASS (nm_device_generic_parent_class)->dispose (object); +} + +static void +get_property (GObject *object, guint prop_id, + 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: + 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_class_init (NMDeviceGenericClass *klass) { @@ -129,10 +199,24 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass) g_type_class_add_private (klass, sizeof (NMDeviceGenericPrivate)); + object_class->constructed = constructed; + object_class->dispose = dispose; + object_class->get_property = get_property; + object_class->set_property = set_property; + parent_class->get_generic_capabilities = get_generic_capabilities; parent_class->is_available = is_available; parent_class->check_connection_compatible = check_connection_compatible; + /* properties */ + g_object_class_install_property + (object_class, PROP_TYPE_DESCRIPTION, + g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, + "Type Description", + "Type description", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + /* signals */ signals[PROPERTIES_CHANGED] = nm_properties_changed_signal_new (object_class, diff --git a/src/nm-device-generic.h b/src/nm-device-generic.h index 5c21c8ab25..e2609e238e 100644 --- a/src/nm-device-generic.h +++ b/src/nm-device-generic.h @@ -42,6 +42,7 @@ typedef enum } NMDeviceGenericError; #define NM_DEVICE_GENERIC_HW_ADDRESS "hw-address" +#define NM_DEVICE_GENERIC_TYPE_DESCRIPTION "type-description" typedef struct { NMDevice parent;