Changeset 4643

Show
Ignore:
Timestamp:
07/24/07 10:19:59 (7 years ago)
Author:
khali
Message:

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.)

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
5 modified

Legend:

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

    r4642 r4643  
    334334} 
    335335 
    336 /* nr1-1 is the last main feature found; nr2-1 is the last subfeature found */ 
     336/* nr-1 is the last feature returned */ 
    337337const sensors_feature_data *sensors_get_all_features(sensors_chip_name name, 
    338                                                      int *nr1, int *nr2) 
     338                                                     int *nr) 
    339339{ 
    340340        sensors_chip_feature *feature_list; 
     
    344344                if (sensors_match_chip(sensors_proc_chips[i].chip, name)) { 
    345345                        feature_list = sensors_proc_chips[i].feature; 
    346                         if (!*nr1 && !*nr2) {   /* Return the first entry */ 
    347                                 *nr1 = *nr2 = 1; 
    348                                 return &feature_list->data; 
    349                         } 
    350                         for ((*nr2)++; feature_list[*nr2 - 1].data.name; (*nr2)++) 
    351                                 if (feature_list[*nr2 - 1].data.mapping == 
    352                                     feature_list[*nr1 - 1].data.number) 
    353                                         return &((feature_list + *nr2 - 1)->data); 
    354                         for ((*nr1)++; 
    355                              feature_list[*nr1 - 1].data.name 
    356                              && (feature_list[*nr1 - 1].data.mapping != 
    357                                  SENSORS_NO_MAPPING); (*nr1)++) ; 
    358                         *nr2 = *nr1; 
    359                         if (!feature_list[*nr1 - 1].data.name) 
     346                        if (!feature_list[*nr].data.name) 
    360347                                return NULL; 
    361                         return &((feature_list + *nr1 - 1)->data); 
     348                        return &feature_list[(*nr)++].data; 
    362349                } 
    363350        return NULL; 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/libsensors.3

    r4629 r4643  
    5050.B const sensors_chip_name *sensors_get_detected_chips(int *nr); 
    5151.B const sensors_feature_data *sensors_get_all_features  
    52              \fB(sensors_chip_name name, int *nr1,int *nr2);\fP 
     52             \fB(sensors_chip_name name, int *nr);\fP 
    5353.B const char *libsensors_version; 
    5454.fi 
     
    134134 
    135135\fBconst sensors_feature_data *sensors_get_all_features 
    136       (sensors_chip_name name, int *nr1,int *nr2);\fP 
     136      (sensors_chip_name name, int *nr);\fP 
    137137.br 
    138 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. 
     138This returns all features of a specific chip. They are returned in bunches: 
     139everything with the same mapping is returned just after each other, with 
     140the master feature in front (that feature does not map to itself, but 
     141has SENSORS_NO_MAPPING as mapping field). nr is an internally used variable. 
     142Set it to zero to start again at the begin of the list. If no more features 
     143are found NULL is returned. Do not try to change the returned structure; you 
     144will corrupt internal data structures. 
    139145 
    140146\fBconst char *libsensors_version;\fP 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h

    r4629 r4643  
    180180   bunches: everything with the same mapping is returned just after each 
    181181   other, with the master feature in front (that feature does not map to 
    182    itself, but has SENSORS_NO_MAPPING as mapping field). nr1 and nr2 are 
    183    two internally used variables. Set both to zero to start again at the 
     182   itself, but has SENSORS_NO_MAPPING as mapping field). nr is 
     183   an internally used variable. Set it to zero to start again at the 
    184184   begin of the list. If no more features are found NULL is returned. 
    185185   Do not try to change the returned structure; you will corrupt internal 
    186186   data structures. */ 
    187187extern const sensors_feature_data *sensors_get_all_features 
    188              (sensors_chip_name name, int *nr1,int *nr2); 
     188             (sensors_chip_name name, int *nr); 
    189189 
    190190#ifdef __cplusplus 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips.c

    r4578 r4643  
    119119void print_unknown_chip(const sensors_chip_name *name) 
    120120{ 
    121   int a,b,valid; 
     121  int a, valid; 
    122122  const sensors_feature_data *data; 
    123123  char *label; 
    124124  double val; 
    125125  
    126   a=b=0; 
    127   while((data=sensors_get_all_features(*name,&a,&b))) { 
     126  a = 0; 
     127  while((data=sensors_get_all_features(*name, &a))) { 
    128128    if (sensors_get_label_and_valid(*name,data->number,&label,&valid)) { 
    129129      printf("ERROR: Can't get feature `%s' data!\n",data->name); 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips_generic.c

    r4639 r4643  
    3636static void sensors_get_available_features(const sensors_chip_name *name,  
    3737                                           const sensors_feature_data *feature,  
    38                                            int i, int j,  
     38                                           int i, 
    3939                                           short *has_features,  
    4040                                           double *feature_vals,  
     
    4444  const sensors_feature_data *iter; 
    4545   
    46   while((iter = sensors_get_all_features(*name, &i, &j)) &&  
     46  while((iter = sensors_get_all_features(*name, &i)) && 
    4747      iter->mapping == feature->number) { 
    4848    int indx; 
     
    6363static int sensors_get_label_size(const sensors_chip_name *name) 
    6464{ 
    65   int i, j, valid; 
     65  int i, valid; 
    6666  const sensors_feature_data *iter; 
    6767  char *label; 
    6868  unsigned int max_size = 11; /* Initialised to 11 as minumum label-width */ 
    6969 
    70   i = j = 0; 
    71   while((iter = sensors_get_all_features(*name, &i, &j))) { 
     70  i = 0; 
     71  while((iter = sensors_get_all_features(*name, &i))) { 
    7272    if (!sensors_get_label_and_valid(*name, iter->number, &label, &valid) && 
    7373        valid && strlen(label) > max_size) 
     
    9090static void print_generic_chip_temp(const sensors_chip_name *name,  
    9191                                    const sensors_feature_data *feature, 
    92                                     int i, int j, int label_size) 
     92                                    int i, int label_size) 
    9393{ 
    9494  double val, max, min; 
     
    114114  } 
    115115   
    116   sensors_get_available_features(name, feature, i, j, has_features,  
     116  sensors_get_available_features(name, feature, i, has_features, 
    117117      feature_vals, size, SENSORS_FEATURE_TEMP); 
    118118   
     
    208208static void print_generic_chip_in(const sensors_chip_name *name,  
    209209                                  const sensors_feature_data *feature, 
    210                                   int i, int j, int label_size) 
     210                                  int i, int label_size) 
    211211{ 
    212212  const int size = SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN; 
     
    232232  } 
    233233   
    234   sensors_get_available_features(name, feature, i, j, has_features, feature_vals, 
     234  sensors_get_available_features(name, feature, i, has_features, feature_vals, 
    235235      size, SENSORS_FEATURE_IN); 
    236236   
     
    275275static void print_generic_chip_fan(const sensors_chip_name *name,  
    276276                                   const sensors_feature_data *feature, 
    277                                    int i, int j, int label_size) 
     277                                   int i, int label_size) 
    278278{ 
    279279  char *label; 
     
    309309    printf("%4.0f RPM", val); 
    310310   
    311   sensors_get_available_features(name, feature, i, j, has_features, feature_vals, 
     311  sensors_get_available_features(name, feature, i, has_features, feature_vals, 
    312312      size, SENSORS_FEATURE_FAN); 
    313313   
     
    333333{ 
    334334  const sensors_feature_data *feature; 
    335   int i,j, label_size; 
     335  int i, label_size; 
    336336   
    337337  label_size = sensors_get_label_size(name); 
    338338   
    339   i = j = 0; 
    340   while((feature = sensors_get_all_features(*name, &i, &j))) { 
     339  i = 0; 
     340  while((feature = sensors_get_all_features(*name, &i))) { 
    341341    if (feature->mapping != SENSORS_NO_MAPPING) 
    342342      continue; 
     
    344344    switch (feature->type) { 
    345345      case SENSORS_FEATURE_TEMP: 
    346         print_generic_chip_temp(name, feature, i, j, label_size); break; 
     346        print_generic_chip_temp(name, feature, i, label_size); break; 
    347347      case SENSORS_FEATURE_IN: 
    348         print_generic_chip_in(name, feature, i, j, label_size); break; 
     348        print_generic_chip_in(name, feature, i, label_size); break; 
    349349      case SENSORS_FEATURE_FAN: 
    350         print_generic_chip_fan(name, feature, i, j, label_size); break; 
     350        print_generic_chip_fan(name, feature, i, label_size); break; 
    351351      case SENSORS_FEATURE_VID: 
    352352        print_vid_info(name, feature->number, label_size); break;