mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
Clean up headers by using 'static' whenever possible.
Reduces resulting code size.
This commit is contained in:
parent
12f4f09e6e
commit
da23c8c5a1
@ -7,6 +7,23 @@
|
||||
#include "debug.h"
|
||||
#include <assert.h>
|
||||
|
||||
static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
|
||||
HandlerResult result = IGNORED;
|
||||
CheckItem* selected = (CheckItem*) Panel_getSelected(this);
|
||||
switch(ch) {
|
||||
case ' ':
|
||||
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
||||
result = HANDLED;
|
||||
break;
|
||||
case 0x0a:
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
result = BREAK_LOOP;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Panel* AffinityPanel_new(int processorCount, unsigned long mask) {
|
||||
Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare);
|
||||
this->eventHandler = AffinityPanel_eventHandler;
|
||||
@ -29,20 +46,3 @@ unsigned long AffinityPanel_getAffinity(Panel* this) {
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
|
||||
HandlerResult result = IGNORED;
|
||||
CheckItem* selected = (CheckItem*) Panel_getSelected(this);
|
||||
switch(ch) {
|
||||
case ' ':
|
||||
CheckItem_set(selected, ! (CheckItem_get(selected)) );
|
||||
result = HANDLED;
|
||||
break;
|
||||
case 0x0a:
|
||||
case 0x0d:
|
||||
case KEY_ENTER:
|
||||
result = BREAK_LOOP;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -14,6 +14,4 @@ Panel* AffinityPanel_new(int processorCount, unsigned long mask);
|
||||
|
||||
unsigned long AffinityPanel_getAffinity(Panel* this);
|
||||
|
||||
HandlerResult AffinityPanel_eventHandler(Panel* this, int ch);
|
||||
|
||||
#endif
|
||||
|
@ -22,34 +22,14 @@ typedef struct AvailableColumnsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) {
|
||||
AvailableColumnsPanel* this = (AvailableColumnsPanel*) malloc(sizeof(AvailableColumnsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = AvailableColumnsPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = AvailableColumnsPanel_eventHandler;
|
||||
|
||||
Panel_setHeader(super, "Available Columns");
|
||||
|
||||
for (int i = 1; i < LAST_PROCESSFIELD; i++) {
|
||||
if (i != COMM)
|
||||
Panel_add(super, (Object*) ListItem_new(Process_fieldNames[i], 0));
|
||||
}
|
||||
this->columns = columns;
|
||||
return this;
|
||||
}
|
||||
|
||||
void AvailableColumnsPanel_delete(Object* object) {
|
||||
static void AvailableColumnsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
|
||||
Panel_done(super);
|
||||
free(this);
|
||||
}
|
||||
|
||||
HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
|
||||
char* text = ((ListItem*) Panel_getSelected(super))->value;
|
||||
HandlerResult result = IGNORED;
|
||||
@ -69,3 +49,23 @@ HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) {
|
||||
AvailableColumnsPanel* this = (AvailableColumnsPanel*) malloc(sizeof(AvailableColumnsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = AvailableColumnsPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = AvailableColumnsPanel_eventHandler;
|
||||
|
||||
Panel_setHeader(super, "Available Columns");
|
||||
|
||||
for (int i = 1; i < LAST_PROCESSFIELD; i++) {
|
||||
if (i != COMM)
|
||||
Panel_add(super, (Object*) ListItem_new(Process_fieldNames[i], 0));
|
||||
}
|
||||
this->columns = columns;
|
||||
return this;
|
||||
}
|
||||
|
@ -25,8 +25,4 @@ typedef struct AvailableColumnsPanel_ {
|
||||
|
||||
AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr);
|
||||
|
||||
void AvailableColumnsPanel_delete(Object* object);
|
||||
|
||||
HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch);
|
||||
|
||||
#endif
|
||||
|
@ -23,41 +23,7 @@ typedef struct AvailableMetersPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr) {
|
||||
AvailableMetersPanel* this = (AvailableMetersPanel*) malloc(sizeof(AvailableMetersPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = AvailableMetersPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->leftPanel = leftMeters;
|
||||
this->rightPanel = rightMeters;
|
||||
this->scr = scr;
|
||||
super->eventHandler = AvailableMetersPanel_EventHandler;
|
||||
|
||||
Panel_setHeader(super, "Available meters");
|
||||
for (int i = 1; Meter_types[i]; i++) {
|
||||
MeterType* type = Meter_types[i];
|
||||
if (type != &CPUMeter) {
|
||||
Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16));
|
||||
}
|
||||
}
|
||||
MeterType* type = &CPUMeter;
|
||||
int processors = settings->pl->processorCount;
|
||||
if (processors > 1) {
|
||||
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
||||
for (int i = 1; i <= processors; i++) {
|
||||
char buffer[50];
|
||||
sprintf(buffer, "%s %d", type->uiName, i);
|
||||
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
||||
}
|
||||
} else {
|
||||
Panel_add(super, (Object*) ListItem_new("CPU", 1));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void AvailableMetersPanel_delete(Object* object) {
|
||||
static void AvailableMetersPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
AvailableMetersPanel* this = (AvailableMetersPanel*) object;
|
||||
Panel_done(super);
|
||||
@ -69,7 +35,7 @@ static inline void AvailableMetersPanel_addHeader(Header* header, Panel* panel,
|
||||
Panel_add(panel, (Object*) Meter_toListItem(meter));
|
||||
}
|
||||
|
||||
HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch) {
|
||||
static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
|
||||
AvailableMetersPanel* this = (AvailableMetersPanel*) super;
|
||||
Header* header = this->settings->header;
|
||||
|
||||
@ -104,3 +70,37 @@ HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr) {
|
||||
AvailableMetersPanel* this = (AvailableMetersPanel*) malloc(sizeof(AvailableMetersPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = AvailableMetersPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->leftPanel = leftMeters;
|
||||
this->rightPanel = rightMeters;
|
||||
this->scr = scr;
|
||||
super->eventHandler = AvailableMetersPanel_eventHandler;
|
||||
|
||||
Panel_setHeader(super, "Available meters");
|
||||
for (int i = 1; Meter_types[i]; i++) {
|
||||
MeterType* type = Meter_types[i];
|
||||
if (type != &CPUMeter) {
|
||||
Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16));
|
||||
}
|
||||
}
|
||||
MeterType* type = &CPUMeter;
|
||||
int processors = settings->pl->processorCount;
|
||||
if (processors > 1) {
|
||||
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
||||
for (int i = 1; i <= processors; i++) {
|
||||
char buffer[50];
|
||||
sprintf(buffer, "%s %d", type->uiName, i);
|
||||
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
||||
}
|
||||
} else {
|
||||
Panel_add(super, (Object*) ListItem_new("CPU", 1));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -26,8 +26,4 @@ typedef struct AvailableMetersPanel_ {
|
||||
|
||||
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr);
|
||||
|
||||
void AvailableMetersPanel_delete(Object* object);
|
||||
|
||||
HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch);
|
||||
|
||||
#endif
|
||||
|
68
CPUMeter.c
68
CPUMeter.c
@ -22,33 +22,6 @@ int CPUMeter_attributes[] = {
|
||||
CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_IOWAIT
|
||||
};
|
||||
|
||||
MeterType CPUMeter = {
|
||||
.setValues = CPUMeter_setValues,
|
||||
.display = CPUMeter_display,
|
||||
.mode = BAR_METERMODE,
|
||||
.items = 6,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "CPU",
|
||||
.uiName = "CPU",
|
||||
.caption = "CPU",
|
||||
.init = CPUMeter_init
|
||||
};
|
||||
|
||||
MeterType AllCPUsMeter = {
|
||||
.mode = 0,
|
||||
.items = 1,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "AllCPUs",
|
||||
.uiName = "All CPUs",
|
||||
.caption = "CPU",
|
||||
.draw = AllCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
.setMode = AllCPUsMeter_setMode,
|
||||
.done = AllCPUsMeter_done
|
||||
};
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
@ -56,7 +29,7 @@ MeterType AllCPUsMeter = {
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
void CPUMeter_init(Meter* this) {
|
||||
static void CPUMeter_init(Meter* this) {
|
||||
int processor = this->param;
|
||||
if (this->pl->processorCount > 1) {
|
||||
char caption[10];
|
||||
@ -67,7 +40,7 @@ void CPUMeter_init(Meter* this) {
|
||||
Meter_setCaption(this, "Avg");
|
||||
}
|
||||
|
||||
void CPUMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void CPUMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
ProcessList* pl = this->pl;
|
||||
int processor = this->param;
|
||||
double total = (double) pl->totalPeriod[processor];
|
||||
@ -90,7 +63,7 @@ void CPUMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
snprintf(buffer, size, "%5.1f%%", cpu );
|
||||
}
|
||||
|
||||
void CPUMeter_display(Object* cast, RichString* out) {
|
||||
static void CPUMeter_display(Object* cast, RichString* out) {
|
||||
char buffer[50];
|
||||
Meter* this = (Meter*)cast;
|
||||
RichString_init(out);
|
||||
@ -123,7 +96,7 @@ void CPUMeter_display(Object* cast, RichString* out) {
|
||||
}
|
||||
}
|
||||
|
||||
void AllCPUsMeter_init(Meter* this) {
|
||||
static void AllCPUsMeter_init(Meter* this) {
|
||||
int processors = this->pl->processorCount;
|
||||
this->drawBuffer = malloc(sizeof(Meter*) * processors);
|
||||
Meter** meters = (Meter**) this->drawBuffer;
|
||||
@ -133,21 +106,21 @@ void AllCPUsMeter_init(Meter* this) {
|
||||
this->mode = BAR_METERMODE;
|
||||
}
|
||||
|
||||
void AllCPUsMeter_done(Meter* this) {
|
||||
static void AllCPUsMeter_done(Meter* this) {
|
||||
int processors = this->pl->processorCount;
|
||||
Meter** meters = (Meter**) this->drawBuffer;
|
||||
for (int i = 0; i < processors; i++)
|
||||
Meter_delete((Object*)meters[i]);
|
||||
}
|
||||
|
||||
void AllCPUsMeter_setMode(Meter* this, int mode) {
|
||||
static void AllCPUsMeter_setMode(Meter* this, int mode) {
|
||||
this->mode = mode;
|
||||
int processors = this->pl->processorCount;
|
||||
int h = Meter_modes[this->mode]->h;
|
||||
this->h = h * processors;
|
||||
}
|
||||
|
||||
void AllCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
||||
static void AllCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
||||
int processors = this->pl->processorCount;
|
||||
Meter** meters = (Meter**) this->drawBuffer;
|
||||
for (int i = 0; i < processors; i++) {
|
||||
@ -156,3 +129,30 @@ void AllCPUsMeter_draw(Meter* this, int x, int y, int w) {
|
||||
y += meters[i]->h;
|
||||
}
|
||||
}
|
||||
|
||||
MeterType CPUMeter = {
|
||||
.setValues = CPUMeter_setValues,
|
||||
.display = CPUMeter_display,
|
||||
.mode = BAR_METERMODE,
|
||||
.items = 6,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "CPU",
|
||||
.uiName = "CPU",
|
||||
.caption = "CPU",
|
||||
.init = CPUMeter_init
|
||||
};
|
||||
|
||||
MeterType AllCPUsMeter = {
|
||||
.mode = 0,
|
||||
.items = 1,
|
||||
.total = 100.0,
|
||||
.attributes = CPUMeter_attributes,
|
||||
.name = "AllCPUs",
|
||||
.uiName = "All CPUs",
|
||||
.caption = "CPU",
|
||||
.draw = AllCPUsMeter_draw,
|
||||
.init = AllCPUsMeter_init,
|
||||
.setMode = AllCPUsMeter_setMode,
|
||||
.done = AllCPUsMeter_done
|
||||
};
|
||||
|
18
CPUMeter.h
18
CPUMeter.h
@ -23,10 +23,6 @@ in the source distribution for its full text.
|
||||
|
||||
extern int CPUMeter_attributes[];
|
||||
|
||||
extern MeterType CPUMeter;
|
||||
|
||||
extern MeterType AllCPUsMeter;
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
@ -34,18 +30,8 @@ extern MeterType AllCPUsMeter;
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
void CPUMeter_init(Meter* this);
|
||||
extern MeterType CPUMeter;
|
||||
|
||||
void CPUMeter_setValues(Meter* this, char* buffer, int size);
|
||||
|
||||
void CPUMeter_display(Object* cast, RichString* out);
|
||||
|
||||
void AllCPUsMeter_init(Meter* this);
|
||||
|
||||
void AllCPUsMeter_done(Meter* this);
|
||||
|
||||
void AllCPUsMeter_setMode(Meter* this, int mode);
|
||||
|
||||
void AllCPUsMeter_draw(Meter* this, int x, int y, int w);
|
||||
extern MeterType AllCPUsMeter;
|
||||
|
||||
#endif
|
||||
|
22
CRT.c
22
CRT.c
@ -114,6 +114,17 @@ int CRT_colors[LAST_COLORELEMENT] = { 0 };
|
||||
|
||||
char* CRT_termType;
|
||||
|
||||
static void CRT_handleSIGSEGV(int signal) {
|
||||
CRT_done();
|
||||
fprintf(stderr, "htop " VERSION " aborted. Please report bug at http://htop.sf.net\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void CRT_handleSIGTERM(int signal) {
|
||||
CRT_done();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// TODO: pass an instance of Settings instead.
|
||||
|
||||
void CRT_init(int delay, int colorScheme) {
|
||||
@ -182,17 +193,6 @@ void CRT_enableDelay() {
|
||||
halfdelay(CRT_delay);
|
||||
}
|
||||
|
||||
void CRT_handleSIGSEGV(int signal) {
|
||||
CRT_done();
|
||||
fprintf(stderr, "htop " VERSION " aborted. Please report bug at http://htop.sf.net\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void CRT_handleSIGTERM(int signal) {
|
||||
CRT_done();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void CRT_setColors(int colorScheme) {
|
||||
CRT_colorScheme = colorScheme;
|
||||
if (colorScheme == COLORSCHEME_BLACKNIGHT) {
|
||||
|
4
CRT.h
4
CRT.h
@ -127,10 +127,6 @@ void CRT_disableDelay();
|
||||
|
||||
void CRT_enableDelay();
|
||||
|
||||
void CRT_handleSIGSEGV(int signal);
|
||||
|
||||
void CRT_handleSIGTERM(int signal);
|
||||
|
||||
void CRT_setColors(int colorScheme);
|
||||
|
||||
#endif
|
||||
|
@ -35,31 +35,40 @@ static char* ColorsFunctions[10] = {" ", " ", " ", " ", "
|
||||
|
||||
static char* AvailableColumnsFunctions[10] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done "};
|
||||
|
||||
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
CategoriesPanel* this = (CategoriesPanel*) malloc(sizeof(CategoriesPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = CategoriesPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = CategoriesPanel_eventHandler;
|
||||
Panel_setHeader(super, "Setup");
|
||||
Panel_add(super, (Object*) ListItem_new("Meters", 0));
|
||||
Panel_add(super, (Object*) ListItem_new("Display options", 0));
|
||||
Panel_add(super, (Object*) ListItem_new("Colors", 0));
|
||||
Panel_add(super, (Object*) ListItem_new("Columns", 0));
|
||||
return this;
|
||||
}
|
||||
|
||||
void CategoriesPanel_delete(Object* object) {
|
||||
static void CategoriesPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
CategoriesPanel* this = (CategoriesPanel*) object;
|
||||
Panel_done(super);
|
||||
free(this);
|
||||
}
|
||||
|
||||
HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
|
||||
Panel* leftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
|
||||
Panel* rightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
|
||||
Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, leftMeters, rightMeters, this->scr);
|
||||
ScreenManager_add(this->scr, leftMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, rightMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, availableMeters, FunctionBar_new(10, AvailableMetersFunctions, NULL, NULL), -1);
|
||||
}
|
||||
|
||||
static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
|
||||
Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
|
||||
ScreenManager_add(this->scr, displayOptions, FunctionBar_new(10, DisplayOptionsFunctions, NULL, NULL), -1);
|
||||
}
|
||||
|
||||
static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
|
||||
Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
|
||||
ScreenManager_add(this->scr, colors, FunctionBar_new(10, ColorsFunctions, NULL, NULL), -1);
|
||||
}
|
||||
|
||||
static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
|
||||
Panel* columns = (Panel*) ColumnsPanel_new(this->settings, this->scr);
|
||||
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(this->settings, columns, this->scr);
|
||||
ScreenManager_add(this->scr, columns, FunctionBar_new(10, ColumnsFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, availableColumns, FunctionBar_new(10, AvailableColumnsFunctions, NULL, NULL), -1);
|
||||
}
|
||||
|
||||
static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
CategoriesPanel* this = (CategoriesPanel*) super;
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
@ -107,28 +116,19 @@ HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
|
||||
Panel* leftMeters = (Panel*) MetersPanel_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
|
||||
Panel* rightMeters = (Panel*) MetersPanel_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
|
||||
Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, leftMeters, rightMeters, this->scr);
|
||||
ScreenManager_add(this->scr, leftMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, rightMeters, FunctionBar_new(10, MetersFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, availableMeters, FunctionBar_new(10, AvailableMetersFunctions, NULL, NULL), -1);
|
||||
}
|
||||
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
CategoriesPanel* this = (CategoriesPanel*) malloc(sizeof(CategoriesPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = CategoriesPanel_delete;
|
||||
|
||||
void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
|
||||
Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
|
||||
ScreenManager_add(this->scr, displayOptions, FunctionBar_new(10, DisplayOptionsFunctions, NULL, NULL), -1);
|
||||
}
|
||||
|
||||
void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
|
||||
Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr);
|
||||
ScreenManager_add(this->scr, colors, FunctionBar_new(10, ColorsFunctions, NULL, NULL), -1);
|
||||
}
|
||||
|
||||
void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) {
|
||||
Panel* columns = (Panel*) ColumnsPanel_new(this->settings, this->scr);
|
||||
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(this->settings, columns, this->scr);
|
||||
ScreenManager_add(this->scr, columns, FunctionBar_new(10, ColumnsFunctions, NULL, NULL), 20);
|
||||
ScreenManager_add(this->scr, availableColumns, FunctionBar_new(10, AvailableColumnsFunctions, NULL, NULL), -1);
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = CategoriesPanel_eventHandler;
|
||||
Panel_setHeader(super, "Setup");
|
||||
Panel_add(super, (Object*) ListItem_new("Meters", 0));
|
||||
Panel_add(super, (Object*) ListItem_new("Display options", 0));
|
||||
Panel_add(super, (Object*) ListItem_new("Colors", 0));
|
||||
Panel_add(super, (Object*) ListItem_new("Columns", 0));
|
||||
return this;
|
||||
}
|
||||
|
@ -24,18 +24,8 @@ typedef struct CategoriesPanel_ {
|
||||
} CategoriesPanel;
|
||||
|
||||
|
||||
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr);
|
||||
|
||||
void CategoriesPanel_delete(Object* object);
|
||||
|
||||
HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch);
|
||||
|
||||
void CategoriesPanel_makeMetersPage(CategoriesPanel* this);
|
||||
|
||||
void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this);
|
||||
|
||||
void CategoriesPanel_makeColorsPage(CategoriesPanel* this);
|
||||
|
||||
void CategoriesPanel_makeColumnsPage(CategoriesPanel* this);
|
||||
CategoriesPanel* CategoriesPanel_new(Settings* settings, ScreenManager* scr);
|
||||
|
||||
#endif
|
||||
|
40
CheckItem.c
40
CheckItem.c
@ -28,6 +28,26 @@ char* CHECKITEM_CLASS = "CheckItem";
|
||||
#define CHECKITEM_CLASS NULL
|
||||
#endif
|
||||
|
||||
static void CheckItem_delete(Object* cast) {
|
||||
CheckItem* this = (CheckItem*)cast;
|
||||
assert (this != NULL);
|
||||
|
||||
free(this->text);
|
||||
free(this);
|
||||
}
|
||||
|
||||
static void CheckItem_display(Object* cast, RichString* out) {
|
||||
CheckItem* this = (CheckItem*)cast;
|
||||
assert (this != NULL);
|
||||
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
||||
if (CheckItem_get(this))
|
||||
RichString_append(out, CRT_colors[CHECK_MARK], "x");
|
||||
else
|
||||
RichString_append(out, CRT_colors[CHECK_MARK], " ");
|
||||
RichString_append(out, CRT_colors[CHECK_BOX], "] ");
|
||||
RichString_append(out, CRT_colors[CHECK_TEXT], this->text);
|
||||
}
|
||||
|
||||
CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
|
||||
CheckItem* this = malloc(sizeof(CheckItem));
|
||||
Object_setClass(this, CHECKITEM_CLASS);
|
||||
@ -39,14 +59,6 @@ CheckItem* CheckItem_new(char* text, bool* ref, bool value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
void CheckItem_delete(Object* cast) {
|
||||
CheckItem* this = (CheckItem*)cast;
|
||||
assert (this != NULL);
|
||||
|
||||
free(this->text);
|
||||
free(this);
|
||||
}
|
||||
|
||||
void CheckItem_set(CheckItem* this, bool value) {
|
||||
if (this->ref)
|
||||
*(this->ref) = value;
|
||||
@ -60,15 +72,3 @@ bool CheckItem_get(CheckItem* this) {
|
||||
else
|
||||
return this->value;
|
||||
}
|
||||
|
||||
void CheckItem_display(Object* cast, RichString* out) {
|
||||
CheckItem* this = (CheckItem*)cast;
|
||||
assert (this != NULL);
|
||||
RichString_write(out, CRT_colors[CHECK_BOX], "[");
|
||||
if (CheckItem_get(this))
|
||||
RichString_append(out, CRT_colors[CHECK_MARK], "x");
|
||||
else
|
||||
RichString_append(out, CRT_colors[CHECK_MARK], " ");
|
||||
RichString_append(out, CRT_colors[CHECK_BOX], "] ");
|
||||
RichString_append(out, CRT_colors[CHECK_TEXT], this->text);
|
||||
}
|
||||
|
@ -31,12 +31,8 @@ extern char* CHECKITEM_CLASS;
|
||||
|
||||
CheckItem* CheckItem_new(char* text, bool* ref, bool value);
|
||||
|
||||
void CheckItem_delete(Object* cast);
|
||||
|
||||
void CheckItem_set(CheckItem* this, bool value);
|
||||
|
||||
bool CheckItem_get(CheckItem* this);
|
||||
|
||||
void CheckItem_display(Object* cast, RichString* out);
|
||||
|
||||
#endif
|
||||
|
14
ClockMeter.c
14
ClockMeter.c
@ -16,6 +16,13 @@ int ClockMeter_attributes[] = {
|
||||
CLOCK
|
||||
};
|
||||
|
||||
static void ClockMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
time_t t = time(NULL);
|
||||
struct tm *lt = localtime(&t);
|
||||
this->values[0] = lt->tm_hour * 60 + lt->tm_min;
|
||||
strftime(buffer, size, "%H:%M:%S", lt);
|
||||
}
|
||||
|
||||
MeterType ClockMeter = {
|
||||
.setValues = ClockMeter_setValues,
|
||||
.display = NULL,
|
||||
@ -27,10 +34,3 @@ MeterType ClockMeter = {
|
||||
.uiName = "Clock",
|
||||
.caption = "Time: ",
|
||||
};
|
||||
|
||||
void ClockMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
time_t t = time(NULL);
|
||||
struct tm *lt = localtime(&t);
|
||||
this->values[0] = lt->tm_hour * 60 + lt->tm_min;
|
||||
strftime(buffer, size, "%H:%M:%S", lt);
|
||||
}
|
||||
|
@ -19,6 +19,4 @@ extern int ClockMeter_attributes[];
|
||||
|
||||
extern MeterType ClockMeter;
|
||||
|
||||
void ClockMeter_setValues(Meter* this, char* buffer, int size);
|
||||
|
||||
#endif
|
||||
|
@ -37,32 +37,14 @@ static char* ColorSchemes[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
ColorsPanel* this = (ColorsPanel*) malloc(sizeof(ColorsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
|
||||
((Object*)this)->delete = ColorsPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = ColorsPanel_EventHandler;
|
||||
|
||||
Panel_setHeader(super, "Colors");
|
||||
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false));
|
||||
}
|
||||
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
void ColorsPanel_delete(Object* object) {
|
||||
static void ColorsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
ColorsPanel* this = (ColorsPanel*) object;
|
||||
Panel_done(super);
|
||||
free(this);
|
||||
}
|
||||
|
||||
HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
|
||||
static HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
|
||||
ColorsPanel* this = (ColorsPanel*) super;
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
@ -93,3 +75,20 @@ HandlerResult ColorsPanel_EventHandler(Panel* super, int ch) {
|
||||
return result;
|
||||
}
|
||||
|
||||
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
ColorsPanel* this = (ColorsPanel*) malloc(sizeof(ColorsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
|
||||
((Object*)this)->delete = ColorsPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = ColorsPanel_EventHandler;
|
||||
|
||||
Panel_setHeader(super, "Colors");
|
||||
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false));
|
||||
}
|
||||
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
|
||||
return this;
|
||||
}
|
||||
|
@ -30,9 +30,4 @@ typedef struct ColorsPanel_ {
|
||||
|
||||
ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr);
|
||||
|
||||
void ColorsPanel_delete(Object* object);
|
||||
|
||||
HandlerResult ColorsPanel_EventHandler(Panel* super, int ch);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -19,57 +19,14 @@ typedef struct ColumnsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
ColumnsPanel* this = (ColumnsPanel*) malloc(sizeof(ColumnsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = ColumnsPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = ColumnsPanel_eventHandler;
|
||||
Panel_setHeader(super, "Active Columns");
|
||||
|
||||
ProcessField* fields = this->settings->pl->fields;
|
||||
for (; *fields; fields++) {
|
||||
Panel_add(super, (Object*) ListItem_new(Process_fieldNames[*fields], 0));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void ColumnsPanel_delete(Object* object) {
|
||||
static void ColumnsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
ColumnsPanel* this = (ColumnsPanel*) object;
|
||||
Panel_done(super);
|
||||
free(this);
|
||||
}
|
||||
|
||||
int ColumnsPanel_fieldNameToIndex(const char* name) {
|
||||
for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
|
||||
if (String_eq(name, Process_fieldNames[j])) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ColumnsPanel_update(Panel* super) {
|
||||
ColumnsPanel* this = (ColumnsPanel*) super;
|
||||
int size = Panel_getSize(super);
|
||||
this->settings->changed = true;
|
||||
// FIXME: this is crappily inefficient
|
||||
free(this->settings->pl->fields);
|
||||
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
|
||||
for (int i = 0; i < size; i++) {
|
||||
char* text = ((ListItem*) Panel_get(super, i))->value;
|
||||
int j = ColumnsPanel_fieldNameToIndex(text);
|
||||
if (j > 0)
|
||||
this->settings->pl->fields[i] = j;
|
||||
}
|
||||
this->settings->pl->fields[size] = 0;
|
||||
}
|
||||
|
||||
HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
|
||||
int selected = Panel_getSelectedIndex(super);
|
||||
HandlerResult result = IGNORED;
|
||||
@ -108,3 +65,47 @@ HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) {
|
||||
ColumnsPanel_update(super);
|
||||
return result;
|
||||
}
|
||||
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
ColumnsPanel* this = (ColumnsPanel*) malloc(sizeof(ColumnsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = ColumnsPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = ColumnsPanel_eventHandler;
|
||||
Panel_setHeader(super, "Active Columns");
|
||||
|
||||
ProcessField* fields = this->settings->pl->fields;
|
||||
for (; *fields; fields++) {
|
||||
Panel_add(super, (Object*) ListItem_new(Process_fieldNames[*fields], 0));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
int ColumnsPanel_fieldNameToIndex(const char* name) {
|
||||
for (int j = 1; j <= LAST_PROCESSFIELD; j++) {
|
||||
if (String_eq(name, Process_fieldNames[j])) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ColumnsPanel_update(Panel* super) {
|
||||
ColumnsPanel* this = (ColumnsPanel*) super;
|
||||
int size = Panel_getSize(super);
|
||||
this->settings->changed = true;
|
||||
// FIXME: this is crappily inefficient
|
||||
free(this->settings->pl->fields);
|
||||
this->settings->pl->fields = (ProcessField*) malloc(sizeof(ProcessField) * (size+1));
|
||||
for (int i = 0; i < size; i++) {
|
||||
char* text = ((ListItem*) Panel_get(super, i))->value;
|
||||
int j = ColumnsPanel_fieldNameToIndex(text);
|
||||
if (j > 0)
|
||||
this->settings->pl->fields[i] = j;
|
||||
}
|
||||
this->settings->pl->fields[size] = 0;
|
||||
}
|
||||
|
||||
|
@ -22,12 +22,9 @@ typedef struct ColumnsPanel_ {
|
||||
|
||||
ColumnsPanel* ColumnsPanel_new(Settings* settings, ScreenManager* scr);
|
||||
|
||||
void ColumnsPanel_delete(Object* object);
|
||||
|
||||
int ColumnsPanel_fieldNameToIndex(const char* name);
|
||||
|
||||
void ColumnsPanel_update(Panel* super);
|
||||
|
||||
HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch);
|
||||
|
||||
#endif
|
||||
|
@ -20,37 +20,14 @@ typedef struct DisplayOptionsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
DisplayOptionsPanel* this = (DisplayOptionsPanel*) malloc(sizeof(DisplayOptionsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
|
||||
((Object*)this)->delete = DisplayOptionsPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = DisplayOptionsPanel_eventHandler;
|
||||
|
||||
Panel_setHeader(super, "Display options");
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Display threads in a different color"), &(settings->pl->highlightThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight megabytes in memory counters"), &(settings->pl->highlightMegabytes), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ)"), &(settings->pl->detailedCPUTime), false));
|
||||
return this;
|
||||
}
|
||||
|
||||
void DisplayOptionsPanel_delete(Object* object) {
|
||||
static void DisplayOptionsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
|
||||
Panel_done(super);
|
||||
free(this);
|
||||
}
|
||||
|
||||
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
@ -75,3 +52,25 @@ HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
|
||||
return result;
|
||||
}
|
||||
|
||||
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||
DisplayOptionsPanel* this = (DisplayOptionsPanel*) malloc(sizeof(DisplayOptionsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, CHECKITEM_CLASS, true);
|
||||
((Object*)this)->delete = DisplayOptionsPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->scr = scr;
|
||||
super->eventHandler = DisplayOptionsPanel_eventHandler;
|
||||
|
||||
Panel_setHeader(super, "Display options");
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Display threads in a different color"), &(settings->pl->highlightThreads), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight megabytes in memory counters"), &(settings->pl->highlightMegabytes), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false));
|
||||
Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ)"), &(settings->pl->detailedCPUTime), false));
|
||||
return this;
|
||||
}
|
||||
|
@ -23,9 +23,4 @@ typedef struct DisplayOptionsPanel_ {
|
||||
|
||||
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
|
||||
|
||||
void DisplayOptionsPanel_delete(Object* object);
|
||||
|
||||
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -34,7 +34,7 @@ struct Hashtable_ {
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
bool Hashtable_isConsistent(Hashtable* this) {
|
||||
static bool Hashtable_isConsistent(Hashtable* this) {
|
||||
int items = 0;
|
||||
for (int i = 0; i < this->size; i++) {
|
||||
HashtableItem* bucket = this->buckets[i];
|
||||
@ -61,7 +61,7 @@ int Hashtable_count(Hashtable* this) {
|
||||
|
||||
#endif
|
||||
|
||||
HashtableItem* HashtableItem_new(unsigned int key, void* value) {
|
||||
static HashtableItem* HashtableItem_new(unsigned int key, void* value) {
|
||||
HashtableItem* this;
|
||||
|
||||
this = (HashtableItem*) malloc(sizeof(HashtableItem));
|
||||
@ -99,11 +99,6 @@ void Hashtable_delete(Hashtable* this) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
inline int Hashtable_size(Hashtable* this) {
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return this->items;
|
||||
}
|
||||
|
||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
|
||||
unsigned int index = key % this->size;
|
||||
HashtableItem** bucketPtr = &(this->buckets[index]);
|
||||
|
@ -35,20 +35,14 @@ struct Hashtable_ {
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
bool Hashtable_isConsistent(Hashtable* this);
|
||||
|
||||
int Hashtable_count(Hashtable* this);
|
||||
|
||||
#endif
|
||||
|
||||
HashtableItem* HashtableItem_new(unsigned int key, void* value);
|
||||
|
||||
Hashtable* Hashtable_new(int size, bool owner);
|
||||
|
||||
void Hashtable_delete(Hashtable* this);
|
||||
|
||||
extern int Hashtable_size(Hashtable* this);
|
||||
|
||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value);
|
||||
|
||||
void* Hashtable_remove(Hashtable* this, unsigned int key);
|
||||
|
30
ListItem.c
30
ListItem.c
@ -29,6 +29,21 @@ char* LISTITEM_CLASS = "ListItem";
|
||||
#define LISTITEM_CLASS NULL
|
||||
#endif
|
||||
|
||||
static void ListItem_delete(Object* cast) {
|
||||
ListItem* this = (ListItem*)cast;
|
||||
free(this->value);
|
||||
free(this);
|
||||
}
|
||||
|
||||
static void ListItem_display(Object* cast, RichString* out) {
|
||||
ListItem* this = (ListItem*)cast;
|
||||
assert (this != NULL);
|
||||
int len = strlen(this->value)+1;
|
||||
char buffer[len+1];
|
||||
snprintf(buffer, len, "%s", this->value);
|
||||
RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer);
|
||||
}
|
||||
|
||||
ListItem* ListItem_new(char* value, int key) {
|
||||
ListItem* this = malloc(sizeof(ListItem));
|
||||
Object_setClass(this, LISTITEM_CLASS);
|
||||
@ -46,21 +61,6 @@ void ListItem_append(ListItem* this, char* text) {
|
||||
this->value = buf;
|
||||
}
|
||||
|
||||
void ListItem_delete(Object* cast) {
|
||||
ListItem* this = (ListItem*)cast;
|
||||
free(this->value);
|
||||
free(this);
|
||||
}
|
||||
|
||||
void ListItem_display(Object* cast, RichString* out) {
|
||||
ListItem* this = (ListItem*)cast;
|
||||
assert (this != NULL);
|
||||
int len = strlen(this->value)+1;
|
||||
char buffer[len+1];
|
||||
snprintf(buffer, len, "%s", this->value);
|
||||
RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer);
|
||||
}
|
||||
|
||||
const char* ListItem_getRef(ListItem* this) {
|
||||
return this->value;
|
||||
}
|
||||
|
@ -34,10 +34,6 @@ ListItem* ListItem_new(char* value, int key);
|
||||
|
||||
void ListItem_append(ListItem* this, char* text);
|
||||
|
||||
void ListItem_delete(Object* cast);
|
||||
|
||||
void ListItem_display(Object* cast, RichString* out);
|
||||
|
||||
const char* ListItem_getRef(ListItem* this);
|
||||
|
||||
int ListItem_compare(const void* cast1, const void* cast2);
|
||||
|
@ -16,6 +16,52 @@ int LoadAverageMeter_attributes[] = {
|
||||
LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE
|
||||
};
|
||||
|
||||
int LoadMeter_attributes[] = { LOAD };
|
||||
|
||||
static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
|
||||
int activeProcs, totalProcs, lastProc;
|
||||
FILE *fd = fopen(PROCDIR "/loadavg", "r");
|
||||
int read = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
|
||||
&activeProcs, &totalProcs, &lastProc);
|
||||
(void) read;
|
||||
assert(read == 6);
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
|
||||
snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]);
|
||||
}
|
||||
|
||||
static void LoadAverageMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
char buffer[20];
|
||||
RichString_init(out);
|
||||
sprintf(buffer, "%.2f ", this->values[2]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[1]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[0]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
||||
}
|
||||
|
||||
static void LoadMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
double five, fifteen;
|
||||
LoadAverageMeter_scan(&this->values[0], &five, &fifteen);
|
||||
if (this->values[0] > this->total) {
|
||||
this->total = this->values[0];
|
||||
}
|
||||
snprintf(buffer, size, "%.2f", this->values[0]);
|
||||
}
|
||||
|
||||
static void LoadMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
char buffer[20];
|
||||
RichString_init(out);
|
||||
sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]);
|
||||
RichString_append(out, CRT_colors[LOAD], buffer);
|
||||
}
|
||||
|
||||
MeterType LoadAverageMeter = {
|
||||
.setValues = LoadAverageMeter_setValues,
|
||||
.display = LoadAverageMeter_display,
|
||||
@ -28,8 +74,6 @@ MeterType LoadAverageMeter = {
|
||||
.caption = "Load average: "
|
||||
};
|
||||
|
||||
int LoadMeter_attributes[] = { LOAD };
|
||||
|
||||
MeterType LoadMeter = {
|
||||
.setValues = LoadMeter_setValues,
|
||||
.display = LoadMeter_display,
|
||||
@ -41,47 +85,3 @@ MeterType LoadMeter = {
|
||||
.uiName = "Load",
|
||||
.caption = "Load: "
|
||||
};
|
||||
|
||||
static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
|
||||
int activeProcs, totalProcs, lastProc;
|
||||
FILE *fd = fopen(PROCDIR "/loadavg", "r");
|
||||
int read = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
|
||||
&activeProcs, &totalProcs, &lastProc);
|
||||
(void) read;
|
||||
assert(read == 6);
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
|
||||
snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]);
|
||||
}
|
||||
|
||||
void LoadAverageMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
char buffer[20];
|
||||
RichString_init(out);
|
||||
sprintf(buffer, "%.2f ", this->values[2]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[1]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
|
||||
sprintf(buffer, "%.2f ", this->values[0]);
|
||||
RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
||||
}
|
||||
|
||||
void LoadMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
double five, fifteen;
|
||||
LoadAverageMeter_scan(&this->values[0], &five, &fifteen);
|
||||
if (this->values[0] > this->total) {
|
||||
this->total = this->values[0];
|
||||
}
|
||||
snprintf(buffer, size, "%.2f", this->values[0]);
|
||||
}
|
||||
|
||||
void LoadMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
char buffer[20];
|
||||
RichString_init(out);
|
||||
sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]);
|
||||
RichString_append(out, CRT_colors[LOAD], buffer);
|
||||
}
|
||||
|
@ -17,18 +17,10 @@ in the source distribution for its full text.
|
||||
|
||||
extern int LoadAverageMeter_attributes[];
|
||||
|
||||
extern MeterType LoadAverageMeter;
|
||||
|
||||
extern int LoadMeter_attributes[];
|
||||
|
||||
extern MeterType LoadAverageMeter;
|
||||
|
||||
extern MeterType LoadMeter;
|
||||
|
||||
void LoadAverageMeter_setValues(Meter* this, char* buffer, int size);
|
||||
|
||||
void LoadAverageMeter_display(Object* cast, RichString* out);
|
||||
|
||||
void LoadMeter_setValues(Meter* this, char* buffer, int size);
|
||||
|
||||
void LoadMeter_display(Object* cast, RichString* out);
|
||||
|
||||
#endif
|
||||
|
@ -23,19 +23,7 @@ int MemoryMeter_attributes[] = {
|
||||
MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE
|
||||
};
|
||||
|
||||
MeterType MemoryMeter = {
|
||||
.setValues = MemoryMeter_setValues,
|
||||
.display = MemoryMeter_display,
|
||||
.mode = BAR_METERMODE,
|
||||
.items = 3,
|
||||
.total = 100.0,
|
||||
.attributes = MemoryMeter_attributes,
|
||||
"Memory",
|
||||
"Memory",
|
||||
"Mem"
|
||||
};
|
||||
|
||||
void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
long int usedMem = this->pl->usedMem;
|
||||
long int buffersMem = this->pl->buffersMem;
|
||||
long int cachedMem = this->pl->cachedMem;
|
||||
@ -47,7 +35,7 @@ void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
|
||||
snprintf(buffer, size, "%ld/%ldMB", (long int) usedMem / 1024, (long int) this->total / 1024);
|
||||
}
|
||||
|
||||
void MemoryMeter_display(Object* cast, RichString* out) {
|
||||
static void MemoryMeter_display(Object* cast, RichString* out) {
|
||||
char buffer[50];
|
||||
Meter* this = (Meter*)cast;
|
||||
int div = 1024; char* format = "%ldM ";
|
||||
@ -69,3 +57,15 @@ void MemoryMeter_display(Object* cast, RichString* out) {
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "cache:");
|
||||
RichString_append(out, CRT_colors[MEMORY_CACHE], buffer);
|
||||
}
|
||||
|
||||
MeterType MemoryMeter = {
|
||||
.setValues = MemoryMeter_setValues,
|
||||
.display = MemoryMeter_display,
|
||||
.mode = BAR_METERMODE,
|
||||
.items = 3,
|
||||
.total = 100.0,
|
||||
.attributes = MemoryMeter_attributes,
|
||||
"Memory",
|
||||
"Memory",
|
||||
"Mem"
|
||||
};
|
||||
|
@ -26,8 +26,4 @@ extern int MemoryMeter_attributes[];
|
||||
|
||||
extern MeterType MemoryMeter;
|
||||
|
||||
void MemoryMeter_setValues(Meter* this, char* buffer, int size);
|
||||
|
||||
void MemoryMeter_display(Object* cast, RichString* out);
|
||||
|
||||
#endif
|
||||
|
86
Meter.c
86
Meter.c
@ -124,45 +124,6 @@ MeterType* Meter_types[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static MeterMode BarMeterMode = {
|
||||
.uiName = "Bar",
|
||||
.h = 1,
|
||||
.draw = BarMeterMode_draw,
|
||||
};
|
||||
|
||||
static MeterMode TextMeterMode = {
|
||||
.uiName = "Text",
|
||||
.h = 1,
|
||||
.draw = TextMeterMode_draw,
|
||||
};
|
||||
|
||||
#ifdef USE_FUNKY_MODES
|
||||
|
||||
static MeterMode GraphMeterMode = {
|
||||
.uiName = "Graph",
|
||||
.h = 3,
|
||||
.draw = GraphMeterMode_draw,
|
||||
};
|
||||
|
||||
static MeterMode LEDMeterMode = {
|
||||
.uiName = "LED",
|
||||
.h = 3,
|
||||
.draw = LEDMeterMode_draw,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
MeterMode* Meter_modes[] = {
|
||||
NULL,
|
||||
&BarMeterMode,
|
||||
&TextMeterMode,
|
||||
#ifdef USE_FUNKY_MODES
|
||||
&GraphMeterMode,
|
||||
&LEDMeterMode,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
static RichString Meter_stringBuffer;
|
||||
|
||||
Meter* Meter_new(ProcessList* pl, int param, MeterType* type) {
|
||||
@ -254,7 +215,7 @@ ListItem* Meter_toListItem(Meter* this) {
|
||||
|
||||
/* ---------- TextMeterMode ---------- */
|
||||
|
||||
void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
MeterType* type = this->type;
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
type->setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
@ -274,7 +235,7 @@ void TextMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
|
||||
static char BarMeterMode_characters[] = "|#*@$%&";
|
||||
|
||||
void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
MeterType* type = this->type;
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
type->setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
@ -362,7 +323,7 @@ static int GraphMeterMode_colors[21] = {
|
||||
|
||||
static char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_";
|
||||
|
||||
void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
|
||||
if (!this->drawBuffer) this->drawBuffer = calloc(sizeof(double), METER_BUFFER_LEN);
|
||||
double* drawBuffer = (double*) this->drawBuffer;
|
||||
@ -408,7 +369,7 @@ static void LEDMeterMode_drawDigit(int x, int y, int n) {
|
||||
mvaddstr(y+i, x, LEDMeterMode_digits[i][n]);
|
||||
}
|
||||
|
||||
void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
MeterType* type = this->type;
|
||||
char buffer[METER_BUFFER_LEN];
|
||||
type->setValues(this, buffer, METER_BUFFER_LEN - 1);
|
||||
@ -432,3 +393,42 @@ void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static MeterMode BarMeterMode = {
|
||||
.uiName = "Bar",
|
||||
.h = 1,
|
||||
.draw = BarMeterMode_draw,
|
||||
};
|
||||
|
||||
static MeterMode TextMeterMode = {
|
||||
.uiName = "Text",
|
||||
.h = 1,
|
||||
.draw = TextMeterMode_draw,
|
||||
};
|
||||
|
||||
#ifdef USE_FUNKY_MODES
|
||||
|
||||
static MeterMode GraphMeterMode = {
|
||||
.uiName = "Graph",
|
||||
.h = 3,
|
||||
.draw = GraphMeterMode_draw,
|
||||
};
|
||||
|
||||
static MeterMode LEDMeterMode = {
|
||||
.uiName = "LED",
|
||||
.h = 3,
|
||||
.draw = LEDMeterMode_draw,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
MeterMode* Meter_modes[] = {
|
||||
NULL,
|
||||
&BarMeterMode,
|
||||
&TextMeterMode,
|
||||
#ifdef USE_FUNKY_MODES
|
||||
&GraphMeterMode,
|
||||
&LEDMeterMode,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
18
Meter.h
18
Meter.h
@ -114,12 +114,6 @@ extern char* METER_CLASS;
|
||||
|
||||
extern MeterType* Meter_types[];
|
||||
|
||||
#ifdef USE_FUNKY_MODES
|
||||
|
||||
#endif
|
||||
|
||||
extern MeterMode* Meter_modes[];
|
||||
|
||||
Meter* Meter_new(ProcessList* pl, int param, MeterType* type);
|
||||
|
||||
void Meter_delete(Object* cast);
|
||||
@ -132,24 +126,22 @@ ListItem* Meter_toListItem(Meter* this);
|
||||
|
||||
/* ---------- TextMeterMode ---------- */
|
||||
|
||||
void TextMeterMode_draw(Meter* this, int x, int y, int w);
|
||||
|
||||
/* ---------- BarMeterMode ---------- */
|
||||
|
||||
void BarMeterMode_draw(Meter* this, int x, int y, int w);
|
||||
|
||||
#ifdef USE_FUNKY_MODES
|
||||
|
||||
/* ---------- GraphMeterMode ---------- */
|
||||
|
||||
#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0)
|
||||
|
||||
void GraphMeterMode_draw(Meter* this, int x, int y, int w);
|
||||
|
||||
/* ---------- LEDMeterMode ---------- */
|
||||
|
||||
void LEDMeterMode_draw(Meter* this, int x, int y, int w);
|
||||
#endif
|
||||
|
||||
#ifdef USE_FUNKY_MODES
|
||||
|
||||
#endif
|
||||
|
||||
extern MeterMode* Meter_modes[];
|
||||
|
||||
#endif
|
||||
|
@ -20,32 +20,14 @@ typedef struct MetersPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) {
|
||||
MetersPanel* this = (MetersPanel*) malloc(sizeof(MetersPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = MetersPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->meters = meters;
|
||||
this->scr = scr;
|
||||
super->eventHandler = MetersPanel_EventHandler;
|
||||
Panel_setHeader(super, header);
|
||||
for (int i = 0; i < Vector_size(meters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||
Panel_add(super, (Object*) Meter_toListItem(meter));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void MetersPanel_delete(Object* object) {
|
||||
static void MetersPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
MetersPanel* this = (MetersPanel*) object;
|
||||
Panel_done(super);
|
||||
free(this);
|
||||
}
|
||||
|
||||
HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
|
||||
static HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
|
||||
MetersPanel* this = (MetersPanel*) super;
|
||||
|
||||
int selected = Panel_getSelectedIndex(super);
|
||||
@ -103,3 +85,21 @@ HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) {
|
||||
MetersPanel* this = (MetersPanel*) malloc(sizeof(MetersPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
|
||||
((Object*)this)->delete = MetersPanel_delete;
|
||||
|
||||
this->settings = settings;
|
||||
this->meters = meters;
|
||||
this->scr = scr;
|
||||
super->eventHandler = MetersPanel_EventHandler;
|
||||
Panel_setHeader(super, header);
|
||||
for (int i = 0; i < Vector_size(meters); i++) {
|
||||
Meter* meter = (Meter*) Vector_get(meters, i);
|
||||
Panel_add(super, (Object*) Meter_toListItem(meter));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -23,8 +23,4 @@ typedef struct MetersPanel_ {
|
||||
|
||||
MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr);
|
||||
|
||||
void MetersPanel_delete(Object* object);
|
||||
|
||||
HandlerResult MetersPanel_EventHandler(Panel* super, int ch);
|
||||
|
||||
#endif
|
||||
|
2
Object.c
2
Object.c
@ -48,7 +48,7 @@ void Object_setClass(void* this, char* class) {
|
||||
((Object*)this)->class = class;
|
||||
}
|
||||
|
||||
void Object_display(Object* this, RichString* out) {
|
||||
static void Object_display(Object* this, RichString* out) {
|
||||
char objAddress[50];
|
||||
sprintf(objAddress, "%s @ %p", this->class, (void*) this);
|
||||
RichString_write(out, CRT_colors[DEFAULT_COLOR], objAddress);
|
||||
|
2
Object.h
2
Object.h
@ -47,8 +47,6 @@ extern char* OBJECT_CLASS;
|
||||
|
||||
void Object_setClass(void* this, char* class);
|
||||
|
||||
void Object_display(Object* this, RichString* out);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
172
Process.c
172
Process.c
@ -160,91 +160,6 @@ char *Process_fieldNames[] = {
|
||||
|
||||
static int Process_getuid = -1;
|
||||
|
||||
Process* Process_new(struct ProcessList_ *pl) {
|
||||
Process* this = calloc(sizeof(Process), 1);
|
||||
Object_setClass(this, PROCESS_CLASS);
|
||||
((Object*)this)->display = Process_display;
|
||||
((Object*)this)->delete = Process_delete;
|
||||
this->pid = 0;
|
||||
this->pl = pl;
|
||||
this->tag = false;
|
||||
this->updated = false;
|
||||
this->utime = 0;
|
||||
this->stime = 0;
|
||||
this->comm = NULL;
|
||||
this->indent = 0;
|
||||
if (Process_getuid == -1) Process_getuid = getuid();
|
||||
return this;
|
||||
}
|
||||
|
||||
Process* Process_clone(Process* this) {
|
||||
Process* clone = malloc(sizeof(Process));
|
||||
#if HAVE_TASKSTATS
|
||||
this->io_rchar = 0;
|
||||
this->io_wchar = 0;
|
||||
this->io_syscr = 0;
|
||||
this->io_syscw = 0;
|
||||
this->io_read_bytes = 0;
|
||||
this->io_rate_read_bps = 0;
|
||||
this->io_rate_read_time = 0;
|
||||
this->io_write_bytes = 0;
|
||||
this->io_rate_write_bps = 0;
|
||||
this->io_rate_write_time = 0;
|
||||
this->io_cancelled_write_bytes = 0;
|
||||
#endif
|
||||
memcpy(clone, this, sizeof(Process));
|
||||
this->comm = NULL;
|
||||
this->pid = 0;
|
||||
return clone;
|
||||
}
|
||||
|
||||
void Process_delete(Object* cast) {
|
||||
Process* this = (Process*) cast;
|
||||
assert (this != NULL);
|
||||
if (this->comm) free(this->comm);
|
||||
free(this);
|
||||
}
|
||||
|
||||
void Process_display(Object* cast, RichString* out) {
|
||||
Process* this = (Process*) cast;
|
||||
ProcessField* fields = this->pl->fields;
|
||||
RichString_init(out);
|
||||
for (int i = 0; fields[i]; i++)
|
||||
Process_writeField(this, out, fields[i]);
|
||||
if (this->pl->shadowOtherUsers && this->st_uid != Process_getuid)
|
||||
RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]);
|
||||
if (this->tag == true)
|
||||
RichString_setAttr(out, CRT_colors[PROCESS_TAG]);
|
||||
assert(out->len > 0);
|
||||
}
|
||||
|
||||
void Process_toggleTag(Process* this) {
|
||||
this->tag = this->tag == true ? false : true;
|
||||
}
|
||||
|
||||
bool Process_setPriority(Process* this, int priority) {
|
||||
int old_prio = getpriority(PRIO_PROCESS, this->pid);
|
||||
int err = setpriority(PRIO_PROCESS, this->pid, priority);
|
||||
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
|
||||
this->nice = priority;
|
||||
}
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
unsigned long Process_getAffinity(Process* this) {
|
||||
unsigned long mask = 0;
|
||||
plpa_sched_getaffinity(this->pid, sizeof(unsigned long), (plpa_cpu_set_t*) &mask);
|
||||
return mask;
|
||||
}
|
||||
|
||||
bool Process_setAffinity(Process* this, unsigned long mask) {
|
||||
return (plpa_sched_setaffinity(this->pid, sizeof(unsigned long), (plpa_cpu_set_t*) &mask) == 0);
|
||||
}
|
||||
|
||||
void Process_sendSignal(Process* this, int signal) {
|
||||
kill(this->pid, signal);
|
||||
}
|
||||
|
||||
#define ONE_K 1024
|
||||
#define ONE_M (ONE_K * ONE_K)
|
||||
#define ONE_G (ONE_M * ONE_K)
|
||||
@ -315,7 +230,7 @@ static inline void Process_writeCommand(Process* this, int attr, int baseattr, R
|
||||
}
|
||||
}
|
||||
|
||||
void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
static void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
char buffer[PROCESS_COMM_LEN];
|
||||
int attr = CRT_colors[DEFAULT_COLOR];
|
||||
int baseattr = CRT_colors[PROCESS_BASENAME];
|
||||
@ -450,6 +365,91 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
RichString_append(str, attr, buffer);
|
||||
}
|
||||
|
||||
static void Process_display(Object* cast, RichString* out) {
|
||||
Process* this = (Process*) cast;
|
||||
ProcessField* fields = this->pl->fields;
|
||||
RichString_init(out);
|
||||
for (int i = 0; fields[i]; i++)
|
||||
Process_writeField(this, out, fields[i]);
|
||||
if (this->pl->shadowOtherUsers && this->st_uid != Process_getuid)
|
||||
RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]);
|
||||
if (this->tag == true)
|
||||
RichString_setAttr(out, CRT_colors[PROCESS_TAG]);
|
||||
assert(out->len > 0);
|
||||
}
|
||||
|
||||
void Process_delete(Object* cast) {
|
||||
Process* this = (Process*) cast;
|
||||
assert (this != NULL);
|
||||
if (this->comm) free(this->comm);
|
||||
free(this);
|
||||
}
|
||||
|
||||
Process* Process_new(struct ProcessList_ *pl) {
|
||||
Process* this = calloc(sizeof(Process), 1);
|
||||
Object_setClass(this, PROCESS_CLASS);
|
||||
((Object*)this)->display = Process_display;
|
||||
((Object*)this)->delete = Process_delete;
|
||||
this->pid = 0;
|
||||
this->pl = pl;
|
||||
this->tag = false;
|
||||
this->updated = false;
|
||||
this->utime = 0;
|
||||
this->stime = 0;
|
||||
this->comm = NULL;
|
||||
this->indent = 0;
|
||||
if (Process_getuid == -1) Process_getuid = getuid();
|
||||
return this;
|
||||
}
|
||||
|
||||
Process* Process_clone(Process* this) {
|
||||
Process* clone = malloc(sizeof(Process));
|
||||
#if HAVE_TASKSTATS
|
||||
this->io_rchar = 0;
|
||||
this->io_wchar = 0;
|
||||
this->io_syscr = 0;
|
||||
this->io_syscw = 0;
|
||||
this->io_read_bytes = 0;
|
||||
this->io_rate_read_bps = 0;
|
||||
this->io_rate_read_time = 0;
|
||||
this->io_write_bytes = 0;
|
||||
this->io_rate_write_bps = 0;
|
||||
this->io_rate_write_time = 0;
|
||||
this->io_cancelled_write_bytes = 0;
|
||||
#endif
|
||||
memcpy(clone, this, sizeof(Process));
|
||||
this->comm = NULL;
|
||||
this->pid = 0;
|
||||
return clone;
|
||||
}
|
||||
|
||||
void Process_toggleTag(Process* this) {
|
||||
this->tag = this->tag == true ? false : true;
|
||||
}
|
||||
|
||||
bool Process_setPriority(Process* this, int priority) {
|
||||
int old_prio = getpriority(PRIO_PROCESS, this->pid);
|
||||
int err = setpriority(PRIO_PROCESS, this->pid, priority);
|
||||
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
|
||||
this->nice = priority;
|
||||
}
|
||||
return (err == 0);
|
||||
}
|
||||
|
||||
unsigned long Process_getAffinity(Process* this) {
|
||||
unsigned long mask = 0;
|
||||
plpa_sched_getaffinity(this->pid, sizeof(unsigned long), (plpa_cpu_set_t*) &mask);
|
||||
return mask;
|
||||
}
|
||||
|
||||
bool Process_setAffinity(Process* this, unsigned long mask) {
|
||||
return (plpa_sched_setaffinity(this->pid, sizeof(unsigned long), (plpa_cpu_set_t*) &mask) == 0);
|
||||
}
|
||||
|
||||
void Process_sendSignal(Process* this, int signal) {
|
||||
kill(this->pid, signal);
|
||||
}
|
||||
|
||||
int Process_pidCompare(const void* v1, const void* v2) {
|
||||
Process* p1 = (Process*)v1;
|
||||
Process* p2 = (Process*)v2;
|
||||
|
16
Process.h
16
Process.h
@ -150,13 +150,15 @@ extern char* PROCESS_CLASS;
|
||||
|
||||
extern char *Process_fieldNames[];
|
||||
|
||||
Process* Process_new(struct ProcessList_ *pl);
|
||||
|
||||
Process* Process_clone(Process* this);
|
||||
#define ONE_K 1024
|
||||
#define ONE_M (ONE_K * ONE_K)
|
||||
#define ONE_G (ONE_M * ONE_K)
|
||||
|
||||
void Process_delete(Object* cast);
|
||||
|
||||
void Process_display(Object* cast, RichString* out);
|
||||
Process* Process_new(struct ProcessList_ *pl);
|
||||
|
||||
Process* Process_clone(Process* this);
|
||||
|
||||
void Process_toggleTag(Process* this);
|
||||
|
||||
@ -168,12 +170,6 @@ bool Process_setAffinity(Process* this, unsigned long mask);
|
||||
|
||||
void Process_sendSignal(Process* this, int signal);
|
||||
|
||||
#define ONE_K 1024
|
||||
#define ONE_M (ONE_K * ONE_K)
|
||||
#define ONE_G (ONE_M * ONE_K)
|
||||
|
||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
||||
|
||||
int Process_pidCompare(const void* v1, const void* v2);
|
||||
|
||||
int Process_compare(const void* v1, const void* v2);
|
||||
|
@ -295,12 +295,7 @@ RichString ProcessList_printHeader(ProcessList* this) {
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void ProcessList_prune(ProcessList* this) {
|
||||
Vector_prune(this->processes);
|
||||
}
|
||||
|
||||
void ProcessList_add(ProcessList* this, Process* p) {
|
||||
static void ProcessList_add(ProcessList* this, Process* p) {
|
||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1);
|
||||
assert(Hashtable_get(this->processTable, p->pid) == NULL);
|
||||
Vector_add(this->processes, p);
|
||||
@ -310,7 +305,7 @@ void ProcessList_add(ProcessList* this, Process* p) {
|
||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
||||
}
|
||||
|
||||
void ProcessList_remove(ProcessList* this, Process* p) {
|
||||
static void ProcessList_remove(ProcessList* this, Process* p) {
|
||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
|
||||
assert(Hashtable_get(this->processTable, p->pid) != NULL);
|
||||
Process* pp = Hashtable_remove(this->processTable, p->pid);
|
||||
@ -462,34 +457,10 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name) {
|
||||
static bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name) {
|
||||
char statusfilename[MAX_NAME+1];
|
||||
statusfilename[MAX_NAME] = '\0';
|
||||
|
||||
bool success = false;
|
||||
char buffer[256];
|
||||
buffer[255] = '\0';
|
||||
|
||||
// We need to parse the status file just for tgid, which is missing in stat.
|
||||
snprintf(statusfilename, MAX_NAME, "%s/%s/status", dirname, name);
|
||||
FILE* status = ProcessList_fopen(this, statusfilename, "r");
|
||||
if (status) {
|
||||
while (!feof(status)) {
|
||||
char* ok = fgets(buffer, 255, status);
|
||||
if (!ok)
|
||||
break;
|
||||
if (String_startsWith(buffer, "Tgid:")) {
|
||||
int tgid;
|
||||
int ok = ProcessList_read(this, buffer, "Tgid:\t%d", &tgid);
|
||||
if (ok >= 1) {
|
||||
proc->tgid = tgid;
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(status);
|
||||
}
|
||||
snprintf(statusfilename, MAX_NAME, "%s/%s", dirname, name);
|
||||
struct stat sstat;
|
||||
int statok = stat(statusfilename, &sstat);
|
||||
@ -500,20 +471,19 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
|
||||
}
|
||||
|
||||
#ifdef HAVE_TASKSTATS
|
||||
void ProcessList_readIoFile(ProcessList* this, Process* proc, char* dirname, char* name) {
|
||||
|
||||
static void ProcessList_readIoFile(ProcessList* this, Process* proc, char* dirname, char* name) {
|
||||
char iofilename[MAX_NAME+1];
|
||||
iofilename[MAX_NAME] = '\0';
|
||||
|
||||
char buffer[256];
|
||||
buffer[255] = '\0';
|
||||
|
||||
snprintf(iofilename, MAX_NAME, "%s/%s/io", dirname, name);
|
||||
FILE* io = ProcessList_fopen(this, iofilename, "r");
|
||||
if (io) {
|
||||
char buffer[256];
|
||||
buffer[255] = '\0';
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,NULL);
|
||||
unsigned long long now = tv.tv_sec*1000+tv.tv_usec/1000;
|
||||
|
||||
unsigned long long last_read = proc->io_read_bytes;
|
||||
unsigned long long last_write = proc->io_write_bytes;
|
||||
while (!feof(io)) {
|
||||
@ -541,9 +511,10 @@ void ProcessList_readIoFile(ProcessList* this, Process* proc, char* dirname, cha
|
||||
fclose(io);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool ProcessList_processEntries(ProcessList* this, char* dirname, Process* parent, float period) {
|
||||
static bool ProcessList_processEntries(ProcessList* this, char* dirname, Process* parent, float period) {
|
||||
DIR* dir;
|
||||
struct dirent* entry;
|
||||
Process* prototype = this->prototype;
|
||||
@ -590,6 +561,9 @@ bool ProcessList_processEntries(ProcessList* this, char* dirname, Process* paren
|
||||
process->pid = pid;
|
||||
}
|
||||
}
|
||||
if (parent) {
|
||||
process->tgid = parent->pid;
|
||||
}
|
||||
|
||||
#ifdef HAVE_TASKSTATS
|
||||
ProcessList_readIoFile(this, process, dirname, name);
|
||||
|
@ -150,26 +150,15 @@ void ProcessList_invertSortOrder(ProcessList* this);
|
||||
|
||||
RichString ProcessList_printHeader(ProcessList* this);
|
||||
|
||||
|
||||
void ProcessList_prune(ProcessList* this);
|
||||
|
||||
void ProcessList_add(ProcessList* this, Process* p);
|
||||
|
||||
void ProcessList_remove(ProcessList* this, Process* p);
|
||||
|
||||
Process* ProcessList_get(ProcessList* this, int index);
|
||||
|
||||
int ProcessList_size(ProcessList* this);
|
||||
|
||||
void ProcessList_sort(ProcessList* this);
|
||||
|
||||
bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name);
|
||||
|
||||
#ifdef HAVE_TASKSTATS
|
||||
void ProcessList_readIoFile(ProcessList* this, Process* proc, char* dirname, char* name);
|
||||
#endif
|
||||
|
||||
bool ProcessList_processEntries(ProcessList* this, char* dirname, Process* parent, float period);
|
||||
#endif
|
||||
|
||||
void ProcessList_scan(ProcessList* this);
|
||||
|
||||
|
@ -98,12 +98,6 @@ Panel* ScreenManager_remove(ScreenManager* this, int index) {
|
||||
return panel;
|
||||
}
|
||||
|
||||
void ScreenManager_setFunctionBar(ScreenManager* this, FunctionBar* fuBar) {
|
||||
if (this->owner && this->fuBar)
|
||||
FunctionBar_delete((Object*)this->fuBar);
|
||||
this->fuBar = fuBar;
|
||||
}
|
||||
|
||||
void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
|
||||
this->x1 = x1;
|
||||
this->y1 = y1;
|
||||
|
@ -49,8 +49,6 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int
|
||||
|
||||
Panel* ScreenManager_remove(ScreenManager* this, int index);
|
||||
|
||||
void ScreenManager_setFunctionBar(ScreenManager* this, FunctionBar* fuBar);
|
||||
|
||||
void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2);
|
||||
|
||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey);
|
||||
|
70
Settings.c
70
Settings.c
@ -27,40 +27,6 @@ typedef struct Settings_ {
|
||||
|
||||
}*/
|
||||
|
||||
Settings* Settings_new(ProcessList* pl, Header* header) {
|
||||
Settings* this = malloc(sizeof(Settings));
|
||||
this->pl = pl;
|
||||
this->header = header;
|
||||
char* home;
|
||||
char* rcfile;
|
||||
home = getenv("HOME_ETC");
|
||||
if (!home) home = getenv("HOME");
|
||||
if (!home) home = "";
|
||||
rcfile = getenv("HOMERC");
|
||||
if (!rcfile)
|
||||
this->userSettings = String_cat(home, "/.htoprc");
|
||||
else
|
||||
this->userSettings = String_copy(rcfile);
|
||||
this->colorScheme = 0;
|
||||
this->changed = false;
|
||||
this->delay = DEFAULT_DELAY;
|
||||
bool ok = Settings_read(this, this->userSettings);
|
||||
if (!ok) {
|
||||
this->changed = true;
|
||||
// TODO: how to get SYSCONFDIR correctly through Autoconf?
|
||||
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
|
||||
ok = Settings_read(this, systemSettings);
|
||||
free(systemSettings);
|
||||
if (!ok) {
|
||||
Header_defaultMeters(this->header);
|
||||
pl->hideKernelThreads = true;
|
||||
pl->highlightMegabytes = true;
|
||||
pl->highlightThreads = false;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void Settings_delete(Settings* this) {
|
||||
free(this->userSettings);
|
||||
free(this);
|
||||
@ -89,7 +55,7 @@ static void Settings_readMeterModes(Settings* this, char* line, HeaderSide side)
|
||||
String_freeArray(ids);
|
||||
}
|
||||
|
||||
bool Settings_read(Settings* this, char* fileName) {
|
||||
static bool Settings_read(Settings* this, char* fileName) {
|
||||
// TODO: implement File object and make
|
||||
// file I/O object-oriented.
|
||||
FILE* fd;
|
||||
@ -232,3 +198,37 @@ bool Settings_write(Settings* this) {
|
||||
fclose(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
Settings* Settings_new(ProcessList* pl, Header* header) {
|
||||
Settings* this = malloc(sizeof(Settings));
|
||||
this->pl = pl;
|
||||
this->header = header;
|
||||
char* home;
|
||||
char* rcfile;
|
||||
home = getenv("HOME_ETC");
|
||||
if (!home) home = getenv("HOME");
|
||||
if (!home) home = "";
|
||||
rcfile = getenv("HOMERC");
|
||||
if (!rcfile)
|
||||
this->userSettings = String_cat(home, "/.htoprc");
|
||||
else
|
||||
this->userSettings = String_copy(rcfile);
|
||||
this->colorScheme = 0;
|
||||
this->changed = false;
|
||||
this->delay = DEFAULT_DELAY;
|
||||
bool ok = Settings_read(this, this->userSettings);
|
||||
if (!ok) {
|
||||
this->changed = true;
|
||||
// TODO: how to get SYSCONFDIR correctly through Autoconf?
|
||||
char* systemSettings = String_cat(SYSCONFDIR, "/htoprc");
|
||||
ok = Settings_read(this, systemSettings);
|
||||
free(systemSettings);
|
||||
if (!ok) {
|
||||
Header_defaultMeters(this->header);
|
||||
pl->hideKernelThreads = true;
|
||||
pl->highlightMegabytes = true;
|
||||
pl->highlightThreads = false;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -28,12 +28,10 @@ typedef struct Settings_ {
|
||||
} Settings;
|
||||
|
||||
|
||||
Settings* Settings_new(ProcessList* pl, Header* header);
|
||||
|
||||
void Settings_delete(Settings* this);
|
||||
|
||||
bool Settings_read(Settings* this, char* fileName);
|
||||
|
||||
bool Settings_write(Settings* this);
|
||||
|
||||
Settings* Settings_new(ProcessList* pl, Header* header);
|
||||
|
||||
#endif
|
||||
|
34
SignalItem.c
34
SignalItem.c
@ -31,7 +31,23 @@ char* SIGNAL_CLASS = "Signal";
|
||||
#define SIGNAL_CLASS NULL
|
||||
#endif
|
||||
|
||||
Signal* Signal_new(char* name, int number) {
|
||||
static void Signal_delete(Object* cast) {
|
||||
Signal* this = (Signal*)cast;
|
||||
assert (this != NULL);
|
||||
// names are string constants, so we're not deleting them.
|
||||
free(this);
|
||||
}
|
||||
|
||||
static void Signal_display(Object* cast, RichString* out) {
|
||||
Signal* this = (Signal*)cast;
|
||||
assert (this != NULL);
|
||||
|
||||
char buffer[31];
|
||||
snprintf(buffer, 30, "%2d %s", this->number, this->name);
|
||||
RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer);
|
||||
}
|
||||
|
||||
static Signal* Signal_new(char* name, int number) {
|
||||
Signal* this = malloc(sizeof(Signal));
|
||||
Object_setClass(this, SIGNAL_CLASS);
|
||||
((Object*)this)->display = Signal_display;
|
||||
@ -41,22 +57,6 @@ Signal* Signal_new(char* name, int number) {
|
||||
return this;
|
||||
}
|
||||
|
||||
void Signal_delete(Object* cast) {
|
||||
Signal* this = (Signal*)cast;
|
||||
assert (this != NULL);
|
||||
// names are string constants, so we're not deleting them.
|
||||
free(this);
|
||||
}
|
||||
|
||||
void Signal_display(Object* cast, RichString* out) {
|
||||
Signal* this = (Signal*)cast;
|
||||
assert (this != NULL);
|
||||
|
||||
char buffer[31];
|
||||
snprintf(buffer, 30, "%2d %s", this->number, this->name);
|
||||
RichString_write(out, CRT_colors[DEFAULT_COLOR], buffer);
|
||||
}
|
||||
|
||||
int Signal_getSignalCount() {
|
||||
return SIGNAL_COUNT;
|
||||
}
|
||||
|
@ -32,12 +32,6 @@ extern char* SIGNAL_CLASS;
|
||||
#define SIGNAL_CLASS NULL
|
||||
#endif
|
||||
|
||||
Signal* Signal_new(char* name, int number);
|
||||
|
||||
void Signal_delete(Object* cast);
|
||||
|
||||
void Signal_display(Object* cast, RichString* out);
|
||||
|
||||
int Signal_getSignalCount();
|
||||
|
||||
Signal** Signal_getSignalTable();
|
||||
|
@ -20,38 +20,7 @@ typedef struct SignalsPanel_ {
|
||||
|
||||
}*/
|
||||
|
||||
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
|
||||
SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, x, y, w, h, SIGNAL_CLASS, true);
|
||||
((Object*)this)->delete = SignalsPanel_delete;
|
||||
|
||||
this->signals = Signal_getSignalTable();
|
||||
super->eventHandler = SignalsPanel_eventHandler;
|
||||
int sigCount = Signal_getSignalCount();
|
||||
for(int i = 0; i < sigCount; i++)
|
||||
Panel_set(super, i, (Object*) this->signals[i]);
|
||||
SignalsPanel_reset(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
void SignalsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
SignalsPanel* this = (SignalsPanel*) object;
|
||||
Panel_done(super);
|
||||
free(this->signals);
|
||||
free(this);
|
||||
}
|
||||
|
||||
void SignalsPanel_reset(SignalsPanel* this) {
|
||||
Panel* super = (Panel*) this;
|
||||
|
||||
Panel_setHeader(super, "Send signal:");
|
||||
Panel_setSelected(super, 16); // 16th item is SIGTERM
|
||||
this->state = 0;
|
||||
}
|
||||
|
||||
HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
|
||||
static HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
|
||||
SignalsPanel* this = (SignalsPanel*) super;
|
||||
|
||||
int size = Panel_getSize(super);
|
||||
@ -75,3 +44,34 @@ HandlerResult SignalsPanel_eventHandler(Panel* super, int ch) {
|
||||
}
|
||||
return IGNORED;
|
||||
}
|
||||
|
||||
static void SignalsPanel_delete(Object* object) {
|
||||
Panel* super = (Panel*) object;
|
||||
SignalsPanel* this = (SignalsPanel*) object;
|
||||
Panel_done(super);
|
||||
free(this->signals);
|
||||
free(this);
|
||||
}
|
||||
|
||||
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) {
|
||||
SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel));
|
||||
Panel* super = (Panel*) this;
|
||||
Panel_init(super, x, y, w, h, SIGNAL_CLASS, true);
|
||||
((Object*)this)->delete = SignalsPanel_delete;
|
||||
|
||||
this->signals = Signal_getSignalTable();
|
||||
super->eventHandler = SignalsPanel_eventHandler;
|
||||
int sigCount = Signal_getSignalCount();
|
||||
for(int i = 0; i < sigCount; i++)
|
||||
Panel_set(super, i, (Object*) this->signals[i]);
|
||||
SignalsPanel_reset(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
void SignalsPanel_reset(SignalsPanel* this) {
|
||||
Panel* super = (Panel*) this;
|
||||
|
||||
Panel_setHeader(super, "Send signal:");
|
||||
Panel_setSelected(super, 16); // 16th item is SIGTERM
|
||||
this->state = 0;
|
||||
}
|
||||
|
@ -23,10 +23,6 @@ typedef struct SignalsPanel_ {
|
||||
|
||||
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h);
|
||||
|
||||
void SignalsPanel_delete(Object* object);
|
||||
|
||||
void SignalsPanel_reset(SignalsPanel* this);
|
||||
|
||||
HandlerResult SignalsPanel_eventHandler(Panel* super, int ch);
|
||||
|
||||
#endif
|
||||
|
55
String.c
55
String.c
@ -18,10 +18,6 @@ in the source distribution for its full text.
|
||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||
}*/
|
||||
|
||||
inline void String_delete(char* s) {
|
||||
free(s);
|
||||
}
|
||||
|
||||
inline char* String_copy(char* orig) {
|
||||
return strdup(orig);
|
||||
}
|
||||
@ -49,53 +45,6 @@ char* String_trim(char* in) {
|
||||
return out;
|
||||
}
|
||||
|
||||
char* String_copyUpTo(char* orig, char upTo) {
|
||||
int len;
|
||||
|
||||
int origLen = strlen(orig);
|
||||
char* at = strchr(orig, upTo);
|
||||
if (at != NULL)
|
||||
len = at - orig;
|
||||
else
|
||||
len = origLen;
|
||||
char* copy = (char*) malloc(len+1);
|
||||
strncpy(copy, orig, len);
|
||||
copy[len] = '\0';
|
||||
return copy;
|
||||
}
|
||||
|
||||
char* String_sub(char* orig, int from, int to) {
|
||||
char* copy;
|
||||
int len;
|
||||
|
||||
len = strlen(orig);
|
||||
if (to > len)
|
||||
to = len;
|
||||
if (from > len)
|
||||
to = len;
|
||||
len = to-from+1;
|
||||
copy = (char*) malloc(len+1);
|
||||
strncpy(copy, orig+from, len);
|
||||
copy[len] = '\0';
|
||||
return copy;
|
||||
}
|
||||
|
||||
void String_println(char* s) {
|
||||
printf("%s\n", s);
|
||||
}
|
||||
|
||||
void String_print(char* s) {
|
||||
printf("%s", s);
|
||||
}
|
||||
|
||||
void String_printInt(int i) {
|
||||
printf("%i", i);
|
||||
}
|
||||
|
||||
void String_printPointer(void* p) {
|
||||
printf("%p", p);
|
||||
}
|
||||
|
||||
inline int String_eq(const char* s1, const char* s2) {
|
||||
if (s1 == NULL || s2 == NULL) {
|
||||
if (s1 == NULL && s2 == NULL)
|
||||
@ -144,10 +93,6 @@ void String_freeArray(char** s) {
|
||||
free(s);
|
||||
}
|
||||
|
||||
int String_startsWith_i(char* s, char* match) {
|
||||
return (strncasecmp(s, match, strlen(match)) == 0);
|
||||
}
|
||||
|
||||
int String_contains_i(char* s, char* match) {
|
||||
int lens = strlen(s);
|
||||
int lenmatch = strlen(match);
|
||||
|
16
String.h
16
String.h
@ -19,34 +19,18 @@ in the source distribution for its full text.
|
||||
|
||||
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
|
||||
|
||||
extern void String_delete(char* s);
|
||||
|
||||
extern char* String_copy(char* orig);
|
||||
|
||||
char* String_cat(char* s1, char* s2);
|
||||
|
||||
char* String_trim(char* in);
|
||||
|
||||
char* String_copyUpTo(char* orig, char upTo);
|
||||
|
||||
char* String_sub(char* orig, int from, int to);
|
||||
|
||||
void String_println(char* s);
|
||||
|
||||
void String_print(char* s);
|
||||
|
||||
void String_printInt(int i);
|
||||
|
||||
void String_printPointer(void* p);
|
||||
|
||||
extern int String_eq(const char* s1, const char* s2);
|
||||
|
||||
char** String_split(char* s, char sep);
|
||||
|
||||
void String_freeArray(char** s);
|
||||
|
||||
int String_startsWith_i(char* s, char* match);
|
||||
|
||||
int String_contains_i(char* s, char* match);
|
||||
|
||||
#endif
|
||||
|
28
SwapMeter.c
28
SwapMeter.c
@ -23,26 +23,14 @@ int SwapMeter_attributes[] = {
|
||||
SWAP
|
||||
};
|
||||
|
||||
MeterType SwapMeter = {
|
||||
.setValues = SwapMeter_setValues,
|
||||
.display = SwapMeter_display,
|
||||
.mode = BAR_METERMODE,
|
||||
.items = 1,
|
||||
.total = 100.0,
|
||||
.attributes = SwapMeter_attributes,
|
||||
.name = "Swap",
|
||||
.uiName = "Swap",
|
||||
.caption = "Swp"
|
||||
};
|
||||
|
||||
void SwapMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
static void SwapMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
long int usedSwap = this->pl->usedSwap;
|
||||
this->total = this->pl->totalSwap;
|
||||
this->values[0] = usedSwap;
|
||||
snprintf(buffer, len, "%ld/%ldMB", (long int) usedSwap / 1024, (long int) this->total / 1024);
|
||||
}
|
||||
|
||||
void SwapMeter_display(Object* cast, RichString* out) {
|
||||
static void SwapMeter_display(Object* cast, RichString* out) {
|
||||
char buffer[50];
|
||||
Meter* this = (Meter*)cast;
|
||||
long int swap = (long int) this->values[0];
|
||||
@ -54,3 +42,15 @@ void SwapMeter_display(Object* cast, RichString* out) {
|
||||
RichString_append(out, CRT_colors[METER_TEXT], "used:");
|
||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||
}
|
||||
|
||||
MeterType SwapMeter = {
|
||||
.setValues = SwapMeter_setValues,
|
||||
.display = SwapMeter_display,
|
||||
.mode = BAR_METERMODE,
|
||||
.items = 1,
|
||||
.total = 100.0,
|
||||
.attributes = SwapMeter_attributes,
|
||||
.name = "Swap",
|
||||
.uiName = "Swap",
|
||||
.caption = "Swp"
|
||||
};
|
||||
|
@ -26,8 +26,4 @@ extern int SwapMeter_attributes[];
|
||||
|
||||
extern MeterType SwapMeter;
|
||||
|
||||
void SwapMeter_setValues(Meter* this, char* buffer, int len);
|
||||
|
||||
void SwapMeter_display(Object* cast, RichString* out);
|
||||
|
||||
#endif
|
||||
|
36
TasksMeter.c
36
TasksMeter.c
@ -18,6 +18,24 @@ int TasksMeter_attributes[] = {
|
||||
TASKS_RUNNING
|
||||
};
|
||||
|
||||
static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
this->total = this->pl->totalTasks;
|
||||
this->values[0] = this->pl->runningTasks;
|
||||
snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
|
||||
}
|
||||
|
||||
static void TasksMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
RichString_init(out);
|
||||
char buffer[20];
|
||||
sprintf(buffer, "%d", (int)this->total);
|
||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " total, ");
|
||||
sprintf(buffer, "%d", (int)this->values[0]);
|
||||
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " running");
|
||||
}
|
||||
|
||||
MeterType TasksMeter = {
|
||||
.setValues = TasksMeter_setValues,
|
||||
.display = TasksMeter_display,
|
||||
@ -29,21 +47,3 @@ MeterType TasksMeter = {
|
||||
.uiName = "Task counter",
|
||||
.caption = "Tasks: "
|
||||
};
|
||||
|
||||
void TasksMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
this->total = this->pl->totalTasks;
|
||||
this->values[0] = this->pl->runningTasks;
|
||||
snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
|
||||
}
|
||||
|
||||
void TasksMeter_display(Object* cast, RichString* out) {
|
||||
Meter* this = (Meter*)cast;
|
||||
RichString_init(out);
|
||||
char buffer[20];
|
||||
sprintf(buffer, "%d", (int)this->total);
|
||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " total, ");
|
||||
sprintf(buffer, "%d", (int)this->values[0]);
|
||||
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
|
||||
RichString_append(out, CRT_colors[METER_TEXT], " running");
|
||||
}
|
||||
|
@ -21,8 +21,4 @@ extern int TasksMeter_attributes[];
|
||||
|
||||
extern MeterType TasksMeter;
|
||||
|
||||
void TasksMeter_setValues(Meter* this, char* buffer, int len);
|
||||
|
||||
void TasksMeter_display(Object* cast, RichString* out);
|
||||
|
||||
#endif
|
||||
|
@ -53,7 +53,7 @@ void TraceScreen_delete(TraceScreen* this) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
void TraceScreen_draw(TraceScreen* this) {
|
||||
static void TraceScreen_draw(TraceScreen* this) {
|
||||
attrset(CRT_colors[PANEL_HEADER_FOCUS]);
|
||||
mvhline(0, 0, ' ', COLS);
|
||||
mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, this->process->comm);
|
||||
|
@ -37,8 +37,6 @@ TraceScreen* TraceScreen_new(Process* process);
|
||||
|
||||
void TraceScreen_delete(TraceScreen* this);
|
||||
|
||||
void TraceScreen_draw(TraceScreen* this);
|
||||
|
||||
void TraceScreen_run(TraceScreen* this);
|
||||
|
||||
#endif
|
||||
|
@ -18,19 +18,7 @@ int UptimeMeter_attributes[] = {
|
||||
UPTIME
|
||||
};
|
||||
|
||||
MeterType UptimeMeter = {
|
||||
.setValues = UptimeMeter_setValues,
|
||||
.display = NULL,
|
||||
.mode = TEXT_METERMODE,
|
||||
.items = 1,
|
||||
.total = 100.0,
|
||||
.attributes = UptimeMeter_attributes,
|
||||
.name = "Uptime",
|
||||
.uiName = "Uptime",
|
||||
.caption = "Uptime: "
|
||||
};
|
||||
|
||||
void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
double uptime;
|
||||
FILE* fd = fopen(PROCDIR "/uptime", "r");
|
||||
fscanf(fd, "%lf", &uptime);
|
||||
@ -56,3 +44,15 @@ void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
|
||||
}
|
||||
snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
|
||||
}
|
||||
|
||||
MeterType UptimeMeter = {
|
||||
.setValues = UptimeMeter_setValues,
|
||||
.display = NULL,
|
||||
.mode = TEXT_METERMODE,
|
||||
.items = 1,
|
||||
.total = 100.0,
|
||||
.attributes = UptimeMeter_attributes,
|
||||
.name = "Uptime",
|
||||
.uiName = "Uptime",
|
||||
.caption = "Uptime: "
|
||||
};
|
||||
|
@ -21,6 +21,4 @@ extern int UptimeMeter_attributes[];
|
||||
|
||||
extern MeterType UptimeMeter;
|
||||
|
||||
void UptimeMeter_setValues(Meter* this, char* buffer, int len);
|
||||
|
||||
#endif
|
||||
|
@ -47,10 +47,6 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
|
||||
return name;
|
||||
}
|
||||
|
||||
inline int UsersTable_size(UsersTable* this) {
|
||||
return (Hashtable_size(this->users));
|
||||
}
|
||||
|
||||
inline void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData) {
|
||||
Hashtable_foreach(this->users, f, userData);
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ void UsersTable_delete(UsersTable* this);
|
||||
|
||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid);
|
||||
|
||||
extern int UsersTable_size(UsersTable* this);
|
||||
|
||||
extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData);
|
||||
|
||||
#endif
|
||||
|
12
Vector.c
12
Vector.c
@ -218,7 +218,9 @@ inline int Vector_size(Vector* this) {
|
||||
return this->items;
|
||||
}
|
||||
|
||||
void Vector_merge(Vector* this, Vector* v2) {
|
||||
/*
|
||||
|
||||
static void Vector_merge(Vector* this, Vector* v2) {
|
||||
int i;
|
||||
assert(Vector_isConsistent(this));
|
||||
|
||||
@ -229,6 +231,8 @@ void Vector_merge(Vector* this, Vector* v2) {
|
||||
assert(Vector_isConsistent(this));
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void Vector_add(Vector* this, void* data_) {
|
||||
assert(data_ && ((Object*)data_)->class == this->vectorType);
|
||||
Object* data = data_;
|
||||
@ -252,7 +256,9 @@ inline int Vector_indexOf(Vector* this, void* search_, Object_Compare compare) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Vector_foreach(Vector* this, Vector_procedure f) {
|
||||
/*
|
||||
|
||||
static void Vector_foreach(Vector* this, Vector_procedure f) {
|
||||
int i;
|
||||
assert(Vector_isConsistent(this));
|
||||
|
||||
@ -260,3 +266,5 @@ void Vector_foreach(Vector* this, Vector_procedure f) {
|
||||
f(this->array[i]);
|
||||
assert(Vector_isConsistent(this));
|
||||
}
|
||||
|
||||
*/
|
||||
|
8
Vector.h
8
Vector.h
@ -65,12 +65,16 @@ extern Object* Vector_get(Vector* this, int index);
|
||||
|
||||
extern int Vector_size(Vector* this);
|
||||
|
||||
void Vector_merge(Vector* this, Vector* v2);
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
void Vector_add(Vector* this, void* data_);
|
||||
|
||||
extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare);
|
||||
|
||||
void Vector_foreach(Vector* this, Vector_procedure f);
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
10
htop.c
10
htop.c
@ -35,14 +35,14 @@ in the source distribution for its full text.
|
||||
|
||||
#define INCSEARCH_MAX 40
|
||||
|
||||
void printVersionFlag() {
|
||||
static void printVersionFlag() {
|
||||
clear();
|
||||
printf("htop " VERSION " - (C) 2004-2008 Hisham Muhammad.\n");
|
||||
printf("Released under the GNU GPL.\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void printHelpFlag() {
|
||||
static void printHelpFlag() {
|
||||
clear();
|
||||
printf("htop " VERSION " - (C) 2004-2008 Hisham Muhammad.\n");
|
||||
printf("Released under the GNU GPL.\n\n");
|
||||
@ -54,7 +54,7 @@ void printHelpFlag() {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void showHelp(ProcessList* pl) {
|
||||
static void showHelp(ProcessList* pl) {
|
||||
clear();
|
||||
attrset(CRT_colors[HELP_BOLD]);
|
||||
|
||||
@ -201,13 +201,13 @@ static Object* pickFromList(Panel* panel, Panel* list, int x, int y, char** keyL
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void addUserToList(int key, void* userCast, void* panelCast) {
|
||||
static void addUserToList(int key, void* userCast, void* panelCast) {
|
||||
char* user = (char*) userCast;
|
||||
Panel* panel = (Panel*) panelCast;
|
||||
Panel_add(panel, (Object*) ListItem_new(user, key));
|
||||
}
|
||||
|
||||
void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
|
||||
static void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
|
||||
struct passwd* user = getpwnam(userName);
|
||||
if (user) {
|
||||
*userOnly = true;
|
||||
|
10
htop.h
10
htop.h
@ -39,16 +39,6 @@ in the source distribution for its full text.
|
||||
|
||||
#define INCSEARCH_MAX 40
|
||||
|
||||
void printVersionFlag();
|
||||
|
||||
void printHelpFlag();
|
||||
|
||||
void showHelp(ProcessList* pl);
|
||||
|
||||
void addUserToList(int key, void* userCast, void* panelCast);
|
||||
|
||||
void setUserOnly(const char* userName, bool* userOnly, uid_t* userId);
|
||||
|
||||
int main(int argc, char** argv);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user