]> git.ipfire.org Git - telemetry.git/commitdiff
client: Pass the object in the options array
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 20 Oct 2025 14:16:56 +0000 (14:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 20 Oct 2025 14:16:56 +0000 (14:16 +0000)
This makes it all a little bit easier

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/client/main.c
src/daemon/graph-bus.c

index 0cf2a2098516c832c38f0bbee3540acae3af4a65..07776d99c2ec776dee16f2c90847c26923f3676b 100644 (file)
@@ -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);
index e5e7c767f02ffd48198506f5160519daf1b4ad2f..b93b33291f52bd6d249b726f82a26f9dc061095d 100644 (file)
@@ -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