Richard Hughes has uploaded this change for review.

View Change

libflashrom: Allow getting the progress_state from the flashctx

External users of the libflashrom API cannot peek into the abstract
flashrom_flashctx structure, unlike the local CLI. Provide some API to
get the flashrom_progress struct from a flashrom_flashctx.

This allows fwupd to use the new flashrom_set_progress_callback() API
without using a global variable with the callback data.

Change-Id: I322bf56ff92f7b4d0ffc92768e9f0cdf7cb82010
Signed-off-by: Richard Hughes <richard@hughsie.com>
---
M cli_output.c
M include/libflashrom.h
M libflashrom.c
M libflashrom.map
4 files changed, 19 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/63/64663/1
diff --git a/cli_output.c b/cli_output.c
index e5b829a..9b7c70d 100644
--- a/cli_output.c
+++ b/cli_output.c
@@ -77,7 +77,7 @@

void flashrom_progress_cb(struct flashrom_flashctx *flashctx)
{
- struct flashrom_progress *progress_state = flashctx->progress_state;
+ struct flashrom_progress *progress_state = flashrom_get_progress_state(flashctx);
unsigned int pc = 0;
unsigned int *percentages = progress_state->user_data;
if (progress_state->current > 0 && progress_state->total > 0)
diff --git a/include/libflashrom.h b/include/libflashrom.h
index 21a5785..e6d1cf7 100644
--- a/include/libflashrom.h
+++ b/include/libflashrom.h
@@ -97,6 +97,17 @@
void flashrom_set_progress_callback(struct flashrom_flashctx *const flashctx,
flashrom_progress_callback *progress_callback, struct flashrom_progress *progress_state);

+/**
+ * @brief Get the progress state.
+ *
+ * Get the progress state set in flashrom_set_progress_callback().
+ *
+ * @param flashctx The current flash context.
+ * @return last set progress state
+ */
+struct flashrom_progress *flashrom_get_progress_state(struct flashrom_flashctx *flashctx);
+
+
/** @} */ /* end flashrom-general */

/**
diff --git a/libflashrom.c b/libflashrom.c
index 0c6613e..6499387 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -65,6 +65,12 @@
return 0;
}

+struct flashrom_progress *
+flashrom_get_progress_state(struct flashrom_flashctx *flashctx)
+{
+ return flashctx->progress_state;
+}
+
void flashrom_set_progress_callback(struct flashrom_flashctx *flashctx, flashrom_progress_callback *progress_callback, struct flashrom_progress *progress_state)
{
flashctx->progress_callback = progress_callback;
diff --git a/libflashrom.map b/libflashrom.map
index b3af70b..7eb2903 100644
--- a/libflashrom.map
+++ b/libflashrom.map
@@ -10,6 +10,7 @@
flashrom_flash_getsize;
flashrom_flash_probe;
flashrom_flash_release;
+ flashrom_get_progress_state;
flashrom_image_read;
flashrom_image_verify;
flashrom_image_write;

To view, visit change 64663. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I322bf56ff92f7b4d0ffc92768e9f0cdf7cb82010
Gerrit-Change-Number: 64663
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Hughes <richard@hughsie.com>
Gerrit-MessageType: newchange