From de3633581a665ac9f5ee34c2ffb53789dd2ef2e9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 29 Sep 2025 17:40:16 +0000 Subject: [PATCH] graphs: Add scaffolding for a graph collection Signed-off-by: Michael Tremer --- src/daemon/graphs.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ src/daemon/graphs.h | 34 ++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 src/daemon/graphs.c create mode 100644 src/daemon/graphs.h diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c new file mode 100644 index 0000000..9daf43a --- /dev/null +++ b/src/daemon/graphs.c @@ -0,0 +1,78 @@ +/*############################################################################# +# # +# collecty - A system statistics collection daemon for IPFire # +# Copyright (C) 2025 IPFire Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include + +#include "ctx.h" +#include "daemon.h" +#include "graphs.h" + +struct collecty_graphs { + collecty_ctx* ctx; + int nrefs; + + // Daemon + collecty_daemon* daemon; +}; + +static void collecty_graphs_free(collecty_graphs* self) { + if (self->daemon) + collecty_daemon_unref(self->daemon); + if (self->ctx) + collecty_ctx_unref(self->ctx); + free(self); +} + +int collecty_graphs_create(collecty_graphs** graphs, + collecty_ctx* ctx, collecty_daemon* daemon) { + collecty_graphs* self = NULL; + + // Allocate some memory + self = calloc(1, sizeof(*self)); + if (!self) + return -errno; + + // Initialize the reference counter + self->nrefs = 1; + + // Store a reference to the context + self->ctx = collecty_ctx_ref(ctx); + + // Store a reference to the daemon + self->daemon = collecty_daemon_ref(daemon); + + // Return the pointer + *graphs = self; + return 0; +} + +collecty_graphs* collecty_graphs_ref(collecty_graphs* self) { + ++self->nrefs; + return self; +} + +collecty_graphs* collecty_graphs_unref(collecty_graphs* self) { + if (--self->nrefs > 0) + return self; + + collecty_graphs_free(self); + return NULL; +} diff --git a/src/daemon/graphs.h b/src/daemon/graphs.h new file mode 100644 index 0000000..92c2f0c --- /dev/null +++ b/src/daemon/graphs.h @@ -0,0 +1,34 @@ +/*############################################################################# +# # +# collecty - A system statistics collection daemon for IPFire # +# Copyright (C) 2025 IPFire Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef COLLECTY_GRAPHS_H +#define COLLECTY_GRAPHS_H + +typedef struct collecty_graphs collecty_graphs; + +#include "ctx.h" +#include "daemon.h" + +int collecty_graphs_create(collecty_graphs** graphs, collecty_ctx* ctx, collecty_daemon* daemon); + +collecty_graphs* collecty_graphs_ref(collecty_graphs* self); +collecty_graphs* collecty_graphs_unref(collecty_graphs* self); + +#endif /* COLLECTY_GRAPHS_H */ -- 2.47.3