mirror of
https://git.proxmox.com/git/fwupd
synced 2025-05-13 09:04:03 +00:00
Set the progress and state on the FuDevice, not the FuPlugin
This makes more sense; we're updating the device, not the plugin itself. This also means we don't need to funnel everything through callbacks like GFileProgressCallback and we can also update the state without adding an explicit callback to each derived device type.
This commit is contained in:
parent
e3bc2bcf88
commit
4a036018f7
@ -429,12 +429,23 @@ fu_altos_device_write_page (FuAltosDevice *device,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
fu_altos_device_set_progress (FuAltosDevice *device, guint current, guint total)
|
||||
{
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
percentage = (100.f * (gdouble) current) / (gdouble) total;
|
||||
if (g_getenv ("FWUPD_ALTOS_VERBOSE") != NULL) {
|
||||
g_debug ("written %u/%u bytes [%.1f%%]",
|
||||
current, total, percentage);
|
||||
}
|
||||
fu_device_set_progress (FU_DEVICE (device), (guint) percentage);
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_altos_device_write_firmware (FuAltosDevice *device,
|
||||
GBytes *fw,
|
||||
FuAltosDeviceWriteFirmwareFlag flags,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error)
|
||||
{
|
||||
FuAltosDevicePrivate *priv = GET_PRIVATE (device);
|
||||
@ -556,11 +567,7 @@ fu_altos_device_write_firmware (FuAltosDevice *device,
|
||||
}
|
||||
|
||||
/* progress */
|
||||
if (progress_cb != NULL) {
|
||||
progress_cb ((goffset) i,
|
||||
(goffset) flash_len,
|
||||
progress_data);
|
||||
}
|
||||
fu_altos_device_set_progress (device, i, flash_len);
|
||||
g_string_append_len (buf, str->str, str->len);
|
||||
}
|
||||
|
||||
@ -571,21 +578,14 @@ fu_altos_device_write_firmware (FuAltosDevice *device,
|
||||
}
|
||||
|
||||
/* progress complete */
|
||||
if (progress_cb != NULL) {
|
||||
progress_cb ((goffset) flash_len,
|
||||
(goffset) flash_len,
|
||||
progress_data);
|
||||
}
|
||||
fu_altos_device_set_progress (device, flash_len, flash_len);
|
||||
|
||||
/* success */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GBytes *
|
||||
fu_altos_device_read_firmware (FuAltosDevice *device,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error)
|
||||
fu_altos_device_read_firmware (FuAltosDevice *device, GError **error)
|
||||
{
|
||||
FuAltosDevicePrivate *priv = GET_PRIVATE (device);
|
||||
guint flash_len;
|
||||
@ -636,11 +636,9 @@ fu_altos_device_read_firmware (FuAltosDevice *device,
|
||||
return NULL;
|
||||
|
||||
/* progress */
|
||||
if (progress_cb != NULL) {
|
||||
progress_cb ((goffset) (i - priv->addr_base),
|
||||
(goffset) (priv->addr_bound - priv->addr_base),
|
||||
progress_data);
|
||||
}
|
||||
fu_altos_device_set_progress (device,
|
||||
i - priv->addr_base,
|
||||
priv->addr_bound - priv->addr_base);
|
||||
g_string_append_len (buf, str->str, str->len);
|
||||
}
|
||||
|
||||
|
@ -61,12 +61,8 @@ gboolean fu_altos_device_probe (FuAltosDevice *device,
|
||||
gboolean fu_altos_device_write_firmware (FuAltosDevice *device,
|
||||
GBytes *fw,
|
||||
FuAltosDeviceWriteFirmwareFlag flags,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error);
|
||||
GBytes *fu_altos_device_read_firmware (FuAltosDevice *device,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -24,13 +24,9 @@
|
||||
#include "fu-altos-device.h"
|
||||
|
||||
static void
|
||||
fu_altos_tool_write_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
fu_altos_tool_progress_cb (FuDevice *device, GParamSpec *pspec, gpointer user_data)
|
||||
{
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
percentage = (100.f * (gdouble) current) / (gdouble) total;
|
||||
g_print ("Written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT " bytes [%.1f%%]\n",
|
||||
current, total, percentage);
|
||||
g_print ("Written %u%%\n", fu_device_get_progress (device));
|
||||
}
|
||||
|
||||
int
|
||||
@ -94,9 +90,10 @@ main (int argc, char **argv)
|
||||
|
||||
/* update with data blob */
|
||||
fw = g_bytes_new (data, len);
|
||||
g_signal_connect (dev, "notify::progress",
|
||||
G_CALLBACK (fu_altos_tool_progress_cb), NULL);
|
||||
if (!fu_altos_device_write_firmware (dev, fw,
|
||||
FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_NONE,
|
||||
fu_altos_tool_write_progress_cb, NULL,
|
||||
&error)) {
|
||||
g_print ("Failed to write firmware: %s\n", error->message);
|
||||
return 1;
|
||||
|
@ -64,18 +64,6 @@ fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **e
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
fu_plugin_altos_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
{
|
||||
FuPlugin *plugin = FU_PLUGIN (user_data);
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
percentage = (100.f * (gdouble) current) / (gdouble) total;
|
||||
g_debug ("written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT " bytes [%.1f%%]",
|
||||
current, total, percentage);
|
||||
fu_plugin_set_percentage (plugin, (guint) percentage);
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_verify (FuPlugin *plugin,
|
||||
FuDevice *dev,
|
||||
@ -89,10 +77,8 @@ fu_plugin_verify (FuPlugin *plugin,
|
||||
0 };
|
||||
|
||||
/* get data */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_VERIFY);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_VERIFY);
|
||||
blob_fw = fu_altos_device_read_firmware (FU_ALTOS_DEVICE (dev),
|
||||
fu_plugin_altos_progress_cb,
|
||||
plugin,
|
||||
error);
|
||||
if (blob_fw == NULL)
|
||||
return FALSE;
|
||||
@ -101,7 +87,6 @@ fu_plugin_verify (FuPlugin *plugin,
|
||||
hash = g_compute_checksum_for_bytes (checksum_types[i], blob_fw);
|
||||
fu_device_add_checksum (dev, hash);
|
||||
}
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_IDLE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -112,15 +97,12 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
FwupdInstallFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!fu_altos_device_write_firmware (FU_ALTOS_DEVICE (dev),
|
||||
blob_fw,
|
||||
FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT,
|
||||
fu_plugin_altos_progress_cb,
|
||||
plugin,
|
||||
error)) {
|
||||
return FALSE;
|
||||
}
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_IDLE);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -31,8 +31,6 @@ typedef struct
|
||||
{
|
||||
ChDeviceQueue *device_queue;
|
||||
gboolean is_bootloader;
|
||||
GFileProgressCallback progress_cb;
|
||||
gpointer progress_data;
|
||||
} FuColorhugDevicePrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (FuColorhugDevice, fu_colorhug_device, FU_TYPE_USB_DEVICE)
|
||||
@ -55,10 +53,7 @@ fu_colorhug_device_progress_cb (ChDeviceQueue *device_queue,
|
||||
guint percentage,
|
||||
FuColorhugDevice *device)
|
||||
{
|
||||
FuColorhugDevicePrivate *priv = GET_PRIVATE (device);
|
||||
/* not ideal, but do as best we can */
|
||||
if (priv->progress_cb != NULL)
|
||||
priv->progress_cb (percentage, 100, priv->progress_data);
|
||||
fu_device_set_progress (FU_DEVICE (device), percentage);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -75,11 +70,7 @@ fu_colorhug_device_detach (FuColorhugDevice *device, GError **error)
|
||||
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
|
||||
/* set up progress callback */
|
||||
priv->progress_cb = NULL;
|
||||
priv->progress_data = NULL;
|
||||
|
||||
g_debug ("rebooting...");
|
||||
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_RESTART);
|
||||
ch_device_queue_reset (priv->device_queue, usb_device);
|
||||
if (!ch_device_queue_process (priv->device_queue,
|
||||
CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE,
|
||||
@ -101,11 +92,7 @@ fu_colorhug_device_attach (FuColorhugDevice *device, GError **error)
|
||||
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
|
||||
/* set up progress callback */
|
||||
priv->progress_cb = NULL;
|
||||
priv->progress_data = NULL;
|
||||
|
||||
g_debug ("rebooting...");
|
||||
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_RESTART);
|
||||
ch_device_queue_boot_flash (priv->device_queue, usb_device);
|
||||
if (!ch_device_queue_process (priv->device_queue,
|
||||
CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE,
|
||||
@ -127,10 +114,6 @@ fu_colorhug_device_set_flash_success (FuColorhugDevice *device, GError **error)
|
||||
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
|
||||
/* set up progress callback */
|
||||
priv->progress_cb = NULL;
|
||||
priv->progress_data = NULL;
|
||||
|
||||
g_debug ("setting flash success");
|
||||
ch_device_queue_set_flash_success (priv->device_queue,
|
||||
usb_device,
|
||||
@ -224,10 +207,6 @@ fu_colorhug_device_open (FuUsbDevice *device, GError **error)
|
||||
FuColorhugDevicePrivate *priv = GET_PRIVATE (self);
|
||||
GUsbDevice *usb_device = fu_usb_device_get_dev (device);
|
||||
|
||||
/* set up progress callback */
|
||||
priv->progress_cb = NULL;
|
||||
priv->progress_data = NULL;
|
||||
|
||||
/* got the version using the HID API */
|
||||
if (!g_usb_device_set_configuration (usb_device, CH_USB_CONFIG, error))
|
||||
return FALSE;
|
||||
@ -260,10 +239,7 @@ fu_colorhug_device_open (FuUsbDevice *device, GError **error)
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_colorhug_device_verify_firmware (FuColorhugDevice *device,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error)
|
||||
fu_colorhug_device_verify_firmware (FuColorhugDevice *device, GError **error)
|
||||
{
|
||||
FuColorhugDevicePrivate *priv = GET_PRIVATE (device);
|
||||
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
|
||||
@ -275,12 +251,8 @@ fu_colorhug_device_verify_firmware (FuColorhugDevice *device,
|
||||
G_CHECKSUM_SHA256,
|
||||
0 };
|
||||
|
||||
/* set up progress callback */
|
||||
priv->progress_cb = progress_cb;
|
||||
priv->progress_data = progress_data;
|
||||
|
||||
/* get the firmware from the device */
|
||||
g_debug ("verifying firmware");
|
||||
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_VERIFY);
|
||||
ch_device_queue_read_firmware (priv->device_queue, usb_device,
|
||||
&data2, &len);
|
||||
if (!ch_device_queue_process (priv->device_queue,
|
||||
@ -306,20 +278,14 @@ fu_colorhug_device_verify_firmware (FuColorhugDevice *device,
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error)
|
||||
fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw, GError **error)
|
||||
{
|
||||
FuColorhugDevicePrivate *priv = GET_PRIVATE (device);
|
||||
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
|
||||
/* set up progress callback */
|
||||
priv->progress_cb = progress_cb;
|
||||
priv->progress_data = progress_data;
|
||||
|
||||
g_debug ("writing firmware");
|
||||
/* write firmware */
|
||||
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_WRITE);
|
||||
ch_device_queue_set_flash_success (priv->device_queue,
|
||||
usb_device,
|
||||
0x00);
|
||||
@ -338,7 +304,7 @@ fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw,
|
||||
}
|
||||
|
||||
/* verify firmware */
|
||||
g_debug ("verifying firmware");
|
||||
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_VERIFY);
|
||||
ch_device_queue_verify_firmware (priv->device_queue, usb_device,
|
||||
g_bytes_get_data (fw, NULL),
|
||||
g_bytes_get_size (fw));
|
||||
|
@ -49,12 +49,8 @@ gboolean fu_colorhug_device_set_flash_success (FuColorhugDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_colorhug_device_write_firmware (FuColorhugDevice *device,
|
||||
GBytes *fw,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error);
|
||||
gboolean fu_colorhug_device_verify_firmware (FuColorhugDevice *device,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -49,7 +49,6 @@ fu_plugin_update_detach (FuPlugin *plugin, FuDevice *device, GError **error)
|
||||
}
|
||||
|
||||
/* reset */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
|
||||
if (!fu_colorhug_device_detach (colorhug_dev, error))
|
||||
return FALSE;
|
||||
|
||||
@ -90,7 +89,6 @@ fu_plugin_update_attach (FuPlugin *plugin, FuDevice *device, GError **error)
|
||||
}
|
||||
|
||||
/* reset */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
|
||||
if (!fu_colorhug_device_attach (colorhug_dev, error))
|
||||
return FALSE;
|
||||
|
||||
@ -126,13 +124,6 @@ fu_plugin_update_reload (FuPlugin *plugin, FuDevice *device, GError **error)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
fu_plugin_colorhug_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
{
|
||||
FuPlugin *plugin = FU_PLUGIN (user_data);
|
||||
fu_plugin_set_percentage (plugin, (guint) current);
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_update (FuPlugin *plugin,
|
||||
FuDevice *device,
|
||||
@ -162,11 +153,7 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
locker = fu_device_locker_new (device, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
|
||||
return fu_colorhug_device_write_firmware (colorhug_dev, blob_fw,
|
||||
fu_plugin_colorhug_progress_cb,
|
||||
plugin,
|
||||
error);
|
||||
return fu_colorhug_device_write_firmware (colorhug_dev, blob_fw, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -182,11 +169,7 @@ fu_plugin_verify (FuPlugin *plugin,
|
||||
locker = fu_device_locker_new (device, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_VERIFY);
|
||||
return fu_colorhug_device_verify_firmware (colorhug_dev,
|
||||
fu_plugin_colorhug_progress_cb,
|
||||
plugin,
|
||||
error);
|
||||
return fu_colorhug_device_verify_firmware (colorhug_dev, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -900,7 +900,7 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
* This won't actually cause any bad behavior because the real
|
||||
* payload GUID is extracted later on.
|
||||
*/
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_SCHEDULING);
|
||||
fu_device_set_status (device, FWUPD_STATUS_SCHEDULING);
|
||||
rc = fwup_set_up_update_with_buf (re, 0,
|
||||
g_bytes_get_data (blob_fw, NULL),
|
||||
g_bytes_get_size (blob_fw));
|
||||
|
@ -435,11 +435,21 @@ fu_ebitdo_device_get_serial (FuEbitdoDevice *device)
|
||||
return priv->serial;
|
||||
}
|
||||
|
||||
static void
|
||||
fu_ebitdo_device_set_progress (FuEbitdoDevice *device, guint32 current, guint32 total)
|
||||
{
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
percentage = (100.f * (gdouble) current) / (gdouble) total;
|
||||
if (g_getenv ("FWUPD_EBITDO_VERBOSE") != NULL) {
|
||||
g_debug ("written %" G_GUINT32_FORMAT "/%" G_GUINT32_FORMAT " bytes [%.1f%%]",
|
||||
current, total, percentage);
|
||||
}
|
||||
fu_device_set_progress (FU_DEVICE (device), (guint) percentage);
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error)
|
||||
fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **error)
|
||||
{
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoFirmwareHeader *hdr;
|
||||
@ -523,8 +533,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw,
|
||||
g_debug ("writing %u bytes to 0x%04x of 0x%04x",
|
||||
chunk_sz, offset, payload_len);
|
||||
}
|
||||
if (progress_cb != NULL)
|
||||
progress_cb (offset, payload_len, progress_data);
|
||||
fu_ebitdo_device_set_progress (device, offset, payload_len);
|
||||
if (!fu_ebitdo_device_send (device,
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD,
|
||||
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
@ -549,8 +558,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw,
|
||||
}
|
||||
|
||||
/* mark as complete */
|
||||
if (progress_cb != NULL)
|
||||
progress_cb (payload_len, payload_len, progress_data);
|
||||
fu_ebitdo_device_set_progress (device, payload_len, payload_len);
|
||||
|
||||
/* set the "encode id" which is likely a checksum, bluetooth pairing
|
||||
* or maybe just security-through-obscurity -- also note:
|
||||
|
@ -64,8 +64,6 @@ const guint32 *fu_ebitdo_device_get_serial (FuEbitdoDevice *device);
|
||||
/* object methods */
|
||||
gboolean fu_ebitdo_device_write_firmware (FuEbitdoDevice *device,
|
||||
GBytes *fw,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -26,14 +26,11 @@
|
||||
#include "fu-ebitdo-common.h"
|
||||
#include "fu-ebitdo-device.h"
|
||||
|
||||
|
||||
static void
|
||||
fu_ebitdo_write_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
fu_ebitdo_tool_progress_cb (FuDevice *device, GParamSpec *pspec, gpointer user_data)
|
||||
{
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
percentage = (100.f * (gdouble) current) / (gdouble) total;
|
||||
g_print ("Written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT " bytes [%.1f%%]\n",
|
||||
current, total, percentage);
|
||||
g_print ("Written %u%%\n", fu_device_get_progress (device));
|
||||
}
|
||||
|
||||
int
|
||||
@ -127,9 +124,9 @@ main (int argc, char **argv)
|
||||
|
||||
/* update with data blob */
|
||||
fw = g_bytes_new (data, len);
|
||||
if (!fu_ebitdo_device_write_firmware (dev, fw,
|
||||
fu_ebitdo_write_progress_cb, NULL,
|
||||
&error)) {
|
||||
g_signal_connect (dev, "notify::progress",
|
||||
G_CALLBACK (fu_ebitdo_tool_progress_cb), NULL);
|
||||
if (!fu_ebitdo_device_write_firmware (dev, fw, &error)) {
|
||||
g_print ("Failed to write firmware: %s\n", error->message);
|
||||
return 1;
|
||||
}
|
||||
|
@ -43,18 +43,6 @@ fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **e
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
ebitdo_write_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
{
|
||||
FuPlugin *plugin = FU_PLUGIN (user_data);
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
percentage = (100.f * (gdouble) current) / (gdouble) total;
|
||||
g_debug ("written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT " bytes [%.1f%%]",
|
||||
current, total, percentage);
|
||||
fu_plugin_set_percentage (plugin, (guint) percentage);
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_update (FuPlugin *plugin,
|
||||
FuDevice *dev,
|
||||
@ -80,15 +68,13 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
locker = fu_device_locker_new (ebitdo_dev, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!fu_ebitdo_device_write_firmware (ebitdo_dev, blob_fw,
|
||||
ebitdo_write_progress_cb, plugin,
|
||||
error))
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!fu_ebitdo_device_write_firmware (ebitdo_dev, blob_fw, error))
|
||||
return FALSE;
|
||||
|
||||
/* when doing a soft-reboot the device does not re-enumerate properly
|
||||
* so manually reboot the GUsbDevice */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_RESTART);
|
||||
if (!g_usb_device_reset (usb_device, error)) {
|
||||
g_prefix_error (error, "failed to force-reset device: ");
|
||||
return FALSE;
|
||||
|
@ -152,12 +152,12 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
g_autofree gchar *fwfn = NULL;
|
||||
|
||||
/* decompress anything matching either glob */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
|
||||
fu_device_set_status (device, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!fu_common_extract_archive (blob_fw, data->fw_dir, error))
|
||||
return FALSE;
|
||||
|
||||
/* get the new VC build info */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_VERIFY);
|
||||
fu_device_set_status (device, FWUPD_STATUS_DEVICE_VERIFY);
|
||||
fwfn = g_build_filename (data->fw_dir,
|
||||
FU_PLUGIN_RPI_FIRMWARE_FILENAME,
|
||||
NULL);
|
||||
|
@ -31,9 +31,12 @@
|
||||
#include "fu-test.h"
|
||||
|
||||
static void
|
||||
_plugin_status_changed_cb (FuPlugin *plugin, FwupdStatus status, gpointer user_data)
|
||||
_plugin_status_changed_cb (FuDevice *device, GParamSpec *pspec, gpointer user_data)
|
||||
{
|
||||
guint *cnt = (guint *) user_data;
|
||||
g_debug ("device %s now %s",
|
||||
fu_device_get_id (device),
|
||||
fwupd_status_to_string (fu_device_get_status (device)));
|
||||
(*cnt)++;
|
||||
}
|
||||
|
||||
@ -74,9 +77,6 @@ fu_plugin_raspberrypi_func (void)
|
||||
g_signal_connect (plugin, "device-added",
|
||||
G_CALLBACK (_plugin_device_added_cb),
|
||||
&device);
|
||||
g_signal_connect (plugin, "status-changed",
|
||||
G_CALLBACK (_plugin_status_changed_cb),
|
||||
&cnt);
|
||||
ret = fu_plugin_runner_startup (plugin, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret);
|
||||
@ -105,6 +105,9 @@ fu_plugin_raspberrypi_func (void)
|
||||
g_assert_no_error (error);
|
||||
g_assert (mapped_file != NULL);
|
||||
blob_fw = g_mapped_file_get_bytes (mapped_file);
|
||||
g_signal_connect (device, "notify::status",
|
||||
G_CALLBACK (_plugin_status_changed_cb),
|
||||
&cnt);
|
||||
ret = fu_plugin_runner_update (plugin, device, NULL, blob_fw,
|
||||
FWUPD_INSTALL_FLAG_NONE, &error);
|
||||
g_assert_no_error (error);
|
||||
|
@ -285,13 +285,13 @@ fu_plugin_synapticsmst_enumerate (FuPlugin *plugin,
|
||||
static void
|
||||
fu_synapticsmst_write_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
{
|
||||
FuPlugin *plugin = FU_PLUGIN (user_data);
|
||||
FuDevice *device = FU_DEVICE (user_data);
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
percentage = (100.f * (gdouble) current) / (gdouble) total;
|
||||
g_debug ("written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT "[%.1f%%]",
|
||||
current, total, percentage);
|
||||
fu_plugin_set_percentage (plugin, (guint) percentage);
|
||||
fu_device_set_progress (device, (guint) percentage);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -322,7 +322,7 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
/* sleep to allow device wakeup to complete */
|
||||
g_debug ("waiting %d seconds for MST hub wakeup",
|
||||
SYNAPTICS_FLASH_MODE_DELAY);
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_BUSY);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_BUSY);
|
||||
g_usleep (SYNAPTICS_FLASH_MODE_DELAY * 1000000);
|
||||
|
||||
device = synapticsmst_device_new (kind, aux_node, layer, rad);
|
||||
@ -331,10 +331,10 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
data->system_type, error))
|
||||
return FALSE;
|
||||
if (synapticsmst_device_board_id_to_string (synapticsmst_device_get_board_id (device)) != NULL) {
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!synapticsmst_device_write_firmware (device, blob_fw,
|
||||
fu_synapticsmst_write_progress_cb,
|
||||
plugin,
|
||||
device,
|
||||
error)) {
|
||||
g_prefix_error (error, "failed to flash firmware: ");
|
||||
return FALSE;
|
||||
@ -348,7 +348,7 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
}
|
||||
|
||||
/* Re-run device enumeration to find the new device version */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_RESTART);
|
||||
if (!synapticsmst_device_enumerate_device (device, data->dock_type,
|
||||
data->system_type, error)) {
|
||||
return FALSE;
|
||||
|
@ -106,20 +106,20 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
FwupdInstallFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DECOMPRESSING);
|
||||
fu_device_set_status (device, FWUPD_STATUS_DECOMPRESSING);
|
||||
for (guint i = 1; i <= 100; i++) {
|
||||
g_usleep (1000);
|
||||
fu_plugin_set_percentage (plugin, i);
|
||||
fu_device_set_progress (device, i);
|
||||
}
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
|
||||
fu_device_set_status (device, FWUPD_STATUS_DEVICE_WRITE);
|
||||
for (guint i = 1; i <= 100; i++) {
|
||||
g_usleep (1000);
|
||||
fu_plugin_set_percentage (plugin, i);
|
||||
fu_device_set_progress (device, i);
|
||||
}
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_VERIFY);
|
||||
fu_device_set_status (device, FWUPD_STATUS_DEVICE_VERIFY);
|
||||
for (guint i = 1; i <= 100; i++) {
|
||||
g_usleep (1000);
|
||||
fu_plugin_set_percentage (plugin, i);
|
||||
fu_device_set_progress (device, i);
|
||||
}
|
||||
|
||||
/* upgrade, or downgrade */
|
||||
|
@ -241,7 +241,7 @@ fu_plugin_update_prepare (FuPlugin *plugin,
|
||||
|
||||
data->needs_forcepower = TRUE;
|
||||
/* wait for the device to come back onto the bus */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
|
||||
fu_device_set_status (device, FWUPD_STATUS_DEVICE_RESTART);
|
||||
g_usleep (TBT_NEW_DEVICE_TIMEOUT * G_USEC_PER_SEC);
|
||||
|
||||
return TRUE;
|
||||
|
@ -445,7 +445,7 @@ fu_plugin_thunderbolt_trigger_update (GUdevDevice *udevice,
|
||||
}
|
||||
|
||||
static void
|
||||
fu_plugin_thunderbolt_report_progress (FuPlugin *plugin,
|
||||
fu_plugin_thunderbolt_report_progress (FuDevice *device,
|
||||
gsize nwritten,
|
||||
gsize total)
|
||||
{
|
||||
@ -455,11 +455,11 @@ fu_plugin_thunderbolt_report_progress (FuPlugin *plugin,
|
||||
g_debug ("written %" G_GSIZE_FORMAT "/%" G_GSIZE_FORMAT " bytes [%.1f%%]",
|
||||
nwritten, total, percentage);
|
||||
|
||||
fu_plugin_set_percentage (plugin, (guint) percentage);
|
||||
fu_device_set_progress (device, (guint) percentage);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
fu_plugin_thunderbolt_write_firmware (FuPlugin *plugin,
|
||||
fu_plugin_thunderbolt_write_firmware (FuDevice *device,
|
||||
GUdevDevice *udevice,
|
||||
GBytes *blob_fw,
|
||||
GError **error)
|
||||
@ -484,7 +484,7 @@ fu_plugin_thunderbolt_write_firmware (FuPlugin *plugin,
|
||||
|
||||
nwritten = 0;
|
||||
fw_size = g_bytes_get_size (blob_fw);
|
||||
fu_plugin_thunderbolt_report_progress (plugin, nwritten, fw_size);
|
||||
fu_plugin_thunderbolt_report_progress (device, nwritten, fw_size);
|
||||
|
||||
do {
|
||||
g_autoptr(GBytes) fw_data = NULL;
|
||||
@ -501,7 +501,7 @@ fu_plugin_thunderbolt_write_firmware (FuPlugin *plugin,
|
||||
return FALSE;
|
||||
|
||||
nwritten += n;
|
||||
fu_plugin_thunderbolt_report_progress (plugin, nwritten, fw_size);
|
||||
fu_plugin_thunderbolt_report_progress (device, nwritten, fw_size);
|
||||
|
||||
} while (nwritten < fw_size);
|
||||
|
||||
@ -799,8 +799,8 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
g_warning ("%s", msg);
|
||||
}
|
||||
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!fu_plugin_thunderbolt_write_firmware (plugin, udevice, blob_fw, &error_local)) {
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!fu_plugin_thunderbolt_write_firmware (dev, udevice, blob_fw, &error_local)) {
|
||||
g_set_error (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_WRITE,
|
||||
@ -818,7 +818,7 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_RESTART);
|
||||
|
||||
/* the device will disappear and we need to wait until it reappears,
|
||||
* and then check if we find an error */
|
||||
|
@ -397,7 +397,7 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
|
||||
/* perform the update */
|
||||
g_debug ("Performing UEFI capsule update");
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_SCHEDULING);
|
||||
fu_device_set_status (device, FWUPD_STATUS_SCHEDULING);
|
||||
if (!fu_plugin_uefi_update_splash (&error_splash)) {
|
||||
g_warning ("failed to upload BGRT splash text: %s",
|
||||
error_splash->message);
|
||||
|
@ -108,13 +108,13 @@ fu_plugin_unifying_device_added (FuPlugin *plugin,
|
||||
static void
|
||||
lu_write_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
{
|
||||
FuPlugin *plugin = FU_PLUGIN (user_data);
|
||||
FuDevice *device = FU_DEVICE (user_data);
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
percentage = (100.f * (gdouble) current) / (gdouble) total;
|
||||
g_debug ("written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT " bytes [%.1f%%]",
|
||||
current, total, percentage);
|
||||
fu_plugin_set_percentage (plugin, (guint) percentage);
|
||||
fu_device_set_progress (device, (guint) percentage);
|
||||
}
|
||||
|
||||
static LuDevice *
|
||||
@ -179,7 +179,7 @@ fu_plugin_update_detach (FuPlugin *plugin, FuDevice *dev, GError **error)
|
||||
return TRUE;
|
||||
|
||||
/* wait for device to come back */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_RESTART);
|
||||
if (lu_device_has_flag (device, LU_DEVICE_FLAG_DETACH_WILL_REPLUG)) {
|
||||
g_debug ("doing detach in idle");
|
||||
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
|
||||
@ -217,7 +217,7 @@ fu_plugin_update_attach (FuPlugin *plugin, FuDevice *dev, GError **error)
|
||||
return TRUE;
|
||||
|
||||
/* wait for device to come back */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_RESTART);
|
||||
if (lu_device_has_flag (device, LU_DEVICE_FLAG_ATTACH_WILL_REPLUG)) {
|
||||
g_debug ("doing attach in idle");
|
||||
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
|
||||
@ -272,9 +272,9 @@ fu_plugin_update (FuPlugin *plugin,
|
||||
return FALSE;
|
||||
|
||||
/* write the firmware */
|
||||
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
|
||||
fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!lu_device_write_firmware (device, blob_fw,
|
||||
lu_write_progress_cb, plugin,
|
||||
lu_write_progress_cb, dev,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
|
140
src/fu-device.c
140
src/fu-device.c
@ -46,11 +46,57 @@ typedef struct {
|
||||
FuDevice *alternate;
|
||||
GHashTable *metadata;
|
||||
guint remove_delay; /* ms */
|
||||
FwupdStatus status;
|
||||
guint progress;
|
||||
} FuDevicePrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_STATUS,
|
||||
PROP_PROGRESS,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (FuDevice, fu_device, FWUPD_TYPE_DEVICE)
|
||||
#define GET_PRIVATE(o) (fu_device_get_instance_private (o))
|
||||
|
||||
static void
|
||||
fu_device_get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
FuDevice *device = FU_DEVICE (object);
|
||||
FuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
switch (prop_id) {
|
||||
case PROP_STATUS:
|
||||
g_value_set_uint (value, priv->status);
|
||||
break;
|
||||
case PROP_PROGRESS:
|
||||
g_value_set_uint (value, priv->progress);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fu_device_set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
FuDevice *device = FU_DEVICE (object);
|
||||
switch (prop_id) {
|
||||
case PROP_STATUS:
|
||||
fu_device_set_status (device, g_value_get_uint (value));
|
||||
break;
|
||||
case PROP_PROGRESS:
|
||||
fu_device_set_progress (device, g_value_get_uint (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const gchar *
|
||||
fu_device_get_equivalent_id (FuDevice *device)
|
||||
{
|
||||
@ -483,6 +529,82 @@ fu_device_set_remove_delay (FuDevice *device, guint remove_delay)
|
||||
priv->remove_delay = remove_delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_get_status:
|
||||
* @device: A #FuDevice
|
||||
*
|
||||
* Returns what the device is currently doing.
|
||||
*
|
||||
* Returns: the status value, e.g. %FWUPD_STATUS_DEVICE_WRITE
|
||||
*
|
||||
* Since: 1.0.3
|
||||
**/
|
||||
FwupdStatus
|
||||
fu_device_get_status (FuDevice *device)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
g_return_val_if_fail (FU_IS_DEVICE (device), 0);
|
||||
return priv->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_set_status:
|
||||
* @device: A #FuDevice
|
||||
* @status: the status value, e.g. %FWUPD_STATUS_DEVICE_WRITE
|
||||
*
|
||||
* Sets what the device is currently doing.
|
||||
*
|
||||
* Since: 1.0.3
|
||||
**/
|
||||
void
|
||||
fu_device_set_status (FuDevice *device, FwupdStatus status)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
g_return_if_fail (FU_IS_DEVICE (device));
|
||||
if (priv->status == status)
|
||||
return;
|
||||
priv->status = status;
|
||||
g_object_notify (G_OBJECT (device), "status");
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_get_progress:
|
||||
* @device: A #FuDevice
|
||||
*
|
||||
* Returns the progress completion.
|
||||
*
|
||||
* Returns: value in percent
|
||||
*
|
||||
* Since: 1.0.3
|
||||
**/
|
||||
guint
|
||||
fu_device_get_progress (FuDevice *device)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
g_return_val_if_fail (FU_IS_DEVICE (device), 0);
|
||||
return priv->progress;
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_set_progress:
|
||||
* @device: A #FuDevice
|
||||
* @progress: the progress percentage value
|
||||
*
|
||||
* Sets the progress completion.
|
||||
*
|
||||
* Since: 1.0.3
|
||||
**/
|
||||
void
|
||||
fu_device_set_progress (FuDevice *device, guint progress)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
g_return_if_fail (FU_IS_DEVICE (device));
|
||||
if (priv->progress == progress)
|
||||
return;
|
||||
priv->progress = progress;
|
||||
g_object_notify (G_OBJECT (device), "progress");
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_device_to_string:
|
||||
* @device: A #FuDevice
|
||||
@ -526,13 +648,31 @@ static void
|
||||
fu_device_class_init (FuDeviceClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
object_class->finalize = fu_device_finalize;
|
||||
object_class->get_property = fu_device_get_property;
|
||||
object_class->set_property = fu_device_set_property;
|
||||
|
||||
pspec = g_param_spec_uint ("status", NULL, NULL,
|
||||
FWUPD_STATUS_UNKNOWN,
|
||||
FWUPD_STATUS_LAST,
|
||||
FWUPD_STATUS_UNKNOWN,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_NAME);
|
||||
g_object_class_install_property (object_class, PROP_STATUS, pspec);
|
||||
|
||||
pspec = g_param_spec_uint ("progress", NULL, NULL,
|
||||
0, 100, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_NAME);
|
||||
g_object_class_install_property (object_class, PROP_PROGRESS, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
fu_device_init (FuDevice *device)
|
||||
{
|
||||
FuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
priv->status = FWUPD_STATUS_IDLE;
|
||||
priv->metadata = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, g_free);
|
||||
}
|
||||
|
@ -130,6 +130,12 @@ void fu_device_set_name (FuDevice *device,
|
||||
guint fu_device_get_remove_delay (FuDevice *device);
|
||||
void fu_device_set_remove_delay (FuDevice *device,
|
||||
guint remove_delay);
|
||||
FwupdStatus fu_device_get_status (FuDevice *device);
|
||||
void fu_device_set_status (FuDevice *device,
|
||||
FwupdStatus status);
|
||||
guint fu_device_get_progress (FuDevice *device);
|
||||
void fu_device_set_progress (FuDevice *device,
|
||||
guint progress);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -110,24 +110,6 @@ fu_engine_emit_device_changed (FuEngine *self, FuDevice *device)
|
||||
g_signal_emit (self, signals[SIGNAL_DEVICE_CHANGED], 0, device);
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_device_added_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self)
|
||||
{
|
||||
g_signal_emit (self, signals[SIGNAL_DEVICE_ADDED], 0, device);
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_device_removed_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self)
|
||||
{
|
||||
g_signal_emit (self, signals[SIGNAL_DEVICE_REMOVED], 0, device);
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_device_changed_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self)
|
||||
{
|
||||
fu_engine_emit_device_changed (self, device);
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_engine_get_status:
|
||||
* @self: A #FuEngine
|
||||
@ -181,6 +163,41 @@ fu_engine_set_percentage (FuEngine *self, guint percentage)
|
||||
g_signal_emit (self, signals[SIGNAL_PERCENTAGE_CHANGED], 0, percentage);
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_progress_notify_cb (FuDevice *device, GParamSpec *pspec, FuEngine *self)
|
||||
{
|
||||
fu_engine_set_percentage (self, fu_device_get_progress (device));
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_status_notify_cb (FuDevice *device, GParamSpec *pspec, FuEngine *self)
|
||||
{
|
||||
fu_engine_set_status (self, fu_device_get_status (device));
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_device_added_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self)
|
||||
{
|
||||
g_signal_connect (device, "notify::progress",
|
||||
G_CALLBACK (fu_engine_progress_notify_cb), self);
|
||||
g_signal_connect (device, "notify::status",
|
||||
G_CALLBACK (fu_engine_status_notify_cb), self);
|
||||
g_signal_emit (self, signals[SIGNAL_DEVICE_ADDED], 0, device);
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_device_removed_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_data (device, self);
|
||||
g_signal_emit (self, signals[SIGNAL_DEVICE_REMOVED], 0, device);
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_device_changed_cb (FuDeviceList *device_list, FuDevice *device, FuEngine *self)
|
||||
{
|
||||
fu_engine_emit_device_changed (self, device);
|
||||
}
|
||||
|
||||
static void
|
||||
fu_engine_set_release_from_appstream (FuEngine *self,
|
||||
FwupdRelease *rel,
|
||||
@ -1333,6 +1350,7 @@ fu_engine_install (FuEngine *self,
|
||||
error_local->message);
|
||||
}
|
||||
}
|
||||
fu_device_set_status (device, FWUPD_STATUS_IDLE);
|
||||
return FALSE;
|
||||
}
|
||||
device = fu_device_list_find_by_id (self->device_list, device_id_orig, error);
|
||||
@ -1359,7 +1377,7 @@ fu_engine_install (FuEngine *self,
|
||||
}
|
||||
|
||||
/* make the UI update */
|
||||
fu_engine_set_status (self, FWUPD_STATUS_IDLE);
|
||||
fu_device_set_status (device, FWUPD_STATUS_IDLE);
|
||||
fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC);
|
||||
fu_engine_emit_device_changed (self, device);
|
||||
fu_engine_emit_changed (self);
|
||||
|
@ -663,9 +663,12 @@ fu_hwids_func (void)
|
||||
}
|
||||
|
||||
static void
|
||||
_plugin_status_changed_cb (FuPlugin *plugin, FwupdStatus status, gpointer user_data)
|
||||
_plugin_status_changed_cb (FuDevice *device, GParamSpec *pspec, gpointer user_data)
|
||||
{
|
||||
guint *cnt = (guint *) user_data;
|
||||
g_debug ("device %s now %s",
|
||||
fu_device_get_id (device),
|
||||
fwupd_status_to_string (fu_device_get_status (device)));
|
||||
(*cnt)++;
|
||||
fu_test_loop_quit ();
|
||||
}
|
||||
@ -803,15 +806,11 @@ fu_plugin_module_func (void)
|
||||
g_signal_connect (plugin, "device-register",
|
||||
G_CALLBACK (_plugin_device_register_cb),
|
||||
&device);
|
||||
g_signal_connect (plugin, "status-changed",
|
||||
G_CALLBACK (_plugin_status_changed_cb),
|
||||
&cnt);
|
||||
ret = fu_plugin_runner_coldplug (plugin, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret);
|
||||
|
||||
/* check we did the right thing */
|
||||
g_assert_cmpint (cnt, ==, 0);
|
||||
g_assert (device != NULL);
|
||||
g_assert_cmpstr (fu_device_get_id (device), ==, "08d460be0f1f9f128413f816022a6439e0078018");
|
||||
g_assert_cmpstr (fu_device_get_version_lowest (device), ==, "1.2.0");
|
||||
@ -823,6 +822,9 @@ fu_plugin_module_func (void)
|
||||
"Integrated Webcam™");
|
||||
|
||||
/* schedule an offline update */
|
||||
g_signal_connect (device, "notify::status",
|
||||
G_CALLBACK (_plugin_status_changed_cb),
|
||||
&cnt);
|
||||
mapped_file_fn = fu_test_get_filename (TESTDATADIR, "colorhug/firmware.bin");
|
||||
mapped_file = g_mapped_file_new (mapped_file_fn, FALSE, &error);
|
||||
g_assert_no_error (error);
|
||||
@ -832,7 +834,7 @@ fu_plugin_module_func (void)
|
||||
FWUPD_INSTALL_FLAG_OFFLINE, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret);
|
||||
g_assert_cmpint (cnt, ==, 1);
|
||||
g_assert_cmpint (cnt, ==, 0);
|
||||
|
||||
/* lets check the pending */
|
||||
pending = fu_pending_new ();
|
||||
@ -851,7 +853,7 @@ fu_plugin_module_func (void)
|
||||
FWUPD_INSTALL_FLAG_NONE, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret);
|
||||
g_assert_cmpint (cnt, ==, 4);
|
||||
g_assert_cmpint (cnt, ==, 3);
|
||||
|
||||
/* check the new version */
|
||||
g_assert_cmpstr (fu_device_get_version (device), ==, "1.2.4");
|
||||
|
Loading…
Reference in New Issue
Block a user