summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-01-05 15:57:56 +0000
committerRichard Hughes <richard@hughsie.com>2015-01-05 15:57:56 +0000
commit1475a82804db825ea56726287620449fb054feda (patch)
treeb66ef0aca7d1e07e1bd4f0e33c55492ff6a48aab
parent57b4a061eb31e35bfa69bb3b8f538c483451d940 (diff)
downloadgusb-1475a82804db825ea56726287620449fb054feda.tar.gz
Generate the platform ID in the device itself
It's just cleaner this way.
-rw-r--r--gusb/gusb-context.c25
-rw-r--r--gusb/gusb-device-private.h1
-rw-r--r--gusb/gusb-device.c32
3 files changed, 31 insertions, 27 deletions
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c
index 68668e7..d952f5c 100644
--- a/gusb/gusb-context.c
+++ b/gusb/gusb-context.c
@@ -268,28 +268,11 @@ g_usb_context_emit_device_remove (GUsbContext *context,
}
static void
-g_usb_context_build_platform_id (GString *str,
- libusb_device *dev)
-{
- libusb_device *parent;
- parent = libusb_get_parent (dev);
- if (parent != NULL)
- g_usb_context_build_platform_id (str, parent);
- if (str->len == 0) {
- g_string_append_printf (str, "%02x:",
- libusb_get_bus_number (dev));
- }
- g_string_append_printf (str, "%02x:",
- libusb_get_port_number (dev));
-}
-
-static void
g_usb_context_add_device (GUsbContext *context,
struct libusb_device *dev)
{
GUsbDevice *device = NULL;
GUsbContextPrivate *priv = context->priv;
- GString *platform_id = NULL;
guint8 bus;
guint8 address;
GError *error = NULL;
@@ -305,13 +288,8 @@ g_usb_context_add_device (GUsbContext *context,
goto out;
}
- /* build a topology of the device */
- platform_id = g_string_new ("usb:");
- g_usb_context_build_platform_id (platform_id, dev);
- g_string_truncate (platform_id, platform_id->len - 1);
-
/* add the device */
- device = _g_usb_device_new (context, dev, platform_id->str, &error);
+ device = _g_usb_device_new (context, dev, &error);
if (device == NULL) {
g_debug ("There was a problem creating the device: %s",
error->message);
@@ -323,7 +301,6 @@ g_usb_context_add_device (GUsbContext *context,
out:
if (device != NULL)
g_object_unref (device);
- g_string_free (platform_id, TRUE);
}
static void
diff --git a/gusb/gusb-device-private.h b/gusb/gusb-device-private.h
index 2859ced..f073141 100644
--- a/gusb/gusb-device-private.h
+++ b/gusb/gusb-device-private.h
@@ -27,7 +27,6 @@ G_BEGIN_DECLS
GUsbDevice *_g_usb_device_new (GUsbContext *context,
libusb_device *device,
- const gchar *platform_id,
GError **error);
libusb_device *_g_usb_device_get_device (GUsbDevice *device);
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c
index 2a1474d..62d48b0 100644
--- a/gusb/gusb-device.c
+++ b/gusb/gusb-device.c
@@ -235,6 +235,33 @@ g_usb_device_init (GUsbDevice *device)
device->priv = g_usb_device_get_instance_private (device);
}
+static void
+g_usb_device_build_platform_id_cb (GString *str, libusb_device *dev)
+{
+ libusb_device *parent;
+ parent = libusb_get_parent (dev);
+ if (parent != NULL)
+ g_usb_device_build_platform_id_cb (str, parent);
+ if (str->len == 0) {
+ g_string_append_printf (str, "%02x:",
+ libusb_get_bus_number (dev));
+ }
+ g_string_append_printf (str, "%02x:",
+ libusb_get_port_number (dev));
+}
+
+static gchar *
+g_usb_device_build_platform_id (struct libusb_device *dev)
+{
+ GString *platform_id;
+
+ /* build a topology of the device */
+ platform_id = g_string_new ("usb:");
+ g_usb_device_build_platform_id_cb (platform_id, dev);
+ g_string_truncate (platform_id, platform_id->len - 1);
+ return g_string_free (platform_id, FALSE);
+}
+
static gboolean
g_usb_device_initable_init (GInitable *initable,
GCancellable *cancellable,
@@ -262,6 +289,9 @@ g_usb_device_initable_init (GInitable *initable,
return FALSE;
}
+ /* this does not change on plug->unplug->plug */
+ priv->platform_id = g_usb_device_build_platform_id (priv->device);
+
return TRUE;
}
@@ -281,14 +311,12 @@ g_usb_device_initable_iface_init (GInitableIface *iface)
GUsbDevice *
_g_usb_device_new (GUsbContext *context,
libusb_device *device,
- const gchar *platform_id,
GError **error)
{
return g_initable_new (G_USB_TYPE_DEVICE,
NULL, error,
"context", context,
"libusb-device", device,
- "platform-id", platform_id,
NULL);
}