From: Michael Tremer Date: Fri, 10 Jul 2026 10:29:01 +0000 (+0000) Subject: source: Add convenience function to create a new request X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d8ff4a511e346a6781ac2b2e9f61ae8eafa78329;p=telemetry.git source: Add convenience function to create a new request Signed-off-by: Michael Tremer --- diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index e39c7a3..2e24bd6 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c @@ -480,6 +480,10 @@ struct udev* td_daemon_get_udev(td_daemon* self) { return udev_ref(self->udev); } +td_client* td_daemon_get_client(td_daemon* self) { + return td_client_ref(self->client); +} + td_sources* td_daemon_get_sources(td_daemon* self) { if (self->sources) return td_sources_ref(self->sources); diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h index f99b7e6..d514028 100644 --- a/src/daemon/daemon.h +++ b/src/daemon/daemon.h @@ -27,6 +27,7 @@ typedef struct td_daemon td_daemon; #include "bus.h" +#include "client.h" #include "ctx.h" #include "graphs.h" #include "metrics.h" @@ -45,6 +46,7 @@ int td_daemon_set_path(td_daemon* self, const char* path); sd_event* td_daemon_loop(td_daemon* self); struct udev* td_daemon_get_udev(td_daemon* self); +td_client* td_daemon_get_client(td_daemon* self); td_sources* td_daemon_get_sources(td_daemon* self); td_graphs* td_daemon_get_graphs(td_daemon* self); diff --git a/src/daemon/source.c b/src/daemon/source.c index 6382d50..c9e4617 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -640,6 +640,27 @@ ERROR: return r; } +int td_source_create_request(td_source* self, td_request** request) { + td_client* client = NULL; + int r; + + // Fetch the client + client = td_daemon_get_client(self->daemon); + if (!client) + return -errno; + + // Create the request + r = td_request_create(request, self->ctx, client); + if (r < 0) + goto ERROR; + +ERROR: + if (client) + td_client_unref(client); + + return r; +} + #define td_source_path(source, object, path) \ __td_source_path(source, object, path, sizeof(path)) diff --git a/src/daemon/source.h b/src/daemon/source.h index 67b2b2a..fcc180c 100644 --- a/src/daemon/source.h +++ b/src/daemon/source.h @@ -33,6 +33,7 @@ typedef struct td_source td_source; #include "daemon.h" #include "metrics.h" #include "netlink.h" +#include "request.h" #define MAX_DS 64 #define MAX_RRA 8 @@ -106,6 +107,8 @@ int td_source_create_command(td_source* self, td_command** command); int td_source_run_command(td_source* self, const cap_value_t* caps, const char** argv, td_command_success_callback callback, void* data); +int td_source_create_request(td_source* self, td_request** request); + int td_source_parse_metrics(td_source* self, const char* object, td_file* file, const td_metrics_parser* parser);