From b9b3813eff450a27b811bba35693f89d70e2ab4d Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Sun, 2 May 2021 22:46:03 +0200 Subject: Add finding functions by id and by name Signed-off-by: Daniel Lezcano --- src/libthermal/thermal.c | 31 +++++++++++++++++++++++++++++++ src/libthermal/thermal.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/src/libthermal/thermal.c b/src/libthermal/thermal.c index bbf9693..93a92b5 100644 --- a/src/libthermal/thermal.c +++ b/src/libthermal/thermal.c @@ -31,6 +31,37 @@ int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg) return ret; } +struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz, + const char *name) +{ + int i; + + if (!name) + return NULL; + + for (i = 0; tz[i].id != -1; i++) { + if (!strcmp(tz[i].name, name)) + return &tz[i]; + } + + return NULL; +} + +struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id) +{ + int i; + + if (id < 0) + return NULL; + + for (i = 0; tz[i].id != -1; i++) { + if (tz[i].id == id) + return &tz[i]; + } + + return NULL; +} + static int __thermal_zone_discover(struct thermal_zone *tz, void *th) { if (thermal_cmd_get_trip(th, tz) < 0) diff --git a/src/libthermal/thermal.h b/src/libthermal/thermal.h index e89a3ba..21d779d 100644 --- a/src/libthermal/thermal.h +++ b/src/libthermal/thermal.h @@ -95,6 +95,10 @@ int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg); int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg); +struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz, const char *name); + +struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id); + struct thermal_zone *thermal_zone_discover(struct thermal_handler *th); struct thermal_handler *thermal_init(struct thermal_ops *ops); -- cgit v1.2.3