mirror of
https://git.proxmox.com/git/fwupd
synced 2025-06-11 06:01:58 +00:00
Create the better device GType in the backend
It is weird to do this when constructing the object, and it allows us to match PossiblePlugin quirk matches on potentially better instance IDs added by the superclass.
This commit is contained in:
parent
bb548f15f0
commit
ced79fce4a
@ -70,6 +70,10 @@ fu_mei_device_probe(FuDevice *device, GError **error)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* FuUdevDevice->probe */
|
||||
if (!FU_DEVICE_CLASS(fu_mei_device_parent_class)->probe(device, error))
|
||||
return FALSE;
|
||||
|
||||
/* set the physical ID */
|
||||
return fu_udev_device_set_physical_id(FU_UDEV_DEVICE(device), "pci", error);
|
||||
}
|
||||
@ -324,6 +328,9 @@ fu_mei_device_incorporate(FuDevice *device, FuDevice *donor)
|
||||
static void
|
||||
fu_mei_device_init(FuMeiDevice *self)
|
||||
{
|
||||
fu_udev_device_set_flags(FU_UDEV_DEVICE(self),
|
||||
FU_UDEV_DEVICE_FLAG_OPEN_READ | FU_UDEV_DEVICE_FLAG_OPEN_WRITE |
|
||||
FU_UDEV_DEVICE_FLAG_VENDOR_FROM_PARENT);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -2243,16 +2243,5 @@ fu_udev_device_class_init(FuUdevDeviceClass *klass)
|
||||
FuUdevDevice *
|
||||
fu_udev_device_new(FuContext *ctx, GUdevDevice *udev_device)
|
||||
{
|
||||
#ifdef HAVE_GUDEV
|
||||
/* create the correct object depending on the subsystem */
|
||||
if (g_strcmp0(g_udev_device_get_subsystem(udev_device), "i2c-dev") == 0) {
|
||||
return g_object_new(FU_TYPE_I2C_DEVICE,
|
||||
"context",
|
||||
ctx,
|
||||
"udev-device",
|
||||
udev_device,
|
||||
NULL);
|
||||
}
|
||||
#endif
|
||||
return g_object_new(FU_TYPE_UDEV_DEVICE, "context", ctx, "udev-device", udev_device, NULL);
|
||||
}
|
||||
|
@ -354,7 +354,6 @@ fu_amt_device_setup(FuDevice *device, GError **error)
|
||||
static void
|
||||
fu_amt_device_init(FuAmtDevice *self)
|
||||
{
|
||||
fu_device_set_vendor(FU_DEVICE(self), "Intel");
|
||||
fu_device_set_version_format(FU_DEVICE(self), FWUPD_VERSION_FORMAT_INTEL_ME);
|
||||
fu_device_add_flag(FU_DEVICE(self), FWUPD_DEVICE_FLAG_INTERNAL);
|
||||
fu_device_add_icon(FU_DEVICE(self), "computer");
|
||||
|
@ -8,10 +8,11 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <fwupdplugin.h>
|
||||
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "fu-udev-backend.h"
|
||||
#include "fu-udev-device.h"
|
||||
|
||||
struct _FuUdevBackend {
|
||||
FuBackend parent_instance;
|
||||
@ -25,10 +26,32 @@ G_DEFINE_TYPE(FuUdevBackend, fu_udev_backend, FU_TYPE_BACKEND)
|
||||
static void
|
||||
fu_udev_backend_device_add(FuUdevBackend *self, GUdevDevice *udev_device)
|
||||
{
|
||||
GType gtype = FU_TYPE_UDEV_DEVICE;
|
||||
g_autoptr(FuUdevDevice) device = NULL;
|
||||
struct {
|
||||
const gchar *subsystem;
|
||||
GType gtype;
|
||||
} subsystem_gtype_map[] = {{"mei", FU_TYPE_MEI_DEVICE},
|
||||
{"i2c", FU_TYPE_I2C_DEVICE},
|
||||
{"i2c-dev", FU_TYPE_I2C_DEVICE},
|
||||
{NULL, G_TYPE_INVALID}};
|
||||
|
||||
/* create the correct object depending on the subsystem */
|
||||
for (guint i = 0; subsystem_gtype_map[i].gtype != G_TYPE_INVALID; i++) {
|
||||
if (g_strcmp0(g_udev_device_get_subsystem(udev_device),
|
||||
subsystem_gtype_map[i].subsystem) == 0) {
|
||||
gtype = subsystem_gtype_map[i].gtype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* success */
|
||||
device = fu_udev_device_new(fu_backend_get_context(FU_BACKEND(self)), udev_device);
|
||||
device = g_object_new(gtype,
|
||||
"context",
|
||||
fu_backend_get_context(FU_BACKEND(self)),
|
||||
"udev-device",
|
||||
udev_device,
|
||||
NULL);
|
||||
fu_backend_device_added(FU_BACKEND(self), FU_DEVICE(device));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user