"Fossies" - the Fresh Open Source Software Archive

Member "xosview-1.23/bsd/MeterMaker.cc" (11 Jul 2020, 4273 Bytes) of package /linux/misc/xosview-1.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "MeterMaker.cc" see the Fossies "Dox" file reference documentation.

    1 //
    2 //  Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov )
    3 //  Copyright (c) 1995, 1996, 1997-2002 by Brian Grayson (bgrayson@netbsd.org)
    4 //
    5 //  This file was written by Brian Grayson for the NetBSD and xosview
    6 //    projects.
    7 //  This file may be distributed under terms of the GPL or of the BSD
    8 //    license, whichever you choose.  The full license notices are
    9 //    contained in the files COPYING.GPL and COPYING.BSD, which you
   10 //    should have received.  If not, contact one of the xosview
   11 //    authors for a copy.
   12 //
   13 
   14 #include "MeterMaker.h"
   15 #include "defines.h"
   16 #include "kernel.h"
   17 #include "loadmeter.h"
   18 #include "cpumeter.h"
   19 #include "memmeter.h"
   20 #include "swapmeter.h"
   21 #include "pagemeter.h"
   22 #include "netmeter.h"
   23 #include "diskmeter.h"
   24 #include "intmeter.h"
   25 #include "intratemeter.h"
   26 #include "btrymeter.h"
   27 #if defined(__i386__) || defined(__x86_64__)
   28 #include "coretemp.h"
   29 #endif
   30 #include "sensor.h"
   31 
   32 #include <stdlib.h>
   33 #include <stdio.h>
   34 #include <string.h>
   35 #include <iostream>
   36 
   37 
   38 MeterMaker::MeterMaker(XOSView *xos) {
   39     _xos = xos;
   40 }
   41 
   42 void MeterMaker::makeMeters(void) {
   43     // Standard meters (usually added, but users could turn them off)
   44     if ( _xos->isResourceTrue("load") )
   45         push(new LoadMeter(_xos));
   46 
   47     if ( _xos->isResourceTrue("cpu") ) {
   48         bool single, both, all;
   49         unsigned int cpuCount = BSDCountCpus();
   50 
   51         single = ( strncmp(_xos->getResource("cpuFormat"), "single", 2) == 0 );
   52         both = ( strncmp(_xos->getResource("cpuFormat"), "both", 2) == 0 );
   53         all = ( strncmp(_xos->getResource("cpuFormat"), "all", 2) == 0 );
   54 
   55         if ( strncmp(_xos->getResource("cpuFormat"), "auto", 2) == 0 ) {
   56             if (cpuCount == 1 || cpuCount > 4)
   57                 single = true;
   58             else
   59                 all = true;
   60         }
   61 
   62         if (single || both)
   63             push(new CPUMeter(_xos, 0));
   64 
   65         if (all || both) {
   66             for (unsigned int i = 1; i <= cpuCount; i++)
   67                 push(new CPUMeter(_xos, i));
   68         }
   69     }
   70 
   71     if ( _xos->isResourceTrue("mem") )
   72         push(new MemMeter(_xos));
   73 
   74     if ( _xos->isResourceTrue("swap") )
   75         push(new SwapMeter(_xos));
   76 
   77     if ( _xos->isResourceTrue("page") )
   78         push(new PageMeter(_xos, atof(_xos->getResource("pageBandwidth"))));
   79 
   80     if ( _xos->isResourceTrue("net") )
   81         push(new NetMeter(_xos, atof(_xos->getResource("netBandwidth"))));
   82 
   83     if ( _xos->isResourceTrue("disk") )
   84         push(new DiskMeter(_xos, atof(_xos->getResource("diskBandwidth"))));
   85 
   86     if ( _xos->isResourceTrue("interrupts") )
   87         push(new IntMeter(_xos));
   88 
   89     if ( _xos->isResourceTrue("irqrate") )
   90         push(new IrqRateMeter(_xos));
   91 
   92     if ( _xos->isResourceTrue("battery") && BSDHasBattery() )
   93         push(new BtryMeter(_xos));
   94 
   95 #if defined(__i386__) || defined(__x86_64__)
   96     if ( _xos->isResourceTrue("coretemp") && CoreTemp::countCpus() > 0 ) {
   97         char caption[32];
   98         snprintf(caption, 32, "ACT(\260C)/HIGH/%s",
   99                  _xos->getResourceOrUseDefault( "coretempHighest", "100" ) );
  100         const char *displayType = _xos->getResourceOrUseDefault("coretempDisplayType", "separate");
  101         if (strncmp(displayType, "separate", 1) == 0) {
  102             char name[5];
  103             for (uint i = 0; i < CoreTemp::countCpus(); i++) {
  104                 snprintf(name, 5, "CPU%d", i);
  105                 push(new CoreTemp(_xos, name, caption, i));
  106             }
  107         }
  108         else if (strncmp(displayType, "average", 1) == 0)
  109             push(new CoreTemp(_xos, "CPU", caption, -1));
  110         else if (strncmp(displayType, "maximum", 1) == 0)
  111             push(new CoreTemp(_xos, "CPU", caption, -2));
  112         else {
  113             std::cerr << "Unknown value of coretempDisplayType: " << displayType << std::endl;
  114             _xos->done(1);
  115         }
  116     }
  117 #endif
  118 
  119     if ( _xos->isResourceTrue("bsdsensor") ) {
  120         char caption[16], l[8], s[16];
  121         for (int i = 1 ; ; i++) {
  122             snprintf(s, 16, "bsdsensorHighest%d", i);
  123             float highest = atof( _xos->getResourceOrUseDefault(s, "100") );
  124             snprintf(caption, 16, "ACT/HIGH/%f", highest);
  125             snprintf(s, 16, "bsdsensor%d", i);
  126             const char *name = _xos->getResourceOrUseDefault(s, NULL);
  127             if (!name || !*name)
  128                 break;
  129             snprintf(s, 16, "bsdsensorHigh%d", i);
  130             const char *high = _xos->getResourceOrUseDefault(s, NULL);
  131             snprintf(s, 16, "bsdsensorLow%d", i);
  132             const char *low = _xos->getResourceOrUseDefault(s, NULL);
  133             snprintf(s, 16, "bsdsensorLabel%d", i);
  134             snprintf(l, 8, "SEN%d", i);
  135             const char *label = _xos->getResourceOrUseDefault(s, l);
  136             push(new BSDSensor(_xos, name, high, low, label, caption, i));
  137         }
  138     }
  139 }