fwupd/libfwupdplugin/fu-progress.h
Richard Hughes 40cd18fa97 Allow using a per-device global percentage completion
It's actually quite hard to build a front-end for fwupd at the moment
as you're never sure when the progress bar is going to zip back to 0%
and start all over again. Some plugins go 0..100% for write, others
go 0..100% for erase, then again for write, then *again* for verify.

By creating a helper object we can easily split up the progress of the
specific task, e.g. write_firmware().

We can encode at the plugin level "the erase takes 50% of the time, the
write takes 40% and the read takes 10%". This means we can have a
progressbar which goes up just once at a consistent speed.
2021-09-13 14:28:15 +01:00

111 lines
2.5 KiB
C

/*
* Copyright (C) 2021 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#pragma once
#include <fwupd.h>
#include <gio/gio.h>
#define FU_TYPE_PROGRESS (fu_progress_get_type())
G_DECLARE_DERIVABLE_TYPE(FuProgress, fu_progress, FU, PROGRESS, GObject)
struct _FuProgressClass {
GObjectClass parent_class;
/* signals */
void (*percentage_changed)(FuProgress *self, guint value);
void (*status_changed)(FuProgress *self, FwupdStatus status);
/*< private >*/
gpointer padding[29];
};
/**
* FuProgressFlags:
*
* The progress internal flags.
**/
typedef guint64 FuProgressFlags;
/**
* FU_PROGRESS_FLAG_NONE:
*
* No flags set.
*
* Since: 1.7.0
*/
#define FU_PROGRESS_FLAG_NONE (0)
/**
* FU_PROGRESS_FLAG_UNKNOWN:
*
* Unknown flag value.
*
* Since: 1.7.0
*/
#define FU_PROGRESS_FLAG_UNKNOWN G_MAXUINT64
/**
* FU_PROGRESS_FLAG_GUESSED:
*
* The steps have not been measured on real hardware and have been guessed.
*
* Since: 1.7.0
*/
#define FU_PROGRESS_FLAG_GUESSED (1ull << 0)
/**
* FU_PROGRESS_FLAG_NO_PROFILE:
*
* The steps cannot be accurate enough for a profile result.
*
* Since: 1.7.0
*/
#define FU_PROGRESS_FLAG_NO_PROFILE (1ull << 1)
FuProgress *
fu_progress_new(const gchar *id);
const gchar *
fu_progress_get_id(FuProgress *self);
void
fu_progress_set_id(FuProgress *self, const gchar *id);
const gchar *
fu_progress_flag_to_string(FuProgressFlags flag);
FuProgressFlags
fu_progress_flag_from_string(const gchar *flag);
void
fu_progress_add_flag(FuProgress *self, FuProgressFlags flag);
void
fu_progress_remove_flag(FuProgress *self, FuProgressFlags flag);
gboolean
fu_progress_has_flag(FuProgress *self, FuProgressFlags flag);
FwupdStatus
fu_progress_get_status(FuProgress *self);
void
fu_progress_set_status(FuProgress *self, FwupdStatus status);
void
fu_progress_set_percentage(FuProgress *self, guint percentage);
void
fu_progress_set_percentage_full(FuProgress *self, gsize progress_done, gsize progress_total);
guint
fu_progress_get_percentage(FuProgress *self);
void
fu_progress_set_profile(FuProgress *self, gboolean profile);
void
fu_progress_reset(FuProgress *self);
void
fu_progress_set_steps(FuProgress *self, guint step_max);
guint
fu_progress_get_steps(FuProgress *self);
void
fu_progress_add_step(FuProgress *self, FwupdStatus status, guint value);
void
fu_progress_finished(FuProgress *self);
void
fu_progress_step_done(FuProgress *self);
FuProgress *
fu_progress_get_child(FuProgress *self);
void
fu_progress_sleep(FuProgress *self, guint delay_ms);