From: Michael Tremer Date: Thu, 2 Oct 2025 19:26:02 +0000 (+0000) Subject: graph: Send further rendering options over dbus X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a7fef09c311477ac5fe8748898ab0906bb0a149;p=telemetry.git graph: Send further rendering options over dbus Signed-off-by: Michael Tremer --- diff --git a/src/client/main.c b/src/client/main.c index 7ecf036..1de55dd 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -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); diff --git a/src/daemon/graph-bus.c b/src/daemon/graph-bus.c index c5f51b3..ddae4e1 100644 --- a/src/daemon/graph-bus.c +++ b/src/daemon/graph-bus.c @@ -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