Changeset 4831

Show
Ignore:
Timestamp:
09/23/07 14:00:59 (1 year ago)
Author:
khali
Message:

Split sensors_get_all_features() into two distinct functions, one to
get the list of all main features, and one to get the list of all the
subfeatures of a given main feature. This is a more logical interface for
applications to use. The current implementation is admittedly less than
optimal, because the storage structures weren't meant for it, but this
issue can (and will) be addressed later.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/branches/lm-sensors-3.0.0/lib/access.c

    r4830 r4831  
    344344} 
    345345 
    346 /* nr-1 is the last feature returned */ 
    347 const sensors_feature_data *sensors_get_all_features(const sensors_chip_name *name, 
    348                                                      int *nr) 
     346static const sensors_feature_data * 
     347sensors_get_all_features(const sensors_chip_name *name, int *nr) 
    349348{ 
    350349        sensors_feature_data *feature_list; 
     
    362361                } 
    363362        return NULL; 
     363} 
     364 
     365const sensors_feature_data * 
     366sensors_get_features(const sensors_chip_name *name, int *nr) 
     367{ 
     368        const sensors_feature_data *feature; 
     369 
     370        while ((feature = sensors_get_all_features(name, nr))) { 
     371                if (feature->mapping == SENSORS_NO_MAPPING) 
     372                        return feature; 
     373        } 
     374        return NULL;    /* end of list */ 
     375} 
     376 
     377const sensors_feature_data * 
     378sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr) 
     379{ 
     380        const sensors_feature_data *subfeature; 
     381 
     382        /* Seek directly to the first subfeature */ 
     383        if (*nr < feature) 
     384                *nr = feature; 
     385 
     386        subfeature = sensors_get_all_features(name, nr); 
     387        if (!subfeature) 
     388                return NULL;    /* end of list */ 
     389        if (subfeature->number == feature || 
     390            subfeature->mapping == feature) 
     391                return subfeature; 
     392        return NULL;            /* end of subfeature list */ 
    364393} 
    365394 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/libsensors.3

    r4758 r4831  
    4545.B const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name 
    4646                                                    \fB*match, int *nr);\fP 
    47 .B const sensors_feature_data *sensors_get_all_features  
     47.B const sensors_feature_data *sensors_get_features 
    4848             \fB(const sensors_chip_name *name, int *nr);\fP 
     49.B const sensors_feature_data *sensors_get_all_subfeatures 
     50             \fB(const sensors_chip_name *name, int feature, int *nr);\fP 
    4951.B const char *libsensors_version; 
    5052.fi 
     
    122124(affected by the computation rules of the main feature). 
    123125 
    124 \fBconst sensors_feature_data *sensors_get_all_features 
    125       (const sensors_chip_name *name, int *nr);\fP 
     126\fBconst sensors_feature_data *sensors_get_features(const sensors_chip_name *name, int *nr);\fP 
    126127.br 
    127 This returns all features of a specific chip. They are returned in bunches: 
    128 everything with the same mapping is returned just after each other, with 
    129 the master feature in front (that feature does not map to itself, but 
    130 has SENSORS_NO_MAPPING as mapping field). nr is an internally used variable. 
    131 Set it to zero to start again at the begin of the list. If no more features 
    132 are found NULL is returned. Do not try to change the returned structure; you 
    133 will corrupt internal data structures. 
     128This returns all main features of a specific chip. nr is an internally 
     129used variable. Set it to zero to start at the begin of the list. If no 
     130more features are found NULL is returned. 
     131Do not try to change the returned structure; you will corrupt internal 
     132data structures. 
     133 
     134\fBconst sensors_feature_data *sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr);\fP 
     135.br 
     136This returns all subfeatures of a given main feature (including that 
     137main feature itself, in first position.) nr is an internally used 
     138variable. Set it to zero to start at the begin of the list. If no more 
     139features are found NULL is returned. 
     140Do not try to change the returned structure; you will corrupt internal 
     141data structures. 
    134142 
    135143\fBconst char *libsensors_version;\fP 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h

    r4830 r4831  
    184184} sensors_feature_data; 
    185185 
    186 /* This returns all features of a specific chip. They are returned in 
    187    bunches: everything with the same mapping is returned just after each 
    188    other, with the master feature in front (that feature does not map to 
    189    itself, but has SENSORS_NO_MAPPING as mapping field). nr is 
    190    an internally used variable. Set it to zero to start again at the 
    191    begin of the list. If no more features are found NULL is returned. 
     186/* This returns all main features of a specific chip. nr is an internally 
     187   used variable. Set it to zero to start at the begin of the list. If no 
     188   more features are found NULL is returned. 
    192189   Do not try to change the returned structure; you will corrupt internal 
    193190   data structures. */ 
    194 const sensors_feature_data *sensors_get_all_features 
    195                 (const sensors_chip_name *name, int *nr); 
     191const sensors_feature_data * 
     192sensors_get_features(const sensors_chip_name *name, int *nr); 
     193 
     194/* This returns all subfeatures of a given main feature (including that 
     195   main feature itself, in first position.) nr is an internally used 
     196   variable. Set it to zero to start at the begin of the list. If no more 
     197   features are found NULL is returned. 
     198   Do not try to change the returned structure; you will corrupt internal 
     199   data structures. */ 
     200const sensors_feature_data * 
     201sensors_get_all_subfeatures(const sensors_chip_name *name, int feature, int *nr); 
    196202 
    197203#ifdef __cplusplus 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/chips.c

    r4828 r4831  
    143143static void getAvailableFeatures (const sensors_chip_name *name, 
    144144                                  const sensors_feature_data *feature, 
    145                                   int i, short *has_features, 
     145                                  short *has_features, 
    146146                                  int *feature_nrs, int size, 
    147147                                  int first_val) 
    148148{ 
    149149  const sensors_feature_data *iter; 
    150  
    151   while ((iter = sensors_get_all_features (name, &i)) && 
    152          iter->mapping == feature->number) { 
     150  int i = 0; 
     151 
     152  while ((iter = sensors_get_all_subfeatures(name, feature->number, &i))) { 
    153153    int index0; 
    154154 
     
    167167static void fillChipVoltage (FeatureDescriptor *voltage, 
    168168                             const sensors_chip_name *name, 
    169                              const sensors_feature_data *feature, int i
     169                             const sensors_feature_data *feature
    170170{ 
    171171  const int size = SENSORS_FEATURE_IN_BEEP - SENSORS_FEATURE_IN; 
     
    178178  voltage->dataNumbers[pos++] = feature->number; 
    179179 
    180   getAvailableFeatures (name, feature, i, has_features, 
     180  getAvailableFeatures (name, feature, has_features, 
    181181                        feature_nrs, size, SENSORS_FEATURE_IN); 
    182182 
     
    215215static void fillChipTemperature (FeatureDescriptor *temperature, 
    216216                                 const sensors_chip_name *name, 
    217                                  const sensors_feature_data *feature, int i
     217                                 const sensors_feature_data *feature
    218218{ 
    219219  const int size = SENSORS_FEATURE_TEMP_BEEP - SENSORS_FEATURE_TEMP; 
     
    226226  temperature->dataNumbers[pos++] = feature->number; 
    227227 
    228   getAvailableFeatures (name, feature, i, has_features, 
     228  getAvailableFeatures (name, feature, has_features, 
    229229                        feature_nrs, size, SENSORS_FEATURE_TEMP); 
    230230 
     
    266266static void fillChipFan (FeatureDescriptor *fan, 
    267267                         const sensors_chip_name *name, 
    268                          const sensors_feature_data *feature, int i
     268                         const sensors_feature_data *feature
    269269{ 
    270270  const int size = SENSORS_FEATURE_FAN_BEEP - SENSORS_FEATURE_FAN; 
     
    277277  fan->dataNumbers[pos++] = feature->number; 
    278278 
    279   getAvailableFeatures (name, feature, i, has_features, 
     279  getAvailableFeatures (name, feature, has_features, 
    280280                        feature_nrs, size, SENSORS_FEATURE_FAN); 
    281281 
     
    342342        /* How many main features do we have? */ 
    343343        nr = 0; 
    344         while ((sensor = sensors_get_all_features(chip, &nr))) { 
    345                 if (sensor->mapping == SENSORS_NO_MAPPING) 
    346                         count++; 
    347         } 
     344        while ((sensor = sensors_get_features(chip, &nr))) 
     345                count++; 
    348346 
    349347        /* Allocate the memory we need */ 
     
    355353        count = 0; 
    356354        nr = 0; 
    357         while ((sensor = sensors_get_all_features(chip, &nr))) { 
    358                 if (sensor->mapping != SENSORS_NO_MAPPING) 
    359                         continue; 
    360  
     355        while ((sensor = sensors_get_features(chip, &nr))) { 
    361356                switch (sensor->type) { 
    362357                case SENSORS_FEATURE_TEMP: 
    363                         fillChipTemperature(&features[count], chip, sensor, nr); 
     358                        fillChipTemperature(&features[count], chip, sensor); 
    364359                        break; 
    365360                case SENSORS_FEATURE_IN: 
    366                         fillChipVoltage(&features[count], chip, sensor, nr); 
     361                        fillChipVoltage(&features[count], chip, sensor); 
    367362                        break; 
    368363                case SENSORS_FEATURE_FAN: 
    369                         fillChipFan(&features[count], chip, sensor, nr); 
     364                        fillChipFan(&features[count], chip, sensor); 
    370365                        break; 
    371366                case SENSORS_FEATURE_VID: 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sense.c

    r4828 r4831  
    3737getRawLabel 
    3838(const sensors_chip_name *name, int feature, const char **label) { 
    39   const sensors_feature_data *rawFeature; 
    40   int nr = 0, err = 0; 
    41   do { 
    42     rawFeature = sensors_get_all_features (name, &nr); 
    43   } while (rawFeature && (rawFeature->number != feature)); 
     39  const sensors_feature_data *mainfeat, *sub; 
     40  int a, b; 
     41 
     42  a = 0; 
     43  while ((mainfeat = sensors_get_features(name, &a))) { 
     44    b = 0; 
     45    while ((sub = sensors_get_all_subfeatures(name, mainfeat->number, &b))) { 
     46      if (sub->number == feature) { 
     47        *label = sub->name; 
     48        return 0; 
     49      } 
     50    } 
     51  } 
    4452  /* TODO: Ensure labels match RRD construct and are not repeated! */ 
    45   if (!rawFeature) { 
    46     err = -1; 
    47   } else { 
    48     *label = rawFeature->name; 
    49   } 
    50   return err; 
     53  return -1; 
    5154} 
    5255 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips.c

    r4822 r4831  
    3131void print_chip_raw(const sensors_chip_name *name) 
    3232{ 
    33         int a
    34         const sensors_feature_data *data
     33        int a, b
     34        const sensors_feature_data *feature, *sub
    3535        char *label; 
    3636        double val; 
    3737 
    3838        a = 0; 
    39         while ((data = sensors_get_all_features(name, &a))) { 
    40                 if (!(label = sensors_get_label(name, data->number))) { 
    41                         printf("ERROR: Can't get feature `%s' label!\n", 
    42                                data->name); 
    43                         continue; 
    44                 } 
    45                 if (data->flags & SENSORS_MODE_R) { 
    46                         if (sensors_get_value(name, data->number, &val)) 
    47                                 printf("ERROR: Can't get feature `%s' data!\n", 
    48                                        data->name); 
    49                         else if (data->mapping != SENSORS_NO_MAPPING) 
    50                                 printf("  %s: %.2f\n", label, val); 
    51                         else 
    52                                 printf("%s: %.2f (%s)\n", label, val, 
    53                                        data->name); 
    54                 } else 
    55                         printf("(%s)\n", label); 
    56                 free(label); 
     39        while ((feature = sensors_get_features(name, &a))) { 
     40                b = 0; 
     41                while ((sub = sensors_get_all_subfeatures(name, feature->number, 
     42                                                      &b))) { 
     43                        if (!(label = sensors_get_label(name, sub->number))) { 
     44                                printf("ERROR: Can't get feature `%s' label!\n", 
     45                                       sub->name); 
     46                                continue; 
     47                        } 
     48                        if (sub->flags & SENSORS_MODE_R) { 
     49                                if (sensors_get_value(name, sub->number, &val)) 
     50                                        printf("ERROR: Can't get feature `%s' " 
     51                                               "data!\n", sub->name); 
     52                                else if (sub->mapping != SENSORS_NO_MAPPING) 
     53                                        printf("  %s: %.2f\n", label, val); 
     54                                else 
     55                                        printf("%s: %.2f (%s)\n", label, val, 
     56                                               sub->name); 
     57                        } else 
     58                                printf("(%s)\n", label); 
     59                        free(label); 
     60                } 
    5761        } 
    5862} 
     
    7175static void sensors_get_available_features(const sensors_chip_name *name, 
    7276                                           const sensors_feature_data *feature, 
    73                                            int i, short *has_features, 
     77                                           short *has_features, 
    7478                                           double *feature_vals, int size, 
    7579                                           int first_val) 
    7680{ 
    7781        const sensors_feature_data *iter; 
    78  
    79         while ((iter = sensors_get_all_features(name, &i)) && 
    80                iter->mapping == feature->number) { 
     82        int i = 0; 
     83 
     84        while ((iter = sensors_get_all_subfeatures(name, feature->number, &i))) { 
    8185                int indx, err; 
    8286 
     
    105109 
    106110        i = 0; 
    107         while ((iter = sensors_get_all_features(name, &i))) { 
    108                 if (iter->mapping != SENSORS_NO_MAPPING) 
    109                         continue; 
     111        while ((iter = sensors_get_features(name, &i))) { 
    110112                if ((label = sensors_get_label(name, iter->number)) && 
    111113                    strlen(label) > max_size) 
     
    142144#define TEMP_FEATURE_VAL(x)     feature_vals[x - SENSORS_FEATURE_TEMP - 1] 
    143145static void print_chip_temp(const sensors_chip_name *name, 
    144                             const sensors_feature_data *feature, int i, 
     146                            const sensors_feature_data *feature, 
    145147                            int label_size) 
    146148{ 
     
    164166        } 
    165167 
    166         sensors_get_available_features(name, feature, i, has_features, 
     168        sensors_get_available_features(name, feature, has_features, 
    167169                                       feature_vals, size, 
    168170                                       SENSORS_FEATURE_TEMP); 
     
    280282#define IN_FEATURE_VAL(x)       feature_vals[x - SENSORS_FEATURE_IN - 1] 
    281283static void print_chip_in(const sensors_chip_name *name, 
    282                           const sensors_feature_data *feature, int i, 
     284                          const sensors_feature_data *feature, 
    283285                          int label_size) 
    284286{ 
     
    300302        } 
    301303 
    302         sensors_get_available_features(name, feature, i, has_features, 
     304        sensors_get_available_features(name, feature, has_features, 
    303305                                       feature_vals, size, SENSORS_FEATURE_IN); 
    304306 
     
    345347#define FAN_FEATURE_VAL(x)      feature_vals[x - SENSORS_FEATURE_FAN - 1] 
    346348static void print_chip_fan(const sensors_chip_name *name, 
    347                            const sensors_feature_data *feature, int i, 
     349                           const sensors_feature_data *feature, 
    348350                           int label_size) 
    349351{ 
     
    368370        free(label); 
    369371 
    370         sensors_get_available_features(name, feature, i, has_features, 
     372        sensors_get_available_features(name, feature, has_features, 
    371373                                       feature_vals, size, SENSORS_FEATURE_FAN); 
    372374 
     
    433435 
    434436        i = 0; 
    435         while ((feature = sensors_get_all_features(name, &i))) { 
    436                 if (feature->mapping != SENSORS_NO_MAPPING) 
    437                         continue; 
    438  
     437        while ((feature = sensors_get_features(name, &i))) { 
    439438                switch (feature->type) { 
    440439                case SENSORS_FEATURE_TEMP: 
    441                         print_chip_temp(name, feature, i, label_size); 
     440                        print_chip_temp(name, feature, label_size); 
    442441                        break; 
    443442                case SENSORS_FEATURE_IN: 
    444                         print_chip_in(name, feature, i, label_size); 
     443                        print_chip_in(name, feature, label_size); 
    445444                        break; 
    446445                case SENSORS_FEATURE_FAN: 
    447                         print_chip_fan(name, feature, i, label_size); 
     446                        print_chip_fan(name, feature, label_size); 
    448447                        break; 
    449448                case SENSORS_FEATURE_VID: