From fe82dfe6ecc9a5088b7ed5d82124ce8c76812853 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 2 Oct 2025 08:58:22 +0000 Subject: [PATCH] graph: Add a helper function to pull in all data sources from a module Signed-off-by: Michael Tremer --- src/daemon/graph.c | 35 +++++++++++++++++++++++++++++++++++ src/daemon/graph.h | 3 +++ src/daemon/module.c | 4 ++++ src/daemon/module.h | 4 ++++ 4 files changed, 46 insertions(+) diff --git a/src/daemon/graph.c b/src/daemon/graph.c index e043418..900f836 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -108,6 +108,41 @@ char* collecty_graph_get_bus_path(collecty_graph* self) { return path; } +int collecty_graph_require_module(collecty_graph* self, + collecty_args* args, const char* name, const char* object) { + collecty_modules* modules = NULL; + collecty_module* module = NULL; + int r; + + // Fetch all modules + modules = collecty_daemon_get_modules(self->daemon); + if (!modules) { + r = -ENOTSUP; + goto ERROR; + } + + // Fetch the module by its name + module = collecty_modules_get_by_name(modules, name); + if (!module) { + ERROR(self->ctx, "Could not find module '%s'\n", name); + r = -ENOENT; + goto ERROR; + } + + // Add the data of the module + r = collecty_module_render(module, args, object); + if (r < 0) + goto ERROR; + +ERROR: + if (modules) + collecty_modules_unref(modules); + if (module) + collecty_module_unref(module); + + return r; +} + int collecty_graph_render(collecty_graph* self, const char* object, char** buffer, size_t* length) { collecty_args* args = NULL; diff --git a/src/daemon/graph.h b/src/daemon/graph.h index 3322344..1f703c1 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -47,6 +47,9 @@ collecty_graph* collecty_graph_unref(collecty_graph* self); const char* collecty_graph_get_name(collecty_graph* self); char* collecty_graph_get_bus_path(collecty_graph* self); +int collecty_graph_require_module(collecty_graph* self, + collecty_args* args, const char* name, const char* object); + int collecty_graph_render(collecty_graph* self, const char* object, char** buffer, size_t* length); diff --git a/src/daemon/module.c b/src/daemon/module.c index a94f4d7..02dd238 100644 --- a/src/daemon/module.c +++ b/src/daemon/module.c @@ -401,3 +401,7 @@ int collecty_module_commit(collecty_module* self, return 0; } + +int collecty_module_render(collecty_module* self, collecty_args* args, const char* object) { + return 0; +} diff --git a/src/daemon/module.h b/src/daemon/module.h index 0678991..c4db559 100644 --- a/src/daemon/module.h +++ b/src/daemon/module.h @@ -23,6 +23,7 @@ typedef struct collecty_module collecty_module; +#include "args.h" #include "ctx.h" #include "daemon.h" @@ -83,4 +84,7 @@ int collecty_module_submit(collecty_module* self, const char* object, int collecty_module_commit(collecty_module* self, const char* object, unsigned int num_samples, const char** samples); +int collecty_module_render(collecty_module* self, + collecty_args* args, const char* object); + #endif /* COLLECTY_MODULE_H */ -- 2.47.3