mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-12-04 21:58:18 +00:00
Add a parameter to sensors_get_detected_chips(), to optionally let the
caller select which subset of chips it wants. This is slightly better size-wise than letting all applications do the filtering by themselves. This will change the way the command line parameters of "sensors" are interpreted. Beforehand, the chips were always returned in the order in which they were listed by the library. Also, each chip could be listed only once. From now on, the chips will be listed in the order in which they are passed on the command line, which I think makes more sense. A side effect is that chips can be listed more than once, if that's what the user asks for. Not very useful though. This change makes it possible to make sensors_match_chip() internal to the library. Filtering the list of chips returned by sensors_get_detected_chips() was the last known external use for this function. This patch looks much bigger than it really is, but the largest part is really only code reindentation. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4701 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
ff4cfd53d5
commit
4d6bec8bb2
6 files changed
+76
-70
No files matched your search
+31
-33
@@ -139,41 +139,39 @@ applyToFeatures
|
||||
const sensors_chip_name *chip;
|
||||
int i = 0, j, ret = 0, num = 0;
|
||||
|
||||
while ((ret == 0) && ((chip = sensors_get_detected_chips (&i)) != NULL)) {
|
||||
for (j = 0; (ret == 0) && (j < numChipNames); ++ j) {
|
||||
if (sensors_match_chip (chip, &chipNames[j])) {
|
||||
int index0, subindex, chipindex = -1;
|
||||
for (index0 = 0; knownChips[index0]; ++ index0)
|
||||
for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex)
|
||||
if (!strcmp (chip->prefix, knownChips[index0]->names[subindex]))
|
||||
chipindex = index0;
|
||||
if (chipindex >= 0) {
|
||||
const ChipDescriptor *descriptor = knownChips[chipindex];
|
||||
const FeatureDescriptor *features = descriptor->features;
|
||||
for (j = 0; (ret == 0) && (j < numChipNames); ++ j) {
|
||||
while ((ret == 0) && ((chip = sensors_get_detected_chips (&chipNames[j], &i)) != NULL)) {
|
||||
int index0, subindex, chipindex = -1;
|
||||
for (index0 = 0; knownChips[index0]; ++ index0)
|
||||
for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex)
|
||||
if (!strcmp (chip->prefix, knownChips[index0]->names[subindex]))
|
||||
chipindex = index0;
|
||||
if (chipindex >= 0) {
|
||||
const ChipDescriptor *descriptor = knownChips[chipindex];
|
||||
const FeatureDescriptor *features = descriptor->features;
|
||||
|
||||
for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) {
|
||||
const FeatureDescriptor *feature = features + index0;
|
||||
int labelNumber = feature->dataNumbers[0];
|
||||
const char *rawLabel = NULL;
|
||||
char *label = NULL;
|
||||
int valid = 0;
|
||||
if (getValid (chip, labelNumber, &valid)) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor validity: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (getRawLabel (chip, labelNumber, &rawLabel)) {
|
||||
sensorLog (LOG_ERR, "Error getting raw sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (!(label = sensors_get_label (chip, labelNumber))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (valid) {
|
||||
rrdCheckLabel (rawLabel, num);
|
||||
ret = fn (data, rrdLabels[num], label, feature);
|
||||
++ num;
|
||||
}
|
||||
if (label)
|
||||
free (label);
|
||||
for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) {
|
||||
const FeatureDescriptor *feature = features + index0;
|
||||
int labelNumber = feature->dataNumbers[0];
|
||||
const char *rawLabel = NULL;
|
||||
char *label = NULL;
|
||||
int valid = 0;
|
||||
if (getValid (chip, labelNumber, &valid)) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor validity: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (getRawLabel (chip, labelNumber, &rawLabel)) {
|
||||
sensorLog (LOG_ERR, "Error getting raw sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (!(label = sensors_get_label (chip, labelNumber))) {
|
||||
sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber);
|
||||
ret = -1;
|
||||
} else if (valid) {
|
||||
rrdCheckLabel (rawLabel, num);
|
||||
ret = fn (data, rrdLabels[num], label, feature);
|
||||
++ num;
|
||||
}
|
||||
if (label)
|
||||
free (label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,11 +238,9 @@ doChips
|
||||
const sensors_chip_name *chip;
|
||||
int i = 0, j, ret = 0;
|
||||
|
||||
while ((ret == 0) && ((chip = sensors_get_detected_chips (&i)) != NULL)) {
|
||||
for (j = 0; (ret == 0) && (j < numChipNames); ++ j) {
|
||||
if (sensors_match_chip (chip, &chipNames[j])) {
|
||||
ret = doChip (chip, action);
|
||||
}
|
||||
for (j = 0; (ret == 0) && (j < numChipNames); ++ j) {
|
||||
while ((ret == 0) && ((chip = sensors_get_detected_chips (&chipNames[j], &i)) != NULL)) {
|
||||
ret = doChip (chip, action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -251,18 +251,18 @@ int do_the_real_work(int *error)
|
||||
int cnt = 0;
|
||||
|
||||
*error = 0;
|
||||
for (chip_nr = 0; (chip = sensors_get_detected_chips(&chip_nr));)
|
||||
for(i = 0; i < chips_count; i++)
|
||||
if (sensors_match_chip(chip, &chips[i])) {
|
||||
if(do_sets) {
|
||||
if (do_a_set(chip))
|
||||
*error = 1;
|
||||
} else
|
||||
do_a_print(chip);
|
||||
i = chips_count;
|
||||
cnt++;
|
||||
}
|
||||
return(cnt);
|
||||
for (i = 0; i < chips_count; i++) {
|
||||
chip_nr = 0;
|
||||
while ((chip = sensors_get_detected_chips(&chips[i], &chip_nr))) {
|
||||
if (do_sets) {
|
||||
if (do_a_set(chip))
|
||||
*error = 1;
|
||||
} else
|
||||
do_a_print(chip);
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/* returns 1 on error */
|
||||
|
||||
Reference in new issue
Block a user