Commit da23c8c5 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Clean up headers by using 'static' whenever possible.

Reduces resulting code size.
parent 12f4f09e
...@@ -20,37 +20,14 @@ typedef struct DisplayOptionsPanel_ { ...@@ -20,37 +20,14 @@ typedef struct DisplayOptionsPanel_ {
}*/ }*/
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) { static void DisplayOptionsPanel_delete(Object* object) {
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) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object; DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
Panel_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super; DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
...@@ -75,3 +52,25 @@ HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { ...@@ -75,3 +52,25 @@ HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
return result; 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_ { ...@@ -23,9 +23,4 @@ typedef struct DisplayOptionsPanel_ {
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr);
void DisplayOptionsPanel_delete(Object* object);
HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch);
#endif #endif
...@@ -34,7 +34,7 @@ struct Hashtable_ { ...@@ -34,7 +34,7 @@ struct Hashtable_ {
#ifdef DEBUG #ifdef DEBUG
bool Hashtable_isConsistent(Hashtable* this) { static bool Hashtable_isConsistent(Hashtable* this) {
int items = 0; int items = 0;
for (int i = 0; i < this->size; i++) { for (int i = 0; i < this->size; i++) {
HashtableItem* bucket = this->buckets[i]; HashtableItem* bucket = this->buckets[i];
...@@ -61,7 +61,7 @@ int Hashtable_count(Hashtable* this) { ...@@ -61,7 +61,7 @@ int Hashtable_count(Hashtable* this) {
#endif #endif
HashtableItem* HashtableItem_new(unsigned int key, void* value) { static HashtableItem* HashtableItem_new(unsigned int key, void* value) {
HashtableItem* this; HashtableItem* this;
this = (HashtableItem*) malloc(sizeof(HashtableItem)); this = (HashtableItem*) malloc(sizeof(HashtableItem));
...@@ -99,11 +99,6 @@ void Hashtable_delete(Hashtable* this) { ...@@ -99,11 +99,6 @@ void Hashtable_delete(Hashtable* this) {
free(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) { void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
unsigned int index = key % this->size; unsigned int index = key % this->size;
HashtableItem** bucketPtr = &(this->buckets[index]); HashtableItem** bucketPtr = &(this->buckets[index]);
......
...@@ -35,20 +35,14 @@ struct Hashtable_ { ...@@ -35,20 +35,14 @@ struct Hashtable_ {
#ifdef DEBUG #ifdef DEBUG
bool Hashtable_isConsistent(Hashtable* this);
int Hashtable_count(Hashtable* this); int Hashtable_count(Hashtable* this);
#endif #endif
HashtableItem* HashtableItem_new(unsigned int key, void* value);
Hashtable* Hashtable_new(int size, bool owner); Hashtable* Hashtable_new(int size, bool owner);
void Hashtable_delete(Hashtable* this); void Hashtable_delete(Hashtable* this);
extern int Hashtable_size(Hashtable* this);
void Hashtable_put(Hashtable* this, unsigned int key, void* value); void Hashtable_put(Hashtable* this, unsigned int key, void* value);
void* Hashtable_remove(Hashtable* this, unsigned int key); void* Hashtable_remove(Hashtable* this, unsigned int key);
......
...@@ -29,6 +29,21 @@ char* LISTITEM_CLASS = "ListItem"; ...@@ -29,6 +29,21 @@ char* LISTITEM_CLASS = "ListItem";
#define LISTITEM_CLASS NULL #define LISTITEM_CLASS NULL
#endif #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* ListItem_new(char* value, int key) {
ListItem* this = malloc(sizeof(ListItem)); ListItem* this = malloc(sizeof(ListItem));
Object_setClass(this, LISTITEM_CLASS); Object_setClass(this, LISTITEM_CLASS);
...@@ -46,21 +61,6 @@ void ListItem_append(ListItem* this, char* text) { ...@@ -46,21 +61,6 @@ void ListItem_append(ListItem* this, char* text) {
this->value = buf; 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) { const char* ListItem_getRef(ListItem* this) {
return this->value; return this->value;
} }
......
...@@ -34,10 +34,6 @@ ListItem* ListItem_new(char* value, int key); ...@@ -34,10 +34,6 @@ ListItem* ListItem_new(char* value, int key);
void ListItem_append(ListItem* this, char* text); 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); const char* ListItem_getRef(ListItem* this);
int ListItem_compare(const void* cast1, const void* cast2); int ListItem_compare(const void* cast1, const void* cast2);
......
...@@ -16,32 +16,8 @@ int LoadAverageMeter_attributes[] = { ...@@ -16,32 +16,8 @@ int LoadAverageMeter_attributes[] = {
LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE
}; };
MeterType LoadAverageMeter = {
.setValues = LoadAverageMeter_setValues,
.display = LoadAverageMeter_display,
.mode = TEXT_METERMODE,
.items = 3,
.total = 100.0,
.attributes = LoadAverageMeter_attributes,
.name = "LoadAverage",
.uiName = "Load average",
.caption = "Load average: "
};
int LoadMeter_attributes[] = { LOAD }; int LoadMeter_attributes[] = { LOAD };
MeterType LoadMeter = {
.setValues = LoadMeter_setValues,
.display = LoadMeter_display,
.mode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = LoadMeter_attributes,
.name = "Load",
.uiName = "Load",
.caption = "Load: "
};
static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) { static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
int activeProcs, totalProcs, lastProc; int activeProcs, totalProcs, lastProc;
FILE *fd = fopen(PROCDIR "/loadavg", "r"); FILE *fd = fopen(PROCDIR "/loadavg", "r");
...@@ -52,12 +28,12 @@ static inline void LoadAverageMeter_scan(double* one, double* five, double* fift ...@@ -52,12 +28,12 @@ static inline void LoadAverageMeter_scan(double* one, double* five, double* fift
fclose(fd); fclose(fd);
} }
void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) { static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]); 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]); snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]);
} }
void LoadAverageMeter_display(Object* cast, RichString* out) { static void LoadAverageMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
char buffer[20]; char buffer[20];
RichString_init(out); RichString_init(out);
...@@ -69,7 +45,7 @@ void LoadAverageMeter_display(Object* cast, RichString* out) { ...@@ -69,7 +45,7 @@ void LoadAverageMeter_display(Object* cast, RichString* out) {
RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer); RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
} }
void LoadMeter_setValues(Meter* this, char* buffer, int size) { static void LoadMeter_setValues(Meter* this, char* buffer, int size) {
double five, fifteen; double five, fifteen;
LoadAverageMeter_scan(&this->values[0], &five, &fifteen); LoadAverageMeter_scan(&this->values[0], &five, &fifteen);
if (this->values[0] > this->total) { if (this->values[0] > this->total) {
...@@ -78,10 +54,34 @@ void LoadMeter_setValues(Meter* this, char* buffer, int size) { ...@@ -78,10 +54,34 @@ void LoadMeter_setValues(Meter* this, char* buffer, int size) {
snprintf(buffer, size, "%.2f", this->values[0]); snprintf(buffer, size, "%.2f", this->values[0]);
} }
void LoadMeter_display(Object* cast, RichString* out) { static void LoadMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
char buffer[20]; char buffer[20];
RichString_init(out); RichString_init(out);
sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]); sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]);
RichString_append(out, CRT_colors[LOAD], buffer); RichString_append(out, CRT_colors[LOAD], buffer);
} }
MeterType LoadAverageMeter = {
.setValues = LoadAverageMeter_setValues,
.display = LoadAverageMeter_display,
.mode = TEXT_METERMODE,
.items = 3,
.total = 100.0,
.attributes = LoadAverageMeter_attributes,
.name = "LoadAverage",
.uiName = "Load average",
.caption = "Load average: "
};
MeterType LoadMeter = {
.setValues = LoadMeter_setValues,
.display = LoadMeter_display,
.mode = TEXT_METERMODE,
.items = 1,
.total = 100.0,
.attributes = LoadMeter_attributes,
.name = "Load",
.uiName = "Load",
.caption = "Load: "
};
...@@ -17,18 +17,10 @@ in the source distribution for its full text. ...@@ -17,18 +17,10 @@ in the source distribution for its full text.
extern int LoadAverageMeter_attributes[]; extern int LoadAverageMeter_attributes[];
extern MeterType LoadAverageMeter;
extern int LoadMeter_attributes[]; extern int LoadMeter_attributes[];
extern MeterType LoadMeter; extern MeterType LoadAverageMeter;
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); extern MeterType LoadMeter;
#endif #endif
...@@ -23,19 +23,7 @@ int MemoryMeter_attributes[] = { ...@@ -23,19 +23,7 @@ int MemoryMeter_attributes[] = {
MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE
}; };
MeterType MemoryMeter = { static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
.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) {
long int usedMem = this->pl->usedMem; long int usedMem = this->pl->usedMem;
long int buffersMem = this->pl->buffersMem; long int buffersMem = this->pl->buffersMem;
long int cachedMem = this->pl->cachedMem; long int cachedMem = this->pl->cachedMem;
...@@ -47,7 +35,7 @@ void MemoryMeter_setValues(Meter* this, char* buffer, int size) { ...@@ -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); 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]; char buffer[50];
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
int div = 1024; char* format = "%ldM "; int div = 1024; char* format = "%ldM ";
...@@ -69,3 +57,15 @@ void MemoryMeter_display(Object* cast, RichString* out) { ...@@ -69,3 +57,15 @@ void MemoryMeter_display(Object* cast, RichString* out) {
RichString_append(out, CRT_colors[METER_TEXT], "cache:"); RichString_append(out, CRT_colors[METER_TEXT], "cache:");
RichString_append(out, CRT_colors[MEMORY_CACHE], buffer); 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[]; ...@@ -26,8 +26,4 @@ extern int MemoryMeter_attributes[];
extern MeterType MemoryMeter; extern MeterType MemoryMeter;
void MemoryMeter_setValues(Meter* this, char* buffer, int size);
void MemoryMeter_display(Object* cast, RichString* out);
#endif #endif
...@@ -124,45 +124,6 @@ MeterType* Meter_types[] = { ...@@ -124,45 +124,6 @@ MeterType* Meter_types[] = {
NULL 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; static RichString Meter_stringBuffer;
Meter* Meter_new(ProcessList* pl, int param, MeterType* type) { Meter* Meter_new(ProcessList* pl, int param, MeterType* type) {
...@@ -254,7 +215,7 @@ ListItem* Meter_toListItem(Meter* this) { ...@@ -254,7 +215,7 @@ ListItem* Meter_toListItem(Meter* this) {
/* ---------- TextMeterMode ---------- */ /* ---------- 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; MeterType* type = this->type;
char buffer[METER_BUFFER_LEN]; char buffer[METER_BUFFER_LEN];
type->setValues(this, buffer, METER_BUFFER_LEN - 1); type->setValues(this, buffer, METER_BUFFER_LEN - 1);
...@@ -274,7 +235,7 @@ void TextMeterMode_draw(Meter* this, int x, int y, int w) { ...@@ -274,7 +235,7 @@ void TextMeterMode_draw(Meter* this, int x, int y, int w) {
static char BarMeterMode_characters[] = "|#*@$%&"; 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; MeterType* type = this->type;
char buffer[METER_BUFFER_LEN]; char buffer[METER_BUFFER_LEN];
type->setValues(this, buffer, METER_BUFFER_LEN - 1); type->setValues(this, buffer, METER_BUFFER_LEN - 1);
...@@ -362,7 +323,7 @@ static int GraphMeterMode_colors[21] = { ...@@ -362,7 +323,7 @@ static int GraphMeterMode_colors[21] = {
static char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_"; 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); if (!this->drawBuffer) this->drawBuffer = calloc(sizeof(double), METER_BUFFER_LEN);
double* drawBuffer = (double*) this->drawBuffer; double* drawBuffer = (double*) this->drawBuffer;
...@@ -408,7 +369,7 @@ static void LEDMeterMode_drawDigit(int x, int y, int n) { ...@@ -408,7 +369,7 @@ static void LEDMeterMode_drawDigit(int x, int y, int n) {
mvaddstr(y+i, x, LEDMeterMode_digits[i][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; MeterType* type = this->type;
char buffer[METER_BUFFER_LEN]; char buffer[METER_BUFFER_LEN];
type->setValues(this, buffer, METER_BUFFER_LEN - 1); type->setValues(this, buffer, METER_BUFFER_LEN - 1);
...@@ -432,3 +393,42 @@ void LEDMeterMode_draw(Meter* this, int x, int y, int w) { ...@@ -432,3 +393,42 @@ void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
} }
#endif #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
};
...@@ -114,12 +114,6 @@ extern char* METER_CLASS; ...@@ -114,12 +114,6 @@ extern char* METER_CLASS;
extern MeterType* Meter_types[]; extern MeterType* Meter_types[];
#ifdef USE_FUNKY_MODES
#endif
extern MeterMode* Meter_modes[];
Meter* Meter_new(ProcessList* pl, int param, MeterType* type); Meter* Meter_new(ProcessList* pl, int param, MeterType* type);
void Meter_delete(Object* cast); void Meter_delete(Object* cast);
...@@ -132,24 +126,22 @@ ListItem* Meter_toListItem(Meter* this); ...@@ -132,24 +126,22 @@ ListItem* Meter_toListItem(Meter* this);
/* ---------- TextMeterMode ---------- */ /* ---------- TextMeterMode ---------- */
void TextMeterMode_draw(Meter* this, int x, int y, int w);
/* ---------- BarMeterMode ---------- */ /* ---------- BarMeterMode ---------- */
void BarMeterMode_draw(Meter* this, int x, int y, int w);
#ifdef USE_FUNKY_MODES #ifdef USE_FUNKY_MODES
/* ---------- GraphMeterMode ---------- */ /* ---------- GraphMeterMode ---------- */
#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0) #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 ---------- */ /* ---------- LEDMeterMode ---------- */
void LEDMeterMode_draw(Meter* this, int x, int y, int w); #endif
#ifdef USE_FUNKY_MODES
#endif #endif
extern MeterMode* Meter_modes[];
#endif #endif
...@@ -20,32 +20,14 @@ typedef struct MetersPanel_ { ...@@ -20,32 +20,14 @@ typedef struct MetersPanel_ {
}*/ }*/
MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr) { static void MetersPanel_delete(Object* object) {
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) {
Panel* super = (Panel*) object; Panel* super = (Panel*) object;
MetersPanel* this = (MetersPanel*) object; MetersPanel* this = (MetersPanel*) object;
Panel_done(super); Panel_done(super);
free(this); free(this);
} }
HandlerResult MetersPanel_EventHandler(Panel* super, int ch) { static HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
MetersPanel* this = (MetersPanel*) super; MetersPanel* this = (MetersPanel*) super;
int selected = Panel_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
...@@ -103,3 +85,21 @@ HandlerResult MetersPanel_EventHandler(Panel* super, int ch) { ...@@ -103,3 +85,21 @@ HandlerResult MetersPanel_EventHandler(Panel* super, int ch) {
} }
return result; 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_ { ...@@ -23,8 +23,4 @@ typedef struct MetersPanel_ {
MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr); MetersPanel* MetersPanel_new(Settings* settings, char* header, Vector* meters, ScreenManager* scr);
void MetersPanel_delete(Object* object);
HandlerResult MetersPanel_EventHandler(Panel* super, int ch);
#endif #endif
...@@ -48,7 +48,7 @@ void Object_setClass(void* this, char* class) { ...@@ -48,7 +48,7 @@ void Object_setClass(void* this, char* class) {
((Object*)this)->class = class; ((Object*)this)->class = class;
} }
void Object_display(Object* this, RichString* out) { static void Object_display(Object* this, RichString* out) {
char objAddress[50]; char objAddress[50];
sprintf(objAddress, "%s @ %p", this->class, (void*) this); sprintf(objAddress, "%s @ %p", this->class, (void*) this);
RichString_write(out, CRT_colors[DEFAULT_COLOR], objAddress); RichString_write(out, CRT_colors[DEFAULT_COLOR], objAddress);
......
...@@ -47,8 +47,6 @@ extern char* OBJECT_CLASS; ...@@ -47,8 +47,6 @@ extern char* OBJECT_CLASS;
void Object_setClass(void* this, char* class); void Object_setClass(void* this, char* class);
void Object_display(Object* this, RichString* out);
#endif #endif
#endif #endif
...@@ -160,91 +160,6 @@ char *Process_fieldNames[] = { ...@@ -160,91 +160,6 @@ char *Process_fieldNames[] = {
static int Process_getuid = -1; 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_K 1024
#define ONE_M (ONE_K * ONE_K) #define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * 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 ...@@ -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]; char buffer[PROCESS_COMM_LEN];
int attr = CRT_colors[DEFAULT_COLOR]; int attr = CRT_colors[DEFAULT_COLOR];
int baseattr = CRT_colors[PROCESS_BASENAME]; int baseattr = CRT_colors[PROCESS_BASENAME];
...@@ -450,6 +365,91 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { ...@@ -450,6 +365,91 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
RichString_append(str, attr, buffer); 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) { int Process_pidCompare(const void* v1, const void* v2) {
Process* p1 = (Process*)v1; Process* p1 = (Process*)v1;
Process* p2 = (Process*)v2; Process* p2 = (Process*)v2;
......
...@@ -150,13 +150,15 @@ extern char* PROCESS_CLASS; ...@@ -150,13 +150,15 @@ extern char* PROCESS_CLASS;
extern char *Process_fieldNames[]; extern char *Process_fieldNames[];
Process* Process_new(struct ProcessList_ *pl); #define ONE_K 1024
#define ONE_M (ONE_K * ONE_K)
Process* Process_clone(Process* this); #define ONE_G (ONE_M * ONE_K)
void Process_delete(Object* cast); 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); void Process_toggleTag(Process* this);
...@@ -168,12 +170,6 @@ bool Process_setAffinity(Process* this, unsigned long mask); ...@@ -168,12 +170,6 @@ bool Process_setAffinity(Process* this, unsigned long mask);
void Process_sendSignal(Process* this, int signal); 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_pidCompare(const void* v1, const void* v2);
int Process_compare(const void* v1, const void* v2); int Process_compare(const void* v1, const void* v2);
......
...@@ -295,12 +295,7 @@ RichString ProcessList_printHeader(ProcessList* this) { ...@@ -295,12 +295,7 @@ RichString ProcessList_printHeader(ProcessList* this) {
return out; return out;
} }
static void ProcessList_add(ProcessList* this, Process* p) {
void ProcessList_prune(ProcessList* this) {
Vector_prune(this->processes);
}
void ProcessList_add(ProcessList* this, Process* p) {
assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1); assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1);
assert(Hashtable_get(this->processTable, p->pid) == NULL); assert(Hashtable_get(this->processTable, p->pid) == NULL);
Vector_add(this->processes, p); Vector_add(this->processes, p);
...@@ -310,7 +305,7 @@ void ProcessList_add(ProcessList* this, Process* p) { ...@@ -310,7 +305,7 @@ void ProcessList_add(ProcessList* this, Process* p) {
assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); 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(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
assert(Hashtable_get(this->processTable, p->pid) != NULL); assert(Hashtable_get(this->processTable, p->pid) != NULL);
Process* pp = Hashtable_remove(this->processTable, p->pid); Process* pp = Hashtable_remove(this->processTable, p->pid);
...@@ -462,34 +457,10 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c ...@@ -462,34 +457,10 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
return 1; 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]; char statusfilename[MAX_NAME+1];
statusfilename[MAX_NAME] = '\0'; 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); snprintf(statusfilename, MAX_NAME, "%s/%s", dirname, name);
struct stat sstat; struct stat sstat;
int statok = stat(statusfilename, &sstat); int statok = stat(statusfilename, &sstat);
...@@ -500,20 +471,19 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, ...@@ -500,20 +471,19 @@ bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname,
} }
#ifdef HAVE_TASKSTATS #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]; char iofilename[MAX_NAME+1];
iofilename[MAX_NAME] = '\0'; iofilename[MAX_NAME] = '\0';
char buffer[256];
buffer[255] = '\0';
snprintf(iofilename, MAX_NAME, "%s/%s/io", dirname, name); snprintf(iofilename, MAX_NAME, "%s/%s/io", dirname, name);
FILE* io = ProcessList_fopen(this, iofilename, "r"); FILE* io = ProcessList_fopen(this, iofilename, "r");
if (io) { if (io) {
char buffer[256];
buffer[255] = '\0';
struct timeval tv; struct timeval tv;
gettimeofday(&tv,NULL); gettimeofday(&tv,NULL);
unsigned long long now = tv.tv_sec*1000+tv.tv_usec/1000; 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_read = proc->io_read_bytes;
unsigned long long last_write = proc->io_write_bytes; unsigned long long last_write = proc->io_write_bytes;
while (!feof(io)) { while (!feof(io)) {
...@@ -541,9 +511,10 @@ void ProcessList_readIoFile(ProcessList* this, Process* proc, char* dirname, cha ...@@ -541,9 +511,10 @@ void ProcessList_readIoFile(ProcessList* this, Process* proc, char* dirname, cha
fclose(io); fclose(io);
} }
} }
#endif #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; DIR* dir;
struct dirent* entry; struct dirent* entry;
Process* prototype = this->prototype; Process* prototype = this->prototype;
...@@ -590,6 +561,9 @@ bool ProcessList_processEntries(ProcessList* this, char* dirname, Process* paren ...@@ -590,6 +561,9 @@ bool ProcessList_processEntries(ProcessList* this, char* dirname, Process* paren
process->pid = pid; process->pid = pid;
} }
} }
if (parent) {
process->tgid = parent->pid;
}
#ifdef HAVE_TASKSTATS #ifdef HAVE_TASKSTATS
ProcessList_readIoFile(this, process, dirname, name); ProcessList_readIoFile(this, process, dirname, name);
......
...@@ -150,26 +150,15 @@ void ProcessList_invertSortOrder(ProcessList* this); ...@@ -150,26 +150,15 @@ void ProcessList_invertSortOrder(ProcessList* this);
RichString ProcessList_printHeader(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); Process* ProcessList_get(ProcessList* this, int index);
int ProcessList_size(ProcessList* this); int ProcessList_size(ProcessList* this);
void ProcessList_sort(ProcessList* this); void ProcessList_sort(ProcessList* this);
bool ProcessList_readStatusFile(ProcessList* this, Process* proc, char* dirname, char* name);
#ifdef HAVE_TASKSTATS #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); void ProcessList_scan(ProcessList* this);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment