diff --git a/libfwupdplugin/fu-plugin-private.h b/libfwupdplugin/fu-plugin-private.h index 54da55bbd..a1862440b 100644 --- a/libfwupdplugin/fu-plugin-private.h +++ b/libfwupdplugin/fu-plugin-private.h @@ -86,6 +86,9 @@ gboolean fu_plugin_runner_udev_device_added (FuPlugin *self, gboolean fu_plugin_runner_udev_device_changed (FuPlugin *self, FuUdevDevice *device, GError **error); +gboolean fu_plugin_runner_device_created (FuPlugin *self, + FuDevice *device, + GError **error); void fu_plugin_runner_device_removed (FuPlugin *self, FuDevice *device); void fu_plugin_runner_device_register (FuPlugin *self, diff --git a/libfwupdplugin/fu-plugin-vfuncs.h b/libfwupdplugin/fu-plugin-vfuncs.h index 6de3ee440..0cdbc3bdb 100644 --- a/libfwupdplugin/fu-plugin-vfuncs.h +++ b/libfwupdplugin/fu-plugin-vfuncs.h @@ -324,6 +324,19 @@ gboolean fu_plugin_udev_device_changed (FuPlugin *plugin, gboolean fu_plugin_device_removed (FuPlugin *plugin, FuDevice *device, GError **error); +/** + * fu_plugin_device_created + * @plugin: A #FuPlugin + * @device: A #FuDevice + * @error: A #GError or %NULL + * + * Function run when the subclassed device has been created. + * + * Since: 1.3.9 + **/ +gboolean fu_plugin_device_created (FuPlugin *plugin, + FuDevice *dev, + GError **error); /** * fu_plugin_device_registered * @plugin: A #FuPlugin diff --git a/libfwupdplugin/fu-plugin.c b/libfwupdplugin/fu-plugin.c index c2e7f425d..b62f61b31 100644 --- a/libfwupdplugin/fu-plugin.c +++ b/libfwupdplugin/fu-plugin.c @@ -1678,6 +1678,8 @@ fu_plugin_usb_device_added (FuPlugin *self, FuUsbDevice *device, GError **error) /* create new device and incorporate existing properties */ dev = g_object_new (device_gtype, NULL); fu_device_incorporate (dev, FU_DEVICE (device)); + if (!fu_plugin_runner_device_created (self, dev, error)) + return FALSE; /* there are a lot of different devices that match, but not all respond * well to opening -- so limit some ones with issued updates */ @@ -1715,6 +1717,8 @@ fu_plugin_udev_device_added (FuPlugin *self, FuUdevDevice *device, GError **erro /* create new device and incorporate existing properties */ dev = g_object_new (device_gtype, NULL); fu_device_incorporate (FU_DEVICE (dev), FU_DEVICE (device)); + if (!fu_plugin_runner_device_created (self, dev, error)) + return FALSE; /* there are a lot of different devices that match, but not all respond * well to opening -- so limit some ones with issued updates */ @@ -1950,6 +1954,38 @@ fu_plugin_runner_device_register (FuPlugin *self, FuDevice *device) } } +/** + * fu_plugin_runner_device_created: + * @self: a #FuPlugin + * @device: a #FuDevice + * @error: a #GError or NULL + * + * Call the device_created routine for the plugin + * + * Returns: #TRUE for success, #FALSE for failure + * + * Since: 1.3.9 + **/ +gboolean +fu_plugin_runner_device_created (FuPlugin *self, FuDevice *device, GError **error) +{ + FuPluginPrivate *priv = GET_PRIVATE (self); + FuPluginDeviceFunc func = NULL; + + /* not enabled */ + if (!priv->enabled) + return TRUE; + if (priv->module == NULL) + return TRUE; + + /* optional */ + g_module_symbol (priv->module, "fu_plugin_device_created", (gpointer *) &func); + if (func == NULL) + return TRUE; + g_debug ("performing fu_plugin_device_created() on %s", priv->name); + return func (self, device, error); +} + /** * fu_plugin_runner_verify: * @self: a #FuPlugin diff --git a/libfwupdplugin/fwupdplugin.map b/libfwupdplugin/fwupdplugin.map index 8abd920a0..04d807c48 100644 --- a/libfwupdplugin/fwupdplugin.map +++ b/libfwupdplugin/fwupdplugin.map @@ -531,3 +531,9 @@ LIBFWUPDPLUGIN_1.3.8 { fu_common_kernel_locked_down; local: *; } LIBFWUPDPLUGIN_1.3.6; + +LIBFWUPDPLUGIN_1.3.9 { + global: + fu_plugin_runner_device_created; + local: *; +} LIBFWUPDPLUGIN_1.3.8;