Changeset 4668

Show
Ignore:
Timestamp:
08/13/07 22:19:44 (7 years ago)
Author:
khali
Message:

Pass structures by reference in sensors and sensord, again for a
small performance gain and better consistency with the new
libsensors API.

Location:
lm-sensors/branches/lm-sensors-3.0.0/prog
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/rrd.c

    r4666 r4668  
    158158            char *label = NULL; 
    159159            int valid = 0; 
    160             if (getValid (*chip, labelNumber, &valid)) { 
     160            if (getValid (chip, labelNumber, &valid)) { 
    161161              sensorLog (LOG_ERR, "Error getting sensor validity: %s/#%d", chip->prefix, labelNumber); 
    162162              ret = -1; 
    163             } else if (getRawLabel (*chip, labelNumber, &rawLabel)) { 
     163            } else if (getRawLabel (chip, labelNumber, &rawLabel)) { 
    164164              sensorLog (LOG_ERR, "Error getting raw sensor label: %s/#%d", chip->prefix, labelNumber); 
    165165              ret = -1; 
    166             } else if (getLabel (*chip, labelNumber, &label)) { 
     166            } else if (getLabel (chip, labelNumber, &label)) { 
    167167              sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber); 
    168168              ret = -1; 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sense.c

    r4666 r4668  
    3636int 
    3737getValid 
    38 (sensors_chip_name name, int feature, int *valid) { 
     38(const sensors_chip_name *name, int feature, int *valid) { 
    3939  int err; 
    4040  err = sensors_get_ignored (name, feature); 
     
    4848int 
    4949getLabel 
    50 (sensors_chip_name name, int feature, char **label) { 
     50(const sensors_chip_name *name, int feature, char **label) { 
    5151  int err; 
    52   err = sensors_get_label (&name, feature, label); 
     52  err = sensors_get_label (name, feature, label); 
    5353  return err; 
    5454} 
     
    5656int 
    5757getRawLabel 
    58 (sensors_chip_name name, int feature, const char **label) { 
     58(const sensors_chip_name *name, int feature, const char **label) { 
    5959  const sensors_feature_data *rawFeature; 
    6060  int nr1 = 0, nr2 = 0, err = 0; 
    6161  do { 
    62     rawFeature = sensors_get_all_features (&name, &nr1, &nr2); 
     62    rawFeature = sensors_get_all_features (name, &nr1, &nr2); 
    6363  } while (rawFeature && (rawFeature->number != feature)); 
    6464  /* TODO: Ensure labels match RRD construct and are not repeated! */ 
     
    111111    double value; 
    112112     
    113     if (getValid (*chip, sensor->number, &valid)) { 
     113    if (getValid (chip, sensor->number, &valid)) { 
    114114      sensorLog (LOG_ERR, "Error getting sensor validity: %s/%s", chip->prefix, sensor->name); 
    115115      ret = 20; 
    116     } else if (getLabel (*chip, sensor->number, &label)) { 
     116    } else if (getLabel (chip, sensor->number, &label)) { 
    117117      sensorLog (LOG_ERR, "Error getting sensor label: %s/%s", chip->prefix, sensor->name); 
    118118      ret = 21; 
     
    171171    if ((action == DO_SCAN) && !alarm) { 
    172172      continue; 
    173     } else if (getValid (*chip, labelNumber, &valid)) { 
     173    } else if (getValid (chip, labelNumber, &valid)) { 
    174174      sensorLog (LOG_ERR, "Error getting sensor validity: %s/#%d", chip->prefix, labelNumber); 
    175175      ret = 22; 
    176     } else if (getLabel (*chip, labelNumber, &label)) { 
     176    } else if (getLabel (chip, labelNumber, &label)) { 
    177177      sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber); 
    178178      ret = 22; 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sensord.h

    r2503 r4668  
    5959/* from sense.c */ 
    6060 
    61 extern int getValid (sensors_chip_name name, int feature, int *valid); 
    62 extern int getLabel (sensors_chip_name name, int feature, char **label); 
    63 extern int getRawLabel (sensors_chip_name name, int feature, const char **label); 
     61extern int getValid (const sensors_chip_name *name, int feature, int *valid); 
     62extern int getLabel (const sensors_chip_name *name, int feature, char **label); 
     63extern int getRawLabel (const sensors_chip_name *name, int feature, const char **label); 
    6464 
    6565extern int readChips (void); 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/main.c

    r4666 r4668  
    4747static void print_long_help(void); 
    4848static void print_version(void); 
    49 static void do_a_print(sensors_chip_name name); 
    50 static int do_a_set(sensors_chip_name name); 
     49static void do_a_print(const sensors_chip_name *name); 
     50static int do_a_set(const sensors_chip_name *name); 
    5151static int do_the_real_work(int *error); 
    52 static const char *sprintf_chip_name(sensors_chip_name name); 
     52static const char *sprintf_chip_name(const sensors_chip_name *name); 
    5353 
    5454#define CHIPS_MAX 20 
     
    262262      if (sensors_match_chip(chip, &chips[i])) { 
    263263        if(do_sets) { 
    264           if (do_a_set(*chip)) 
     264          if (do_a_set(chip)) 
    265265            *error = 1; 
    266266        } else 
    267           do_a_print(*chip); 
     267          do_a_print(chip); 
    268268        i = chips_count; 
    269269        cnt++; 
     
    273273 
    274274/* returns 1 on error */ 
    275 int do_a_set(sensors_chip_name name) 
     275int do_a_set(const sensors_chip_name *name) 
    276276{ 
    277277  int res; 
    278278 
    279   if ((res = sensors_do_chip_sets(&name))) { 
     279  if ((res = sensors_do_chip_sets(name))) { 
    280280    if (res == -SENSORS_ERR_PROC) { 
    281281      fprintf(stderr,"%s: %s for writing;\n",sprintf_chip_name(name), 
     
    294294} 
    295295 
    296 const char *sprintf_chip_name(sensors_chip_name name) 
     296const char *sprintf_chip_name(const sensors_chip_name *name) 
    297297{ 
    298298  #define BUF_SIZE 200 
    299299  static char buf[BUF_SIZE]; 
    300300 
    301   if (name.bus == SENSORS_CHIP_NAME_BUS_ISA) 
    302     snprintf(buf,BUF_SIZE,"%s-isa-%04x",name.prefix,name.addr); 
    303   else if (name.bus == SENSORS_CHIP_NAME_BUS_PCI) 
    304     snprintf(buf,BUF_SIZE,"%s-pci-%04x",name.prefix,name.addr); 
    305   else if (name.bus == SENSORS_CHIP_NAME_BUS_DUMMY) 
    306     snprintf(buf,BUF_SIZE,"%s-%s-%04x",name.prefix,name.busname,name.addr); 
     301  if (name->bus == SENSORS_CHIP_NAME_BUS_ISA) 
     302    snprintf(buf, BUF_SIZE, "%s-isa-%04x", name->prefix, name->addr); 
     303  else if (name->bus == SENSORS_CHIP_NAME_BUS_PCI) 
     304    snprintf(buf, BUF_SIZE, "%s-pci-%04x", name->prefix, name->addr); 
     305  else if (name->bus == SENSORS_CHIP_NAME_BUS_DUMMY) 
     306    snprintf(buf, BUF_SIZE, "%s-%s-%04x", name->prefix, name->busname, 
     307             name->addr); 
    307308  else 
    308     snprintf(buf,BUF_SIZE,"%s-i2c-%d-%02x",name.prefix,name.bus,name.addr); 
     309    snprintf(buf, BUF_SIZE, "%s-i2c-%d-%02x", name->prefix, name->bus, 
     310             name->addr); 
    309311  return buf; 
    310312} 
    311313 
    312 void do_a_print(sensors_chip_name name) 
     314void do_a_print(const sensors_chip_name *name) 
    313315{ 
    314316  if (hide_unknown) 
     
    317319  printf("%s\n",sprintf_chip_name(name)); 
    318320  if (!hide_adapter) { 
    319     const char *adap = sensors_get_adapter_name(name.bus); 
     321    const char *adap = sensors_get_adapter_name(name->bus); 
    320322    if (adap) 
    321323      printf("Adapter: %s\n", adap); 
    322324    else 
    323       fprintf(stderr, "Can't get adapter name for bus %d\n", name.bus); 
     325      fprintf(stderr, "Can't get adapter name for bus %d\n", name->bus); 
    324326  } 
    325327  if (do_unknown) 
    326     print_unknown_chip(&name); 
     328    print_unknown_chip(name); 
    327329  else 
    328     print_generic_chip(&name); 
     330    print_generic_chip(name); 
    329331  printf("\n"); 
    330332}