mirror of
https://git.proxmox.com/git/fwupd
synced 2025-07-09 18:15:40 +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().
|
* manually closed using g_clear_object().
|
||||||
*
|
*
|
||||||
* The functions used for opening and closing the device are set automatically.
|
* 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
|
* If the @device is not a type or supertype of #GUsbDevice, #FuUsbDevice or
|
||||||
* then this function will not work.
|
* #FuDevice then this function will not work.
|
||||||
*
|
*
|
||||||
* For custom objects please use fu_device_locker_new_full().
|
* 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,
|
(FuDeviceLockerFunc) fu_usb_device_close,
|
||||||
error);
|
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_set_error_literal (error,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_NOT_SUPPORTED,
|
G_IO_ERROR_NOT_SUPPORTED,
|
||||||
|
@ -39,6 +39,7 @@ typedef struct {
|
|||||||
guint progress;
|
guint progress;
|
||||||
guint order;
|
guint order;
|
||||||
guint priority;
|
guint priority;
|
||||||
|
gboolean done_probe;
|
||||||
} FuDevicePrivate;
|
} FuDevicePrivate;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -1243,6 +1244,101 @@ fu_device_attach (FuDevice *device, GError **error)
|
|||||||
return klass->attach (device, 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:
|
* fu_device_incorporate:
|
||||||
* @device: A #FuDevice
|
* @device: A #FuDevice
|
||||||
|
@ -31,8 +31,14 @@ struct _FuDeviceClass
|
|||||||
GError **error);
|
GError **error);
|
||||||
gboolean (*attach) (FuDevice *device,
|
gboolean (*attach) (FuDevice *device,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
gboolean (*open) (FuDevice *device,
|
||||||
|
GError **error);
|
||||||
|
gboolean (*close) (FuDevice *device,
|
||||||
|
GError **error);
|
||||||
|
gboolean (*probe) (FuDevice *device,
|
||||||
|
GError **error);
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
gpointer padding[28];
|
gpointer padding[25];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,6 +178,12 @@ gboolean fu_device_detach (FuDevice *device,
|
|||||||
GError **error);
|
GError **error);
|
||||||
void fu_device_incorporate (FuDevice *self,
|
void fu_device_incorporate (FuDevice *self,
|
||||||
FuDevice *donor);
|
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
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user