[Concept,14/27] expo: Use a configurable output function in expo_dump()

Message ID 20260119204130.3972647-15-sjg@u-boot.org
State New
Headers
Series Expo debugging and textedit improvements (part E) |

Commit Message

Simon Glass Jan. 19, 2026, 8:41 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Refactor the dump context to use a configurable output function instead
of directly writing to a membuf. This allows different output targets
to be used.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 boot/expo_dump.c | 44 +++++++++++++++++++++++++++++++++++++-------
 1 file changed, 37 insertions(+), 7 deletions(-)
  

Patch

diff --git a/boot/expo_dump.c b/boot/expo_dump.c
index b2ea60db50c..d357aa6a5be 100644
--- a/boot/expo_dump.c
+++ b/boot/expo_dump.c
@@ -15,36 +15,64 @@ 
 #include <video.h>
 #include "scene_internal.h"
 
+/**
+ * typedef dump_out_func - Function type for dump output
+ *
+ * @priv: Private data for the output function
+ * @buf: Buffer containing data to output
+ * @len: Length of data in buffer
+ */
+typedef void (*dump_out_func)(void *priv, const char *buf, int len);
+
 /**
  * struct dump_ctx - Context for dumping expo structures
  *
- * @mb: Membuf to write output to
+ * @out: Output function to call for each piece of output
+ * @priv: Private data to pass to output function
  * @scn: Current scene being dumped (or NULL if not in a scene)
  * @indent: Current indentation level (number of spaces)
  */
 struct dump_ctx {
-	struct membuf *mb;
+	dump_out_func out;
+	void *priv;
 	struct scene *scn;
 	int indent;
 };
 
+/**
+ * dump_out_membuf() - Output function that writes to a membuf
+ *
+ * @priv: Pointer to struct membuf
+ * @buf: Buffer containing data to output
+ * @len: Length of data in buffer
+ */
+static void dump_out_membuf(void *priv, const char *buf, int len)
+{
+	struct membuf *mb = priv;
+
+	membuf_put(mb, buf, len);
+}
+
 /**
  * outf() - Output a formatted string with indentation
  *
- * @ctx: Dump context containing membuf, scene, and indent level
+ * @ctx: Dump context containing output function, scene, and indent level
  * @fmt: Format string
  * @...: Arguments for format string
  */
 static void outf(struct dump_ctx *ctx, const char *fmt, ...)
 {
 	char buf[256];
+	char indent_buf[64];
 	va_list args;
 	int len;
 
+	len = snprintf(indent_buf, sizeof(indent_buf), "%*s", ctx->indent, "");
+	ctx->out(ctx->priv, indent_buf, len);
+
 	va_start(args, fmt);
-	membuf_printf(ctx->mb, "%*s", ctx->indent, "");
 	len = vsnprintf(buf, sizeof(buf), fmt, args);
-	membuf_put(ctx->mb, buf, len);
+	ctx->out(ctx->priv, buf, len);
 	va_end(args);
 }
 
@@ -196,7 +224,8 @@  void scene_dump(struct membuf *mb, struct scene *scn, int indent)
 {
 	struct dump_ctx ctx;
 
-	ctx.mb = mb;
+	ctx.out = dump_out_membuf;
+	ctx.priv = mb;
 	ctx.scn = scn;
 	ctx.indent = indent;
 
@@ -262,7 +291,8 @@  void expo_dump(struct expo *exp, struct membuf *mb)
 {
 	struct dump_ctx ctx;
 
-	ctx.mb = mb;
+	ctx.out = dump_out_membuf;
+	ctx.priv = mb;
 	ctx.scn = NULL;
 	ctx.indent = 0;