Show
Ignore:
Timestamp:
09/23/07 14:00:59 (6 years 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:
1 modified

Legend:

Unmodified
Added
Removed
  • 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: