]> git.ipfire.org Git - telemetry.git/commitdiff
graphs: Declare the state struct globally
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Mar 2026 16:48:49 +0000 (16:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Mar 2026 16:48:49 +0000 (16:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph.h
src/daemon/graphs/processor-temperature.c

index 2c126f0fed110fae64d990a8584c3dd16d5251db..606b752f125b384d851128ec467676b720e449bc 100644 (file)
@@ -102,6 +102,22 @@ int td_graph_require_sources(td_graph* self,
 int td_graph_render(td_graph* self, const char* object,
        const td_graph_render_options* options, char** buffer, size_t* length);
 
+/*
+       This is a convenience type that can be used when the render state
+       has to be passed to a callback. Instead of defining it multiple times,
+       I felt that it was handy to define it globally.
+*/
+typedef struct td_graph_render_state {
+       // Graph
+       td_graph* graph;
+
+       // Options
+       const td_graph_render_options* options;
+
+       // Args
+       td_args* args;
+} td_graph_render_state;
+
 /*
        Temperatures
 */
index 361b938694fa5fe232a8de241f8298be2be5bedf..aa19b86d6e7b25ea28fa9b3025884e631ebfe5a4 100644 (file)
 #include "graph.h"
 #include "processor-temperature.h"
 
-typedef struct processor_temperature_state {
-       td_graph* graph;
-       const td_graph_render_options* options;
-       td_args* args;
-} processor_temperature_state;
-
 const char* supported_sensors[] = {
        // Intel
        "coretemp-*",
@@ -50,7 +44,7 @@ static int processor_temperature_title(td_ctx* ctx, td_graph* graph,
 static int processor_temperature_render_sensor(td_ctx* ctx, td_source* source,
                const sensors_feature_type type, const sensors_chip_name* chip,
                const sensors_feature* feature, void* data) {
-       const processor_temperature_state* state = data;
+       const td_graph_render_state* state = data;
        char name[NAME_MAX];
        int r;
 
@@ -83,7 +77,7 @@ static int processor_temperature_render_sensor(td_ctx* ctx, td_source* source,
 
 static int processor_temperature_render(td_ctx* ctx, td_graph* graph,
                const td_graph_render_options* options, td_args* args, const char* object) {
-       processor_temperature_state state = {
+       td_graph_render_state state = {
                .graph   = graph,
                .options = options,
                .args    = args,