]> git.ipfire.org Git - collecty.git/commitdiff
graph: Add a Render() method to the bus to render graphs
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Sep 2025 16:34:25 +0000 (16:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Sep 2025 16:34:25 +0000 (16:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph-bus.c
src/daemon/graph.c
src/daemon/graph.h

index f2820ece1aa066400a068ad7f82b816ae02ace15..b26ef6dcdd06c53011e162085ac25dbaab0678c5 100644 (file)
@@ -18,6 +18,8 @@
 #                                                                             #
 #############################################################################*/
 
+#include <stdlib.h>
+
 #include <systemd/sd-bus.h>
 
 #include "graph.h"
@@ -93,11 +95,53 @@ ERROR:
        return r;
 }
 
+static int collecty_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* error) {
+       collecty_graph* graph = data;
+       sd_bus_message* reply = NULL;
+       const char* format = NULL;
+       char* buffer = NULL;
+       size_t length = 0;
+       int r;
+
+       // Parse the arguments
+       r = sd_bus_message_read(m, "s", &format);
+       if (r < 0)
+               goto ERROR;
+
+       // Render the graph
+       r = collecty_graph_render(graph, format, &buffer, &length);
+       if (r < 0)
+               goto ERROR;
+
+       // Make the reply message
+       r = sd_bus_message_new_method_return(m, &reply);
+       if (r < 0)
+               goto ERROR;
+
+       // Append the graph
+       r = sd_bus_message_append_array(reply, 'y', buffer, length);
+       if (r < 0)
+               goto ERROR;
+
+       // Send the reply
+       r = sd_bus_send(NULL, reply, NULL);
+
+ERROR:
+       if (reply)
+               sd_bus_message_unref(reply);
+       if (buffer)
+               free(buffer);
+
+       return r;
+}
+
+
 static const sd_bus_vtable collecty_graph_vtable[] = {
        SD_BUS_VTABLE_START(0),
 
        // Operations
-       //XXX TODO
+       SD_BUS_METHOD_WITH_ARGS("Render", SD_BUS_ARGS("s", format), SD_BUS_RESULT("ay", graph),
+               collecty_graph_bus_render, SD_BUS_VTABLE_UNPRIVILEGED),
 
        SD_BUS_VTABLE_END
 };
index d03f8f1c370eed5b98dbd48020f2437905e85ce5..888a45ed8e8623a4abe42c7550837c47e5a79106 100644 (file)
@@ -104,3 +104,18 @@ char* collecty_graph_get_bus_path(collecty_graph* self) {
 
        return path;
 }
+
+int collecty_graph_render(collecty_graph* self,
+               const char* format, char** buffer, size_t* length) {
+       char* p = NULL;
+       int r;
+
+       r = asprintf(&p, "GRAPH");
+       if (r < 0)
+               return r;
+
+       *buffer = p;
+       *length = r;
+
+       return 0;
+}
index 8330c1e7fb451ebcc292881c9e9b7dab3532bfe7..01509be6a58e4e029aa9a36d9979b7ed5b6180d2 100644 (file)
@@ -42,4 +42,7 @@ collecty_graph* collecty_graph_unref(collecty_graph* self);
 const char* collecty_graph_get_name(collecty_graph* self);
 char* collecty_graph_get_bus_path(collecty_graph* self);
 
+int collecty_graph_render(collecty_graph* self,
+       const char* format, char** buffer, size_t* length);
+
 #endif /* COLLECTY_GRAPH_H */