]> git.ipfire.org Git - collecty.git/commitdiff
graphs: Add scaffolding for a new object
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Sep 2025 17:13:19 +0000 (17:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Sep 2025 17:13:19 +0000 (17:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/graph-bus.c
src/daemon/graph.c [new file with mode: 0644]
src/daemon/graph.h [new file with mode: 0644]

index e03cbdb15b1b9286f4143f6bddc857675b8b8825..c5adb6b84fcebac14e54b35fed78f5b25875f8f2 100644 (file)
@@ -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 \
index 156498e054f03ef5caa6da4c84df329bcba06f07..8e5139c09162ac5ecff47385dee3d0ebf346f484 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <systemd/sd-bus.h>
 
+#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 (file)
index 0000000..ea0049b
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdlib.h>
+
+#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 (file)
index 0000000..0cf37b0
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#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 */