# #
#############################################################################*/
+#include <stdlib.h>
+
#include <systemd/sd-bus.h>
#include "graph.h"
return r;
}
+static int collecty_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* error) {
+ collecty_graph* graph = data;
+ sd_bus_message* reply = NULL;
+ const char* format = NULL;
+ char* buffer = NULL;
+ size_t length = 0;
+ int r;
+
+ // Parse the arguments
+ r = sd_bus_message_read(m, "s", &format);
+ if (r < 0)
+ goto ERROR;
+
+ // Render the graph
+ r = collecty_graph_render(graph, format, &buffer, &length);
+ if (r < 0)
+ goto ERROR;
+
+ // Make the reply message
+ r = sd_bus_message_new_method_return(m, &reply);
+ if (r < 0)
+ goto ERROR;
+
+ // Append the graph
+ r = sd_bus_message_append_array(reply, 'y', buffer, length);
+ if (r < 0)
+ goto ERROR;
+
+ // Send the reply
+ r = sd_bus_send(NULL, reply, NULL);
+
+ERROR:
+ if (reply)
+ sd_bus_message_unref(reply);
+ if (buffer)
+ free(buffer);
+
+ return r;
+}
+
+
static const sd_bus_vtable collecty_graph_vtable[] = {
SD_BUS_VTABLE_START(0),
// Operations
- //XXX TODO
+ SD_BUS_METHOD_WITH_ARGS("Render", SD_BUS_ARGS("s", format), SD_BUS_RESULT("ay", graph),
+ collecty_graph_bus_render, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END
};
return path;
}
+
+int collecty_graph_render(collecty_graph* self,
+ const char* format, char** buffer, size_t* length) {
+ char* p = NULL;
+ int r;
+
+ r = asprintf(&p, "GRAPH");
+ if (r < 0)
+ return r;
+
+ *buffer = p;
+ *length = r;
+
+ return 0;
+}
const char* collecty_graph_get_name(collecty_graph* self);
char* collecty_graph_get_bus_path(collecty_graph* self);
+int collecty_graph_render(collecty_graph* self,
+ const char* format, char** buffer, size_t* length);
+
#endif /* COLLECTY_GRAPH_H */