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:
Richard Hughes 2017-11-30 16:33:24 +00:00
parent e3bc2bcf88
commit 4a036018f7
24 changed files with 291 additions and 215 deletions

View File

@ -429,12 +429,23 @@ fu_altos_device_write_page (FuAltosDevice *device,
return TRUE; 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 gboolean
fu_altos_device_write_firmware (FuAltosDevice *device, fu_altos_device_write_firmware (FuAltosDevice *device,
GBytes *fw, GBytes *fw,
FuAltosDeviceWriteFirmwareFlag flags, FuAltosDeviceWriteFirmwareFlag flags,
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error) GError **error)
{ {
FuAltosDevicePrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
@ -556,11 +567,7 @@ fu_altos_device_write_firmware (FuAltosDevice *device,
} }
/* progress */ /* progress */
if (progress_cb != NULL) { fu_altos_device_set_progress (device, i, flash_len);
progress_cb ((goffset) i,
(goffset) flash_len,
progress_data);
}
g_string_append_len (buf, str->str, str->len); g_string_append_len (buf, str->str, str->len);
} }
@ -571,21 +578,14 @@ fu_altos_device_write_firmware (FuAltosDevice *device,
} }
/* progress complete */ /* progress complete */
if (progress_cb != NULL) { fu_altos_device_set_progress (device, flash_len, flash_len);
progress_cb ((goffset) flash_len,
(goffset) flash_len,
progress_data);
}
/* success */ /* success */
return TRUE; return TRUE;
} }
GBytes * GBytes *
fu_altos_device_read_firmware (FuAltosDevice *device, fu_altos_device_read_firmware (FuAltosDevice *device, GError **error)
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error)
{ {
FuAltosDevicePrivate *priv = GET_PRIVATE (device); FuAltosDevicePrivate *priv = GET_PRIVATE (device);
guint flash_len; guint flash_len;
@ -636,11 +636,9 @@ fu_altos_device_read_firmware (FuAltosDevice *device,
return NULL; return NULL;
/* progress */ /* progress */
if (progress_cb != NULL) { fu_altos_device_set_progress (device,
progress_cb ((goffset) (i - priv->addr_base), i - priv->addr_base,
(goffset) (priv->addr_bound - priv->addr_base), priv->addr_bound - priv->addr_base);
progress_data);
}
g_string_append_len (buf, str->str, str->len); g_string_append_len (buf, str->str, str->len);
} }

View File

@ -61,12 +61,8 @@ gboolean fu_altos_device_probe (FuAltosDevice *device,
gboolean fu_altos_device_write_firmware (FuAltosDevice *device, gboolean fu_altos_device_write_firmware (FuAltosDevice *device,
GBytes *fw, GBytes *fw,
FuAltosDeviceWriteFirmwareFlag flags, FuAltosDeviceWriteFirmwareFlag flags,
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error); GError **error);
GBytes *fu_altos_device_read_firmware (FuAltosDevice *device, GBytes *fu_altos_device_read_firmware (FuAltosDevice *device,
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error); GError **error);
G_END_DECLS G_END_DECLS

View File

@ -24,13 +24,9 @@
#include "fu-altos-device.h" #include "fu-altos-device.h"
static void 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; g_print ("Written %u%%\n", fu_device_get_progress (device));
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);
} }
int int
@ -94,9 +90,10 @@ main (int argc, char **argv)
/* update with data blob */ /* update with data blob */
fw = g_bytes_new (data, len); 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, if (!fu_altos_device_write_firmware (dev, fw,
FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_NONE, FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_NONE,
fu_altos_tool_write_progress_cb, NULL,
&error)) { &error)) {
g_print ("Failed to write firmware: %s\n", error->message); g_print ("Failed to write firmware: %s\n", error->message);
return 1; return 1;

View File

@ -64,18 +64,6 @@ fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **e
return TRUE; 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 gboolean
fu_plugin_verify (FuPlugin *plugin, fu_plugin_verify (FuPlugin *plugin,
FuDevice *dev, FuDevice *dev,
@ -89,10 +77,8 @@ fu_plugin_verify (FuPlugin *plugin,
0 }; 0 };
/* get data */ /* 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), blob_fw = fu_altos_device_read_firmware (FU_ALTOS_DEVICE (dev),
fu_plugin_altos_progress_cb,
plugin,
error); error);
if (blob_fw == NULL) if (blob_fw == NULL)
return FALSE; return FALSE;
@ -101,7 +87,6 @@ fu_plugin_verify (FuPlugin *plugin,
hash = g_compute_checksum_for_bytes (checksum_types[i], blob_fw); hash = g_compute_checksum_for_bytes (checksum_types[i], blob_fw);
fu_device_add_checksum (dev, hash); fu_device_add_checksum (dev, hash);
} }
fu_plugin_set_status (plugin, FWUPD_STATUS_IDLE);
return TRUE; return TRUE;
} }
@ -112,15 +97,12 @@ fu_plugin_update (FuPlugin *plugin,
FwupdInstallFlags flags, FwupdInstallFlags flags,
GError **error) 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), if (!fu_altos_device_write_firmware (FU_ALTOS_DEVICE (dev),
blob_fw, blob_fw,
FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT, FU_ALTOS_DEVICE_WRITE_FIRMWARE_FLAG_REBOOT,
fu_plugin_altos_progress_cb,
plugin,
error)) { error)) {
return FALSE; return FALSE;
} }
fu_plugin_set_status (plugin, FWUPD_STATUS_IDLE);
return TRUE; return TRUE;
} }

View File

@ -31,8 +31,6 @@ typedef struct
{ {
ChDeviceQueue *device_queue; ChDeviceQueue *device_queue;
gboolean is_bootloader; gboolean is_bootloader;
GFileProgressCallback progress_cb;
gpointer progress_data;
} FuColorhugDevicePrivate; } FuColorhugDevicePrivate;
G_DEFINE_TYPE_WITH_PRIVATE (FuColorhugDevice, fu_colorhug_device, FU_TYPE_USB_DEVICE) 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, guint percentage,
FuColorhugDevice *device) FuColorhugDevice *device)
{ {
FuColorhugDevicePrivate *priv = GET_PRIVATE (device); fu_device_set_progress (FU_DEVICE (device), percentage);
/* not ideal, but do as best we can */
if (priv->progress_cb != NULL)
priv->progress_cb (percentage, 100, priv->progress_data);
} }
gboolean 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)); GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
/* set up progress callback */ fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_RESTART);
priv->progress_cb = NULL;
priv->progress_data = NULL;
g_debug ("rebooting...");
ch_device_queue_reset (priv->device_queue, usb_device); ch_device_queue_reset (priv->device_queue, usb_device);
if (!ch_device_queue_process (priv->device_queue, if (!ch_device_queue_process (priv->device_queue,
CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE, 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)); GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
/* set up progress callback */ fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_RESTART);
priv->progress_cb = NULL;
priv->progress_data = NULL;
g_debug ("rebooting...");
ch_device_queue_boot_flash (priv->device_queue, usb_device); ch_device_queue_boot_flash (priv->device_queue, usb_device);
if (!ch_device_queue_process (priv->device_queue, if (!ch_device_queue_process (priv->device_queue,
CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE, 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)); GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
/* set up progress callback */
priv->progress_cb = NULL;
priv->progress_data = NULL;
g_debug ("setting flash success"); g_debug ("setting flash success");
ch_device_queue_set_flash_success (priv->device_queue, ch_device_queue_set_flash_success (priv->device_queue,
usb_device, usb_device,
@ -224,10 +207,6 @@ fu_colorhug_device_open (FuUsbDevice *device, GError **error)
FuColorhugDevicePrivate *priv = GET_PRIVATE (self); FuColorhugDevicePrivate *priv = GET_PRIVATE (self);
GUsbDevice *usb_device = fu_usb_device_get_dev (device); 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 */ /* got the version using the HID API */
if (!g_usb_device_set_configuration (usb_device, CH_USB_CONFIG, error)) if (!g_usb_device_set_configuration (usb_device, CH_USB_CONFIG, error))
return FALSE; return FALSE;
@ -260,10 +239,7 @@ fu_colorhug_device_open (FuUsbDevice *device, GError **error)
} }
gboolean gboolean
fu_colorhug_device_verify_firmware (FuColorhugDevice *device, fu_colorhug_device_verify_firmware (FuColorhugDevice *device, GError **error)
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error)
{ {
FuColorhugDevicePrivate *priv = GET_PRIVATE (device); FuColorhugDevicePrivate *priv = GET_PRIVATE (device);
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (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, G_CHECKSUM_SHA256,
0 }; 0 };
/* set up progress callback */
priv->progress_cb = progress_cb;
priv->progress_data = progress_data;
/* get the firmware from the device */ /* 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, ch_device_queue_read_firmware (priv->device_queue, usb_device,
&data2, &len); &data2, &len);
if (!ch_device_queue_process (priv->device_queue, if (!ch_device_queue_process (priv->device_queue,
@ -306,20 +278,14 @@ fu_colorhug_device_verify_firmware (FuColorhugDevice *device,
} }
gboolean gboolean
fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw, fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw, GError **error)
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error)
{ {
FuColorhugDevicePrivate *priv = GET_PRIVATE (device); FuColorhugDevicePrivate *priv = GET_PRIVATE (device);
GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device)); GUsbDevice *usb_device = fu_usb_device_get_dev (FU_USB_DEVICE (device));
g_autoptr(GError) error_local = NULL; g_autoptr(GError) error_local = NULL;
/* set up progress callback */ /* write firmware */
priv->progress_cb = progress_cb; fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_WRITE);
priv->progress_data = progress_data;
g_debug ("writing firmware");
ch_device_queue_set_flash_success (priv->device_queue, ch_device_queue_set_flash_success (priv->device_queue,
usb_device, usb_device,
0x00); 0x00);
@ -338,7 +304,7 @@ fu_colorhug_device_write_firmware (FuColorhugDevice *device, GBytes *fw,
} }
/* verify firmware */ /* 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, ch_device_queue_verify_firmware (priv->device_queue, usb_device,
g_bytes_get_data (fw, NULL), g_bytes_get_data (fw, NULL),
g_bytes_get_size (fw)); g_bytes_get_size (fw));

View File

@ -49,12 +49,8 @@ gboolean fu_colorhug_device_set_flash_success (FuColorhugDevice *device,
GError **error); GError **error);
gboolean fu_colorhug_device_write_firmware (FuColorhugDevice *device, gboolean fu_colorhug_device_write_firmware (FuColorhugDevice *device,
GBytes *fw, GBytes *fw,
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error); GError **error);
gboolean fu_colorhug_device_verify_firmware (FuColorhugDevice *device, gboolean fu_colorhug_device_verify_firmware (FuColorhugDevice *device,
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error); GError **error);
G_END_DECLS G_END_DECLS

View File

@ -49,7 +49,6 @@ fu_plugin_update_detach (FuPlugin *plugin, FuDevice *device, GError **error)
} }
/* reset */ /* reset */
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
if (!fu_colorhug_device_detach (colorhug_dev, error)) if (!fu_colorhug_device_detach (colorhug_dev, error))
return FALSE; return FALSE;
@ -90,7 +89,6 @@ fu_plugin_update_attach (FuPlugin *plugin, FuDevice *device, GError **error)
} }
/* reset */ /* reset */
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_RESTART);
if (!fu_colorhug_device_attach (colorhug_dev, error)) if (!fu_colorhug_device_attach (colorhug_dev, error))
return FALSE; return FALSE;
@ -126,13 +124,6 @@ fu_plugin_update_reload (FuPlugin *plugin, FuDevice *device, GError **error)
return TRUE; 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 gboolean
fu_plugin_update (FuPlugin *plugin, fu_plugin_update (FuPlugin *plugin,
FuDevice *device, FuDevice *device,
@ -162,11 +153,7 @@ fu_plugin_update (FuPlugin *plugin,
locker = fu_device_locker_new (device, error); locker = fu_device_locker_new (device, error);
if (locker == NULL) if (locker == NULL)
return FALSE; return FALSE;
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE); return fu_colorhug_device_write_firmware (colorhug_dev, blob_fw, error);
return fu_colorhug_device_write_firmware (colorhug_dev, blob_fw,
fu_plugin_colorhug_progress_cb,
plugin,
error);
} }
gboolean gboolean
@ -182,11 +169,7 @@ fu_plugin_verify (FuPlugin *plugin,
locker = fu_device_locker_new (device, error); locker = fu_device_locker_new (device, error);
if (locker == NULL) if (locker == NULL)
return FALSE; return FALSE;
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_VERIFY); return fu_colorhug_device_verify_firmware (colorhug_dev, error);
return fu_colorhug_device_verify_firmware (colorhug_dev,
fu_plugin_colorhug_progress_cb,
plugin,
error);
} }
gboolean gboolean

View File

@ -900,7 +900,7 @@ fu_plugin_update (FuPlugin *plugin,
* This won't actually cause any bad behavior because the real * This won't actually cause any bad behavior because the real
* payload GUID is extracted later on. * 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, rc = fwup_set_up_update_with_buf (re, 0,
g_bytes_get_data (blob_fw, NULL), g_bytes_get_data (blob_fw, NULL),
g_bytes_get_size (blob_fw)); g_bytes_get_size (blob_fw));

View File

@ -435,11 +435,21 @@ fu_ebitdo_device_get_serial (FuEbitdoDevice *device)
return priv->serial; 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 gboolean
fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw, GError **error)
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error)
{ {
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device); FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
FuEbitdoFirmwareHeader *hdr; 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", g_debug ("writing %u bytes to 0x%04x of 0x%04x",
chunk_sz, offset, payload_len); chunk_sz, offset, payload_len);
} }
if (progress_cb != NULL) fu_ebitdo_device_set_progress (device, offset, payload_len);
progress_cb (offset, payload_len, progress_data);
if (!fu_ebitdo_device_send (device, if (!fu_ebitdo_device_send (device,
FU_EBITDO_PKT_TYPE_USER_CMD, FU_EBITDO_PKT_TYPE_USER_CMD,
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA, FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
@ -549,8 +558,7 @@ fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw,
} }
/* mark as complete */ /* mark as complete */
if (progress_cb != NULL) fu_ebitdo_device_set_progress (device, payload_len, payload_len);
progress_cb (payload_len, payload_len, progress_data);
/* set the "encode id" which is likely a checksum, bluetooth pairing /* set the "encode id" which is likely a checksum, bluetooth pairing
* or maybe just security-through-obscurity -- also note: * or maybe just security-through-obscurity -- also note:

View File

@ -64,8 +64,6 @@ const guint32 *fu_ebitdo_device_get_serial (FuEbitdoDevice *device);
/* object methods */ /* object methods */
gboolean fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, gboolean fu_ebitdo_device_write_firmware (FuEbitdoDevice *device,
GBytes *fw, GBytes *fw,
GFileProgressCallback progress_cb,
gpointer progress_data,
GError **error); GError **error);
G_END_DECLS G_END_DECLS

View File

@ -26,14 +26,11 @@
#include "fu-ebitdo-common.h" #include "fu-ebitdo-common.h"
#include "fu-ebitdo-device.h" #include "fu-ebitdo-device.h"
static void 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; g_print ("Written %u%%\n", fu_device_get_progress (device));
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);
} }
int int
@ -127,9 +124,9 @@ main (int argc, char **argv)
/* update with data blob */ /* update with data blob */
fw = g_bytes_new (data, len); fw = g_bytes_new (data, len);
if (!fu_ebitdo_device_write_firmware (dev, fw, g_signal_connect (dev, "notify::progress",
fu_ebitdo_write_progress_cb, NULL, G_CALLBACK (fu_ebitdo_tool_progress_cb), NULL);
&error)) { if (!fu_ebitdo_device_write_firmware (dev, fw, &error)) {
g_print ("Failed to write firmware: %s\n", error->message); g_print ("Failed to write firmware: %s\n", error->message);
return 1; return 1;
} }

View File

@ -43,18 +43,6 @@ fu_plugin_usb_device_added (FuPlugin *plugin, GUsbDevice *usb_device, GError **e
return TRUE; 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 gboolean
fu_plugin_update (FuPlugin *plugin, fu_plugin_update (FuPlugin *plugin,
FuDevice *dev, FuDevice *dev,
@ -80,15 +68,13 @@ fu_plugin_update (FuPlugin *plugin,
locker = fu_device_locker_new (ebitdo_dev, error); locker = fu_device_locker_new (ebitdo_dev, error);
if (locker == NULL) if (locker == NULL)
return FALSE; return FALSE;
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE); fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
if (!fu_ebitdo_device_write_firmware (ebitdo_dev, blob_fw, if (!fu_ebitdo_device_write_firmware (ebitdo_dev, blob_fw, error))
ebitdo_write_progress_cb, plugin,
error))
return FALSE; return FALSE;
/* when doing a soft-reboot the device does not re-enumerate properly /* when doing a soft-reboot the device does not re-enumerate properly
* so manually reboot the GUsbDevice */ * 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)) { if (!g_usb_device_reset (usb_device, error)) {
g_prefix_error (error, "failed to force-reset device: "); g_prefix_error (error, "failed to force-reset device: ");
return FALSE; return FALSE;

View File

@ -152,12 +152,12 @@ fu_plugin_update (FuPlugin *plugin,
g_autofree gchar *fwfn = NULL; g_autofree gchar *fwfn = NULL;
/* decompress anything matching either glob */ /* 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)) if (!fu_common_extract_archive (blob_fw, data->fw_dir, error))
return FALSE; return FALSE;
/* get the new VC build info */ /* 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, fwfn = g_build_filename (data->fw_dir,
FU_PLUGIN_RPI_FIRMWARE_FILENAME, FU_PLUGIN_RPI_FIRMWARE_FILENAME,
NULL); NULL);

View File

@ -31,9 +31,12 @@
#include "fu-test.h" #include "fu-test.h"
static 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; 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)++; (*cnt)++;
} }
@ -74,9 +77,6 @@ fu_plugin_raspberrypi_func (void)
g_signal_connect (plugin, "device-added", g_signal_connect (plugin, "device-added",
G_CALLBACK (_plugin_device_added_cb), G_CALLBACK (_plugin_device_added_cb),
&device); &device);
g_signal_connect (plugin, "status-changed",
G_CALLBACK (_plugin_status_changed_cb),
&cnt);
ret = fu_plugin_runner_startup (plugin, &error); ret = fu_plugin_runner_startup (plugin, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ret); g_assert (ret);
@ -105,6 +105,9 @@ fu_plugin_raspberrypi_func (void)
g_assert_no_error (error); g_assert_no_error (error);
g_assert (mapped_file != NULL); g_assert (mapped_file != NULL);
blob_fw = g_mapped_file_get_bytes (mapped_file); 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, ret = fu_plugin_runner_update (plugin, device, NULL, blob_fw,
FWUPD_INSTALL_FLAG_NONE, &error); FWUPD_INSTALL_FLAG_NONE, &error);
g_assert_no_error (error); g_assert_no_error (error);

View File

@ -285,13 +285,13 @@ fu_plugin_synapticsmst_enumerate (FuPlugin *plugin,
static void static void
fu_synapticsmst_write_progress_cb (goffset current, goffset total, gpointer user_data) 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; gdouble percentage = -1.f;
if (total > 0) if (total > 0)
percentage = (100.f * (gdouble) current) / (gdouble) total; percentage = (100.f * (gdouble) current) / (gdouble) total;
g_debug ("written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT "[%.1f%%]", g_debug ("written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT "[%.1f%%]",
current, total, percentage); current, total, percentage);
fu_plugin_set_percentage (plugin, (guint) percentage); fu_device_set_progress (device, (guint) percentage);
} }
gboolean gboolean
@ -322,7 +322,7 @@ fu_plugin_update (FuPlugin *plugin,
/* sleep to allow device wakeup to complete */ /* sleep to allow device wakeup to complete */
g_debug ("waiting %d seconds for MST hub wakeup", g_debug ("waiting %d seconds for MST hub wakeup",
SYNAPTICS_FLASH_MODE_DELAY); 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); g_usleep (SYNAPTICS_FLASH_MODE_DELAY * 1000000);
device = synapticsmst_device_new (kind, aux_node, layer, rad); device = synapticsmst_device_new (kind, aux_node, layer, rad);
@ -331,10 +331,10 @@ fu_plugin_update (FuPlugin *plugin,
data->system_type, error)) data->system_type, error))
return FALSE; return FALSE;
if (synapticsmst_device_board_id_to_string (synapticsmst_device_get_board_id (device)) != NULL) { 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, if (!synapticsmst_device_write_firmware (device, blob_fw,
fu_synapticsmst_write_progress_cb, fu_synapticsmst_write_progress_cb,
plugin, device,
error)) { error)) {
g_prefix_error (error, "failed to flash firmware: "); g_prefix_error (error, "failed to flash firmware: ");
return FALSE; return FALSE;
@ -348,7 +348,7 @@ fu_plugin_update (FuPlugin *plugin,
} }
/* Re-run device enumeration to find the new device version */ /* 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, if (!synapticsmst_device_enumerate_device (device, data->dock_type,
data->system_type, error)) { data->system_type, error)) {
return FALSE; return FALSE;

View File

@ -106,20 +106,20 @@ fu_plugin_update (FuPlugin *plugin,
FwupdInstallFlags flags, FwupdInstallFlags flags,
GError **error) 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++) { for (guint i = 1; i <= 100; i++) {
g_usleep (1000); 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++) { for (guint i = 1; i <= 100; i++) {
g_usleep (1000); 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++) { for (guint i = 1; i <= 100; i++) {
g_usleep (1000); g_usleep (1000);
fu_plugin_set_percentage (plugin, i); fu_device_set_progress (device, i);
} }
/* upgrade, or downgrade */ /* upgrade, or downgrade */

View File

@ -241,7 +241,7 @@ fu_plugin_update_prepare (FuPlugin *plugin,
data->needs_forcepower = TRUE; data->needs_forcepower = TRUE;
/* wait for the device to come back onto the bus */ /* 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); g_usleep (TBT_NEW_DEVICE_TIMEOUT * G_USEC_PER_SEC);
return TRUE; return TRUE;

View File

@ -445,7 +445,7 @@ fu_plugin_thunderbolt_trigger_update (GUdevDevice *udevice,
} }
static void static void
fu_plugin_thunderbolt_report_progress (FuPlugin *plugin, fu_plugin_thunderbolt_report_progress (FuDevice *device,
gsize nwritten, gsize nwritten,
gsize total) gsize total)
{ {
@ -455,11 +455,11 @@ fu_plugin_thunderbolt_report_progress (FuPlugin *plugin,
g_debug ("written %" G_GSIZE_FORMAT "/%" G_GSIZE_FORMAT " bytes [%.1f%%]", g_debug ("written %" G_GSIZE_FORMAT "/%" G_GSIZE_FORMAT " bytes [%.1f%%]",
nwritten, total, percentage); nwritten, total, percentage);
fu_plugin_set_percentage (plugin, (guint) percentage); fu_device_set_progress (device, (guint) percentage);
} }
static gboolean static gboolean
fu_plugin_thunderbolt_write_firmware (FuPlugin *plugin, fu_plugin_thunderbolt_write_firmware (FuDevice *device,
GUdevDevice *udevice, GUdevDevice *udevice,
GBytes *blob_fw, GBytes *blob_fw,
GError **error) GError **error)
@ -484,7 +484,7 @@ fu_plugin_thunderbolt_write_firmware (FuPlugin *plugin,
nwritten = 0; nwritten = 0;
fw_size = g_bytes_get_size (blob_fw); 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 { do {
g_autoptr(GBytes) fw_data = NULL; g_autoptr(GBytes) fw_data = NULL;
@ -501,7 +501,7 @@ fu_plugin_thunderbolt_write_firmware (FuPlugin *plugin,
return FALSE; return FALSE;
nwritten += n; nwritten += n;
fu_plugin_thunderbolt_report_progress (plugin, nwritten, fw_size); fu_plugin_thunderbolt_report_progress (device, nwritten, fw_size);
} while (nwritten < fw_size); } while (nwritten < fw_size);
@ -799,8 +799,8 @@ fu_plugin_update (FuPlugin *plugin,
g_warning ("%s", msg); g_warning ("%s", msg);
} }
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE); fu_device_set_status (dev, FWUPD_STATUS_DEVICE_WRITE);
if (!fu_plugin_thunderbolt_write_firmware (plugin, udevice, blob_fw, &error_local)) { if (!fu_plugin_thunderbolt_write_firmware (dev, udevice, blob_fw, &error_local)) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_WRITE, FWUPD_ERROR_WRITE,
@ -818,7 +818,7 @@ fu_plugin_update (FuPlugin *plugin,
return FALSE; 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, /* the device will disappear and we need to wait until it reappears,
* and then check if we find an error */ * and then check if we find an error */

View File

@ -397,7 +397,7 @@ fu_plugin_update (FuPlugin *plugin,
/* perform the update */ /* perform the update */
g_debug ("Performing UEFI capsule 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)) { if (!fu_plugin_uefi_update_splash (&error_splash)) {
g_warning ("failed to upload BGRT splash text: %s", g_warning ("failed to upload BGRT splash text: %s",
error_splash->message); error_splash->message);

View File

@ -108,13 +108,13 @@ fu_plugin_unifying_device_added (FuPlugin *plugin,
static void static void
lu_write_progress_cb (goffset current, goffset total, gpointer user_data) 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; gdouble percentage = -1.f;
if (total > 0) if (total > 0)
percentage = (100.f * (gdouble) current) / (gdouble) total; percentage = (100.f * (gdouble) current) / (gdouble) total;
g_debug ("written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT " bytes [%.1f%%]", g_debug ("written %" G_GOFFSET_FORMAT "/%" G_GOFFSET_FORMAT " bytes [%.1f%%]",
current, total, percentage); current, total, percentage);
fu_plugin_set_percentage (plugin, (guint) percentage); fu_device_set_progress (device, (guint) percentage);
} }
static LuDevice * static LuDevice *
@ -179,7 +179,7 @@ fu_plugin_update_detach (FuPlugin *plugin, FuDevice *dev, GError **error)
return TRUE; return TRUE;
/* wait for device to come back */ /* 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)) { if (lu_device_has_flag (device, LU_DEVICE_FLAG_DETACH_WILL_REPLUG)) {
g_debug ("doing detach in idle"); g_debug ("doing detach in idle");
g_idle_add_full (G_PRIORITY_DEFAULT_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; return TRUE;
/* wait for device to come back */ /* 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)) { if (lu_device_has_flag (device, LU_DEVICE_FLAG_ATTACH_WILL_REPLUG)) {
g_debug ("doing attach in idle"); g_debug ("doing attach in idle");
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
@ -272,9 +272,9 @@ fu_plugin_update (FuPlugin *plugin,
return FALSE; return FALSE;
/* write the firmware */ /* 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, if (!lu_device_write_firmware (device, blob_fw,
lu_write_progress_cb, plugin, lu_write_progress_cb, dev,
error)) error))
return FALSE; return FALSE;

View File

@ -46,11 +46,57 @@ typedef struct {
FuDevice *alternate; FuDevice *alternate;
GHashTable *metadata; GHashTable *metadata;
guint remove_delay; /* ms */ guint remove_delay; /* ms */
FwupdStatus status;
guint progress;
} FuDevicePrivate; } FuDevicePrivate;
enum {
PROP_0,
PROP_STATUS,
PROP_PROGRESS,
PROP_LAST
};
G_DEFINE_TYPE_WITH_PRIVATE (FuDevice, fu_device, FWUPD_TYPE_DEVICE) G_DEFINE_TYPE_WITH_PRIVATE (FuDevice, fu_device, FWUPD_TYPE_DEVICE)
#define GET_PRIVATE(o) (fu_device_get_instance_private (o)) #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 * const gchar *
fu_device_get_equivalent_id (FuDevice *device) 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; 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: * fu_device_to_string:
* @device: A #FuDevice * @device: A #FuDevice
@ -526,13 +648,31 @@ static void
fu_device_class_init (FuDeviceClass *klass) fu_device_class_init (FuDeviceClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
object_class->finalize = fu_device_finalize; 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 static void
fu_device_init (FuDevice *device) fu_device_init (FuDevice *device)
{ {
FuDevicePrivate *priv = GET_PRIVATE (device); FuDevicePrivate *priv = GET_PRIVATE (device);
priv->status = FWUPD_STATUS_IDLE;
priv->metadata = g_hash_table_new_full (g_str_hash, g_str_equal, priv->metadata = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free); g_free, g_free);
} }

View File

@ -130,6 +130,12 @@ void fu_device_set_name (FuDevice *device,
guint fu_device_get_remove_delay (FuDevice *device); guint fu_device_get_remove_delay (FuDevice *device);
void fu_device_set_remove_delay (FuDevice *device, void fu_device_set_remove_delay (FuDevice *device,
guint remove_delay); 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 G_END_DECLS

View File

@ -110,24 +110,6 @@ fu_engine_emit_device_changed (FuEngine *self, FuDevice *device)
g_signal_emit (self, signals[SIGNAL_DEVICE_CHANGED], 0, 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: * fu_engine_get_status:
* @self: A #FuEngine * @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); 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 static void
fu_engine_set_release_from_appstream (FuEngine *self, fu_engine_set_release_from_appstream (FuEngine *self,
FwupdRelease *rel, FwupdRelease *rel,
@ -1333,6 +1350,7 @@ fu_engine_install (FuEngine *self,
error_local->message); error_local->message);
} }
} }
fu_device_set_status (device, FWUPD_STATUS_IDLE);
return FALSE; return FALSE;
} }
device = fu_device_list_find_by_id (self->device_list, device_id_orig, error); 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 */ /* 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_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC);
fu_engine_emit_device_changed (self, device); fu_engine_emit_device_changed (self, device);
fu_engine_emit_changed (self); fu_engine_emit_changed (self);

View File

@ -663,9 +663,12 @@ fu_hwids_func (void)
} }
static 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; 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)++; (*cnt)++;
fu_test_loop_quit (); fu_test_loop_quit ();
} }
@ -803,15 +806,11 @@ fu_plugin_module_func (void)
g_signal_connect (plugin, "device-register", g_signal_connect (plugin, "device-register",
G_CALLBACK (_plugin_device_register_cb), G_CALLBACK (_plugin_device_register_cb),
&device); &device);
g_signal_connect (plugin, "status-changed",
G_CALLBACK (_plugin_status_changed_cb),
&cnt);
ret = fu_plugin_runner_coldplug (plugin, &error); ret = fu_plugin_runner_coldplug (plugin, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ret); g_assert (ret);
/* check we did the right thing */ /* check we did the right thing */
g_assert_cmpint (cnt, ==, 0);
g_assert (device != NULL); g_assert (device != NULL);
g_assert_cmpstr (fu_device_get_id (device), ==, "08d460be0f1f9f128413f816022a6439e0078018"); g_assert_cmpstr (fu_device_get_id (device), ==, "08d460be0f1f9f128413f816022a6439e0078018");
g_assert_cmpstr (fu_device_get_version_lowest (device), ==, "1.2.0"); g_assert_cmpstr (fu_device_get_version_lowest (device), ==, "1.2.0");
@ -823,6 +822,9 @@ fu_plugin_module_func (void)
"Integrated Webcam™"); "Integrated Webcam™");
/* schedule an offline update */ /* 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_fn = fu_test_get_filename (TESTDATADIR, "colorhug/firmware.bin");
mapped_file = g_mapped_file_new (mapped_file_fn, FALSE, &error); mapped_file = g_mapped_file_new (mapped_file_fn, FALSE, &error);
g_assert_no_error (error); g_assert_no_error (error);
@ -832,7 +834,7 @@ fu_plugin_module_func (void)
FWUPD_INSTALL_FLAG_OFFLINE, &error); FWUPD_INSTALL_FLAG_OFFLINE, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ret); g_assert (ret);
g_assert_cmpint (cnt, ==, 1); g_assert_cmpint (cnt, ==, 0);
/* lets check the pending */ /* lets check the pending */
pending = fu_pending_new (); pending = fu_pending_new ();
@ -851,7 +853,7 @@ fu_plugin_module_func (void)
FWUPD_INSTALL_FLAG_NONE, &error); FWUPD_INSTALL_FLAG_NONE, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ret); g_assert (ret);
g_assert_cmpint (cnt, ==, 4); g_assert_cmpint (cnt, ==, 3);
/* check the new version */ /* check the new version */
g_assert_cmpstr (fu_device_get_version (device), ==, "1.2.4"); g_assert_cmpstr (fu_device_get_version (device), ==, "1.2.4");