diff options
author | Jean Delvare <khali@linux-fr.org> | 2007-09-23 11:59:51 +0000 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2007-09-23 11:59:51 +0000 |
commit | 08a686e3cc35992ffe6de3be3d085edb34517547 (patch) | |
tree | 69c6f0d3a53a7924550156909fe6af12257500f4 | |
parent | 60b50b6cb96b982b640764d421ba0a13b2beb06d (diff) | |
download | lm-sensors-git-08a686e3cc35992ffe6de3be3d085edb34517547.tar.gz |
sensors_feature_data and sensors_chip_feature are now the exact
same structure, so we can get rid of the former for simpler code.
git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4830 7894878c-1315-0410-8ee3-d5d059ff63e0
-rw-r--r-- | lib/access.c | 64 | ||||
-rw-r--r-- | lib/access.h | 2 | ||||
-rw-r--r-- | lib/data.h | 18 | ||||
-rw-r--r-- | lib/init.c | 2 | ||||
-rw-r--r-- | lib/sensors.h | 14 | ||||
-rw-r--r-- | lib/sysfs.c | 58 |
6 files changed, 76 insertions, 82 deletions
diff --git a/lib/access.c b/lib/access.c index f8340f34..1de8e4af 100644 --- a/lib/access.c +++ b/lib/access.c @@ -89,7 +89,7 @@ sensors_for_all_config_chips(const sensors_chip_name *name, /* Look up a resource in the intern chip list, and return a pointer to it. Do not modify the struct the return value points to! Returns NULL if not found.*/ -const sensors_chip_feature *sensors_lookup_feature_nr(const sensors_chip_name *chip, +const sensors_feature_data *sensors_lookup_feature_nr(const sensors_chip_name *chip, int feature) { int i; @@ -107,17 +107,17 @@ const sensors_chip_feature *sensors_lookup_feature_nr(const sensors_chip_name *c /* Look up a resource in the intern chip list, and return a pointer to it. Do not modify the struct the return value points to! Returns NULL if not found.*/ -static const sensors_chip_feature * +static const sensors_feature_data * sensors_lookup_feature_name(const sensors_chip_name *chip, const char *feature) { int i, j; - const sensors_chip_feature *features; + const sensors_feature_data *features; for (i = 0; i < sensors_proc_chips_count; i++) if (sensors_match_chip(&sensors_proc_chips[i].chip, chip)) { features = sensors_proc_chips[i].feature; for (j = 0; j < sensors_proc_chips[i].feature_count; j++) - if (!strcmp(features[j].data.name, feature)) + if (!strcmp(features[j].name, feature)) return features + j; } return NULL; @@ -145,7 +145,7 @@ char *sensors_get_label(const sensors_chip_name *name, int feature) { char *label; const sensors_chip *chip; - const sensors_chip_feature *featureptr; + const sensors_feature_data *featureptr; char buf[128], path[PATH_MAX]; FILE *f; int i; @@ -157,14 +157,14 @@ char *sensors_get_label(const sensors_chip_name *name, int feature) for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));) for (i = 0; i < chip->labels_count; i++) - if (!strcmp(featureptr->data.name, chip->labels[i].name)) { + if (!strcmp(featureptr->name, chip->labels[i].name)) { label = strdup(chip->labels[i].value); goto sensors_get_label_exit; } /* No user specified label, check for a _label sysfs file */ snprintf(path, PATH_MAX, "%s/%s_label", name->path, - featureptr->data.name); + featureptr->name); if ((f = fopen(path, "r"))) { i = fread(buf, 1, sizeof(buf) - 1, f); @@ -178,7 +178,7 @@ char *sensors_get_label(const sensors_chip_name *name, int feature) } /* No label, return the feature name instead */ - label = strdup(featureptr->data.name); + label = strdup(featureptr->name); sensors_get_label_exit: if (!label) @@ -191,21 +191,21 @@ sensors_get_label_exit: 1 if it should be ignored, 0 if not. This function takes mappings into account. */ static int sensors_get_ignored(const sensors_chip_name *name, - const sensors_chip_feature *feature) + const sensors_feature_data *feature) { const sensors_chip *chip; const char *main_feature_name; int i; - if (feature->data.mapping == SENSORS_NO_MAPPING) + if (feature->mapping == SENSORS_NO_MAPPING) main_feature_name = NULL; else main_feature_name = sensors_lookup_feature_nr(name, - feature->data.mapping)->data.name; + feature->mapping)->name; for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));) for (i = 0; i < chip->ignores_count; i++) - if (!strcmp(feature->data.name, chip->ignores[i].name) || + if (!strcmp(feature->name, chip->ignores[i].name) || (main_feature_name && !strcmp(main_feature_name, chip->ignores[i].name))) return 1; @@ -218,8 +218,8 @@ static int sensors_get_ignored(const sensors_chip_name *name, int sensors_get_value(const sensors_chip_name *name, int feature, double *result) { - const sensors_chip_feature *main_feature; - const sensors_chip_feature *alt_feature; + const sensors_feature_data *main_feature; + const sensors_feature_data *alt_feature; const sensors_chip *chip; const sensors_expr *expr = NULL; double val; @@ -231,21 +231,21 @@ int sensors_get_value(const sensors_chip_name *name, int feature, if (!(main_feature = sensors_lookup_feature_nr(name, feature))) return -SENSORS_ERR_NO_ENTRY; - if (main_feature->data.flags & SENSORS_COMPUTE_MAPPING) + if (main_feature->flags & SENSORS_COMPUTE_MAPPING) alt_feature = sensors_lookup_feature_nr(name, - main_feature->data.mapping); + main_feature->mapping); else alt_feature = NULL; - if (!(main_feature->data.flags & SENSORS_MODE_R)) + if (!(main_feature->flags & SENSORS_MODE_R)) return -SENSORS_ERR_ACCESS_R; for (chip = NULL; !expr && (chip = sensors_for_all_config_chips(name, chip));) for (i = 0; !final_expr && (i < chip->computes_count); i++) { - if (!strcmp(main_feature->data.name, chip->computes[i].name)) { + if (!strcmp(main_feature->name, chip->computes[i].name)) { expr = chip->computes[i].from_proc; final_expr = 1; - } else if (alt_feature && !strcmp(alt_feature->data.name, + } else if (alt_feature && !strcmp(alt_feature->name, chip->computes[i].name)) { expr = chip->computes[i].from_proc; } @@ -265,8 +265,8 @@ int sensors_get_value(const sensors_chip_name *name, int feature, int sensors_set_value(const sensors_chip_name *name, int feature, double value) { - const sensors_chip_feature *main_feature; - const sensors_chip_feature *alt_feature; + const sensors_feature_data *main_feature; + const sensors_feature_data *alt_feature; const sensors_chip *chip; const sensors_expr *expr = NULL; int i, res; @@ -278,21 +278,21 @@ int sensors_set_value(const sensors_chip_name *name, int feature, if (!(main_feature = sensors_lookup_feature_nr(name, feature))) return -SENSORS_ERR_NO_ENTRY; - if (main_feature->data.flags & SENSORS_COMPUTE_MAPPING) + if (main_feature->flags & SENSORS_COMPUTE_MAPPING) alt_feature = sensors_lookup_feature_nr(name, - main_feature->data.mapping); + main_feature->mapping); else alt_feature = NULL; - if (!(main_feature->data.flags & SENSORS_MODE_W)) + if (!(main_feature->flags & SENSORS_MODE_W)) return -SENSORS_ERR_ACCESS_W; for (chip = NULL; !expr && (chip = sensors_for_all_config_chips(name, chip));) for (i = 0; !final_expr && (i < chip->computes_count); i++) - if (!strcmp(main_feature->data.name, chip->computes[i].name)) { + if (!strcmp(main_feature->name, chip->computes[i].name)) { expr = chip->computes->to_proc; final_expr = 1; - } else if (alt_feature && !strcmp(alt_feature->data.name, + } else if (alt_feature && !strcmp(alt_feature->name, chip->computes[i].name)) { expr = chip->computes[i].to_proc; } @@ -347,7 +347,7 @@ const char *sensors_get_adapter_name(const sensors_bus_id *bus) const sensors_feature_data *sensors_get_all_features(const sensors_chip_name *name, int *nr) { - sensors_chip_feature *feature_list; + sensors_feature_data *feature_list; int i; for (i = 0; i < sensors_proc_chips_count; i++) @@ -358,7 +358,7 @@ const sensors_feature_data *sensors_get_all_features(const sensors_chip_name *na (*nr)++; if (*nr == sensors_proc_chips[i].feature_count) return NULL; - return &feature_list[(*nr)++].data; + return &feature_list[(*nr)++]; } return NULL; } @@ -370,7 +370,7 @@ int sensors_eval_expr(const sensors_chip_name *name, { double res1, res2; int res; - const sensors_chip_feature *feature; + const sensors_feature_data *feature; if (expr->kind == sensors_kind_val) { *result = expr->data.val; @@ -384,7 +384,7 @@ int sensors_eval_expr(const sensors_chip_name *name, if (!(feature = sensors_lookup_feature_name(name, expr->data.var))) return SENSORS_ERR_NO_ENTRY; - if (!(res = sensors_get_value(name, feature->data.number, result))) + if (!(res = sensors_get_value(name, feature->number, result))) return res; return 0; } @@ -432,7 +432,7 @@ static int sensors_do_this_chip_sets(const sensors_chip_name *name) double value; int i, j; int err = 0, res; - const sensors_chip_feature *feature; + const sensors_feature_data *feature; int *feature_list = NULL; int feature_count = 0; int feature_max = 0; @@ -448,7 +448,7 @@ static int sensors_do_this_chip_sets(const sensors_chip_name *name) err = SENSORS_ERR_NO_ENTRY; continue; } - feature_nr = feature->data.number; + feature_nr = feature->number; /* Check whether we already set this feature */ for (j = 0; j < feature_count; j++) diff --git a/lib/access.h b/lib/access.h index e2073c4a..1aabbdf0 100644 --- a/lib/access.h +++ b/lib/access.h @@ -26,7 +26,7 @@ /* Look up a resource in the intern chip list, and return a pointer to it. Do not modify the struct the return value points to! Returns NULL if not found. */ -const sensors_chip_feature *sensors_lookup_feature_nr(const sensors_chip_name *chip, +const sensors_feature_data *sensors_lookup_feature_nr(const sensors_chip_name *chip, int feature); /* Check whether the chip name is an 'absolute' name, which can only match @@ -120,26 +120,10 @@ typedef struct sensors_bus { int lineno; } sensors_bus; -/* Internal data about a single chip feature. - name is the string name used to refer to this feature (both in config - files and through user functions); - number is the internal feature number, used in many functions to refer - to this feature - mapping is either SENSORS_NO_MAPPING if this is feature is the - main element of category; or it is the number of a feature with which - this feature is logically grouped (a group could be fan, fan_max and - fan_div) - flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable), - SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the - computation rules of the main feature). */ -typedef struct sensors_chip_feature { - sensors_feature_data data; -} sensors_chip_feature; - /* Internal data about all features of a type of chip */ typedef struct sensors_chip_features { struct sensors_chip_name chip; - struct sensors_chip_feature *feature; + struct sensors_feature_data *feature; int feature_count; } sensors_chip_features; @@ -57,7 +57,7 @@ static void free_chip_features(sensors_chip_features *features) int i; for (i = 0; i < features->feature_count; i++) - free(features->feature[i].data.name); + free(features->feature[i].name); free(features->feature); } diff --git a/lib/sensors.h b/lib/sensors.h index c7c5ffb4..d734224e 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -163,8 +163,18 @@ typedef enum sensors_feature_type { SENSORS_FEATURE_UNKNOWN = INT_MAX, } sensors_feature_type; -/* This structure is used when you want to get all features of a specific - chip. */ +/* Data about a single chip feature: + name is the string name used to refer to this feature (in config files) + number is the internal feature number, used in many functions to refer + to this feature + type is the feature or subfeature type + mapping is either SENSORS_NO_MAPPING if this is feature is the + main element of category; or it is the number of a feature with which + this subfeature is logically grouped (a group could be fan, fan_min + and fan_div) + flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable), + SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the + computation rules of the main feature) */ typedef struct sensors_feature_data { char *name; int number; diff --git a/lib/sysfs.c b/lib/sysfs.c index 0e7993a8..b4341f1d 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -161,8 +161,8 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, int i, type, fnum = 0; struct sysfs_attribute *attr; struct dlist *attrs; - sensors_chip_feature *features; - sensors_chip_feature *dyn_features; + sensors_feature_data *features; + sensors_feature_data *dyn_features; attrs = sysfs_get_device_attributes(sysdir); @@ -172,7 +172,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, /* We use a large sparse table at first to store all found features, so that we can store them sorted at type and index and then later create a dense sorted table. */ - features = calloc(ALL_POSSIBLE_FEATURES, sizeof(sensors_chip_feature)); + features = calloc(ALL_POSSIBLE_FEATURES, sizeof(sensors_feature_data)); if (!features) sensors_fatal_error(__FUNCTION__, "Out of memory"); @@ -217,7 +217,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, (type & 0x0F); } - if (features[i].data.name) { + if (features[i].name) { fprintf(stderr, "libsensors error, trying to add dupli" "cate feature: %s to dynamic feature table\n", name); @@ -225,29 +225,29 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, } /* fill in the feature members */ - features[i].data.type = type; + features[i].type = type; /* check for _input extension and remove */ nr = strlen(name); if (nr > 6 && !strcmp(name + nr - 6, "_input")) - features[i].data.name = strndup(name, nr - 6); + features[i].name = strndup(name, nr - 6); else - features[i].data.name = strdup(name); + features[i].name = strdup(name); if ((type & 0x00FF) == 0) { /* main feature */ - features[i].data.mapping = SENSORS_NO_MAPPING; + features[i].mapping = SENSORS_NO_MAPPING; } else { /* sub feature */ /* The mapping is set below after numbering */ if (!(type & 0x10)) - features[i].data.flags |= SENSORS_COMPUTE_MAPPING; + features[i].flags |= SENSORS_COMPUTE_MAPPING; } if (attr->method & SYSFS_METHOD_SHOW) - features[i].data.flags |= SENSORS_MODE_R; + features[i].flags |= SENSORS_MODE_R; if (attr->method & SYSFS_METHOD_STORE) - features[i].data.flags |= SENSORS_MODE_W; + features[i].flags |= SENSORS_MODE_W; fnum++; } @@ -257,14 +257,14 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, goto exit_free; } - dyn_features = calloc(fnum, sizeof(sensors_chip_feature)); + dyn_features = calloc(fnum, sizeof(sensors_feature_data)); if (dyn_features == NULL) { sensors_fatal_error(__FUNCTION__, "Out of memory"); } fnum = 0; for (i = 0; i < ALL_POSSIBLE_FEATURES; i++) { - if (features[i].data.name) { + if (features[i].name) { dyn_features[fnum] = features[i]; fnum++; } @@ -275,14 +275,14 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, for (i = 0; i < fnum; i++) { int j; - dyn_features[i].data.number = i; - if (dyn_features[i].data.mapping == SENSORS_NO_MAPPING) { + dyn_features[i].number = i; + if (dyn_features[i].mapping == SENSORS_NO_MAPPING) { /* Main feature, set the mapping field of all its subfeatures */ for (j = i + 1; j < fnum && - dyn_features[j].data.mapping != SENSORS_NO_MAPPING; + dyn_features[j].mapping != SENSORS_NO_MAPPING; j++) - dyn_features[j].data.mapping = i; + dyn_features[j].mapping = i; } } @@ -513,7 +513,7 @@ exit0: int sensors_read_sysfs_attr(const sensors_chip_name *name, int feature, double *value) { - const sensors_chip_feature *the_feature; + const sensors_feature_data *the_feature; char n[NAME_MAX]; FILE *f; const char *suffix = ""; @@ -522,19 +522,19 @@ int sensors_read_sysfs_attr(const sensors_chip_name *name, int feature, return -SENSORS_ERR_NO_ENTRY; /* REVISIT: this is a ugly hack */ - if (the_feature->data.type == SENSORS_FEATURE_IN - || the_feature->data.type == SENSORS_FEATURE_FAN - || the_feature->data.type == SENSORS_FEATURE_TEMP) + if (the_feature->type == SENSORS_FEATURE_IN + || the_feature->type == SENSORS_FEATURE_FAN + || the_feature->type == SENSORS_FEATURE_TEMP) suffix = "_input"; - snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->data.name, + snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->name, suffix); if ((f = fopen(n, "r"))) { int res = fscanf(f, "%lf", value); fclose(f); if (res != 1) return -SENSORS_ERR_PROC; - *value /= get_type_scaling(the_feature->data.type); + *value /= get_type_scaling(the_feature->type); } else return -SENSORS_ERR_PROC; @@ -544,7 +544,7 @@ int sensors_read_sysfs_attr(const sensors_chip_name *name, int feature, int sensors_write_sysfs_attr(const sensors_chip_name *name, int feature, double value) { - const sensors_chip_feature *the_feature; + const sensors_feature_data *the_feature; char n[NAME_MAX]; FILE *f; const char *suffix = ""; @@ -553,15 +553,15 @@ int sensors_write_sysfs_attr(const sensors_chip_name *name, int feature, return -SENSORS_ERR_NO_ENTRY; /* REVISIT: this is a ugly hack */ - if (the_feature->data.type == SENSORS_FEATURE_IN - || the_feature->data.type == SENSORS_FEATURE_FAN - || the_feature->data.type == SENSORS_FEATURE_TEMP) + if (the_feature->type == SENSORS_FEATURE_IN + || the_feature->type == SENSORS_FEATURE_FAN + || the_feature->type == SENSORS_FEATURE_TEMP) suffix = "_input"; - snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->data.name, + snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->name, suffix); if ((f = fopen(n, "w"))) { - value *= get_type_scaling(the_feature->data.type); + value *= get_type_scaling(the_feature->type); fprintf(f, "%d", (int) value); fclose(f); } else |