diff options
author | Dan Williams <dcbw@redhat.com> | 2007-10-31 22:11:42 +0000 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2007-10-31 22:11:42 +0000 |
commit | b3c00a7be895d908cd4562477c0cacf65e698f42 (patch) | |
tree | 7301f915a79b2390fda6821708ce8aef33efe77a | |
parent | 528858c03900ce5e2d03459e4534785e2a7bdafc (diff) | |
download | NetworkManager-b3c00a7be895d908cd4562477c0cacf65e698f42.tar.gz |
2007-10-31 Dan Williams <dcbw@redhat.com>
* libnm-glib/nm-device.h
libnm-glib/nm-device.c
- (nm_device_get_description): remove
- (nm_device_get_product, nm_device_get_vendor): add
- (nm_device_update_description): new function (private); walk HAL
devices to get product and vendor IDs for a specific device
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3058 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | libnm-glib/nm-device.c | 172 | ||||
-rw-r--r-- | libnm-glib/nm-device.h | 3 |
3 files changed, 142 insertions, 42 deletions
@@ -1,5 +1,14 @@ 2007-10-31 Dan Williams <dcbw@redhat.com> + * libnm-glib/nm-device.h + libnm-glib/nm-device.c + - (nm_device_get_description): remove + - (nm_device_get_product, nm_device_get_vendor): add + - (nm_device_update_description): new function (private); walk HAL + devices to get product and vendor IDs for a specific device + +2007-10-31 Dan Williams <dcbw@redhat.com> + * src/nm-device-802-11-wireless.c - (nm_device_802_11_wireless_get_mode): ignore ENODEV errors diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index 81f0e22b75..8ee2976caf 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -11,6 +11,9 @@ typedef struct { DBusGProxy *device_proxy; NMDeviceState state; + char *product; + char *vendor; + gboolean carrier; gboolean carrier_valid; @@ -48,6 +51,8 @@ nm_device_init (NMDevice *device) priv->carrier = FALSE; priv->carrier_valid = FALSE; priv->disposed = FALSE; + priv->product = NULL; + priv->vendor = NULL; } static GObject* @@ -99,6 +104,17 @@ dispose (GObject *object) } static void +finalize (GObject *object) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object); + + g_free (priv->product); + g_free (priv->vendor); + + G_OBJECT_CLASS (nm_device_parent_class)->finalize (object); +} + +static void nm_device_class_init (NMDeviceClass *device_class) { GObjectClass *object_class = G_OBJECT_CLASS (device_class); @@ -108,6 +124,7 @@ nm_device_class_init (NMDeviceClass *device_class) /* virtual methods */ object_class->constructor = constructor; object_class->dispose = dispose; + object_class->finalize = finalize; /* signals */ signals[STATE_CHANGED] = @@ -251,77 +268,150 @@ nm_device_get_state (NMDevice *device) return priv->state; } -char * -nm_device_get_description (NMDevice *device) +static char * +get_product_and_vendor (DBusGConnection *connection, + const char *udi, + gboolean want_physdev, + gboolean warn, + char **product, + char **vendor) { DBusGProxy *proxy; GError *err = NULL; - char *udi; - char *physical_device_udi = NULL; - char *vendor = NULL; - char *product = NULL; - char *description = NULL; - - g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + char *parent = NULL; + char *tmp_product = NULL; + char *tmp_vendor = NULL; - /* First, get the physical device info */ + g_return_val_if_fail (connection != NULL, NULL); + g_return_val_if_fail (udi != NULL, NULL); - udi = nm_device_get_udi (device); - proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (device)), - "org.freedesktop.Hal", - udi, - "org.freedesktop.Hal.Device"); - g_free (udi); + proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device"); + if (!proxy) + return NULL; if (!dbus_g_proxy_call (proxy, "GetPropertyString", &err, - G_TYPE_STRING, "net.physical_device", + G_TYPE_STRING, "info.product", G_TYPE_INVALID, - G_TYPE_STRING, &physical_device_udi, + G_TYPE_STRING, &tmp_product, G_TYPE_INVALID)) { - g_warning ("Error getting physical device info from HAL: %s", err->message); + if (warn) + g_warning ("Error getting device %s product from HAL: %s", udi, err->message); g_error_free (err); - goto out; + err = NULL; } - g_object_unref (proxy); - - /* Now get the vendor and product info from the physical device */ - - proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (device)), - "org.freedesktop.Hal", - physical_device_udi, - "org.freedesktop.Hal.Device"); if (!dbus_g_proxy_call (proxy, "GetPropertyString", &err, G_TYPE_STRING, "info.vendor", G_TYPE_INVALID, - G_TYPE_STRING, &vendor, + G_TYPE_STRING, &tmp_vendor, G_TYPE_INVALID)) { - g_warning ("Error getting vendor info from HAL: %s", err->message); + if (warn) + g_warning ("Error getting device %s vendor from HAL: %s", udi, err->message); g_error_free (err); - goto out; + err = NULL; } if (!dbus_g_proxy_call (proxy, "GetPropertyString", &err, - G_TYPE_STRING, "info.product", + G_TYPE_STRING, want_physdev ? "net.physical_device" : "info.parent", G_TYPE_INVALID, - G_TYPE_STRING, &product, + G_TYPE_STRING, &parent, G_TYPE_INVALID)) { - g_warning ("Error getting product info from HAL: %s", err->message); + g_warning ("Error getting physical device info from HAL: %s", err->message); g_error_free (err); - goto out; } - description = g_strdup_printf ("%s %s", vendor, product); - - out: + if (parent && tmp_product && tmp_vendor) { + *product = tmp_product; + *vendor = tmp_vendor; + } else { + g_free (tmp_product); + g_free (tmp_vendor); + } g_object_unref (proxy); + + return parent; +} + +static void +nm_device_update_description (NMDevice *device) +{ + NMDevicePrivate *priv; + DBusGConnection *connection; + char *udi; + char *physical_device_udi = NULL; + char *pd_parent_udi = NULL; + char *description = NULL; + + g_return_if_fail (NM_IS_DEVICE (device)); + priv = NM_DEVICE_GET_PRIVATE (device); + + g_free (priv->product); + priv->product = NULL; + g_free (priv->vendor); + priv->vendor = NULL; + + connection = nm_object_get_connection (NM_OBJECT (device)); + g_return_if_fail (connection != NULL); + + /* First, get the physical device info */ + udi = nm_device_get_udi (device); + physical_device_udi = get_product_and_vendor (connection, udi, TRUE, FALSE, &priv->product, &priv->vendor); + g_free (udi); + + /* Ignore product and vendor for the Network Interface */ + if (priv->product || priv->vendor) { + g_free (priv->product); + priv->product = NULL; + g_free (priv->vendor); + priv->vendor = NULL; + } + + /* Get product and vendor off the physical device if possible */ + pd_parent_udi = get_product_and_vendor (connection, + physical_device_udi, + FALSE, + FALSE, + &priv->product, + &priv->vendor); g_free (physical_device_udi); - g_free (vendor); - g_free (product); - return description; + /* If one of the product/vendor isn't found on the physical device, try the + * parent of the physical device. + */ + if (!priv->product || !priv->vendor) { + char *ignore; + ignore = get_product_and_vendor (connection, pd_parent_udi, FALSE, TRUE, + &priv->product, &priv->vendor); + g_free (ignore); + } + g_free (pd_parent_udi); } +char * +nm_device_get_product (NMDevice *device) +{ + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + + priv = NM_DEVICE_GET_PRIVATE (device); + if (!priv->product) + nm_device_update_description (device); + return priv->product; +} + +char * +nm_device_get_vendor (NMDevice *device) +{ + NMDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_DEVICE (device), NULL); + + priv = NM_DEVICE_GET_PRIVATE (device); + if (!priv->vendor) + nm_device_update_description (device); + return priv->vendor; +} gboolean nm_device_get_carrier (NMDevice *device) diff --git a/libnm-glib/nm-device.h b/libnm-glib/nm-device.h index d8aa3f49c5..57c1516828 100644 --- a/libnm-glib/nm-device.h +++ b/libnm-glib/nm-device.h @@ -44,7 +44,8 @@ guint32 nm_device_get_capabilities (NMDevice *device); guint32 nm_device_get_ip4_address (NMDevice *device); NMIP4Config *nm_device_get_ip4_config (NMDevice *device); NMDeviceState nm_device_get_state (NMDevice *device); -char *nm_device_get_description (NMDevice *device); +char *nm_device_get_product (NMDevice *device); +char *nm_device_get_vendor (NMDevice *device); gboolean nm_device_get_carrier (NMDevice *device); NMDeviceType nm_device_type_for_path (DBusGConnection *connection, |