mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-31 13:10:30 +00:00
Define a separate structure to represent main features. This allows
for faster main features lookup. One side effect of this change is that subfeatures can no longer have labels nor be ignored. I do not think that this is a problem in practice, and actually this makes a lot of sense. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4834 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
bfe337fe76
commit
96c914bfda
11 files changed
+160
-126
No files matched your search
+28
-36
@@ -141,30 +141,27 @@ int sensors_chip_name_has_wildcards(const sensors_chip_name *chip)
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself. */
|
||||
char *sensors_get_label(const sensors_chip_name *name, int feature)
|
||||
char *sensors_get_label(const sensors_chip_name *name,
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
char *label;
|
||||
const sensors_chip *chip;
|
||||
const sensors_subfeature *featureptr;
|
||||
char buf[128], path[PATH_MAX];
|
||||
FILE *f;
|
||||
int i;
|
||||
|
||||
if (sensors_chip_name_has_wildcards(name))
|
||||
return NULL;
|
||||
if (!(featureptr = sensors_lookup_feature_nr(name, feature)))
|
||||
return NULL;
|
||||
|
||||
for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
|
||||
for (i = 0; i < chip->labels_count; i++)
|
||||
if (!strcmp(featureptr->name, chip->labels[i].name)) {
|
||||
if (!strcmp(feature->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->name);
|
||||
snprintf(path, PATH_MAX, "%s/%s_label", name->path, feature->name);
|
||||
|
||||
if ((f = fopen(path, "r"))) {
|
||||
i = fread(buf, 1, sizeof(buf) - 1, f);
|
||||
@@ -178,7 +175,7 @@ char *sensors_get_label(const sensors_chip_name *name, int feature)
|
||||
}
|
||||
|
||||
/* No label, return the feature name instead */
|
||||
label = strdup(featureptr->name);
|
||||
label = strdup(feature->name);
|
||||
|
||||
sensors_get_label_exit:
|
||||
if (!label)
|
||||
@@ -188,26 +185,16 @@ sensors_get_label_exit:
|
||||
}
|
||||
|
||||
/* Looks up whether a feature should be ignored. Returns
|
||||
1 if it should be ignored, 0 if not. This function takes
|
||||
mappings into account. */
|
||||
1 if it should be ignored, 0 if not. */
|
||||
static int sensors_get_ignored(const sensors_chip_name *name,
|
||||
const sensors_subfeature *feature)
|
||||
const sensors_feature *feature)
|
||||
{
|
||||
const sensors_chip *chip;
|
||||
const char *main_feature_name;
|
||||
int i;
|
||||
|
||||
if (feature->mapping == SENSORS_NO_MAPPING)
|
||||
main_feature_name = NULL;
|
||||
else
|
||||
main_feature_name = sensors_lookup_feature_nr(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->name, chip->ignores[i].name) ||
|
||||
(main_feature_name &&
|
||||
!strcmp(main_feature_name, chip->ignores[i].name)))
|
||||
if (!strcmp(feature->name, chip->ignores[i].name))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -352,42 +339,47 @@ sensors_get_all_features(const sensors_chip_name *name, int *nr)
|
||||
for (i = 0; i < sensors_proc_chips_count; i++)
|
||||
if (sensors_match_chip(&sensors_proc_chips[i].chip, name)) {
|
||||
subfeature_list = sensors_proc_chips[i].subfeature;
|
||||
while (*nr < sensors_proc_chips[i].subfeature_count
|
||||
&& sensors_get_ignored(name, &subfeature_list[*nr]))
|
||||
(*nr)++;
|
||||
if (*nr == sensors_proc_chips[i].subfeature_count)
|
||||
if (*nr >= sensors_proc_chips[i].subfeature_count)
|
||||
return NULL;
|
||||
return &subfeature_list[(*nr)++];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const sensors_subfeature *
|
||||
const sensors_feature *
|
||||
sensors_get_features(const sensors_chip_name *name, int *nr)
|
||||
{
|
||||
const sensors_subfeature *feature;
|
||||
const sensors_feature *feature_list;
|
||||
int i;
|
||||
|
||||
while ((feature = sensors_get_all_features(name, nr))) {
|
||||
if (feature->mapping == SENSORS_NO_MAPPING)
|
||||
return feature;
|
||||
}
|
||||
for (i = 0; i < sensors_proc_chips_count; i++)
|
||||
if (sensors_match_chip(&sensors_proc_chips[i].chip, name)) {
|
||||
feature_list = sensors_proc_chips[i].feature;
|
||||
while (*nr < sensors_proc_chips[i].feature_count
|
||||
&& sensors_get_ignored(name, &feature_list[*nr]))
|
||||
(*nr)++;
|
||||
if (*nr >= sensors_proc_chips[i].feature_count)
|
||||
return NULL;
|
||||
return &feature_list[(*nr)++];
|
||||
}
|
||||
return NULL; /* end of list */
|
||||
}
|
||||
|
||||
const sensors_subfeature *
|
||||
sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr)
|
||||
sensors_get_all_subfeatures(const sensors_chip_name *name,
|
||||
const sensors_feature *feature, int *nr)
|
||||
{
|
||||
const sensors_subfeature *subfeature;
|
||||
|
||||
/* Seek directly to the first subfeature */
|
||||
if (*nr < feature)
|
||||
*nr = feature;
|
||||
if (*nr < feature->first_subfeature)
|
||||
*nr = feature->first_subfeature;
|
||||
|
||||
subfeature = sensors_get_all_features(name, nr);
|
||||
if (!subfeature)
|
||||
return NULL; /* end of list */
|
||||
if (subfeature->number == feature ||
|
||||
subfeature->mapping == feature)
|
||||
if (subfeature->number == feature->first_subfeature ||
|
||||
subfeature->mapping == feature->first_subfeature)
|
||||
return subfeature;
|
||||
return NULL; /* end of subfeature list */
|
||||
}
|
||||
|
||||
@@ -123,7 +123,9 @@ typedef struct sensors_bus {
|
||||
/* Internal data about all features of a type of chip */
|
||||
typedef struct sensors_chip_features {
|
||||
struct sensors_chip_name chip;
|
||||
struct sensors_feature *feature;
|
||||
struct sensors_subfeature *subfeature;
|
||||
int feature_count;
|
||||
int subfeature_count;
|
||||
} sensors_chip_features;
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ static void free_chip_features(sensors_chip_features *features)
|
||||
for (i = 0; i < features->subfeature_count; i++)
|
||||
free(features->subfeature[i].name);
|
||||
free(features->subfeature);
|
||||
for (i = 0; i < features->feature_count; i++)
|
||||
free(features->feature[i].name);
|
||||
free(features->feature);
|
||||
}
|
||||
|
||||
static void free_bus(sensors_bus *bus)
|
||||
|
||||
+7
-9
@@ -36,7 +36,7 @@ libsensors \- publicly accessible functions provided by the sensors library
|
||||
.B int sensors_parse_chip_name(const char *orig_name,
|
||||
\fBsensors_chip_name *res);\fP
|
||||
.B const char *sensors_get_adapter_name(int bus_nr);
|
||||
.B char *sensors_get_label(const sensors_chip_name *name, int feature);\fP
|
||||
.B char *sensors_get_label(const sensors_chip_name *name, const sensors_feature *feature);\fP
|
||||
.B int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
\fBdouble *value);\fP
|
||||
.B int sensors_set_value(const sensors_chip_name *name, int feature,
|
||||
@@ -44,10 +44,8 @@ libsensors \- publicly accessible functions provided by the sensors library
|
||||
.B int sensors_do_chip_sets(const sensors_chip_name *name);
|
||||
.B const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
|
||||
\fB*match, int *nr);\fP
|
||||
.B const sensors_feature_data *sensors_get_features
|
||||
\fB(const sensors_chip_name *name, int *nr);\fP
|
||||
.B const sensors_feature_data *sensors_get_all_subfeatures
|
||||
\fB(const sensors_chip_name *name, int feature, int *nr);\fP
|
||||
.B const sensors_feature *sensors_get_features(const sensors_chip_name *name, int *nr);\fP
|
||||
.B const sensors_subfeature *sensors_get_all_subfeatures(const sensors_chip_name *name, const sensors_feature *feature, int *nr);\fP
|
||||
.B const char *libsensors_version;
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
@@ -73,7 +71,7 @@ Parse a chip name to the internal representation. Return 0 on succes, <0 on erro
|
||||
This function returns the adapter name of a bus number, as used within the
|
||||
sensors_chip_name structure. If it could not be found, it returns NULL.
|
||||
|
||||
\fBchar *sensors_get_label(const sensors_chip_name *name, int feature);\fP
|
||||
\fBchar *sensors_get_label(const sensors_chip_name *name, const sensors_feature *feature);\fP
|
||||
.br
|
||||
Look up the label which belongs to this chip. Note that chip should not
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
@@ -124,7 +122,7 @@ The flags field 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).
|
||||
|
||||
\fBconst sensors_feature_data *sensors_get_features(const sensors_chip_name *name, int *nr);\fP
|
||||
\fBconst sensors_feature *sensors_get_features(const sensors_chip_name *name, int *nr);\fP
|
||||
.br
|
||||
This returns all main features of a specific chip. nr is an internally
|
||||
used variable. Set it to zero to start at the begin of the list. If no
|
||||
@@ -132,12 +130,12 @@ more features are found NULL is returned.
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures.
|
||||
|
||||
\fBconst sensors_feature_data *sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr);\fP
|
||||
\fBconst sensors_subfeature *sensors_get_all_subfeatures(const sensors_chip_name *name, const sensors_feature *feature, int *nr);\fP
|
||||
.br
|
||||
This returns all subfeatures of a given main feature (including that
|
||||
main feature itself, in first position.) nr is an internally used
|
||||
variable. Set it to zero to start at the begin of the list. If no more
|
||||
features are found NULL is returned.
|
||||
subfeatures are found NULL is returned.
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures.
|
||||
|
||||
|
||||
+14
-3
@@ -82,11 +82,14 @@ int sensors_snprintf_chip_name(char *str, size_t size,
|
||||
it returns NULL */
|
||||
const char *sensors_get_adapter_name(const sensors_bus_id *bus);
|
||||
|
||||
typedef struct sensors_feature sensors_feature;
|
||||
|
||||
/* Look up the label which belongs to this chip. Note that chip should not
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself. */
|
||||
char *sensors_get_label(const sensors_chip_name *name, int feature);
|
||||
char *sensors_get_label(const sensors_chip_name *name,
|
||||
const sensors_feature *feature);
|
||||
|
||||
/* Read the value of a feature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0
|
||||
@@ -163,6 +166,13 @@ typedef enum sensors_feature_type {
|
||||
SENSORS_FEATURE_UNKNOWN = INT_MAX,
|
||||
} sensors_feature_type;
|
||||
|
||||
/* Data about a single chip feature (or category leader) */
|
||||
struct sensors_feature {
|
||||
char *name;
|
||||
int first_subfeature;
|
||||
sensors_feature_type type;
|
||||
};
|
||||
|
||||
/* Data about a single chip subfeature:
|
||||
name is the string name used to refer to this subfeature (in config files)
|
||||
number is the internal subfeature number, used in many functions to refer
|
||||
@@ -188,7 +198,7 @@ typedef struct sensors_subfeature {
|
||||
more features are found NULL is returned.
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures. */
|
||||
const sensors_subfeature *
|
||||
const sensors_feature *
|
||||
sensors_get_features(const sensors_chip_name *name, int *nr);
|
||||
|
||||
/* This returns all subfeatures of a given main feature (including that
|
||||
@@ -198,7 +208,8 @@ sensors_get_features(const sensors_chip_name *name, int *nr);
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures. */
|
||||
const sensors_subfeature *
|
||||
sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr);
|
||||
sensors_get_all_subfeatures(const sensors_chip_name *name,
|
||||
const sensors_feature *feature, int *nr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+26
@@ -163,6 +163,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
struct dlist *attrs;
|
||||
sensors_subfeature *features;
|
||||
sensors_subfeature *dyn_subfeatures;
|
||||
sensors_feature *dyn_features;
|
||||
|
||||
attrs = sysfs_get_device_attributes(sysdir);
|
||||
|
||||
@@ -289,6 +290,31 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
chip->subfeature = dyn_subfeatures;
|
||||
chip->subfeature_count = fnum;
|
||||
|
||||
/* And now the main features */
|
||||
fnum = 0;
|
||||
for (i = 0; i < chip->subfeature_count; i++) {
|
||||
if (chip->subfeature[i].mapping == SENSORS_NO_MAPPING)
|
||||
fnum++;
|
||||
}
|
||||
|
||||
dyn_features = calloc(fnum, sizeof(sensors_feature));
|
||||
if (dyn_features == NULL) {
|
||||
sensors_fatal_error(__FUNCTION__, "Out of memory");
|
||||
}
|
||||
|
||||
fnum = 0;
|
||||
for (i = 0; i < chip->subfeature_count; i++) {
|
||||
if (chip->subfeature[i].mapping == SENSORS_NO_MAPPING) {
|
||||
dyn_features[fnum].name = strdup(chip->subfeature[i].name);
|
||||
dyn_features[fnum].first_subfeature = i;
|
||||
dyn_features[fnum].type = chip->subfeature[i].type;
|
||||
fnum++;
|
||||
}
|
||||
}
|
||||
|
||||
chip->feature = dyn_features;
|
||||
chip->feature_count = fnum;
|
||||
|
||||
exit_free:
|
||||
free(features);
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user