mirror of
https://git.proxmox.com/git/fwupd
synced 2025-07-09 10:24:52 +00:00
Add more common vfuncs to FuDevice
This allows us to abstract out common code for plugins not using FuUsbDevice.
This commit is contained in:
parent
e3f581297f
commit
c0fe556350
@ -72,8 +72,8 @@ fu_device_locker_init (FuDeviceLocker *self)
|
||||
* manually closed using g_clear_object().
|
||||
*
|
||||
* The functions used for opening and closing the device are set automatically.
|
||||
* If the @device is not a type or supertype of #GUsbDevice or #FuUsbDevice
|
||||
* then this function will not work.
|
||||
* If the @device is not a type or supertype of #GUsbDevice, #FuUsbDevice or
|
||||
* #FuDevice then this function will not work.
|
||||
*
|
||||
* For custom objects please use fu_device_locker_new_full().
|
||||
*
|
||||
@ -104,6 +104,14 @@ fu_device_locker_new (gpointer device, GError **error)
|
||||
(FuDeviceLockerFunc) fu_usb_device_close,
|
||||
error);
|
||||
}
|
||||
|
||||
/* FuDevice */
|
||||
if (FU_IS_DEVICE (device)) {
|
||||
return fu_device_locker_new_full (device,
|
||||
(FuDeviceLockerFunc) fu_device_open,
|
||||
(FuDeviceLockerFunc) fu_device_close,
|
||||
error);
|
||||
}
|
||||
g_set_error_literal (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_NOT_SUPPORTED,
|
||||
|
@ -39,6 +39,7 @@ typedef struct {
|
||||
guint progress;
|
||||
guint order;
|
||||
guint priority;
|
||||
gboolean done_probe;
|
||||
} FuDevicePrivate;
|
||||
|
||||
enum {
|
||||
@ -1243,6 +1244,101 @@ fu_device_attach (FuDevice *device, GError **error)
|
||||
return klass->attach (device, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_open:
|
||||
* @device: A #FuDevice
|
||||
* @error: A #GError, or %NULL
|
||||
*
|
||||
* Opens a device, optionally running a object-specific vfunc.
|
||||
*
|
||||
* Returns: %TRUE for success
|
||||
*
|
||||
* Since: 1.1.2
|
||||
**/
|
||||
gboolean
|
||||
fu_device_open (FuDevice *device, GError **error)
|
||||
{
|
||||
FuDeviceClass *klass = FU_DEVICE_GET_CLASS (device);
|
||||
|
||||
g_return_val_if_fail (FU_IS_DEVICE (device), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* probe */
|
||||
if (!fu_device_probe (device, error))
|
||||
return FALSE;
|
||||
|
||||
/* subclassed */
|
||||
if (klass->open != NULL) {
|
||||
if (!klass->open (device, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* success */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_open:
|
||||
* @device: A #FuDevice
|
||||
* @error: A #GError, or %NULL
|
||||
*
|
||||
* Closes a device, optionally running a object-specific vfunc.
|
||||
*
|
||||
* Returns: %TRUE for success
|
||||
*
|
||||
* Since: 1.1.2
|
||||
**/
|
||||
gboolean
|
||||
fu_device_close (FuDevice *device, GError **error)
|
||||
{
|
||||
FuDeviceClass *klass = FU_DEVICE_GET_CLASS (device);
|
||||
|
||||
g_return_val_if_fail (FU_IS_DEVICE (device), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* subclassed */
|
||||
if (klass->close != NULL) {
|
||||
if (!klass->close (device, error))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_probe:
|
||||
* @device: A #FuDevice
|
||||
* @error: A #GError, or %NULL
|
||||
*
|
||||
* Probes a device, setting parameters on the object that does not need
|
||||
* the device open or the interface claimed.
|
||||
* If the device is not compatible then an error should be returned.
|
||||
*
|
||||
* Returns: %TRUE for success
|
||||
*
|
||||
* Since: 1.1.2
|
||||
**/
|
||||
gboolean
|
||||
fu_device_probe (FuDevice *device, GError **error)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuDeviceClass *klass = FU_DEVICE_GET_CLASS (device);
|
||||
|
||||
g_return_val_if_fail (FU_IS_DEVICE (device), FALSE);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
|
||||
/* already done */
|
||||
if (priv->done_probe)
|
||||
return TRUE;
|
||||
|
||||
/* subclassed */
|
||||
if (klass->probe != NULL) {
|
||||
if (!klass->probe (device, error))
|
||||
return FALSE;
|
||||
}
|
||||
priv->done_probe = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_incorporate:
|
||||
* @device: A #FuDevice
|
||||
|
@ -31,8 +31,14 @@ struct _FuDeviceClass
|
||||
GError **error);
|
||||
gboolean (*attach) (FuDevice *device,
|
||||
GError **error);
|
||||
gboolean (*open) (FuDevice *device,
|
||||
GError **error);
|
||||
gboolean (*close) (FuDevice *device,
|
||||
GError **error);
|
||||
gboolean (*probe) (FuDevice *device,
|
||||
GError **error);
|
||||
/*< private >*/
|
||||
gpointer padding[28];
|
||||
gpointer padding[25];
|
||||
};
|
||||
|
||||
/**
|
||||
@ -172,6 +178,12 @@ gboolean fu_device_detach (FuDevice *device,
|
||||
GError **error);
|
||||
void fu_device_incorporate (FuDevice *self,
|
||||
FuDevice *donor);
|
||||
gboolean fu_device_open (FuDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_device_close (FuDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_device_probe (FuDevice *device,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user