mirror of
https://git.proxmox.com/git/fwupd
synced 2025-05-15 11:46:38 +00:00
trivial: Use FwupdStatus in the dfu plugin
This commit is contained in:
parent
e0bd53e439
commit
b73ff8a346
@ -48,6 +48,10 @@ fwupd_status_to_string (FwupdStatus status)
|
||||
return "device-restart";
|
||||
if (status == FWUPD_STATUS_DEVICE_WRITE)
|
||||
return "device-write";
|
||||
if (status == FWUPD_STATUS_DEVICE_READ)
|
||||
return "device-read";
|
||||
if (status == FWUPD_STATUS_DEVICE_ERASE)
|
||||
return "device-erase";
|
||||
if (status == FWUPD_STATUS_DEVICE_VERIFY)
|
||||
return "device-verify";
|
||||
if (status == FWUPD_STATUS_SCHEDULING)
|
||||
@ -88,6 +92,10 @@ fwupd_status_from_string (const gchar *status)
|
||||
return FWUPD_STATUS_SCHEDULING;
|
||||
if (g_strcmp0 (status, "downloading") == 0)
|
||||
return FWUPD_STATUS_DOWNLOADING;
|
||||
if (g_strcmp0 (status, "device-read") == 0)
|
||||
return FWUPD_STATUS_DEVICE_READ;
|
||||
if (g_strcmp0 (status, "device-erase") == 0)
|
||||
return FWUPD_STATUS_DEVICE_ERASE;
|
||||
return FWUPD_STATUS_LAST;
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,8 @@ typedef enum {
|
||||
FWUPD_STATUS_DEVICE_VERIFY, /* Since: 0.1.1 */
|
||||
FWUPD_STATUS_SCHEDULING, /* Since: 0.1.1 */
|
||||
FWUPD_STATUS_DOWNLOADING, /* Since: 0.9.4 */
|
||||
FWUPD_STATUS_DEVICE_READ, /* Since: 1.0.0 */
|
||||
FWUPD_STATUS_DEVICE_ERASE, /* Since: 1.0.0 */
|
||||
/*< private >*/
|
||||
FWUPD_STATUS_LAST
|
||||
} FwupdStatus;
|
||||
|
@ -169,31 +169,3 @@ dfu_version_to_string (DfuVersion version)
|
||||
return "DfuSe";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* dfu_action_to_string:
|
||||
* @action: a #DfuAction, e.g. %DFU_ACTION_VERIFY
|
||||
*
|
||||
* Converts an enumerated value to a string.
|
||||
*
|
||||
* Return value: a string
|
||||
**/
|
||||
const gchar *
|
||||
dfu_action_to_string (DfuAction action)
|
||||
{
|
||||
if (action == DFU_ACTION_IDLE)
|
||||
return "idle";
|
||||
if (action == DFU_ACTION_READ)
|
||||
return "read";
|
||||
if (action == DFU_ACTION_WRITE)
|
||||
return "write";
|
||||
if (action == DFU_ACTION_VERIFY)
|
||||
return "verify";
|
||||
if (action == DFU_ACTION_ERASE)
|
||||
return "erase";
|
||||
if (action == DFU_ACTION_DETACH)
|
||||
return "detach";
|
||||
if (action == DFU_ACTION_ATTACH)
|
||||
return "attach";
|
||||
return NULL;
|
||||
}
|
||||
|
@ -175,32 +175,6 @@ typedef enum {
|
||||
DFU_VERSION_LAST
|
||||
} DfuVersion;
|
||||
|
||||
/**
|
||||
* DfuAction:
|
||||
* @DFU_ACTION_UNKNOWN: No progress state
|
||||
* @DFU_ACTION_IDLE: Device is idle
|
||||
* @DFU_ACTION_READ: Reading from the device
|
||||
* @DFU_ACTION_WRITE: Writing to the device
|
||||
* @DFU_ACTION_VERIFY: Verifying the write
|
||||
* @DFU_ACTION_ERASE: Erasing the device
|
||||
* @DFU_ACTION_DETACH: Detach into DFU mode
|
||||
* @DFU_ACTION_ATTACH: Attach into APP mode
|
||||
*
|
||||
* The device DFU attributes.
|
||||
**/
|
||||
typedef enum {
|
||||
DFU_ACTION_UNKNOWN,
|
||||
DFU_ACTION_IDLE,
|
||||
DFU_ACTION_READ,
|
||||
DFU_ACTION_WRITE,
|
||||
DFU_ACTION_VERIFY,
|
||||
DFU_ACTION_ERASE,
|
||||
DFU_ACTION_DETACH,
|
||||
DFU_ACTION_ATTACH,
|
||||
/*< private >*/
|
||||
DFU_ACTION_LAST
|
||||
} DfuAction;
|
||||
|
||||
#define DFU_METADATA_KEY_LICENSE "License"
|
||||
#define DFU_METADATA_KEY_COPYRIGHT "Copyright"
|
||||
#define DFU_METADATA_KEY_CIPHER_KIND "CipherKind"
|
||||
@ -210,7 +184,6 @@ const gchar *dfu_status_to_string (DfuStatus status);
|
||||
const gchar *dfu_mode_to_string (DfuMode mode);
|
||||
const gchar *dfu_cipher_kind_to_string (DfuCipherKind cipher_kind);
|
||||
const gchar *dfu_version_to_string (DfuVersion version);
|
||||
const gchar *dfu_action_to_string (DfuAction action);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -55,7 +55,7 @@ typedef struct {
|
||||
DfuMode mode;
|
||||
DfuState state;
|
||||
DfuStatus status;
|
||||
DfuAction action_last;
|
||||
FwupdStatus action_last;
|
||||
GPtrArray *targets;
|
||||
GUsbDevice *dev;
|
||||
FuDeviceLocker *dev_locker;
|
||||
@ -139,7 +139,7 @@ dfu_device_class_init (DfuDeviceClass *klass)
|
||||
/**
|
||||
* DfuDevice::action-changed:
|
||||
* @device: the #DfuDevice instance that emitted the signal
|
||||
* @action: the new #DfuAction
|
||||
* @action: the new #FwupdStatus
|
||||
*
|
||||
* The ::action-changed signal is emitted when the high level action changes.
|
||||
**/
|
||||
@ -169,7 +169,7 @@ dfu_device_init (DfuDevice *device)
|
||||
}
|
||||
|
||||
static void
|
||||
dfu_device_set_action (DfuDevice *device, DfuAction action)
|
||||
dfu_device_set_action (DfuDevice *device, FwupdStatus action)
|
||||
{
|
||||
DfuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
if (action == priv->action_last)
|
||||
@ -1090,7 +1090,7 @@ dfu_device_detach (DfuDevice *device, GCancellable *cancellable, GError **error)
|
||||
return FALSE;
|
||||
|
||||
/* inform UI there's going to be a detach:attach */
|
||||
dfu_device_set_action (device, DFU_ACTION_DETACH);
|
||||
dfu_device_set_action (device, FWUPD_STATUS_DEVICE_RESTART);
|
||||
|
||||
if (!g_usb_device_control_transfer (priv->dev,
|
||||
G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
|
||||
@ -1121,7 +1121,7 @@ dfu_device_detach (DfuDevice *device, GCancellable *cancellable, GError **error)
|
||||
}
|
||||
|
||||
/* success */
|
||||
dfu_device_set_action (device, DFU_ACTION_IDLE);
|
||||
dfu_device_set_action (device, FWUPD_STATUS_IDLE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1587,7 +1587,7 @@ dfu_device_wait_for_replug (DfuDevice *device, guint timeout,
|
||||
}
|
||||
|
||||
/* success */
|
||||
dfu_device_set_action (device, DFU_ACTION_IDLE);
|
||||
dfu_device_set_action (device, FWUPD_STATUS_IDLE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1662,7 +1662,7 @@ dfu_device_attach (DfuDevice *device, GError **error)
|
||||
}
|
||||
|
||||
/* inform UI there's going to be a re-attach */
|
||||
dfu_device_set_action (device, DFU_ACTION_ATTACH);
|
||||
dfu_device_set_action (device, FWUPD_STATUS_DEVICE_RESTART);
|
||||
|
||||
/* handle m-stack DFU bootloaders */
|
||||
if (!priv->done_upload_or_download &&
|
||||
@ -1697,7 +1697,7 @@ dfu_device_attach (DfuDevice *device, GError **error)
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
dfu_device_set_action (device, DFU_ACTION_IDLE);
|
||||
dfu_device_set_action (device, FWUPD_STATUS_IDLE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1706,7 +1706,7 @@ dfu_device_attach (DfuDevice *device, GError **error)
|
||||
return FALSE;
|
||||
|
||||
/* success */
|
||||
dfu_device_set_action (device, DFU_ACTION_IDLE);
|
||||
dfu_device_set_action (device, FWUPD_STATUS_IDLE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1718,7 +1718,7 @@ dfu_device_percentage_cb (DfuTarget *target, guint percentage, DfuDevice *device
|
||||
}
|
||||
|
||||
static void
|
||||
dfu_device_action_cb (DfuTarget *target, DfuAction action, DfuDevice *device)
|
||||
dfu_device_action_cb (DfuTarget *target, FwupdStatus action, DfuDevice *device)
|
||||
{
|
||||
dfu_device_set_action (device, action);
|
||||
}
|
||||
@ -1846,7 +1846,7 @@ dfu_device_upload (DfuDevice *device,
|
||||
}
|
||||
|
||||
/* success */
|
||||
dfu_device_set_action (device, DFU_ACTION_IDLE);
|
||||
dfu_device_set_action (device, FWUPD_STATUS_IDLE);
|
||||
return g_object_ref (firmware);
|
||||
}
|
||||
|
||||
@ -2082,7 +2082,7 @@ dfu_device_download (DfuDevice *device,
|
||||
}
|
||||
|
||||
/* success */
|
||||
dfu_device_set_action (device, DFU_ACTION_IDLE);
|
||||
dfu_device_set_action (device, FWUPD_STATUS_IDLE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ struct _DfuDeviceClass
|
||||
void (*percentage_changed) (DfuDevice *device,
|
||||
guint percentage);
|
||||
void (*action_changed) (DfuDevice *device,
|
||||
DfuAction action);
|
||||
FwupdStatus action);
|
||||
/*< private >*/
|
||||
/* Padding for future expansion */
|
||||
void (*_dfu_device_reserved1) (void);
|
||||
|
@ -65,7 +65,7 @@ typedef struct {
|
||||
gchar *alt_name_for_display;
|
||||
GPtrArray *sectors; /* of DfuSector */
|
||||
guint old_percentage;
|
||||
DfuAction old_action;
|
||||
FwupdStatus old_action;
|
||||
} DfuTargetPrivate;
|
||||
|
||||
enum {
|
||||
@ -101,7 +101,7 @@ dfu_target_class_init (DfuTargetClass *klass)
|
||||
/**
|
||||
* DfuTarget::action-changed:
|
||||
* @device: the #DfuTarget instance that emitted the signal
|
||||
* @action: the new DfuAction
|
||||
* @action: the new FwupdStatus
|
||||
*
|
||||
* The ::action-changed signal is emitted when the high level action changes.
|
||||
**/
|
||||
@ -121,7 +121,7 @@ dfu_target_init (DfuTarget *target)
|
||||
DfuTargetPrivate *priv = GET_PRIVATE (target);
|
||||
priv->sectors = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
||||
priv->old_percentage = G_MAXUINT;
|
||||
priv->old_action = DFU_ACTION_IDLE;
|
||||
priv->old_action = FWUPD_STATUS_IDLE;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -900,21 +900,21 @@ dfu_target_upload_chunk (DfuTarget *target, guint8 index,
|
||||
}
|
||||
|
||||
static void
|
||||
dfu_target_set_action (DfuTarget *target, DfuAction action)
|
||||
dfu_target_set_action (DfuTarget *target, FwupdStatus action)
|
||||
{
|
||||
DfuTargetPrivate *priv = GET_PRIVATE (target);
|
||||
|
||||
/* unchanged */
|
||||
if (priv->old_action == action)
|
||||
return;
|
||||
if (priv->old_action != DFU_ACTION_IDLE &&
|
||||
action != DFU_ACTION_IDLE) {
|
||||
if (priv->old_action != FWUPD_STATUS_IDLE &&
|
||||
action != FWUPD_STATUS_IDLE) {
|
||||
g_debug ("ignoring action %s as %s already set and not idle",
|
||||
dfu_action_to_string (action),
|
||||
dfu_action_to_string (priv->old_action));
|
||||
fwupd_status_to_string (action),
|
||||
fwupd_status_to_string (priv->old_action));
|
||||
return;
|
||||
}
|
||||
g_debug ("setting action %s", dfu_action_to_string (action));
|
||||
g_debug ("setting action %s", fwupd_status_to_string (action));
|
||||
g_signal_emit (target, signals[SIGNAL_ACTION_CHANGED], 0, action);
|
||||
priv->old_action = action;
|
||||
}
|
||||
@ -926,7 +926,7 @@ dfu_target_set_percentage_raw (DfuTarget *target, guint percentage)
|
||||
if (percentage == priv->old_percentage)
|
||||
return;
|
||||
g_debug ("setting percentage %u%% of %s",
|
||||
percentage, dfu_action_to_string (priv->old_action));
|
||||
percentage, fwupd_status_to_string (priv->old_action));
|
||||
g_signal_emit (target,
|
||||
signals[SIGNAL_PERCENTAGE_CHANGED],
|
||||
0, percentage);
|
||||
@ -1017,7 +1017,7 @@ dfu_target_upload_element_dfuse (DfuTarget *target,
|
||||
}
|
||||
|
||||
/* update UI */
|
||||
dfu_target_set_action (target, DFU_ACTION_READ);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_DEVICE_READ);
|
||||
|
||||
/* manually set the sector address */
|
||||
g_debug ("setting DfuSe address to 0x%04x", (guint) offset);
|
||||
@ -1087,7 +1087,7 @@ dfu_target_upload_element_dfuse (DfuTarget *target,
|
||||
|
||||
/* done */
|
||||
dfu_target_set_percentage_raw (target, 100);
|
||||
dfu_target_set_action (target, DFU_ACTION_IDLE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_IDLE);
|
||||
|
||||
/* create new image */
|
||||
contents = _g_bytes_array_join (chunks);
|
||||
@ -1120,7 +1120,7 @@ dfu_target_upload_element_dfu (DfuTarget *target,
|
||||
g_autoptr(GPtrArray) chunks = NULL;
|
||||
|
||||
/* update UI */
|
||||
dfu_target_set_action (target, DFU_ACTION_READ);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_DEVICE_READ);
|
||||
|
||||
/* get all the chunks from the hardware */
|
||||
chunks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
|
||||
@ -1169,7 +1169,7 @@ dfu_target_upload_element_dfu (DfuTarget *target,
|
||||
|
||||
/* done */
|
||||
dfu_target_set_percentage_raw (target, 100);
|
||||
dfu_target_set_action (target, DFU_ACTION_IDLE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_IDLE);
|
||||
|
||||
/* create new image */
|
||||
contents = _g_bytes_array_join (chunks);
|
||||
@ -1378,7 +1378,7 @@ dfu_target_download_element_dfu (DfuTarget *target,
|
||||
"zero-length firmware");
|
||||
return FALSE;
|
||||
}
|
||||
dfu_target_set_action (target, DFU_ACTION_WRITE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_DEVICE_WRITE);
|
||||
for (guint i = 0; i < nr_chunks + 1; i++) {
|
||||
gsize length;
|
||||
guint32 offset;
|
||||
@ -1411,7 +1411,7 @@ dfu_target_download_element_dfu (DfuTarget *target,
|
||||
|
||||
/* done */
|
||||
dfu_target_set_percentage_raw (target, 100);
|
||||
dfu_target_set_action (target, DFU_ACTION_IDLE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_IDLE);
|
||||
|
||||
/* success */
|
||||
return TRUE;
|
||||
@ -1486,7 +1486,7 @@ dfu_target_download_element_dfuse (DfuTarget *target,
|
||||
}
|
||||
|
||||
/* 2nd pass: actually erase sectors */
|
||||
dfu_target_set_action (target, DFU_ACTION_ERASE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_DEVICE_ERASE);
|
||||
for (guint i = 0; i < sectors_array->len; i++) {
|
||||
sector = g_ptr_array_index (sectors_array, i);
|
||||
g_debug ("erasing sector at 0x%04x",
|
||||
@ -1499,10 +1499,10 @@ dfu_target_download_element_dfuse (DfuTarget *target,
|
||||
dfu_target_set_percentage (target, i + 1, sectors_array->len);
|
||||
}
|
||||
dfu_target_set_percentage_raw (target, 100);
|
||||
dfu_target_set_action (target, DFU_ACTION_IDLE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_IDLE);
|
||||
|
||||
/* 3rd pass: write data */
|
||||
dfu_target_set_action (target, DFU_ACTION_WRITE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_DEVICE_WRITE);
|
||||
for (guint i = 0; i < nr_chunks; i++) {
|
||||
gsize length;
|
||||
guint32 offset;
|
||||
@ -1555,7 +1555,7 @@ dfu_target_download_element_dfuse (DfuTarget *target,
|
||||
|
||||
/* done */
|
||||
dfu_target_set_percentage_raw (target, 100);
|
||||
dfu_target_set_action (target, DFU_ACTION_IDLE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_IDLE);
|
||||
|
||||
/* success */
|
||||
return TRUE;
|
||||
@ -1592,7 +1592,7 @@ dfu_target_download_element (DfuTarget *target,
|
||||
GBytes *bytes;
|
||||
GBytes *bytes_tmp;
|
||||
g_autoptr(DfuElement) element_tmp = NULL;
|
||||
dfu_target_set_action (target, DFU_ACTION_VERIFY);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_DEVICE_VERIFY);
|
||||
bytes = dfu_element_get_contents (element);
|
||||
element_tmp = dfu_target_upload_element (target,
|
||||
dfu_element_get_address (element),
|
||||
@ -1613,7 +1613,7 @@ dfu_target_download_element (DfuTarget *target,
|
||||
bytes_cmp_str);
|
||||
return FALSE;
|
||||
}
|
||||
dfu_target_set_action (target, DFU_ACTION_IDLE);
|
||||
dfu_target_set_action (target, FWUPD_STATUS_IDLE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "dfu-common.h"
|
||||
#include "dfu-image.h"
|
||||
|
||||
#include "fwupd-enums.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define DFU_TYPE_TARGET (dfu_target_get_type ())
|
||||
@ -40,7 +42,7 @@ struct _DfuTargetClass
|
||||
void (*percentage_changed) (DfuTarget *target,
|
||||
guint percentage);
|
||||
void (*action_changed) (DfuTarget *target,
|
||||
DfuAction action);
|
||||
FwupdStatus action);
|
||||
/*< private >*/
|
||||
/* Padding for future expansion */
|
||||
void (*_dfu_target_reserved1) (void);
|
||||
|
@ -1213,50 +1213,44 @@ fu_tool_percentage_changed_cb (DfuDevice *device,
|
||||
|
||||
static void
|
||||
fu_tool_action_changed_cb (DfuDevice *device,
|
||||
DfuAction action,
|
||||
FwupdStatus action,
|
||||
DfuToolPrivate *priv)
|
||||
{
|
||||
switch (action) {
|
||||
case DFU_ACTION_IDLE:
|
||||
case FWUPD_STATUS_IDLE:
|
||||
dfu_progress_bar_set_percentage (priv->progress_bar, 100);
|
||||
dfu_progress_bar_end (priv->progress_bar);
|
||||
break;
|
||||
case DFU_ACTION_READ:
|
||||
case FWUPD_STATUS_DEVICE_READ:
|
||||
dfu_progress_bar_start (priv->progress_bar,
|
||||
/* TRANSLATORS: read from device to host */
|
||||
_("Reading"));
|
||||
dfu_progress_bar_set_percentage (priv->progress_bar, 0);
|
||||
break;
|
||||
case DFU_ACTION_WRITE:
|
||||
case FWUPD_STATUS_DEVICE_WRITE:
|
||||
dfu_progress_bar_start (priv->progress_bar,
|
||||
/* TRANSLATORS: write from host to device */
|
||||
_("Writing"));
|
||||
dfu_progress_bar_set_percentage (priv->progress_bar, 0);
|
||||
break;
|
||||
case DFU_ACTION_VERIFY:
|
||||
case FWUPD_STATUS_DEVICE_VERIFY:
|
||||
dfu_progress_bar_start (priv->progress_bar,
|
||||
/* TRANSLATORS: read from device to host */
|
||||
_("Verifying"));
|
||||
dfu_progress_bar_set_percentage (priv->progress_bar, 0);
|
||||
break;
|
||||
case DFU_ACTION_ERASE:
|
||||
case FWUPD_STATUS_DEVICE_ERASE:
|
||||
dfu_progress_bar_start (priv->progress_bar,
|
||||
/* TRANSLATORS: read from device to host */
|
||||
_("Erasing"));
|
||||
dfu_progress_bar_set_percentage (priv->progress_bar, 0);
|
||||
break;
|
||||
case DFU_ACTION_DETACH:
|
||||
case FWUPD_STATUS_DEVICE_RESTART:
|
||||
dfu_progress_bar_start (priv->progress_bar,
|
||||
/* TRANSLATORS: waiting for device */
|
||||
_("Detaching"));
|
||||
dfu_progress_bar_set_percentage (priv->progress_bar, -1);
|
||||
break;
|
||||
case DFU_ACTION_ATTACH:
|
||||
dfu_progress_bar_start (priv->progress_bar,
|
||||
/* TRANSLATORS: waiting for device */
|
||||
_("Attaching"));
|
||||
dfu_progress_bar_set_percentage (priv->progress_bar, -1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -63,10 +63,18 @@ fu_progressbar_status_to_string (FwupdStatus status)
|
||||
/* TRANSLATORS: restarting the device to pick up new F/W */
|
||||
return _("Restarting device…");
|
||||
break;
|
||||
case FWUPD_STATUS_DEVICE_READ:
|
||||
/* TRANSLATORS: reading from the flash chips */
|
||||
return _("Reading…");
|
||||
break;
|
||||
case FWUPD_STATUS_DEVICE_WRITE:
|
||||
/* TRANSLATORS: writing to the flash chips */
|
||||
return _("Writing…");
|
||||
break;
|
||||
case FWUPD_STATUS_DEVICE_ERASE:
|
||||
/* TRANSLATORS: erasing contents of the flash chips */
|
||||
return _("Erasing…");
|
||||
break;
|
||||
case FWUPD_STATUS_DEVICE_VERIFY:
|
||||
/* TRANSLATORS: verifying we wrote the firmware correctly */
|
||||
return _("Verifying…");
|
||||
|
Loading…
Reference in New Issue
Block a user