]> git.ipfire.org Git - collecty.git/commitdiff
graph: Send further rendering options over dbus
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 19:26:02 +0000 (19:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 19:26:02 +0000 (19:26 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/client/main.c
src/daemon/graph-bus.c

index 7ecf036a915be5eac9a1563bb7f11023c6fb39d8..1de55dd5f2e4197ecbe730df6016d5dbb54f4a4f 100644 (file)
@@ -94,6 +94,7 @@ static error_t parse(int key, char* arg, struct argp_state* state) {
 }
 
 static int render(collecty_client_ctx* ctx) {
+       sd_bus_message* reply = NULL;
        const void* buffer = NULL;
        sd_bus_message* m = NULL;
        char path[PATH_MAX];
@@ -106,16 +107,57 @@ static int render(collecty_client_ctx* ctx) {
        if (r < 0)
                goto ERROR;
 
-       // Call the render function
-       r = sd_bus_call_method(ctx->bus, "org.ipfire.collecty1", path,
-                       "org.ipfire.collecty1.Graph", "Render", NULL, &m, "s", "");
+       // Prepare to call the render function
+       r = sd_bus_message_new_method_call(ctx->bus, &m,
+                       "org.ipfire.collecty1", path, "org.ipfire.collecty1.Graph", "Render");
+       if (r < 0)
+               goto ERROR;
+
+       // Append the object
+       r = sd_bus_message_append(m, "s", "");
+       if (r < 0)
+               goto ERROR;
+
+       // Add an array for more configuration options
+       r = sd_bus_message_open_container(m, 'a', "{sv}");
+       if (r < 0)
+               goto ERROR;
+
+       // Is available, add the desired output format
+       if (ctx->format) {
+               r = sd_bus_message_open_container(m, 'e', "sv");
+               if (r < 0)
+                       goto ERROR;
+
+               // Add key
+               r = sd_bus_message_append(m, "s", "format");
+               if (r < 0)
+                       goto ERROR;
+
+               // Add the value
+               r = sd_bus_message_append(m, "v", "s", ctx->format);
+               if (r < 0)
+                       goto ERROR;
+
+               r = sd_bus_message_close_container(m);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+       // Close the array
+       r = sd_bus_message_close_container(m);
+       if (r < 0)
+               goto ERROR;
+
+       // Call the message
+       r = sd_bus_call(ctx->bus, m, 0, NULL, &reply);
        if (r < 0) {
                perror("Failed to call the Render() method");
                goto ERROR;
        }
 
        // Read the response
-       r = sd_bus_message_read_array(m, 'y', &buffer, &length);
+       r = sd_bus_message_read_array(reply, 'y', &buffer, &length);
        if (r < 0) {
                perror("Failed to read the response");
                goto ERROR;
@@ -130,6 +172,8 @@ static int render(collecty_client_ctx* ctx) {
        }
 
 ERROR:
+       if (reply)
+               sd_bus_message_unref(reply);
        if (m)
                sd_bus_message_unref(m);
 
index c5f51b36fc10a4a80427df1756d815d5b78af4eb..ddae4e1bac18f7467e8e3e351a9ecfba2a495c32 100644 (file)
@@ -100,6 +100,7 @@ static int collecty_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error
        collecty_graph* graph = data;
        sd_bus_message* reply = NULL;
        const char* object = NULL;
+       const char* key = NULL;
        char* buffer = NULL;
        size_t length = 0;
        int r;
@@ -113,6 +114,43 @@ static int collecty_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error
        if (object && !*object)
                object = NULL;
 
+       // Open the options array
+       r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}");
+       if (r < 0)
+               goto ERROR;
+
+       for (;;) {
+               r = sd_bus_message_enter_container(m, SD_BUS_TYPE_DICT_ENTRY, "sv");
+               if (r < 0)
+                       goto ERROR;
+
+               // Break if we have read everything
+               if (r == 0)
+                       break;
+
+               // Read the key
+               r = sd_bus_message_read(m, "s", &key);
+               if (r < 0)
+                       goto ERROR;
+
+               // Parse the values
+               if (strcmp(key, "format") == 0) {
+                       r = sd_bus_message_read(m, "v", "s", &options.format);
+                       if (r < 0)
+                               goto ERROR;
+               }
+
+               // Leave the container
+               r = sd_bus_message_exit_container(m);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+       // Leave the outer container
+       r = sd_bus_message_exit_container(m);
+       if (r < 0)
+               goto ERROR;
+
        // Render the graph
        r = collecty_graph_render(graph, object, &options, &buffer, &length);
        if (r < 0)
@@ -145,7 +183,7 @@ static const sd_bus_vtable collecty_graph_vtable[] = {
        SD_BUS_VTABLE_START(0),
 
        // Operations
-       SD_BUS_METHOD_WITH_ARGS("Render", SD_BUS_ARGS("s", object), SD_BUS_RESULT("ay", graph),
+       SD_BUS_METHOD_WITH_ARGS("Render", SD_BUS_ARGS("s", graph, "a{sv}", options), SD_BUS_RESULT("ay", graph),
                collecty_graph_bus_render, SD_BUS_VTABLE_UNPRIVILEGED),
 
        SD_BUS_VTABLE_END