summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2011-10-10 15:26:36 +0100
committerRichard Hughes <richard@hughsie.com>2011-10-10 15:26:36 +0100
commit998cf93dabec106a784ec01d2ec9f660263fc5a5 (patch)
treefae087f73c9c4d9c412a20d0dcaff42571c1a04b
parent2b628855808b391cebe6a8831bec0ba40bd2ed91 (diff)
downloadgusb-998cf93dabec106a784ec01d2ec9f660263fc5a5.tar.gz
Add g_usb_device_get_platform_id which returns the sysfs path on Linux
-rw-r--r--gusb/gusb-device-list.c4
-rw-r--r--gusb/gusb-device-private.h4
-rw-r--r--gusb/gusb-device.c40
-rw-r--r--gusb/gusb-device.h2
4 files changed, 46 insertions, 4 deletions
diff --git a/gusb/gusb-device-list.c b/gusb/gusb-device-list.c
index ea03a95..99328e9 100644
--- a/gusb/gusb-device-list.c
+++ b/gusb/gusb-device-list.c
@@ -302,7 +302,9 @@ g_usb_device_list_add_dev (GUsbDeviceList *list, GUdevDevice *udev)
for (i = 0; dev_list && dev_list[i]; i++) {
if (libusb_get_bus_number (dev_list[i]) == bus &&
libusb_get_device_address (dev_list[i]) == address) {
- device = _g_usb_device_new (priv->context, dev_list[i]);
+ device = _g_usb_device_new (priv->context,
+ dev_list[i],
+ udev);
break;
}
}
diff --git a/gusb/gusb-device-private.h b/gusb/gusb-device-private.h
index 5d8c69b..2d25d0e 100644
--- a/gusb/gusb-device-private.h
+++ b/gusb/gusb-device-private.h
@@ -21,12 +21,14 @@
#ifndef __GUSB_DEVICE_PRIVATE_H__
#define __GUSB_DEVICE_PRIVATE_H__
+#include <gudev/gudev.h>
#include <gusb/gusb-device.h>
G_BEGIN_DECLS
GUsbDevice *_g_usb_device_new (GUsbContext *context,
- libusb_device *device);
+ libusb_device *device,
+ GUdevDevice *udev);
libusb_device *_g_usb_device_get_device (GUsbDevice *device);
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c
index 4071018..969ae5c 100644
--- a/gusb/gusb-device.c
+++ b/gusb/gusb-device.c
@@ -49,6 +49,7 @@ static void g_usb_device_finalize (GObject *object);
**/
struct _GUsbDevicePrivate
{
+ gchar *platform_id;
GUsbContext *context;
libusb_device *device;
libusb_device_handle *handle;
@@ -58,7 +59,8 @@ struct _GUsbDevicePrivate
enum {
PROP_0,
PROP_LIBUSB_DEVICE,
- PROP_CONTEXT
+ PROP_CONTEXT,
+ PROP_PLATFORM_ID
};
G_DEFINE_TYPE (GUsbDevice, g_usb_device, G_TYPE_OBJECT)
@@ -1104,6 +1106,9 @@ g_usb_device_set_property (GObject *object,
case PROP_CONTEXT:
priv->context = g_value_dup_object (value);
break;
+ case PROP_PLATFORM_ID:
+ priv->platform_id = g_value_dup_string (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1177,6 +1182,16 @@ g_usb_device_class_init (GUsbDeviceClass *klass)
g_object_class_install_property (object_class, PROP_CONTEXT,
pspec);
+ /**
+ * GUsbDevice:platform-id:
+ */
+ pspec = g_param_spec_string ("platform-id", NULL, NULL,
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY|
+ G_PARAM_WRITABLE);
+ g_object_class_install_property (object_class, PROP_PLATFORM_ID,
+ pspec);
+
g_type_class_add_private (klass, sizeof (GUsbDevicePrivate));
}
@@ -1198,6 +1213,7 @@ g_usb_device_finalize (GObject *object)
GUsbDevice *device = G_USB_DEVICE (object);
GUsbDevicePrivate *priv = device->priv;
+ g_free (priv->platform_id);
libusb_unref_device (priv->device);
g_object_unref (priv->context);
@@ -1212,12 +1228,15 @@ g_usb_device_finalize (GObject *object)
* Since: 0.1.0
**/
GUsbDevice *
-_g_usb_device_new (GUsbContext *context, libusb_device *device)
+_g_usb_device_new (GUsbContext *context,
+ libusb_device *device,
+ GUdevDevice *udev)
{
GObject *obj;
obj = g_object_new (G_USB_TYPE_DEVICE,
"context", context,
"libusb-device", device,
+ "platform-id", g_udev_device_get_sysfs_path (udev),
NULL);
return G_USB_DEVICE (obj);
}
@@ -1237,6 +1256,23 @@ _g_usb_device_get_device (GUsbDevice *device)
}
/**
+ * g_usb_device_get_platform_id:
+ * @device: a #GUsbDevice
+ *
+ * Gets the platform identifier for the device.
+ * On Linux, this is the full sysfs path of the device
+ *
+ * Return value: The platform ID, or %NULL
+ *
+ * Since: 0.1.1
+ **/
+const gchar *
+g_usb_device_get_platform_id (GUsbDevice *device)
+{
+ return device->priv->platform_id;
+}
+
+/**
* g_usb_device_get_bus:
* @device: a #GUsbDevice
*
diff --git a/gusb/gusb-device.h b/gusb/gusb-device.h
index 35bbd1a..661ef9b 100644
--- a/gusb/gusb-device.h
+++ b/gusb/gusb-device.h
@@ -119,6 +119,8 @@ struct _GUsbDeviceClass
GType g_usb_device_get_type (void);
GQuark g_usb_device_error_quark (void);
+const gchar *g_usb_device_get_platform_id (GUsbDevice *device);
+
guint8 g_usb_device_get_bus (GUsbDevice *device);
guint8 g_usb_device_get_address (GUsbDevice *device);