mirror of
https://git.proxmox.com/git/fwupd
synced 2026-02-01 16:55:34 +00:00
Use superclassed versions of FuDevice when calling udev_added() and usb_added()
The daemon creates a baseclass of either FuUsbDevice or FuUdevDevice when the devices are added or coldplugged to match the quirk database and to find out what plugin to run. This is proxied to plugins, but they are given the GUsbDevice or GUdevDevice and the FuDevice is just thrown away. Most plugins either use a FuUsbDevice or superclassed version like FuNvmeDevice and so we re-create the FuDevice, re-probe the hardware, re-query the quirk database and then return this to the daemon. In some cases, plugins actually probe the hardware three times (!) by creating a FuUsbDevice to get the quirks, so that the plugin knows what kind of superclass to create, which then itself probes the hardware again. Passing the temporary FuDevice to the plugins means that the simplest ones can just fu_plugin_device_add() the passed in object, or create a superclass and incorporate the actual GUsbDevice and all the GUIDs. This breaks internal plugin API but speeds up startup substantially and deletes a lot of code.
This commit is contained in:
parent
62867f1f4e
commit
ff704414f6
@ -762,7 +762,7 @@ typedef struct {
|
||||
} FuAltosDeviceVidPid;
|
||||
|
||||
FuAltosDevice *
|
||||
fu_altos_device_new (GUsbDevice *usb_device)
|
||||
fu_altos_device_new (FuUsbDevice *device)
|
||||
{
|
||||
const FuAltosDeviceVidPid vidpids[] = {
|
||||
{ 0xfffe, 0x000a, FU_ALTOS_DEVICE_KIND_BOOTLOADER },
|
||||
@ -772,12 +772,10 @@ fu_altos_device_new (GUsbDevice *usb_device)
|
||||
|
||||
/* set kind */
|
||||
for (guint j = 0; vidpids[j].vid != 0x0000; j++) {
|
||||
if (g_usb_device_get_vid (usb_device) == vidpids[j].vid &&
|
||||
g_usb_device_get_pid (usb_device) == vidpids[j].pid) {
|
||||
FuAltosDevice *self;
|
||||
self = g_object_new (FU_TYPE_ALTOS_DEVICE,
|
||||
"usb-device", usb_device,
|
||||
NULL);
|
||||
if (fu_usb_device_get_vid (device) == vidpids[j].vid &&
|
||||
fu_usb_device_get_pid (device) == vidpids[j].pid) {
|
||||
FuAltosDevice *self = g_object_new (FU_TYPE_ALTOS_DEVICE, NULL);
|
||||
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
|
||||
self->kind = vidpids[j].kind;
|
||||
fu_altos_device_init_real (self);
|
||||
return self;
|
||||
|
||||
@ -32,7 +32,7 @@ typedef enum {
|
||||
FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_LAST
|
||||
} FuAltosDeviceWriteFirmwareFlag;
|
||||
|
||||
FuAltosDevice *fu_altos_device_new (GUsbDevice *usb_device);
|
||||
FuAltosDevice *fu_altos_device_new (FuUsbDevice *device);
|
||||
FuAltosDeviceKind fu_altos_device_kind_from_string (const gchar *kind);
|
||||
const gchar *fu_altos_device_kind_to_string (FuAltosDeviceKind kind);
|
||||
FuAltosDeviceKind fu_altos_device_get_kind (FuAltosDevice *device);
|
||||
|
||||
@ -18,14 +18,15 @@ fu_plugin_init (FuPlugin *plugin)
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
|
||||
{
|
||||
GUsbDevice *usb_device = fu_usb_device_get_dev (device);
|
||||
const gchar *platform_id = NULL;
|
||||
g_autofree gchar *runtime_id = NULL;
|
||||
g_autoptr(FuAltosDevice) dev = NULL;
|
||||
|
||||
/* get kind */
|
||||
dev = fu_altos_device_new (usb_device);
|
||||
dev = fu_altos_device_new (device);
|
||||
if (dev == NULL)
|
||||
return TRUE;
|
||||
|
||||
|
||||
@ -440,11 +440,10 @@ fu_colorhug_device_class_init (FuColorhugDeviceClass *klass)
|
||||
}
|
||||
|
||||
FuColorhugDevice *
|
||||
fu_colorhug_device_new (GUsbDevice *usb_device)
|
||||
fu_colorhug_device_new (FuUsbDevice *device)
|
||||
{
|
||||
FuColorhugDevice *self = NULL;
|
||||
self = g_object_new (FU_TYPE_COLORHUG_DEVICE,
|
||||
"usb-device", usb_device,
|
||||
NULL);
|
||||
self = g_object_new (FU_TYPE_COLORHUG_DEVICE, NULL);
|
||||
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ G_BEGIN_DECLS
|
||||
#define FU_TYPE_COLORHUG_DEVICE (fu_colorhug_device_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (FuColorhugDevice, fu_colorhug_device, FU, COLORHUG_DEVICE, FuUsbDevice)
|
||||
|
||||
FuColorhugDevice *fu_colorhug_device_new (GUsbDevice *usb_device);
|
||||
FuColorhugDevice *fu_colorhug_device_new (FuUsbDevice *device);
|
||||
|
||||
/* object methods */
|
||||
gboolean fu_colorhug_device_set_flash_success (FuColorhugDevice *device,
|
||||
|
||||
@ -99,19 +99,18 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
|
||||
{
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
g_autoptr(FuColorhugDevice) device = NULL;
|
||||
g_autoptr(FuColorhugDevice) dev = NULL;
|
||||
|
||||
/* open the device */
|
||||
device = fu_colorhug_device_new (usb_device);
|
||||
fu_device_set_quirks (FU_DEVICE (device), fu_plugin_get_quirks (plugin));
|
||||
locker = fu_device_locker_new (device, error);
|
||||
dev = fu_colorhug_device_new (device);
|
||||
locker = fu_device_locker_new (dev, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* insert to hash */
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (device));
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (dev));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -599,11 +599,9 @@ fu_csr_device_class_init (FuCsrDeviceClass *klass)
|
||||
}
|
||||
|
||||
FuCsrDevice *
|
||||
fu_csr_device_new (GUsbDevice *usb_device)
|
||||
fu_csr_device_new (FuUsbDevice *device)
|
||||
{
|
||||
FuCsrDevice *device = NULL;
|
||||
device = g_object_new (FU_TYPE_CSR_DEVICE,
|
||||
"usb-device", usb_device,
|
||||
NULL);
|
||||
return device;
|
||||
FuCsrDevice *self = g_object_new (FU_TYPE_CSR_DEVICE, NULL);
|
||||
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ G_BEGIN_DECLS
|
||||
#define FU_TYPE_CSR_DEVICE (fu_csr_device_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (FuCsrDevice, fu_csr_device, FU, CSR_DEVICE, FuUsbDevice)
|
||||
|
||||
FuCsrDevice *fu_csr_device_new (GUsbDevice *usb_device);
|
||||
FuCsrDevice *fu_csr_device_new (FuUsbDevice *device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@ -18,16 +18,15 @@ fu_plugin_init (FuPlugin *plugin)
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
|
||||
{
|
||||
g_autoptr(FuCsrDevice) device = NULL;
|
||||
g_autoptr(FuCsrDevice) dev = NULL;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
device = fu_csr_device_new (usb_device);
|
||||
fu_device_set_quirks (FU_DEVICE (device), fu_plugin_get_quirks (plugin));
|
||||
locker = fu_device_locker_new (device, error);
|
||||
dev = fu_csr_device_new (device);
|
||||
locker = fu_device_locker_new (dev, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (device));
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (dev));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -317,7 +317,7 @@ fu_plugin_dock_node (FuPlugin *plugin, const gchar *platform,
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin,
|
||||
GUsbDevice *device,
|
||||
FuUsbDevice *device,
|
||||
GError **error)
|
||||
{
|
||||
FuPluginData *data = fu_plugin_get_data (plugin);
|
||||
@ -336,9 +336,9 @@ fu_plugin_usb_device_added (FuPlugin *plugin,
|
||||
/* don't look up immediately if a dock is connected as that would
|
||||
mean a SMI on every USB device that showed up on the system */
|
||||
if (!data->smi_obj->fake_smbios) {
|
||||
vid = g_usb_device_get_vid (device);
|
||||
pid = g_usb_device_get_pid (device);
|
||||
platform = g_usb_device_get_platform_id (device);
|
||||
vid = fu_usb_device_get_vid (device);
|
||||
pid = fu_usb_device_get_pid (device);
|
||||
platform = fu_device_get_platform_id (FU_DEVICE (device));
|
||||
} else {
|
||||
vid = data->fake_vid;
|
||||
pid = data->fake_pid;
|
||||
|
||||
@ -31,13 +31,13 @@ fu_plugin_dfu_state_changed_cb (DfuDevice *device,
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *dev, GError **error)
|
||||
{
|
||||
g_autoptr(DfuDevice) device = NULL;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
|
||||
/* open the device */
|
||||
device = dfu_device_new (usb_device);
|
||||
device = dfu_device_new (fu_usb_device_get_dev (dev));
|
||||
fu_device_set_quirks (FU_DEVICE (device), fu_plugin_get_quirks (plugin));
|
||||
dfu_device_set_usb_context (device, fu_plugin_get_usb_context (plugin));
|
||||
locker = fu_device_locker_new (device, error);
|
||||
|
||||
@ -223,23 +223,23 @@ fu_ebitdo_device_set_version (FuEbitdoDevice *self, guint32 version)
|
||||
static gboolean
|
||||
fu_ebitdo_device_validate (FuEbitdoDevice *self, GError **error)
|
||||
{
|
||||
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (self));
|
||||
guint8 idx;
|
||||
g_autofree gchar *ven = NULL;
|
||||
const gchar *ven;
|
||||
const gchar *whitelist[] = {
|
||||
"8Bitdo",
|
||||
"SFC30",
|
||||
NULL };
|
||||
|
||||
/* this is a new, always valid, VID */
|
||||
if (g_usb_device_get_vid (usb_device) == 0x2dc8)
|
||||
if (fu_usb_device_get_vid (FU_USB_DEVICE (self)) == 0x2dc8)
|
||||
return TRUE;
|
||||
|
||||
/* verify the vendor prefix against a whitelist */
|
||||
idx = g_usb_device_get_manufacturer_index (usb_device);
|
||||
ven = g_usb_device_get_string_descriptor (usb_device, idx, error);
|
||||
ven = fu_device_get_vendor (FU_DEVICE (self));
|
||||
if (ven == NULL) {
|
||||
g_prefix_error (error, "could not check vendor descriptor: ");
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_DATA,
|
||||
"could not check vendor descriptor: ");
|
||||
return FALSE;
|
||||
}
|
||||
for (guint i = 0; whitelist[i] != NULL; i++) {
|
||||
@ -605,11 +605,10 @@ fu_ebitdo_device_class_init (FuEbitdoDeviceClass *klass)
|
||||
* Since: 0.1.0
|
||||
**/
|
||||
FuEbitdoDevice *
|
||||
fu_ebitdo_device_new (GUsbDevice *usb_device)
|
||||
fu_ebitdo_device_new (FuUsbDevice *device)
|
||||
{
|
||||
FuEbitdoDevice *self;
|
||||
self = g_object_new (FU_TYPE_EBITDO_DEVICE,
|
||||
"usb-device", usb_device,
|
||||
NULL);
|
||||
self = g_object_new (FU_TYPE_EBITDO_DEVICE, NULL);
|
||||
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
|
||||
return FU_EBITDO_DEVICE (self);
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ G_BEGIN_DECLS
|
||||
#define FU_TYPE_EBITDO_DEVICE (fu_ebitdo_device_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (FuEbitdoDevice, fu_ebitdo_device, FU, EBITDO_DEVICE, FuUsbDevice)
|
||||
|
||||
FuEbitdoDevice *fu_ebitdo_device_new (GUsbDevice *usb_device);
|
||||
FuEbitdoDevice *fu_ebitdo_device_new (FuUsbDevice *device);
|
||||
|
||||
/* getters */
|
||||
const guint32 *fu_ebitdo_device_get_serial (FuEbitdoDevice *device);
|
||||
|
||||
@ -18,20 +18,19 @@ fu_plugin_init (FuPlugin *plugin)
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
|
||||
{
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
g_autoptr(FuEbitdoDevice) device = NULL;
|
||||
g_autoptr(FuEbitdoDevice) dev = NULL;
|
||||
|
||||
/* open the device */
|
||||
device = fu_ebitdo_device_new (usb_device);
|
||||
fu_device_set_quirks (FU_DEVICE (device), fu_plugin_get_quirks (plugin));
|
||||
locker = fu_device_locker_new (device, error);
|
||||
dev = fu_ebitdo_device_new (device);
|
||||
locker = fu_device_locker_new (dev, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* success */
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (device));
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (dev));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -282,11 +282,9 @@ fu_nitrokey_device_class_init (FuNitrokeyDeviceClass *klass)
|
||||
}
|
||||
|
||||
FuNitrokeyDevice *
|
||||
fu_nitrokey_device_new (GUsbDevice *usb_device)
|
||||
fu_nitrokey_device_new (FuUsbDevice *device)
|
||||
{
|
||||
FuNitrokeyDevice *device;
|
||||
device = g_object_new (FU_TYPE_NITROKEY_DEVICE,
|
||||
"usb-device", usb_device,
|
||||
NULL);
|
||||
return FU_NITROKEY_DEVICE (device);
|
||||
FuNitrokeyDevice *self = g_object_new (FU_TYPE_NITROKEY_DEVICE, NULL);
|
||||
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
|
||||
return FU_NITROKEY_DEVICE (self);
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ struct _FuNitrokeyDeviceClass
|
||||
FuUsbDeviceClass parent_class;
|
||||
};
|
||||
|
||||
FuNitrokeyDevice *fu_nitrokey_device_new (GUsbDevice *usb_device);
|
||||
FuNitrokeyDevice *fu_nitrokey_device_new (FuUsbDevice *device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@ -19,18 +19,18 @@ fu_plugin_init (FuPlugin *plugin)
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
|
||||
{
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
g_autoptr(FuNitrokeyDevice) device = NULL;
|
||||
g_autoptr(FuNitrokeyDevice) dev = NULL;
|
||||
|
||||
/* open the device */
|
||||
device = fu_nitrokey_device_new (usb_device);
|
||||
locker = fu_device_locker_new (device, error);
|
||||
dev = fu_nitrokey_device_new (device);
|
||||
locker = fu_device_locker_new (dev, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* success */
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (device));
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (dev));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -393,12 +393,10 @@ fu_nvme_device_class_init (FuNvmeDeviceClass *klass)
|
||||
}
|
||||
|
||||
FuNvmeDevice *
|
||||
fu_nvme_device_new (GUdevDevice *udev_device)
|
||||
fu_nvme_device_new (FuUdevDevice *device)
|
||||
{
|
||||
FuNvmeDevice *self;
|
||||
self = g_object_new (FU_TYPE_NVME_DEVICE,
|
||||
"udev-device", udev_device,
|
||||
NULL);
|
||||
FuNvmeDevice *self = g_object_new (FU_TYPE_NVME_DEVICE, NULL);
|
||||
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
#define __FU_NVME_DEVICE_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "fu-plugin.h"
|
||||
|
||||
@ -17,7 +16,7 @@ G_BEGIN_DECLS
|
||||
#define FU_TYPE_NVME_DEVICE (fu_nvme_device_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (FuNvmeDevice, fu_nvme_device, FU, NVME_DEVICE, FuUdevDevice)
|
||||
|
||||
FuNvmeDevice *fu_nvme_device_new (GUdevDevice *udev_device);
|
||||
FuNvmeDevice *fu_nvme_device_new (FuUdevDevice *device);
|
||||
FuNvmeDevice *fu_nvme_device_new_from_blob (const guint8 *buf,
|
||||
gsize sz,
|
||||
GError **error);
|
||||
|
||||
@ -12,16 +12,16 @@
|
||||
#include "fu-nvme-device.h"
|
||||
|
||||
gboolean
|
||||
fu_plugin_udev_device_added (FuPlugin *plugin, GUdevDevice *udev_device, GError **error)
|
||||
fu_plugin_udev_device_added (FuPlugin *plugin, FuUdevDevice *device, GError **error)
|
||||
{
|
||||
g_autoptr(FuNvmeDevice) dev = NULL;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
|
||||
/* interesting device? */
|
||||
if (g_strcmp0 (g_udev_device_get_subsystem (udev_device), "nvme") != 0)
|
||||
if (g_strcmp0 (fu_udev_device_get_subsystem (device), "nvme") != 0)
|
||||
return TRUE;
|
||||
|
||||
dev = fu_nvme_device_new (udev_device);
|
||||
dev = fu_nvme_device_new (device);
|
||||
locker = fu_device_locker_new (dev, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
|
||||
@ -18,14 +18,14 @@ fu_plugin_init (FuPlugin *plugin)
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
|
||||
{
|
||||
g_autoptr(FuSteelseriesDevice) device = NULL;
|
||||
g_autoptr(FuSteelseriesDevice) dev = NULL;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
device = fu_steelseries_device_new (usb_device);
|
||||
locker = fu_device_locker_new (device, error);
|
||||
dev = fu_steelseries_device_new (device);
|
||||
locker = fu_device_locker_new (dev, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (device));
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (dev));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -127,11 +127,9 @@ fu_steelseries_device_class_init (FuSteelseriesDeviceClass *klass)
|
||||
}
|
||||
|
||||
FuSteelseriesDevice *
|
||||
fu_steelseries_device_new (GUsbDevice *usb_device)
|
||||
fu_steelseries_device_new (FuUsbDevice *device)
|
||||
{
|
||||
FuSteelseriesDevice *device = NULL;
|
||||
device = g_object_new (FU_TYPE_STEELSERIES_DEVICE,
|
||||
"usb-device", usb_device,
|
||||
NULL);
|
||||
return device;
|
||||
FuSteelseriesDevice *self = g_object_new (FU_TYPE_STEELSERIES_DEVICE, NULL);
|
||||
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ struct _FuSteelseriesDeviceClass
|
||||
FuUsbDeviceClass parent_class;
|
||||
};
|
||||
|
||||
FuSteelseriesDevice *fu_steelseries_device_new (GUsbDevice *usb_device);
|
||||
FuSteelseriesDevice *fu_steelseries_device_new (FuUsbDevice *device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@ -68,50 +68,34 @@ fu_plugin_verify (FuPlugin *plugin,
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_udev_device_added (FuPlugin *plugin, GUdevDevice *udev_device, GError **error)
|
||||
fu_plugin_udev_device_added (FuPlugin *plugin, FuUdevDevice *device, GError **error)
|
||||
{
|
||||
FuDevice *dev_tmp;
|
||||
const gchar *guid = NULL;
|
||||
const gchar *id = NULL;
|
||||
g_autofree gchar *rom_fn = NULL;
|
||||
g_autoptr(AsProfile) profile = as_profile_new ();
|
||||
g_autoptr(AsProfileTask) ptask = NULL;
|
||||
g_autoptr(FuDevice) dev = NULL;
|
||||
|
||||
/* interesting device? */
|
||||
if (g_strcmp0 (g_udev_device_get_subsystem (udev_device), "pci") != 0)
|
||||
if (g_strcmp0 (fu_udev_device_get_subsystem (device), "pci") != 0)
|
||||
return TRUE;
|
||||
guid = g_udev_device_get_property (udev_device, "FWUPD_GUID");
|
||||
guid = g_udev_device_get_property (fu_udev_device_get_dev (device), "FWUPD_GUID");
|
||||
if (guid == NULL)
|
||||
return TRUE;
|
||||
|
||||
/* get data */
|
||||
ptask = as_profile_start (profile, "FuPluginUdev:client-add{%s}", guid);
|
||||
g_assert (ptask != NULL);
|
||||
g_debug ("adding udev device: %s", g_udev_device_get_sysfs_path (udev_device));
|
||||
|
||||
/* is already in database */
|
||||
id = g_udev_device_get_sysfs_path (udev_device);
|
||||
dev_tmp = fu_plugin_cache_lookup (plugin, id);
|
||||
if (dev_tmp != NULL) {
|
||||
g_debug ("ignoring duplicate %s", id);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* did we get enough data */
|
||||
dev = fu_udev_device_new (udev_device);
|
||||
fu_device_set_quirks (dev, fu_plugin_get_quirks (plugin));
|
||||
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_INTERNAL);
|
||||
fu_device_add_guid (dev, guid);
|
||||
fu_device_add_icon (dev, "audio-card");
|
||||
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_INTERNAL);
|
||||
fu_device_add_icon (device, "audio-card");
|
||||
|
||||
/* get the FW version from the rom when unlocked */
|
||||
rom_fn = g_build_filename (g_udev_device_get_sysfs_path (udev_device), "rom", NULL);
|
||||
rom_fn = g_build_filename (fu_device_get_platform_id (FU_DEVICE (device)), "rom", NULL);
|
||||
if (g_file_test (rom_fn, G_FILE_TEST_EXISTS))
|
||||
fu_device_set_metadata (dev, "RomFilename", rom_fn);
|
||||
fu_device_set_metadata (FU_DEVICE (device), "RomFilename", rom_fn);
|
||||
|
||||
/* insert to hash */
|
||||
fu_plugin_cache_add (plugin, id, dev);
|
||||
fu_plugin_device_add_delay (plugin, dev);
|
||||
fu_plugin_device_add_delay (plugin, FU_DEVICE (device));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -18,16 +18,15 @@ fu_plugin_init (FuPlugin *plugin)
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
|
||||
{
|
||||
g_autoptr(FuWacDevice) device = NULL;
|
||||
g_autoptr(FuWacDevice) dev = NULL;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
device = fu_wac_device_new (usb_device);
|
||||
fu_device_set_quirks (FU_DEVICE (device), fu_plugin_get_quirks (plugin));
|
||||
locker = fu_device_locker_new (device, error);
|
||||
dev = fu_wac_device_new (device);
|
||||
locker = fu_device_locker_new (dev, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (device));
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (dev));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -890,11 +890,9 @@ fu_wac_device_class_init (FuWacDeviceClass *klass)
|
||||
}
|
||||
|
||||
FuWacDevice *
|
||||
fu_wac_device_new (GUsbDevice *usb_device)
|
||||
fu_wac_device_new (FuUsbDevice *device)
|
||||
{
|
||||
FuWacDevice *device = NULL;
|
||||
device = g_object_new (FU_TYPE_WAC_DEVICE,
|
||||
"usb-device", usb_device,
|
||||
NULL);
|
||||
return device;
|
||||
FuWacDevice *self = g_object_new (FU_TYPE_WAC_DEVICE, NULL);
|
||||
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ typedef enum {
|
||||
FU_WAC_DEVICE_FEATURE_FLAG_LAST
|
||||
} FuWacDeviceFeatureFlags;
|
||||
|
||||
FuWacDevice *fu_wac_device_new (GUsbDevice *usb_device);
|
||||
FuWacDevice *fu_wac_device_new (FuUsbDevice *device);
|
||||
gboolean fu_wac_device_update_reset (FuWacDevice *self,
|
||||
GError **error);
|
||||
gboolean fu_wac_device_get_feature_report (FuWacDevice *self,
|
||||
|
||||
@ -3027,12 +3027,12 @@ fu_engine_udev_device_add (FuEngine *self, GUdevDevice *udev_device)
|
||||
{
|
||||
GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list);
|
||||
const gchar *plugin_name;
|
||||
g_autoptr(FuDevice) device = fu_udev_device_new (udev_device);
|
||||
g_autoptr(FuUdevDevice) device = fu_udev_device_new (udev_device);
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
|
||||
/* add any extra quirks */
|
||||
fu_device_set_quirks (device, self->quirks);
|
||||
if (!fu_device_probe (device, &error_local)) {
|
||||
fu_device_set_quirks (FU_DEVICE (device), self->quirks);
|
||||
if (!fu_device_probe (FU_DEVICE (device), &error_local)) {
|
||||
g_warning ("failed to probe device %s: %s",
|
||||
g_udev_device_get_sysfs_path (udev_device),
|
||||
error_local->message);
|
||||
@ -3040,7 +3040,7 @@ fu_engine_udev_device_add (FuEngine *self, GUdevDevice *udev_device)
|
||||
}
|
||||
|
||||
/* can be specified using a quirk */
|
||||
plugin_name = fu_device_get_plugin (device);
|
||||
plugin_name = fu_device_get_plugin (FU_DEVICE (device));
|
||||
if (plugin_name != NULL) {
|
||||
g_autoptr(GError) error = NULL;
|
||||
FuPlugin *plugin = fu_plugin_list_find_by_name (self->plugin_list,
|
||||
@ -3050,7 +3050,7 @@ fu_engine_udev_device_add (FuEngine *self, GUdevDevice *udev_device)
|
||||
plugin_name, error->message);
|
||||
return;
|
||||
}
|
||||
if (!fu_plugin_runner_udev_device_added (plugin, udev_device, &error)) {
|
||||
if (!fu_plugin_runner_udev_device_added (plugin, device, &error)) {
|
||||
g_warning ("failed to add udev device %s: %s",
|
||||
g_udev_device_get_sysfs_path (udev_device),
|
||||
error->message);
|
||||
@ -3073,7 +3073,7 @@ fu_engine_udev_device_add (FuEngine *self, GUdevDevice *udev_device)
|
||||
}
|
||||
|
||||
/* run all plugins */
|
||||
if (!fu_plugin_runner_udev_device_added (plugin_tmp, udev_device, &error)) {
|
||||
if (!fu_plugin_runner_udev_device_added (plugin_tmp, device, &error)) {
|
||||
if (g_error_matches (error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
|
||||
g_debug ("%s ignoring: %s",
|
||||
fu_plugin_get_name (plugin_tmp),
|
||||
@ -3381,14 +3381,14 @@ fu_engine_usb_device_added_cb (GUsbContext *ctx,
|
||||
{
|
||||
GPtrArray *plugins = fu_plugin_list_get_all (self->plugin_list);
|
||||
const gchar *plugin_name;
|
||||
g_autoptr(FuDevice) device = fu_usb_device_new (usb_device);
|
||||
g_autoptr(FuUsbDevice) device = fu_usb_device_new (usb_device);
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
|
||||
/* add any extra quirks */
|
||||
fu_device_set_quirks (device, self->quirks);
|
||||
if (!fu_device_probe (device, &error_local)) {
|
||||
fu_device_set_quirks (FU_DEVICE (device), self->quirks);
|
||||
if (!fu_device_probe (FU_DEVICE (device), &error_local)) {
|
||||
g_warning ("failed to probe device %s: %s",
|
||||
g_usb_device_get_platform_id (usb_device),
|
||||
fu_device_get_platform_id (FU_DEVICE (device)),
|
||||
error_local->message);
|
||||
return;
|
||||
}
|
||||
@ -3404,7 +3404,7 @@ fu_engine_usb_device_added_cb (GUsbContext *ctx,
|
||||
plugin_name, error->message);
|
||||
return;
|
||||
}
|
||||
if (!fu_plugin_runner_usb_device_added (plugin, usb_device, &error)) {
|
||||
if (!fu_plugin_runner_usb_device_added (plugin, device, &error)) {
|
||||
g_warning ("failed to add USB device %04x:%04x: %s",
|
||||
g_usb_device_get_vid (usb_device),
|
||||
g_usb_device_get_pid (usb_device),
|
||||
@ -3429,7 +3429,7 @@ fu_engine_usb_device_added_cb (GUsbContext *ctx,
|
||||
}
|
||||
|
||||
/* create a device, then probe */
|
||||
if (!fu_plugin_runner_usb_device_added (plugin_tmp, usb_device, &error)) {
|
||||
if (!fu_plugin_runner_usb_device_added (plugin_tmp, device, &error)) {
|
||||
if (g_error_matches (error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED)) {
|
||||
g_debug ("%s ignoring: %s",
|
||||
fu_plugin_get_name (plugin_tmp),
|
||||
|
||||
@ -84,10 +84,10 @@ gboolean fu_plugin_runner_update_reload (FuPlugin *plugin,
|
||||
FuDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_plugin_runner_usb_device_added (FuPlugin *plugin,
|
||||
GUsbDevice *usb_device,
|
||||
FuUsbDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_plugin_runner_udev_device_added (FuPlugin *plugin,
|
||||
GUdevDevice *udev_device,
|
||||
FuUdevDevice *device,
|
||||
GError **error);
|
||||
void fu_plugin_runner_device_removed (FuPlugin *plugin,
|
||||
FuDevice *device);
|
||||
|
||||
@ -66,10 +66,10 @@ gboolean fu_plugin_composite_cleanup (FuPlugin *plugin,
|
||||
GPtrArray *devices,
|
||||
GError **error);
|
||||
gboolean fu_plugin_usb_device_added (FuPlugin *plugin,
|
||||
GUsbDevice *usb_device,
|
||||
FuUsbDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_plugin_udev_device_added (FuPlugin *plugin,
|
||||
GUdevDevice *udev_device,
|
||||
FuUdevDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_plugin_device_removed (FuPlugin *plugin,
|
||||
FuDevice *device,
|
||||
|
||||
@ -95,10 +95,10 @@ typedef gboolean (*FuPluginUpdateFunc) (FuPlugin *plugin,
|
||||
FwupdInstallFlags flags,
|
||||
GError **error);
|
||||
typedef gboolean (*FuPluginUsbDeviceAddedFunc) (FuPlugin *plugin,
|
||||
GUsbDevice *usb_device,
|
||||
FuUsbDevice *device,
|
||||
GError **error);
|
||||
typedef gboolean (*FuPluginUdevDeviceAddedFunc) (FuPlugin *plugin,
|
||||
GUdevDevice *udev_device,
|
||||
FuUdevDevice *device,
|
||||
GError **error);
|
||||
|
||||
/**
|
||||
@ -1212,7 +1212,7 @@ fu_plugin_add_udev_subsystem (FuPlugin *plugin, const gchar *subsystem)
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_runner_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **error)
|
||||
fu_plugin_runner_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
|
||||
{
|
||||
FuPluginPrivate *priv = GET_PRIVATE (plugin);
|
||||
FuPluginUsbDeviceAddedFunc func = NULL;
|
||||
@ -1229,13 +1229,13 @@ fu_plugin_runner_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GEr
|
||||
g_module_symbol (priv->module, "fu_plugin_usb_device_added", (gpointer *) &func);
|
||||
if (func != NULL) {
|
||||
g_debug ("performing usb_device_added() on %s", priv->name);
|
||||
return func (plugin, usb_device, error);
|
||||
return func (plugin, device, error);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_runner_udev_device_added (FuPlugin *plugin, GUdevDevice *udev_device, GError **error)
|
||||
fu_plugin_runner_udev_device_added (FuPlugin *plugin, FuUdevDevice *device, GError **error)
|
||||
{
|
||||
FuPluginPrivate *priv = GET_PRIVATE (plugin);
|
||||
FuPluginUdevDeviceAddedFunc func = NULL;
|
||||
@ -1252,7 +1252,7 @@ fu_plugin_runner_udev_device_added (FuPlugin *plugin, GUdevDevice *udev_device,
|
||||
g_module_symbol (priv->module, "fu_plugin_udev_device_added", (gpointer *) &func);
|
||||
if (func != NULL) {
|
||||
g_debug ("performing udev_device_added() on %s", priv->name);
|
||||
return func (plugin, udev_device, error);
|
||||
return func (plugin, device, error);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -376,11 +376,11 @@ fu_udev_device_class_init (FuUdevDeviceClass *klass)
|
||||
*
|
||||
* Since: 1.1.2
|
||||
**/
|
||||
FuDevice *
|
||||
FuUdevDevice *
|
||||
fu_udev_device_new (GUdevDevice *udev_device)
|
||||
{
|
||||
FuUdevDevice *self = g_object_new (FU_TYPE_UDEV_DEVICE,
|
||||
"udev-device", udev_device,
|
||||
NULL);
|
||||
return FU_DEVICE (self);
|
||||
return FU_UDEV_DEVICE (self);
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ struct _FuUdevDeviceClass
|
||||
gpointer __reserved[31];
|
||||
};
|
||||
|
||||
FuDevice *fu_udev_device_new (GUdevDevice *udev_device);
|
||||
FuUdevDevice *fu_udev_device_new (GUdevDevice *udev_device);
|
||||
void fu_udev_device_emit_changed (FuUdevDevice *self);
|
||||
GUdevDevice *fu_udev_device_get_dev (FuUdevDevice *self);
|
||||
const gchar *fu_udev_device_get_subsystem (FuUdevDevice *self);
|
||||
|
||||
@ -377,12 +377,12 @@ fu_usb_device_incorporate (FuDevice *self, FuDevice *donor)
|
||||
*
|
||||
* Since: 1.0.2
|
||||
**/
|
||||
FuDevice *
|
||||
FuUsbDevice *
|
||||
fu_usb_device_new (GUsbDevice *usb_device)
|
||||
{
|
||||
FuUsbDevice *device = g_object_new (FU_TYPE_USB_DEVICE, NULL);
|
||||
fu_usb_device_set_dev (device, usb_device);
|
||||
return FU_DEVICE (device);
|
||||
return FU_USB_DEVICE (device);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -39,7 +39,7 @@ struct _FuUsbDeviceClass
|
||||
gpointer __reserved[28];
|
||||
};
|
||||
|
||||
FuDevice *fu_usb_device_new (GUsbDevice *usb_device);
|
||||
FuUsbDevice *fu_usb_device_new (GUsbDevice *usb_device);
|
||||
guint16 fu_usb_device_get_vid (FuUsbDevice *self);
|
||||
guint16 fu_usb_device_get_pid (FuUsbDevice *self);
|
||||
GUsbDevice *fu_usb_device_get_dev (FuUsbDevice *device);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user