Decouple Header from Meter classes.

(Yes, that's dynamic typing!)
This commit is contained in:
Hisham Muhammad 2014-11-27 18:38:52 -02:00
parent cda6bdd56b
commit b192af006f
3 changed files with 19 additions and 30 deletions

View File

@ -8,15 +8,6 @@ in the source distribution for its full text.
#include "Header.h"
#include "CRT.h"
#include "CPUMeter.h"
#include "MemoryMeter.h"
#include "SwapMeter.h"
#include "TasksMeter.h"
#include "LoadAverageMeter.h"
#include "UptimeMeter.h"
#include "BatteryMeter.h"
#include "ClockMeter.h"
#include "HostnameMeter.h"
#include "String.h"
#include <assert.h>
@ -138,23 +129,6 @@ MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) {
return meter->mode;
}
void Header_defaultMeters(Header* this, int cpuCount) {
if (cpuCount > 8) {
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LeftCPUs2Meter)));
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(RightCPUs2Meter)));
} else if (cpuCount > 4) {
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LeftCPUsMeter)));
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(RightCPUsMeter)));
} else {
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(AllCPUsMeter)));
}
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(MemoryMeter)));
Vector_add(this->leftMeters, Meter_new(this->pl, 0, (MeterClass*) Class(SwapMeter)));
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(TasksMeter)));
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(LoadAverageMeter)));
Vector_add(this->rightMeters, Meter_new(this->pl, 0, (MeterClass*) Class(UptimeMeter)));
}
void Header_reinit(Header* this) {
for (int i = 0; i < Vector_size(this->leftMeters); i++) {
Meter* meter = (Meter*) Vector_get(this->leftMeters, i);

View File

@ -47,8 +47,6 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side);
MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side);
void Header_defaultMeters(Header* this, int cpuCount);
void Header_reinit(Header* this);
void Header_draw(const Header* this);

View File

@ -61,6 +61,23 @@ static void Settings_readMeterModes(Settings* this, char* line, HeaderSide side)
String_freeArray(ids);
}
static void Settings_defaultMeters(Header* header, int cpuCount) {
if (cpuCount > 8) {
Header_createMeter(header, "LeftCPUs2", LEFT_HEADER);
Header_createMeter(header, "RightCPUs2", RIGHT_HEADER);
} else if (cpuCount > 4) {
Header_createMeter(header, "LeftCPUs", LEFT_HEADER);
Header_createMeter(header, "RightCPUs", RIGHT_HEADER);
} else {
Header_createMeter(header, "AllCPUs", LEFT_HEADER);
}
Header_createMeter(header, "Memory", LEFT_HEADER);
Header_createMeter(header, "Swap", LEFT_HEADER);
Header_createMeter(header, "Tasks", RIGHT_HEADER);
Header_createMeter(header, "LoadAverage", RIGHT_HEADER);
Header_createMeter(header, "Uptime", RIGHT_HEADER);
}
static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
FILE* fd = fopen(fileName, "r");
if (!fd)
@ -153,7 +170,7 @@ static bool Settings_read(Settings* this, const char* fileName, int cpuCount) {
}
fclose(fd);
if (!readMeters) {
Header_defaultMeters(this->header, cpuCount);
Settings_defaultMeters(this->header, cpuCount);
}
return true;
}
@ -273,7 +290,7 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
ok = Settings_read(this, systemSettings, cpuCount);
free(systemSettings);
if (!ok) {
Header_defaultMeters(this->header, cpuCount);
Settings_defaultMeters(this->header, cpuCount);
pl->hideKernelThreads = true;
pl->highlightMegabytes = true;
pl->highlightThreads = false;