]> git.ipfire.org Git - fireperf.git/commitdiff
main: Pass stats to the TUI
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 19 Sep 2024 13:10:17 +0000 (13:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 19 Sep 2024 13:10:17 +0000 (13:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/main.c
src/tui.c
src/tui.h

index c7262379bba2ea2828055a4d5f3fc0ab22e4be68..b1019a06e4edcd3cf2c2e536b7e1505c7f5eb1f5 100644 (file)
@@ -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;
 
index 4c837cdf79a59ef86f82f9e3e4ae0fbeb78f80d4..8bab23f50a2fcb8f5b987aa584e5d8fb52cd632d 100644 (file)
--- a/src/tui.c
+++ b/src/tui.c
 #include <ncurses.h>
 
 #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;
+}
index 6c8226682e6f8ee4950cab449e6a6f3234b6d475..6d29bc69e0ec8ca4969a447213472061fb8cf2c8 100644 (file)
--- 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 */