xosview  1.23
About: xosview is an X Windows based system monitor (cpu, memory, swap and network usage; interrupt and serial activities; load average).
  Fossies Dox: xosview-1.23.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

sensor.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2012 by Tomi Tapper <tomi.o.tapper@jyu.fi>
3 //
4 // File based on linux/lmstemp.* by
5 // Copyright (c) 2000, 2006 by Leopold Toetsch <lt@toetsch.at>
6 //
7 // This file may be distributed under terms of the GPL
8 //
9 //
10 //
11 
12 #include "sensor.h"
13 #include "kernel.h"
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <math.h>
18 #include <string>
19 
20 
21 BSDSensor::BSDSensor( XOSView *parent, const char *name, const char *high,
22  const char *low, const char *label, const char *caption, int nbr )
23  : SensorFieldMeter( parent, label, caption, 1, 1, 0 ) {
24  nbr_ = nbr;
25  highname_[0] = highval_[0] = '\0';
26  lowname_[0] = lowval_[0] = '\0';
27  std::string n(name), tmp;
28  tmp = n.substr( 0, n.find_first_of('.') );
29  strncpy(name_, tmp.c_str(), NAMESIZE);
30  tmp = n.substr( n.find_first_of('.') + 1 );
31  strncpy(val_, tmp.c_str(), NAMESIZE);
32  if (high) {
33  has_high_ = true;
34  if ( sscanf(high, "%lf", &high_) == 0 ) { // high given as number?
35  n = high;
36  tmp = n.substr( 0, n.find_first_of('.') );
37  strncpy(highname_, tmp.c_str(), NAMESIZE);
38  tmp = n.substr( n.find_first_of('.') + 1 );
39  strncpy(highval_, tmp.c_str(), NAMESIZE);
40  }
41  }
42  if (low) {
43  has_low_ = true;
44  if ( sscanf(low, "%lf", &low_) == 0 ) { // low given as number?
45  n = low;
46  tmp = n.substr( 0, n.find_first_of('.') );
47  strncpy(lowname_, tmp.c_str(), NAMESIZE);
48  tmp = n.substr( n.find_first_of('.') + 1 );
49  strncpy(lowval_, tmp.c_str(), NAMESIZE);
50  }
51  }
52 }
53 
55 }
56 
59 
60  actcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorActColor" ) );
61  highcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorHighColor" ) );
62  lowcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorLowColor" ) );
64  setfieldcolor( 1, parent_->getResource( "bsdsensorIdleColor" ) );
66  priority_ = atoi( parent_->getResource( "bsdsensorPriority" ) );
67 
68  char s[32];
69  const char *tmp = parent_->getResourceOrUseDefault( "bsdsensorHighest", "0" );
70  snprintf(s, 32, "bsdsensorHighest%d", nbr_);
71  total_ = fabs( atof( parent_->getResourceOrUseDefault(s, tmp) ) );
72  snprintf(s, 32, "bsdsensorUsedFormat%d", nbr_);
73  const char *f = parent_->getResourceOrUseDefault(s, NULL);
74  SetUsedFormat( f ? f : parent_->getResource( "bsdsensorUsedFormat" ) );
75 
76  if (!has_high_)
77  high_ = total_;
78  if (!has_low_)
79  low_ = 0;
80 
81  // Get the unit.
82  float dummy;
83  BSDGetSensor(name_, val_, &dummy, unit_);
84  updateLegend();
85 }
86 
87 void BSDSensor::checkevent( void ) {
88  getsensor();
89  drawfields();
90 }
91 
92 void BSDSensor::getsensor( void ) {
93  float value, high = high_, low = low_;
94  BSDGetSensor(name_, val_, &value);
95  if ( strlen(highname_) )
97  if ( strlen(lowname_) )
99 
100  fields_[0] = value;
101  checkFields(low, high);
102 }
char lowname_[32]
Definition: sensor.h:34
const char * name(void) const
Definition: sensor.h:26
void checkResources(void)
Definition: sensor.cc:57
char lowval_[32]
Definition: sensor.h:35
char name_[32]
Definition: sensor.h:34
char highval_[32]
Definition: sensor.h:35
int nbr_
Definition: sensor.h:36
void getsensor(void)
Definition: sensor.cc:92
void checkevent(void)
Definition: sensor.cc:87
char val_[32]
Definition: sensor.h:35
char highname_[32]
Definition: sensor.h:34
~BSDSensor(void)
Definition: sensor.cc:54
BSDSensor(XOSView *parent, const char *name, const char *high, const char *low, const char *label, const char *caption, int nbr)
Definition: sensor.cc:21
double total_
Definition: fieldmeter.h:41
virtual void checkResources(void)
Definition: fieldmeter.cc:54
void setfieldcolor(int field, const char *color)
Definition: fieldmeter.cc:108
virtual void drawfields(int mandatory=0)
Definition: fieldmeter.cc:221
double * fields_
Definition: fieldmeter.h:40
void SetUsedFormat(const char *const str)
Definition: fieldmeter.cc:60
int priority_
Definition: meter.h:54
XOSView * parent_
Definition: meter.h:52
void checkFields(double low, double high)
void updateLegend(void)
unsigned long actcolor_
unsigned long lowcolor_
unsigned long highcolor_
unsigned long allocColor(const char *name)
Definition: xwin.cc:383
const char * getResourceOrUseDefault(const char *name, const char *defaultVal)
Definition: xwin.cc:351
const char * getResource(const char *name)
Definition: xwin.cc:362
void BSDGetSensor(const char *name, const char *valname, float *value, char *unit)
Definition: kernel.cc:1275
#define NAMESIZE
Definition: sensor.h:17