From: Michael Tremer Date: Thu, 19 Sep 2024 13:10:17 +0000 (+0000) Subject: main: Pass stats to the TUI X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2dde8fc01338afd17fcbcb0005b56e43b1acbbc2;p=fireperf.git main: Pass stats to the TUI Signed-off-by: Michael Tremer --- diff --git a/src/main.c b/src/main.c index c726237..b1019a0 100644 --- a/src/main.c +++ b/src/main.c @@ -197,8 +197,11 @@ int main(int argc, char* argv[]) { goto ERROR; } - // Print the stats - r = fireperf_ctx_dump_stats(ctx); + // Fetch the stats + struct fireperf_stats stats = fireperf_ctx_get_stats(ctx); + + // Update the TUI + r = fireperf_tui_update(ctx->tui, stats); if (r) goto ERROR; diff --git a/src/tui.c b/src/tui.c index 4c837cd..8bab23f 100644 --- a/src/tui.c +++ b/src/tui.c @@ -27,11 +27,18 @@ #include #include "ctx.h" +#include "stats.h" #include "tui.h" +#define MAX_STATS 128 + struct fireperf_tui { struct fireperf_ctx* ctx; + // Stats + struct fireperf_stats stats[MAX_STATS]; + unsigned int s; + // The main screen WINDOW* screen; @@ -221,3 +228,18 @@ int fireperf_tui_action(struct fireperf_tui* tui) { return 0; } + +/* + Called when there is new data to update the UI +*/ +int fireperf_tui_update(struct fireperf_tui* tui, struct fireperf_stats stats) { + int r; + + // Store stats + tui->stats[tui->s++] = stats; + + // Wrap the pointer around + tui->s %= MAX_STATS; + + return 0; +} diff --git a/src/tui.h b/src/tui.h index 6c82266..6d29bc6 100644 --- a/src/tui.h +++ b/src/tui.h @@ -24,6 +24,7 @@ struct fireperf_tui; #include "ctx.h" +#include "stats.h" int fireperf_tui_init(struct fireperf_tui** tui, struct fireperf_ctx* ctx); void fireperf_tui_finish(struct fireperf_tui* tui); @@ -31,4 +32,6 @@ void fireperf_tui_finish(struct fireperf_tui* tui); int fireperf_tui_register(struct fireperf_tui* tui, int epollfd); int fireperf_tui_action(struct fireperf_tui* tui); +int fireperf_tui_update(struct fireperf_tui* tui, struct fireperf_stats stats); + #endif /* FIREPERF_TUI_H */