From af75522a5eb0cf93ab05e286fca3230cf1e56dba Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 26 Jan 2021 21:43:51 +0000 Subject: [PATCH] dfu: Show the DfuTargets when calling DfuDevice->to_string() This is a much more standard way of doing this. --- plugins/dfu/dfu-device.c | 4 ++++ plugins/dfu/dfu-target.c | 23 ++++++++++++----------- plugins/dfu/dfu-target.h | 3 +++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/plugins/dfu/dfu-device.c b/plugins/dfu/dfu-device.c index 7b881d1ad..82940e679 100644 --- a/plugins/dfu/dfu-device.c +++ b/plugins/dfu/dfu-device.c @@ -134,6 +134,10 @@ dfu_device_to_string (FuDevice *device, guint idt, GString *str) fu_common_string_append_kx (str, idt, "IfaceNumber", priv->iface_number); fu_common_string_append_kx (str, idt, "DnloadTimeout", priv->dnload_timeout); fu_common_string_append_kx (str, idt, "TimeoutMs", priv->timeout_ms); + for (guint i = 0; i < priv->targets->len; i++) { + DfuTarget *target = g_ptr_array_index (priv->targets, i); + dfu_target_to_string (target, idt + 1, str); + } } /** diff --git a/plugins/dfu/dfu-target.c b/plugins/dfu/dfu-target.c index 777dd378a..4ae958ee2 100644 --- a/plugins/dfu/dfu-target.c +++ b/plugins/dfu/dfu-target.c @@ -121,19 +121,23 @@ dfu_target_finalize (GObject *object) G_OBJECT_CLASS (dfu_target_parent_class)->finalize (object); } -static gchar * -dfu_target_sectors_to_string (DfuTarget *target) +void +dfu_target_to_string (DfuTarget *target, guint idt, GString *str) { DfuTargetPrivate *priv = GET_PRIVATE (target); - GString *str = g_string_new (""); + fu_common_string_append_kx (str, idt, "AltSetting", priv->alt_setting); + fu_common_string_append_kx (str, idt, "AltIdx", priv->alt_idx); + fu_common_string_append_kv (str, idt, "AltName", priv->alt_name); + if (priv->alt_name_for_display != NULL) { + fu_common_string_append_kv (str, idt, "AltNameForDisplay", + priv->alt_name_for_display); + } for (guint i = 0; i < priv->sectors->len; i++) { DfuSector *sector = g_ptr_array_index (priv->sectors, i); - g_autofree gchar *tmp = dfu_sector_to_string (sector); - g_string_append_printf (str, "%s\n", tmp); + g_autofree gchar *tmp1 = g_strdup_printf ("Idx%02x", i); + g_autofree gchar *tmp2 = dfu_sector_to_string (sector); + fu_common_string_append_kv (str, idt + 1, tmp1, tmp2); } - if (str->len > 0) - g_string_truncate (str, str->len - 1); - return g_string_free (str, FALSE); } DfuSector * @@ -288,7 +292,6 @@ gboolean dfu_target_parse_sectors (DfuTarget *target, const gchar *alt_name, GError **error) { DfuTargetPrivate *priv = GET_PRIVATE (target); - g_autofree gchar *str_debug = NULL; g_auto(GStrv) zones = NULL; /* not set */ @@ -373,8 +376,6 @@ dfu_target_parse_sectors (DfuTarget *target, const gchar *alt_name, GError **err } /* success */ - str_debug = dfu_target_sectors_to_string (target); - g_debug ("%s", str_debug); return TRUE; } diff --git a/plugins/dfu/dfu-target.h b/plugins/dfu/dfu-target.h index ec521c176..dde4bb827 100644 --- a/plugins/dfu/dfu-target.h +++ b/plugins/dfu/dfu-target.h @@ -83,3 +83,6 @@ gboolean dfu_target_download (DfuTarget *target, GError **error); gboolean dfu_target_mass_erase (DfuTarget *target, GError **error); +void dfu_target_to_string (DfuTarget *target, + guint idt, + GString *str);