}
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];
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;
}
ERROR:
+ if (reply)
+ sd_bus_message_unref(reply);
if (m)
sd_bus_message_unref(m);
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;
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)
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