"Fossies" - the Fresh Open Source Software Archive 
Member "xosview-1.23/linux/MeterMaker.cc" (11 Jul 2020, 7997 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, 2002, 2006 by Mike Romberg ( mike.romberg@noaa.gov )
3 //
4 // This file may be distributed under terms of the GPL
5 //
6
7 #include "MeterMaker.h"
8 #include "xosview.h"
9
10 #include "loadmeter.h"
11 #include "cpumeter.h"
12 #include "memmeter.h"
13 #include "diskmeter.h"
14 #include "raidmeter.h"
15 #include "swapmeter.h"
16 #include "pagemeter.h"
17 #include "wirelessmeter.h"
18 #include "netmeter.h"
19 #include "nfsmeter.h"
20 #include "serialmeter.h"
21 #include "intmeter.h"
22 #include "intratemeter.h"
23 #include "btrymeter.h"
24 #if defined(__i386__) || defined(__x86_64__)
25 #include "coretemp.h"
26 #endif
27 #include "lmstemp.h"
28 #include "acpitemp.h"
29
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <fstream>
34 #include <iostream>
35 #include <sstream>
36 #include <iomanip>
37
38
39 MeterMaker::MeterMaker(XOSView *xos){
40 _xos = xos;
41 }
42
43 void MeterMaker::makeMeters(void){
44 // check for the load meter
45 if (_xos->isResourceTrue("load"))
46 push(new LoadMeter(_xos));
47
48 // Standard meters (usually added, but users could turn them off)
49 if (_xos->isResourceTrue("cpu")){
50 bool single, both, all;
51 unsigned int cpuCount = CPUMeter::countCPUs();
52
53 single = (strncmp(_xos->getResource("cpuFormat"), "single", 2) == 0);
54 both = (strncmp(_xos->getResource("cpuFormat"), "both", 2) == 0);
55 all = (strncmp(_xos->getResource("cpuFormat"), "all", 2) == 0);
56
57 if (strncmp(_xos->getResource("cpuFormat"), "auto", 2) == 0) {
58 if (cpuCount == 1 || cpuCount > 4) {
59 single = true;
60 } else {
61 all = true;
62 }
63 }
64
65 if (single || both)
66 push(new CPUMeter(_xos, CPUMeter::cpuStr(0)));
67
68 if (all || both) {
69 for (unsigned int i = 1; i <= cpuCount; i++)
70 push(new CPUMeter(_xos, CPUMeter::cpuStr(i)));
71 }
72 }
73 if (_xos->isResourceTrue("mem"))
74 push(new MemMeter(_xos));
75 if (_xos->isResourceTrue("disk"))
76 push(new DiskMeter(_xos, atof(_xos->getResource("diskBandwidth"))));
77
78 // check for the RAID meter
79 if (_xos->isResourceTrue("RAID")){
80 int RAIDCount = atoi(_xos->getResource("RAIDdevicecount"));
81 for (int i = 0 ; i < RAIDCount ; i++)
82 push(new RAIDMeter(_xos, i));
83 }
84
85 if (_xos->isResourceTrue("swap"))
86 push(new SwapMeter(_xos));
87
88 if (_xos->isResourceTrue("page"))
89 push(new PageMeter(_xos, atof(_xos->getResource("pageBandwidth"))));
90
91 // check for the wireless meter
92 if ( _xos->isResourceTrue("wireless") ) {
93 std::ifstream stats( WLFILENAME );
94 if (!stats)
95 std::cerr << "Wireless Meter needs Linux Wireless Extensions or cfg80211-"
96 << "WEXT compatibility to work." << std::endl;
97 else {
98 int count = WirelessMeter::countdevices();
99 for (int i = 0; i < count; i++)
100 push(new WirelessMeter(_xos, i, ( count == 1 ? "WLAN" : WirelessMeter::wirelessStr(i))));
101 }
102 }
103
104 // check for the net meter
105 if (_xos->isResourceTrue("net"))
106 push(new NetMeter(_xos, atof(_xos->getResource("netBandwidth"))));
107
108 // check for the NFS mesters
109 if (_xos->isResourceTrue("NFSDStats")){
110 push(new NFSDStats(_xos));
111 }
112 if (_xos->isResourceTrue("NFSStats")){
113 push(new NFSStats(_xos));
114 }
115
116
117 // check for the serial meters.
118 #if defined(__aarch64__) || defined (__arm__) || defined(__mc68000__) || defined(__powerpc__) || defined(__powerpc64__) || defined(__sparc__) || defined(__s390__) || defined(__s390x__)
119 /* these architectures have no ioperm() */
120 #else
121 for (int i = 0 ; i < SerialMeter::numDevices() ; i++)
122 {
123 bool ok ; unsigned long val ;
124 const char *res = SerialMeter::getResourceName((SerialMeter::Device)i);
125 if ( !(ok = _xos->isResourceTrue(res)) )
126 {
127 std::istringstream is(_xos->getResource(res));
128 is >> std::setbase(0) >> val;
129 if (!is)
130 ok = false;
131 else
132 ok = val & 0xFFFF;
133 }
134
135 if ( ok )
136 push(new SerialMeter(_xos, (SerialMeter::Device)i));
137 }
138 #endif
139
140 // check for the interrupt meter
141 if (_xos->isResourceTrue("interrupts")) {
142 int cpuCount = IntMeter::countCPUs();
143 cpuCount = cpuCount == 0 ? 1 : cpuCount;
144 if (_xos->isResourceTrue("intSeparate")) {
145 for (int i = 0 ; i < cpuCount ; i++)
146 push(new IntMeter(_xos, i));
147 }
148 else
149 push(new IntMeter(_xos, cpuCount-1));
150 }
151
152 // check for irqrate meter
153 if (_xos->isResourceTrue("irqrate"))
154 push(new IrqRateMeter(_xos));
155
156 // check for the battery meter
157 if (_xos->isResourceTrue("battery") && BtryMeter::has_source())
158 push(new BtryMeter(_xos));
159
160 #if defined(__i386__) || defined(__x86_64__)
161 // Check for the CPU temperature meter
162 if (_xos->isResourceTrue("coretemp")) {
163 char caption[32], name[8] = "CPU";
164 unsigned int coreCount, pkgCount, cpu, pkg = 0;
165 snprintf(caption, 32, "ACT(\260C)/HIGH/%s",
166 _xos->getResourceOrUseDefault( "coretempHighest", "100" ) );
167 const char *displayType = _xos->getResourceOrUseDefault( "coretempDisplayType", "separate" );
168
169 pkgCount = CoreTemp::countCpus();
170 if ( strncmp(displayType, "separate", 1) == 0 ) {
171 for (pkg = 0; pkg < pkgCount; pkg++) {
172 coreCount = CoreTemp::countCores(pkg);
173 for (cpu = 0; cpu < coreCount; cpu++) {
174 if (pkgCount > 1) {
175 if (cpu == 0) // give title only to first core of each physical cpu
176 snprintf(name, 8, "CPU%d", pkg);
177 else
178 name[0] = '\0';
179 }
180 else {
181 if (coreCount > 1)
182 snprintf(name, 8, "CPU%d", cpu);
183 }
184 push(new CoreTemp(_xos, name, caption, pkg, cpu));
185 }
186 }
187 }
188 else if ( strncmp(displayType, "average", 1) == 0 ) {
189 do {
190 if (pkgCount > 1)
191 snprintf(name, 8, "CPU%d", pkg);
192 push(new CoreTemp(_xos, name, caption, pkg, -1));
193 } while (++pkg < pkgCount);
194 }
195 else if ( strncmp(displayType, "maximum", 1) == 0 ) {
196 do {
197 if (pkgCount > 1)
198 snprintf(name, 8, "CPU%d", pkg);
199 push(new CoreTemp(_xos, name, caption, pkg, -2));
200 } while (++pkg < pkgCount);
201 }
202 else {
203 std::cerr << "Unknown value of coretempDisplayType: " << displayType << std::endl;
204 std::cerr << "Supported types are: separate, average and maximum." << std::endl;
205 _xos->done(1);
206 }
207 }
208 #endif
209
210 // check for the LmsTemp meter
211 if (_xos->isResourceTrue("lmstemp")){
212 char caption[16], s[16];
213 const char *tempfile, *highfile, *lowfile, *name, *label;
214 snprintf( caption, 16, "ACT/HIGH/%s",
215 _xos->getResourceOrUseDefault("lmstempHighest", "100") );
216 for (int i = 1 ; ; i++) {
217 snprintf(s, 16, "lmstemp%d", i);
218 tempfile = _xos->getResourceOrUseDefault(s, NULL);
219 if (!tempfile || !*tempfile)
220 break;
221 snprintf(s, 16, "lmshigh%d", i);
222 highfile = _xos->getResourceOrUseDefault(s, NULL);
223 snprintf(s, 16, "lmslow%d", i);
224 lowfile = _xos->getResourceOrUseDefault(s, NULL);
225 snprintf(s, 16, "lmsname%d", i);
226 name = _xos->getResourceOrUseDefault(s, NULL);
227 snprintf(s, 16, "lmstempLabel%d", i);
228 label = _xos->getResourceOrUseDefault(s, "TMP");
229 push(new LmsTemp(_xos, name, tempfile, highfile, lowfile, label, caption, i));
230 }
231 }
232
233 // check for the ACPITemp meter
234 if (_xos->isResourceTrue("acpitemp")) {
235 char caption[32];
236 snprintf(caption, 32, "ACT(\260C)/HIGH/%s",
237 _xos->getResourceOrUseDefault("acpitempHighest", "100"));
238 for (int i = 1 ; ; i++) {
239 char s[16];
240 snprintf(s, 16, "acpitemp%d", i);
241 const char *tempfile = _xos->getResourceOrUseDefault(s, NULL);
242 if (!tempfile || !*tempfile)
243 break;
244 snprintf(s, 16, "acpihigh%d", i);
245 const char *highfile = _xos->getResourceOrUseDefault(s, NULL);
246 if (!highfile || !*highfile)
247 break;
248 snprintf(s, 16, "acpitempLabel%d", i);
249 const char *lab = _xos->getResourceOrUseDefault(s, "TMP");
250 push(new ACPITemp(_xos, tempfile, highfile, lab, caption));
251 }
252 }
253 }