From: Michael Tremer Date: Mon, 20 Oct 2025 14:16:56 +0000 (+0000) Subject: client: Pass the object in the options array X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=deef672bcfeda7dadb54aed1ae5770ec6e69c2d9;p=telemetry.git client: Pass the object in the options array This makes it all a little bit easier Signed-off-by: Michael Tremer --- diff --git a/src/client/main.c b/src/client/main.c index 0cf2a20..07776d9 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -41,6 +41,9 @@ typedef struct td_client_ctx { // Name of the graph const char* graph; + // Name of the object + const char* object; + // Output Format const char* format; @@ -97,14 +100,17 @@ static error_t parse(int key, char* arg, struct argp_state* state) { // Called for each argument case ARGP_KEY_ARG: // Take the graph name as first argument - if (!ctx->graph) { + if (!ctx->graph) ctx->graph = arg; - return 0; + + // Take the name of the object as second argument + else if (!ctx->object) + ctx->object = arg; // Otherwise show help - } else { + else argp_usage(state); - } + break; // Called once all arguments have been parsed @@ -142,16 +148,18 @@ static int render(td_client_ctx* ctx) { 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; + // Pass the object + if (ctx->object) { + r = sd_bus_message_append(m, "{sv}", "object", "s", ctx->object); + if (r < 0) + goto ERROR; + } + // Is available, add the desired output format if (ctx->format) { r = sd_bus_message_append(m, "{sv}", "format", "s", ctx->format); diff --git a/src/daemon/graph-bus.c b/src/daemon/graph-bus.c index e5e7c76..b93b332 100644 --- a/src/daemon/graph-bus.c +++ b/src/daemon/graph-bus.c @@ -106,15 +106,6 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro size_t length = 0; int r; - // Parse the arguments - r = sd_bus_message_read(m, "s", &object); - if (r < 0) - goto ERROR; - - // If an empty string has been sent, set it to NULL - if (object && !*object) - object = NULL; - // Open the options array r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}"); if (r < 0) @@ -134,8 +125,14 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro if (r < 0) goto ERROR; + // Parse "object" + if (td_string_equals(key, "object")) { + r = sd_bus_message_read(m, "v", "s", &object); + if (r < 0) + goto ERROR; + // Parse "format" - if (td_string_equals(key, "format")) { + } else if (td_string_equals(key, "format")) { r = sd_bus_message_read(m, "v", "s", &options.format); if (r < 0) goto ERROR; @@ -196,7 +193,7 @@ static const sd_bus_vtable td_graph_vtable[] = { SD_BUS_VTABLE_START(0), // Operations - SD_BUS_METHOD_WITH_ARGS("Render", SD_BUS_ARGS("s", graph, "a{sv}", options), SD_BUS_RESULT("ay", graph), + SD_BUS_METHOD_WITH_ARGS("Render", SD_BUS_ARGS("a{sv}", options), SD_BUS_RESULT("ay", graph), td_graph_bus_render, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END