]> git.ipfire.org Git - collecty.git/commitdiff
module: Create a collect() function
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 14:48:34 +0000 (14:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 14:48:34 +0000 (14:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/module.c
src/daemon/module.h

index bba4f8b5636937b972dd5975d03ae21eddd6ad51..e970f5b1ec5d2b5f76522695d344448e2ed330fd 100644 (file)
@@ -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);
index d856e813592930b349d2dadc8a75fe173e4a7353..e8621fbfdd9e08171a461efa116df53723a766da 100644 (file)
@@ -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);