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:
Jean Delvare committed 2007-07-24 08:19:59 +00:00
1 parent a62ee5bac2
commit 6505fef0fd
5 files changed
+36 -43

No files matched your search

+4 -17
View File
@@ -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;
}