From: Michael Tremer Date: Sat, 27 Sep 2025 14:48:34 +0000 (+0000) Subject: module: Create a collect() function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a39b1eacbf1ed73194023bfd8a4a3a1c24c09b1c;p=collecty.git module: Create a collect() function Signed-off-by: Michael Tremer --- diff --git a/src/daemon/module.c b/src/daemon/module.c index bba4f8b..e970f5b 100644 --- a/src/daemon/module.c +++ b/src/daemon/module.c @@ -58,7 +58,12 @@ static int collecty_module_heartbeat(sd_event_source* source, uint64_t usec, voi DEBUG(self->ctx, "Heartbeat called for %s\n", collecty_module_name(self)); - // XXX TODO + // Call the collect method + r = self->methods->collect(self->ctx, self); + if (r < 0) { + ERROR(self->ctx, "collect() failed for %s: %s\n", + collecty_module_name(self), strerror(-r)); + } // Arm the timer again r = sd_event_source_set_time(self->events.heartbeat, usec + HEARTBEAT); @@ -76,6 +81,10 @@ static int collecty_module_heartbeat(sd_event_source* source, uint64_t usec, voi static int collecty_module_register_heartbeat(collecty_module* self) { int r; + // No need to do this if we don't have a collect method + if (!self->methods->collect) + return 0; + // Call the heartbeat function immediately r = sd_event_add_time_relative(self->loop, &self->events.heartbeat, CLOCK_MONOTONIC, 0, 0, collecty_module_heartbeat, self); diff --git a/src/daemon/module.h b/src/daemon/module.h index d856e81..e8621fb 100644 --- a/src/daemon/module.h +++ b/src/daemon/module.h @@ -24,6 +24,8 @@ #include "ctx.h" #include "daemon.h" +typedef struct collecty_module collecty_module; + typedef struct collecty_module_methods { const char* name; @@ -32,9 +34,10 @@ typedef struct collecty_module_methods { // Free int (*free)(collecty_ctx* ctx); -} collecty_module_methods; -typedef struct collecty_module collecty_module; + // Collect + int (*collect)(collecty_ctx* ctx, collecty_module* module); +} collecty_module_methods; int collecty_module_create(collecty_module** module, collecty_ctx* ctx, collecty_daemon* daemon, const collecty_module_methods* methods);