From: Michael Tremer Date: Mon, 29 Sep 2025 17:13:19 +0000 (+0000) Subject: graphs: Add scaffolding for a new object X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=40021af764c56e3eb23bc7f5e4d90313a748db9b;p=collecty.git graphs: Add scaffolding for a new object Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index e03cbdb..c5adb6b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -98,6 +98,8 @@ dist_collectyd_SOURCES = \ src/daemon/ctx.h \ src/daemon/daemon.c \ src/daemon/daemon.h \ + src/daemon/graph.c \ + src/daemon/graph.h \ src/daemon/graph-bus.c \ src/daemon/graph-bus.h \ src/daemon/logging.c \ diff --git a/src/daemon/graph-bus.c b/src/daemon/graph-bus.c index 156498e..8e5139c 100644 --- a/src/daemon/graph-bus.c +++ b/src/daemon/graph-bus.c @@ -20,6 +20,7 @@ #include +#include "graph.h" #include "graph-bus.h" static int collecty_graph_node_enumerator(sd_bus* bus, @@ -33,7 +34,6 @@ static int collecty_graph_node_enumerator(sd_bus* bus, static int collecty_graph_object_find(sd_bus* bus, const char* path, const char* interface, void* data, void** found, sd_bus_error* error) { -#if 0 collecty_daemon* daemon = data; collecty_graph* graph = NULL; char* name = NULL; @@ -44,14 +44,15 @@ static int collecty_graph_object_find(sd_bus* bus, const char* path, if (r <= 0) return 0; +#if 0 // Find the graph graph = collecty_daemon_get_graph_by_name(daemon, name); if (!graph) return 0; +#endif // Match! - *found = collecy_graph_unref(graph); -#endif + *found = collecty_graph_unref(graph); return 1; } diff --git a/src/daemon/graph.c b/src/daemon/graph.c new file mode 100644 index 0000000..ea0049b --- /dev/null +++ b/src/daemon/graph.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 "graph.h" + +struct collecty_graph { + collecty_ctx* ctx; + int nrefs; + + // Daemon + collecty_daemon* daemon; +}; + +static void collecty_graph_free(collecty_graph* self) { + if (self->daemon) + collecty_daemon_unref(self->daemon); + if (self->ctx) + collecty_ctx_unref(self->ctx); + free(self); +} + +int collecty_graph_create(collecty_graph** graph, + collecty_ctx* ctx, collecty_daemon* daemon) { + collecty_graph* 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 + *graph = self; + return 0; +} + +collecty_graph* collecty_graph_ref(collecty_graph* self) { + ++self->nrefs; + return self; +} + +collecty_graph* collecty_graph_unref(collecty_graph* self) { + if (--self->nrefs > 0) + return self; + + collecty_graph_free(self); + return NULL; +} diff --git a/src/daemon/graph.h b/src/daemon/graph.h new file mode 100644 index 0000000..0cf37b0 --- /dev/null +++ b/src/daemon/graph.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_GRAPH_H +#define COLLECTY_GRAPH_H + +typedef struct collecty_graph collecty_graph; + +#include "ctx.h" +#include "daemon.h" + +int collecty_graph_create(collecty_graph** graph, collecty_ctx* ctx, collecty_daemon* daemon); + +collecty_graph* collecty_graph_ref(collecty_graph* self); +collecty_graph* collecty_graph_unref(collecty_graph* self); + +#endif /* COLLECTY_GRAPH_H */