mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-07 16:01:34 +00:00
The way we build the feature lists guarantees that subfeatures always
immediately follow their main feature. This makes it possible to simplify sensors_get_all_features() quite a bit. We no longer need to maintain separate pointers for the last main feature and the last subfeature, we can simply walk the list linearly. Note that I am still not entirely happy with this API. It was obviously designed for debugging purposes (sensors -u) and without performance concernes nor interface cleanliness in mind. I believe that we want to tag main features and subfeatures as such, and let the application ask specifically for the list of main features, and for each feature, for its list of subfeatures (i.e. two functions instead of one.) git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4643 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
a62ee5bac2
commit
6505fef0fd
5 files changed
+36
-43
No files matched your search
+4
-17
@@ -333,9 +333,9 @@ const char *sensors_get_adapter_name(int bus_nr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* nr1-1 is the last main feature found; nr2-1 is the last subfeature found */
|
||||
/* nr-1 is the last feature returned */
|
||||
const sensors_feature_data *sensors_get_all_features(sensors_chip_name name,
|
||||
int *nr1, int *nr2)
|
||||
int *nr)
|
||||
{
|
||||
sensors_chip_feature *feature_list;
|
||||
int i;
|
||||
@@ -343,22 +343,9 @@ const sensors_feature_data *sensors_get_all_features(sensors_chip_name name,
|
||||
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;
|
||||
if (!*nr1 && !*nr2) { /* Return the first entry */
|
||||
*nr1 = *nr2 = 1;
|
||||
return &feature_list->data;
|
||||
}
|
||||
for ((*nr2)++; feature_list[*nr2 - 1].data.name; (*nr2)++)
|
||||
if (feature_list[*nr2 - 1].data.mapping ==
|
||||
feature_list[*nr1 - 1].data.number)
|
||||
return &((feature_list + *nr2 - 1)->data);
|
||||
for ((*nr1)++;
|
||||
feature_list[*nr1 - 1].data.name
|
||||
&& (feature_list[*nr1 - 1].data.mapping !=
|
||||
SENSORS_NO_MAPPING); (*nr1)++) ;
|
||||
*nr2 = *nr1;
|
||||
if (!feature_list[*nr1 - 1].data.name)
|
||||
if (!feature_list[*nr].data.name)
|
||||
return NULL;
|
||||
return &((feature_list + *nr1 - 1)->data);
|
||||
return &feature_list[(*nr)++].data;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+9
-3
@@ -49,7 +49,7 @@ libsensors \- publicly accessible functions provided by the sensors library
|
||||
.B extern int sensors_do_all_sets(void);
|
||||
.B const sensors_chip_name *sensors_get_detected_chips(int *nr);
|
||||
.B const sensors_feature_data *sensors_get_all_features
|
||||
\fB(sensors_chip_name name, int *nr1,int *nr2);\fP
|
||||
\fB(sensors_chip_name name, int *nr);\fP
|
||||
.B const char *libsensors_version;
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
@@ -133,9 +133,15 @@ The mode field can be one of:
|
||||
SENSORS_MODE_NO_RW, SENSORS_MODE_R, SENSORS_MODE_W or SENSORS_MODE_RW.
|
||||
|
||||
\fBconst sensors_feature_data *sensors_get_all_features
|
||||
(sensors_chip_name name, int *nr1,int *nr2);\fP
|
||||
(sensors_chip_name name, int *nr);\fP
|
||||
.br
|
||||
This returns all features of a specific chip. They are returned in bunches: everything with the same mapping is returned just after each other, with the master feature in front (that feature does not map to itself, but has SENSORS_NO_MAPPING as mapping field). nr1 and nr2 are two internally used variables. Set both to zero to start again at the begin of the list. If no more features are found NULL is returned. Do not try to change the returned structure; you will corrupt internal data structures.
|
||||
This returns all features of a specific chip. They are returned in bunches:
|
||||
everything with the same mapping is returned just after each other, with
|
||||
the master feature in front (that feature does not map to itself, but
|
||||
has SENSORS_NO_MAPPING as mapping field). nr is an internally used variable.
|
||||
Set it to zero to start again at the begin of the list. If no more features
|
||||
are found NULL is returned. Do not try to change the returned structure; you
|
||||
will corrupt internal data structures.
|
||||
|
||||
\fBconst char *libsensors_version;\fP
|
||||
.br
|
||||
|
||||
+3
-3
@@ -179,13 +179,13 @@ typedef struct sensors_feature_data {
|
||||
/* This returns all features of a specific chip. They are returned in
|
||||
bunches: everything with the same mapping is returned just after each
|
||||
other, with the master feature in front (that feature does not map to
|
||||
itself, but has SENSORS_NO_MAPPING as mapping field). nr1 and nr2 are
|
||||
two internally used variables. Set both to zero to start again at the
|
||||
itself, but has SENSORS_NO_MAPPING as mapping field). nr is
|
||||
an internally used variable. Set it to zero to start again at the
|
||||
begin of the list. If no more features are found NULL is returned.
|
||||
Do not try to change the returned structure; you will corrupt internal
|
||||
data structures. */
|
||||
extern const sensors_feature_data *sensors_get_all_features
|
||||
(sensors_chip_name name, int *nr1,int *nr2);
|
||||
(sensors_chip_name name, int *nr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user