Create the custom plugin GType in common code

This reduces the amount of boilerplate in plugins.
This commit is contained in:
Richard Hughes 2019-10-05 20:16:47 +01:00
parent 7f67721432
commit 989acf12e7
39 changed files with 58 additions and 328 deletions

View File

@ -469,12 +469,3 @@ fu_colorhug_device_class_init (FuColorhugDeviceClass *klass)
klass_usb_device->open = fu_colorhug_device_open;
klass_usb_device->probe = fu_colorhug_device_probe;
}
FuColorhugDevice *
fu_colorhug_device_new (FuUsbDevice *device)
{
FuColorhugDevice *self = NULL;
self = g_object_new (FU_TYPE_COLORHUG_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -13,6 +13,4 @@ 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 (FuUsbDevice *device);
G_END_DECLS

View File

@ -16,21 +16,5 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.hughski.colorhug");
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuDeviceLocker) locker = NULL;
g_autoptr(FuColorhugDevice) dev = NULL;
/* open the device */
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 (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_COLORHUG_DEVICE);
}

View File

@ -565,11 +565,3 @@ fu_csr_device_class_init (FuCsrDeviceClass *klass)
klass_usb_device->close = fu_csr_device_close;
klass_usb_device->probe = fu_csr_device_probe;
}
FuCsrDevice *
fu_csr_device_new (FuUsbDevice *device)
{
FuCsrDevice *self = g_object_new (FU_TYPE_CSR_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -13,6 +13,4 @@ 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 (FuUsbDevice *device);
G_END_DECLS

View File

@ -16,17 +16,5 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.qualcomm.dfu");
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuCsrDevice) dev = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
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 (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_CSR_DEVICE);
}

View File

@ -610,21 +610,3 @@ fu_ebitdo_device_class_init (FuEbitdoDeviceClass *klass)
klass_usb_device->open = fu_ebitdo_device_open;
klass_usb_device->probe = fu_ebitdo_device_probe;
}
/**
* fu_ebitdo_device_new:
*
* Creates a new #FuEbitdoDevice.
*
* Returns: (transfer full): a #FuEbitdoDevice, or %NULL if not a game pad
*
* Since: 0.1.0
**/
FuEbitdoDevice *
fu_ebitdo_device_new (FuUsbDevice *device)
{
FuEbitdoDevice *self;
self = g_object_new (FU_TYPE_EBITDO_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return FU_EBITDO_DEVICE (self);
}

View File

@ -13,8 +13,6 @@ 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 (FuUsbDevice *device);
/* getters */
const guint32 *fu_ebitdo_device_get_serial (FuEbitdoDevice *device);

View File

@ -16,23 +16,7 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.8bitdo");
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuDeviceLocker) locker = NULL;
g_autoptr(FuEbitdoDevice) dev = NULL;
/* open the device */
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 (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_EBITDO_DEVICE);
}
gboolean

View File

@ -712,11 +712,3 @@ fu_fastboot_device_class_init (FuFastbootDeviceClass *klass)
klass_usb_device->open = fu_fastboot_device_open;
klass_usb_device->close = fu_fastboot_device_close;
}
FuFastbootDevice *
fu_fastboot_device_new (FuUsbDevice *device)
{
FuFastbootDevice *self = g_object_new (FU_TYPE_FASTBOOT_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -13,6 +13,4 @@ G_BEGIN_DECLS
#define FU_TYPE_FASTBOOT_DEVICE (fu_fastboot_device_get_type ())
G_DECLARE_FINAL_TYPE (FuFastbootDevice, fu_fastboot_device, FU, FASTBOOT_DEVICE, FuUsbDevice)
FuFastbootDevice *fu_fastboot_device_new (FuUsbDevice *device);
G_END_DECLS

View File

@ -16,17 +16,5 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.google.fastboot");
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuFastbootDevice) dev = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
dev = fu_fastboot_device_new (device);
locker = fu_device_locker_new (dev, error);
if (locker == NULL)
return FALSE;
fu_plugin_device_add (plugin, FU_DEVICE (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_FASTBOOT_DEVICE);
}

View File

@ -229,11 +229,3 @@ fu_nitrokey_device_class_init (FuNitrokeyDeviceClass *klass)
klass_usb_device->open = fu_nitrokey_device_open;
klass_usb_device->close = fu_nitrokey_device_close;
}
FuNitrokeyDevice *
fu_nitrokey_device_new (FuUsbDevice *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);
}

View File

@ -18,6 +18,4 @@ struct _FuNitrokeyDeviceClass
FuUsbDeviceClass parent_class;
};
FuNitrokeyDevice *fu_nitrokey_device_new (FuUsbDevice *device);
G_END_DECLS

View File

@ -16,21 +16,5 @@ fu_plugin_init (FuPlugin *plugin)
{
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuDeviceLocker) locker = NULL;
g_autoptr(FuNitrokeyDevice) dev = NULL;
/* open the device */
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 (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_NITROKEY_DEVICE);
}

View File

@ -17,24 +17,8 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.realtek.rts54");
fu_plugin_set_device_gtype (plugin, FU_TYPE_RTS54HID_DEVICE);
/* register the custom types */
g_type_ensure (FU_TYPE_RTS54HID_MODULE);
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuDeviceLocker) locker = NULL;
g_autoptr(FuRts54HidDevice) dev = NULL;
/* open the device */
dev = fu_rts54hid_device_new (device);
locker = fu_device_locker_new (dev, error);
if (locker == NULL)
return FALSE;
/* success */
fu_plugin_device_add (plugin, FU_DEVICE (dev));
return TRUE;
}

View File

@ -390,11 +390,3 @@ fu_rts54hid_device_class_init (FuRts54HidDeviceClass *klass)
klass_usb_device->open = fu_rts54hid_device_open;
klass_usb_device->close = fu_rts54hid_device_close;
}
FuRts54HidDevice *
fu_rts54hid_device_new (FuUsbDevice *device)
{
FuRts54HidDevice *self = g_object_new (FU_TYPE_RTS54HID_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -13,7 +13,6 @@ G_BEGIN_DECLS
#define FU_TYPE_RTS54HID_DEVICE (fu_rts54hid_device_get_type ())
G_DECLARE_FINAL_TYPE (FuRts54HidDevice, fu_rts54hid_device, FU, RTS54HID_DEVICE, FuUsbDevice)
FuRts54HidDevice *fu_rts54hid_device_new (FuUsbDevice *device);
gboolean fu_rts54hid_device_set_report (FuRts54HidDevice *self,
guint8 *buf,
gsize buf_sz,

View File

@ -16,21 +16,5 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.realtek.rts54");
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuDeviceLocker) locker = NULL;
g_autoptr(FuRts54HubDevice) dev = NULL;
/* open the device */
dev = fu_rts54hub_device_new (device);
locker = fu_device_locker_new (dev, error);
if (locker == NULL)
return FALSE;
/* success */
fu_plugin_device_add (plugin, FU_DEVICE (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_RTS54HUB_DEVICE);
}

View File

@ -430,11 +430,3 @@ fu_rts54hub_device_class_init (FuRts54HubDeviceClass *klass)
klass_device->prepare_firmware = fu_rts54hub_device_prepare_firmware;
klass_usb_device->close = fu_rts54hub_device_close;
}
FuRts54HubDevice *
fu_rts54hub_device_new (FuUsbDevice *device)
{
FuRts54HubDevice *self = g_object_new (FU_TYPE_RTS54HUB_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -13,6 +13,4 @@ G_BEGIN_DECLS
#define FU_TYPE_RTS54HUB_DEVICE (fu_rts54hub_device_get_type ())
G_DECLARE_FINAL_TYPE (FuRts54HubDevice, fu_rts54hub_device, FU, RTS54HUB_DEVICE, FuUsbDevice)
FuRts54HubDevice *fu_rts54hub_device_new (FuUsbDevice *device);
G_END_DECLS

View File

@ -16,21 +16,5 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.solokeys");
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuDeviceLocker) locker = NULL;
g_autoptr(FuSolokeyDevice) dev = NULL;
/* open the device */
dev = fu_solokey_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 (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_SOLOKEY_DEVICE);
}

View File

@ -499,12 +499,3 @@ fu_solokey_device_class_init (FuSolokeyDeviceClass *klass)
klass_usb_device->close = fu_solokey_device_close;
klass_usb_device->probe = fu_solokey_device_probe;
}
FuSolokeyDevice *
fu_solokey_device_new (FuUsbDevice *device)
{
FuSolokeyDevice *self = NULL;
self = g_object_new (FU_TYPE_SOLOKEY_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -13,6 +13,4 @@ G_BEGIN_DECLS
#define FU_TYPE_SOLOKEY_DEVICE (fu_solokey_device_get_type ())
G_DECLARE_FINAL_TYPE (FuSolokeyDevice, fu_solokey_device, FU, SOLOKEY_DEVICE, FuUsbDevice)
FuSolokeyDevice *fu_solokey_device_new (FuUsbDevice *device);
G_END_DECLS

View File

@ -15,17 +15,5 @@ fu_plugin_init (FuPlugin *plugin)
{
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuSteelseriesDevice) dev = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
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 (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_STEELSERIES_DEVICE);
}

View File

@ -125,11 +125,3 @@ fu_steelseries_device_class_init (FuSteelseriesDeviceClass *klass)
klass_usb_device->open = fu_steelseries_device_open;
klass_usb_device->close = fu_steelseries_device_close;
}
FuSteelseriesDevice *
fu_steelseries_device_new (FuUsbDevice *device)
{
FuSteelseriesDevice *self = g_object_new (FU_TYPE_STEELSERIES_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -18,6 +18,4 @@ struct _FuSteelseriesDeviceClass
FuUsbDeviceClass parent_class;
};
FuSteelseriesDevice *fu_steelseries_device_new (FuUsbDevice *device);
G_END_DECLS

View File

@ -15,17 +15,5 @@ fu_plugin_init (FuPlugin *plugin)
{
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuSynapticsCxaudioDevice) dev = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
dev = fu_synaptics_cxaudio_device_new (device);
locker = fu_device_locker_new (dev, error);
if (locker == NULL)
return FALSE;
fu_plugin_device_add (plugin, FU_DEVICE (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_SYNAPTICS_CXAUDIO_DEVICE);
}

View File

@ -867,11 +867,3 @@ fu_synaptics_cxaudio_device_class_init (FuSynapticsCxaudioDeviceClass *klass)
klass_usb_device->open = fu_synaptics_cxaudio_device_open;
klass_usb_device->close = fu_synaptics_cxaudio_device_close;
}
FuSynapticsCxaudioDevice *
fu_synaptics_cxaudio_device_new (FuUsbDevice *usb_device)
{
FuSynapticsCxaudioDevice *self = g_object_new (FU_TYPE_SYNAPTICS_CXAUDIO_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (usb_device));
return self;
}

View File

@ -18,6 +18,4 @@ struct _FuSynapticsCxaudioDeviceClass
FuUsbDeviceClass parent_class;
};
FuSynapticsCxaudioDevice *fu_synaptics_cxaudio_device_new (FuUsbDevice *usb_device);
G_END_DECLS

View File

@ -16,21 +16,5 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.synaptics.prometheus");
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuDeviceLocker) locker = NULL;
g_autoptr(FuSynapromDevice) dev = NULL;
/* open the device */
dev = fu_synaprom_device_new (device);
locker = fu_device_locker_new (dev, error);
if (locker == NULL)
return FALSE;
/* success */
fu_plugin_device_add (plugin, FU_DEVICE (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_SYNAPROM_DEVICE);
}

View File

@ -16,17 +16,5 @@ fu_plugin_init (FuPlugin *plugin)
{
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuThelioIoDevice) dev = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
dev = fu_thelio_io_device_new (device);
locker = fu_device_locker_new (dev, error);
if (locker == NULL)
return FALSE;
fu_plugin_device_add (plugin, FU_DEVICE (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_THELIO_IO_DEVICE);
}

View File

@ -96,11 +96,3 @@ fu_thelio_io_device_class_init (FuThelioIoDeviceClass *klass)
klass_device->probe = fu_thelio_io_device_probe;
klass_device->detach = fu_thelio_io_device_detach;
}
FuThelioIoDevice *
fu_thelio_io_device_new (FuUsbDevice *device)
{
FuThelioIoDevice *self = g_object_new (FU_TYPE_THELIO_IO_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -14,6 +14,4 @@ G_BEGIN_DECLS
#define FU_TYPE_THELIO_IO_DEVICE (fu_thelio_io_device_get_type ())
G_DECLARE_FINAL_TYPE (FuThelioIoDevice, fu_thelio_io_device, FU, THELIO_IO_DEVICE, FuUsbDevice)
FuThelioIoDevice *fu_thelio_io_device_new (FuUsbDevice *device);
G_END_DECLS

View File

@ -16,19 +16,7 @@ fu_plugin_init (FuPlugin *plugin)
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_REQUIRES_QUIRK, FU_QUIRKS_PLUGIN);
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.wacom.usb");
}
gboolean
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *device, GError **error)
{
g_autoptr(FuWacDevice) dev = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
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 (dev));
return TRUE;
fu_plugin_set_device_gtype (plugin, FU_TYPE_WAC_DEVICE);
}
gboolean

View File

@ -880,11 +880,3 @@ fu_wac_device_class_init (FuWacDeviceClass *klass)
klass_usb_device->open = fu_wac_device_open;
klass_usb_device->close = fu_wac_device_close;
}
FuWacDevice *
fu_wac_device_new (FuUsbDevice *device)
{
FuWacDevice *self = g_object_new (FU_TYPE_WAC_DEVICE, NULL);
fu_device_incorporate (FU_DEVICE (self), FU_DEVICE (device));
return self;
}

View File

@ -20,7 +20,6 @@ typedef enum {
FU_WAC_DEVICE_FEATURE_FLAG_LAST
} FuWacDeviceFeatureFlags;
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,

View File

@ -51,6 +51,7 @@ typedef struct {
GHashTable *compile_versions;
GPtrArray *udev_subsystems;
FuSmbios *smbios;
GType device_gtype;
GHashTable *devices; /* platform_id:GObject */
GRWLock devices_mutex;
GHashTable *report_metadata; /* key:value */
@ -1375,6 +1376,42 @@ fu_plugin_add_udev_subsystem (FuPlugin *self, const gchar *subsystem)
g_ptr_array_add (priv->udev_subsystems, g_strdup (subsystem));
}
/**
* fu_plugin_set_device_gtype:
* @self: a #FuPlugin
* @device_gtype: a #GType `FU_TYPE_DEVICE`
*
* Sets the device #GType which is used when creating devices.
*
* If this method is used then fu_plugin_usb_device_added() is not called, and
* instead the object is created in the daemon for the plugin.
*
* Plugins can use this method only in fu_plugin_init()
*
* Since: 1.3.3
**/
void
fu_plugin_set_device_gtype (FuPlugin *self, GType device_gtype)
{
FuPluginPrivate *priv = GET_PRIVATE (self);
priv->device_gtype = device_gtype;
}
static gboolean
fu_plugin_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error)
{
FuPluginPrivate *priv = GET_PRIVATE (self);
g_autoptr(FuDevice) dev = NULL;
g_autoptr(FuDeviceLocker) locker = NULL;
dev = g_object_new (priv->device_gtype, NULL);
fu_device_incorporate (FU_DEVICE (dev), FU_DEVICE (device));
locker = fu_device_locker_new (dev, error);
if (locker == NULL)
return FALSE;
fu_plugin_device_add (self, FU_DEVICE (dev));
return TRUE;
}
gboolean
fu_plugin_runner_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error)
{
@ -1392,8 +1429,13 @@ fu_plugin_runner_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError *
/* optional */
g_module_symbol (priv->module, "fu_plugin_usb_device_added", (gpointer *) &func);
if (func == NULL)
if (func == NULL) {
if (priv->device_gtype != G_TYPE_INVALID) {
g_debug ("using generic usb_device_added() on %s", priv->name);
return fu_plugin_usb_device_added (self, device, error);
}
return TRUE;
}
g_debug ("performing usb_device_added() on %s", priv->name);
if (!func (self, device, &error_local)) {
if (error_local == NULL) {

View File

@ -109,6 +109,8 @@ void fu_plugin_device_register (FuPlugin *self,
void fu_plugin_request_recoldplug (FuPlugin *self);
void fu_plugin_set_coldplug_delay (FuPlugin *self,
guint duration);
void fu_plugin_set_device_gtype (FuPlugin *self,
GType device_gtype);
gpointer fu_plugin_cache_lookup (FuPlugin *self,
const gchar *id);
void fu_plugin_cache_remove (FuPlugin *self,