Commit 00b324bf authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Changes in object model: separate class objects to store vtable. Also, nicer...

Changes in object model: separate class objects to store vtable. Also, nicer UTF-8 display of big numbers.
parent 2a73405c
...@@ -92,16 +92,22 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { ...@@ -92,16 +92,22 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
return result; return result;
} }
PanelClass MetersPanel_class = {
.super = {
.extends = Class(Panel),
.delete = MetersPanel_delete
},
.eventHandler = MetersPanel_eventHandler
};
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr) { MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr) {
MetersPanel* this = (MetersPanel*) malloc(sizeof(MetersPanel)); MetersPanel* this = AllocThis(MetersPanel);
Panel* super = (Panel*) this; Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
((Object*)this)->delete = MetersPanel_delete;
this->settings = settings; this->settings = settings;
this->meters = meters; this->meters = meters;
this->scr = scr; this->scr = scr;
super->eventHandler = MetersPanel_eventHandler;
Panel_setHeader(super, header); Panel_setHeader(super, header);
for (int i = 0; i < Vector_size(meters); i++) { for (int i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) Vector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
......
...@@ -22,6 +22,8 @@ typedef struct MetersPanel_ { ...@@ -22,6 +22,8 @@ typedef struct MetersPanel_ {
} MetersPanel; } MetersPanel;
extern PanelClass MetersPanel_class;
MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr);
#endif #endif
/* /*
htop - Object.c htop - Object.c
(C) 2004-2011 Hisham H. Muhammad (C) 2004-2012 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "Object.h" #include "Object.h"
#include "CRT.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
/*{ /*{
#include "RichString.h" #include "RichString.h"
#ifndef DEBUG
#define Object_setClass(obj, class)
#endif
typedef struct Object_ Object; typedef struct Object_ Object;
typedef void(*Object_Display)(Object*, RichString*); typedef void(*Object_Display)(Object*, RichString*);
typedef int(*Object_Compare)(const void*, const void*); typedef int(*Object_Compare)(const void*, const void*);
typedef void(*Object_Delete)(Object*); typedef void(*Object_Delete)(Object*);
#define Object_getClass(obj_) ((Object*)(obj_))->klass
#define Object_setClass(obj_, class_) Object_getClass(obj_) = (ObjectClass*) class_
#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
#define Object_displayFn(obj_) Object_getClass(obj_)->display
#define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_)
#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
#define Class(class_) ((ObjectClass*)(&(class_ ## _class)))
#define AllocThis(class_) (class_*) malloc(sizeof(class_)); Object_setClass(this, Class(class_));
typedef struct ObjectClass_ {
const void* extends;
const Object_Display display;
const Object_Delete delete;
const Object_Compare compare;
} ObjectClass;
struct Object_ { struct Object_ {
#ifdef DEBUG ObjectClass* klass;
char* class;
#endif
Object_Display display;
Object_Delete delete;
}; };
}*/
#ifdef DEBUG }*/
char* OBJECT_CLASS = "Object";
#else ObjectClass Object_class = {
#define OBJECT_CLASS NULL .extends = NULL
#endif };
#ifdef DEBUG #ifdef DEBUG
void Object_setClass(void* this, char* class) { bool Object_isA(Object* o, const ObjectClass* klass) {
((Object*)this)->class = class; if (!o)
return false;
const ObjectClass* type = o->klass;
while (type) {
if (type == klass)
return true;
type = type->extends;
}
return false;
} }
#endif #endif
...@@ -4,41 +4,48 @@ ...@@ -4,41 +4,48 @@
#define HEADER_Object #define HEADER_Object
/* /*
htop - Object.h htop - Object.h
(C) 2004-2011 Hisham H. Muhammad (C) 2004-2012 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "RichString.h" #include "RichString.h"
#ifndef DEBUG
#define Object_setClass(obj, class)
#endif
typedef struct Object_ Object; typedef struct Object_ Object;
typedef void(*Object_Display)(Object*, RichString*); typedef void(*Object_Display)(Object*, RichString*);
typedef int(*Object_Compare)(const void*, const void*); typedef int(*Object_Compare)(const void*, const void*);
typedef void(*Object_Delete)(Object*); typedef void(*Object_Delete)(Object*);
#define Object_getClass(obj_) ((Object*)(obj_))->klass
#define Object_setClass(obj_, class_) Object_getClass(obj_) = (ObjectClass*) class_
#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
#define Object_displayFn(obj_) Object_getClass(obj_)->display
#define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_)
#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
#define Class(class_) ((ObjectClass*)(&(class_ ## _class)))
#define AllocThis(class_) (class_*) malloc(sizeof(class_)); Object_setClass(this, Class(class_));
typedef struct ObjectClass_ {
const void* extends;
const Object_Display display;
const Object_Delete delete;
const Object_Compare compare;
} ObjectClass;
struct Object_ { struct Object_ {
#ifdef DEBUG ObjectClass* klass;
char* class;
#endif
Object_Display display;
Object_Delete delete;
}; };
#ifdef DEBUG
extern char* OBJECT_CLASS;
#else extern ObjectClass Object_class;
#define OBJECT_CLASS NULL
#endif
#ifdef DEBUG #ifdef DEBUG
void Object_setClass(void* this, char* class); bool Object_isA(Object* o, const ObjectClass* klass);
#endif #endif
......
...@@ -57,7 +57,7 @@ static int ofsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27}; ...@@ -57,7 +57,7 @@ static int ofsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27};
OpenFilesScreen* OpenFilesScreen_new(Process* process) { OpenFilesScreen* OpenFilesScreen_new(Process* process) {
OpenFilesScreen* this = (OpenFilesScreen*) malloc(sizeof(OpenFilesScreen)); OpenFilesScreen* this = (OpenFilesScreen*) malloc(sizeof(OpenFilesScreen));
this->process = process; this->process = process;
this->display = Panel_new(0, 1, COLS, LINES-3, LISTITEM_CLASS, false, ListItem_compare); this->display = Panel_new(0, 1, COLS, LINES-3, false, Class(ListItem));
if (Process_isThread(process)) if (Process_isThread(process))
this->pid = process->tgid; this->pid = process->tgid;
else else
...@@ -170,7 +170,7 @@ void OpenFilesScreen_run(OpenFilesScreen* this) { ...@@ -170,7 +170,7 @@ void OpenFilesScreen_run(OpenFilesScreen* this) {
FunctionBar* bar = FunctionBar_new(ofsFunctions, ofsKeys, ofsEvents); FunctionBar* bar = FunctionBar_new(ofsFunctions, ofsKeys, ofsEvents);
IncSet* inc = IncSet_new(bar); IncSet* inc = IncSet_new(bar);
Vector* lines = Vector_new(panel->items->type, true, DEFAULT_SIZE, ListItem_compare); Vector* lines = Vector_new(panel->items->type, true, DEFAULT_SIZE);
OpenFilesScreen_scan(this, lines, inc); OpenFilesScreen_scan(this, lines, inc);
OpenFilesScreen_draw(this, inc); OpenFilesScreen_draw(this, inc);
...@@ -234,6 +234,7 @@ void OpenFilesScreen_run(OpenFilesScreen* this) { ...@@ -234,6 +234,7 @@ void OpenFilesScreen_run(OpenFilesScreen* this) {
} }
} }
Vector_delete(lines);
FunctionBar_delete((Object*)bar); FunctionBar_delete((Object*)bar);
IncSet_delete(inc); IncSet_delete(inc);
} }
...@@ -38,8 +38,18 @@ typedef enum HandlerResult_ { ...@@ -38,8 +38,18 @@ typedef enum HandlerResult_ {
typedef HandlerResult(*Panel_EventHandler)(Panel*, int); typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
typedef struct PanelClass_ {
const ObjectClass super;
const Panel_EventHandler eventHandler;
} PanelClass;
#define As_Panel(this_) ((PanelClass*)((this_)->super.klass))
#define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler
#define Panel_eventHandler(this_, ev_) As_Panel(this_)->eventHandler((Panel*)(this_), ev_)
struct Panel_ { struct Panel_ {
Object super; Object super;
PanelClass* class;
int x, y, w, h; int x, y, w, h;
WINDOW* window; WINDOW* window;
Vector* items; Vector* items;
...@@ -49,7 +59,6 @@ struct Panel_ { ...@@ -49,7 +59,6 @@ struct Panel_ {
int oldSelected; int oldSelected;
bool needsRedraw; bool needsRedraw;
RichString header; RichString header;
Panel_EventHandler eventHandler;
char* eventHandlerBuffer; char* eventHandlerBuffer;
}; };
...@@ -62,22 +71,24 @@ struct Panel_ { ...@@ -62,22 +71,24 @@ struct Panel_ {
#define MAX(a,b) ((a)>(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b))
#endif #endif
#ifdef DEBUG
char* PANEL_CLASS = "Panel";
#else
#define PANEL_CLASS NULL
#endif
#define KEY_CTRLN 0016 /* control-n key */ #define KEY_CTRLN 0016 /* control-n key */
#define KEY_CTRLP 0020 /* control-p key */ #define KEY_CTRLP 0020 /* control-p key */
#define KEY_CTRLF 0006 /* control-f key */ #define KEY_CTRLF 0006 /* control-f key */
#define KEY_CTRLB 0002 /* control-b key */ #define KEY_CTRLB 0002 /* control-b key */
Panel* Panel_new(int x, int y, int w, int h, char* type, bool owner, Object_Compare compare) { PanelClass Panel_class = {
.super = {
.extends = Class(Object),
.delete = Panel_delete
},
.eventHandler = Panel_selectByTyping
};
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type) {
Panel* this; Panel* this;
this = malloc(sizeof(Panel)); this = malloc(sizeof(Panel));
Object_setClass(this, Class(Panel));
Panel_init(this, x, y, w, h, type, owner); Panel_init(this, x, y, w, h, type, owner);
this->items->compare = compare;
return this; return this;
} }
...@@ -87,17 +98,13 @@ void Panel_delete(Object* cast) { ...@@ -87,17 +98,13 @@ void Panel_delete(Object* cast) {
free(this); free(this);
} }
void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner) { void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner) {
Object* super = (Object*) this;
Object_setClass(this, PANEL_CLASS);
super->delete = Panel_delete;
this->x = x; this->x = x;
this->y = y; this->y = y;
this->w = w; this->w = w;
this->h = h; this->h = h;
this->eventHandler = NULL;
this->eventHandlerBuffer = NULL; this->eventHandlerBuffer = NULL;
this->items = Vector_new(type, owner, DEFAULT_SIZE, ListItem_compare); this->items = Vector_new(type, owner, DEFAULT_SIZE);
this->scrollV = 0; this->scrollV = 0;
this->scrollH = 0; this->scrollH = 0;
this->selected = 0; this->selected = 0;
...@@ -129,10 +136,6 @@ inline void Panel_setHeader(Panel* this, const char* header) { ...@@ -129,10 +136,6 @@ inline void Panel_setHeader(Panel* this, const char* header) {
this->needsRedraw = true; this->needsRedraw = true;
} }
void Panel_setEventHandler(Panel* this, Panel_EventHandler eh) {
this->eventHandler = eh;
}
void Panel_move(Panel* this, int x, int y) { void Panel_move(Panel* this, int x, int y) {
assert (this != NULL); assert (this != NULL);
...@@ -238,8 +241,8 @@ void Panel_setSelected(Panel* this, int selected) { ...@@ -238,8 +241,8 @@ void Panel_setSelected(Panel* this, int selected) {
selected = MAX(0, MIN(Vector_size(this->items) - 1, selected)); selected = MAX(0, MIN(Vector_size(this->items) - 1, selected));
this->selected = selected; this->selected = selected;
if (this->eventHandler) { if (Panel_eventHandlerFn(this)) {
this->eventHandler(this, EVENT_SETSELECTED); Panel_eventHandler(this, EVENT_SETSELECTED);
} }
} }
...@@ -293,7 +296,7 @@ void Panel_draw(Panel* this, bool focus) { ...@@ -293,7 +296,7 @@ void Panel_draw(Panel* this, bool focus) {
for(int i = first, j = 0; j < this->h && i < last; i++, j++) { for(int i = first, j = 0; j < this->h && i < last; i++, j++) {
Object* itemObj = Vector_get(this->items, i); Object* itemObj = Vector_get(this->items, i);
RichString_begin(item); RichString_begin(item);
itemObj->display(itemObj, &item); Object_display(itemObj, &item);
int itemLen = RichString_sizeVal(item); int itemLen = RichString_sizeVal(item);
int amt = MIN(itemLen - scrollH, this->w); int amt = MIN(itemLen - scrollH, this->w);
if (i == this->selected) { if (i == this->selected) {
...@@ -317,11 +320,11 @@ void Panel_draw(Panel* this, bool focus) { ...@@ -317,11 +320,11 @@ void Panel_draw(Panel* this, bool focus) {
} else { } else {
Object* oldObj = Vector_get(this->items, this->oldSelected); Object* oldObj = Vector_get(this->items, this->oldSelected);
RichString_begin(old); RichString_begin(old);
oldObj->display(oldObj, &old); Object_display(oldObj, &old);
int oldLen = RichString_sizeVal(old); int oldLen = RichString_sizeVal(old);
Object* newObj = Vector_get(this->items, this->selected); Object* newObj = Vector_get(this->items, this->selected);
RichString_begin(new); RichString_begin(new);
newObj->display(newObj, &new); Object_display(newObj, &new);
int newLen = RichString_sizeVal(new); int newLen = RichString_sizeVal(new);
mvhline(y+ this->oldSelected - this->scrollV, x+0, ' ', this->w); mvhline(y+ this->oldSelected - this->scrollV, x+0, ' ', this->w);
if (scrollH < oldLen) if (scrollH < oldLen)
......
...@@ -26,8 +26,18 @@ typedef enum HandlerResult_ { ...@@ -26,8 +26,18 @@ typedef enum HandlerResult_ {
typedef HandlerResult(*Panel_EventHandler)(Panel*, int); typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
typedef struct PanelClass_ {
const ObjectClass super;
const Panel_EventHandler eventHandler;
} PanelClass;
#define As_Panel(this_) ((PanelClass*)((this_)->super.klass))
#define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler
#define Panel_eventHandler(this_, ev_) As_Panel(this_)->eventHandler((Panel*)(this_), ev_)
struct Panel_ { struct Panel_ {
Object super; Object super;
PanelClass* class;
int x, y, w, h; int x, y, w, h;
WINDOW* window; WINDOW* window;
Vector* items; Vector* items;
...@@ -37,7 +47,6 @@ struct Panel_ { ...@@ -37,7 +47,6 @@ struct Panel_ {
int oldSelected; int oldSelected;
bool needsRedraw; bool needsRedraw;
RichString header; RichString header;
Panel_EventHandler eventHandler;
char* eventHandlerBuffer; char* eventHandlerBuffer;
}; };
...@@ -49,22 +58,18 @@ struct Panel_ { ...@@ -49,22 +58,18 @@ struct Panel_ {
#define MAX(a,b) ((a)>(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b))
#endif #endif
#ifdef DEBUG
extern char* PANEL_CLASS;
#else
#define PANEL_CLASS NULL
#endif
#define KEY_CTRLN 0016 /* control-n key */ #define KEY_CTRLN 0016 /* control-n key */
#define KEY_CTRLP 0020 /* control-p key */ #define KEY_CTRLP 0020 /* control-p key */
#define KEY_CTRLF 0006 /* control-f key */ #define KEY_CTRLF 0006 /* control-f key */
#define KEY_CTRLB 0002 /* control-b key */ #define KEY_CTRLB 0002 /* control-b key */
Panel* Panel_new(int x, int y, int w, int h, char* type, bool owner, Object_Compare compare); extern PanelClass Panel_class;
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type);
void Panel_delete(Object* cast); void Panel_delete(Object* cast);
void Panel_init(Panel* this, int x, int y, int w, int h, char* type, bool owner); void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner);
void Panel_done(Panel* this); void Panel_done(Panel* this);
...@@ -72,8 +77,6 @@ RichString* Panel_getHeader(Panel* this); ...@@ -72,8 +77,6 @@ RichString* Panel_getHeader(Panel* this);
extern void Panel_setHeader(Panel* this, const char* header); extern void Panel_setHeader(Panel* this, const char* header);
void Panel_setEventHandler(Panel* this, Panel_EventHandler eh);
void Panel_move(Panel* this, int x, int y); void Panel_move(Panel* this, int x, int y);
void Panel_resize(Panel* this, int w, int h); void Panel_resize(Panel* this, int w, int h);
......
...@@ -175,12 +175,6 @@ typedef struct Process_ { ...@@ -175,12 +175,6 @@ typedef struct Process_ {
}*/ }*/
#ifdef DEBUG
char* PROCESS_CLASS = "Process";
#else
#define PROCESS_CLASS NULL
#endif
const char *Process_fieldNames[] = { const char *Process_fieldNames[] = {
"", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION", "", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION",
"TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT", "TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT",
...@@ -564,11 +558,16 @@ void Process_delete(Object* cast) { ...@@ -564,11 +558,16 @@ void Process_delete(Object* cast) {
free(this); free(this);
} }
ObjectClass Process_class = {
.extends = Class(Object),
.display = Process_display,
.delete = Process_delete,
.compare = Process_compare
};
Process* Process_new(struct ProcessList_ *pl) { Process* Process_new(struct ProcessList_ *pl) {
Process* this = calloc(sizeof(Process), 1); Process* this = calloc(sizeof(Process), 1);
Object_setClass(this, PROCESS_CLASS); Object_setClass(this, Class(Process));
((Object*)this)->display = Process_display;
((Object*)this)->delete = Process_delete;
this->pid = 0; this->pid = 0;
this->pl = pl; this->pl = pl;
this->tag = false; this->tag = false;
......
...@@ -153,12 +153,6 @@ typedef struct Process_ { ...@@ -153,12 +153,6 @@ typedef struct Process_ {
} Process; } Process;
#ifdef DEBUG
extern char* PROCESS_CLASS;
#else
#define PROCESS_CLASS NULL
#endif
extern const char *Process_fieldNames[]; extern const char *Process_fieldNames[];
extern const char *Process_fieldTitles[]; extern const char *Process_fieldTitles[];
...@@ -172,6 +166,8 @@ void Process_getMaxPid(); ...@@ -172,6 +166,8 @@ void Process_getMaxPid();
void Process_delete(Object* cast); void Process_delete(Object* cast);
extern ObjectClass Process_class;
Process* Process_new(struct ProcessList_ *pl); Process* Process_new(struct ProcessList_ *pl);
void Process_toggleTag(Process* this); void Process_toggleTag(Process* this);
......
...@@ -68,12 +68,6 @@ typedef enum TreeStr_ { ...@@ -68,12 +68,6 @@ typedef enum TreeStr_ {
TREE_STR_COUNT TREE_STR_COUNT
} TreeStr; } TreeStr;
typedef enum TreeType_ {
TREE_TYPE_AUTO,
TREE_TYPE_ASCII,
TREE_TYPE_UTF8,
} TreeType;
typedef struct CPUData_ { typedef struct CPUData_ {
unsigned long long int totalTime; unsigned long long int totalTime;
unsigned long long int userTime; unsigned long long int userTime;
...@@ -184,13 +178,13 @@ const char *ProcessList_treeStrUtf8[TREE_STR_COUNT] = { ...@@ -184,13 +178,13 @@ const char *ProcessList_treeStrUtf8[TREE_STR_COUNT] = {
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) { ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
ProcessList* this; ProcessList* this;
this = calloc(sizeof(ProcessList), 1); this = calloc(sizeof(ProcessList), 1);
this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare); this->processes = Vector_new(Class(Process), true, DEFAULT_SIZE);
this->processTable = Hashtable_new(140, false); this->processTable = Hashtable_new(140, false);
this->usersTable = usersTable; this->usersTable = usersTable;
this->pidWhiteList = pidWhiteList; this->pidWhiteList = pidWhiteList;
/* tree-view auxiliary buffers */ /* tree-view auxiliary buffers */
this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare); this->processes2 = Vector_new(Class(Process), true, DEFAULT_SIZE);
FILE* file = fopen(PROCSTATFILE, "r"); FILE* file = fopen(PROCSTATFILE, "r");
if (file == NULL) { if (file == NULL) {
...@@ -243,6 +237,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) { ...@@ -243,6 +237,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
this->treeStr = NULL; this->treeStr = NULL;
this->following = -1; this->following = -1;
if (CRT_utf8)
this->treeStr = CRT_utf8 ? ProcessList_treeStrUtf8 : ProcessList_treeStrAscii;
return this; return this;
} }
...@@ -312,7 +309,7 @@ int ProcessList_size(ProcessList* this) { ...@@ -312,7 +309,7 @@ int ProcessList_size(ProcessList* this) {
} }
static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int indent, int direction, bool show) { static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int indent, int direction, bool show) {
Vector* children = Vector_new(PROCESS_CLASS, false, DEFAULT_SIZE, Process_compare); Vector* children = Vector_new(Class(Process), false, DEFAULT_SIZE);
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* process = (Process*) (Vector_get(this->processes, i)); Process* process = (Process*) (Vector_get(this->processes, i));
......
...@@ -51,12 +51,6 @@ typedef enum TreeStr_ { ...@@ -51,12 +51,6 @@ typedef enum TreeStr_ {
TREE_STR_COUNT TREE_STR_COUNT
} TreeStr; } TreeStr;
typedef enum TreeType_ {
TREE_TYPE_AUTO,
TREE_TYPE_ASCII,
TREE_TYPE_UTF8,
} TreeType;
typedef struct CPUData_ { typedef struct CPUData_ {
unsigned long long int totalTime; unsigned long long int totalTime;
unsigned long long int userTime; unsigned long long int userTime;
......
...@@ -52,8 +52,8 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori ...@@ -52,8 +52,8 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
this->y2 = y2; this->y2 = y2;
this->fuBar = NULL; this->fuBar = NULL;
this->orientation = orientation; this->orientation = orientation;
this->panels = Vector_new(PANEL_CLASS, owner, DEFAULT_SIZE, NULL); this->panels = Vector_new(Class(Panel), owner, DEFAULT_SIZE);
this->fuBars = Vector_new(FUNCTIONBAR_CLASS, true, DEFAULT_SIZE, NULL); this->fuBars = Vector_new(Class(FunctionBar), true, DEFAULT_SIZE);
this->panelCount = 0; this->panelCount = 0;
this->header = header; this->header = header;
this->owner = owner; this->owner = owner;
...@@ -184,8 +184,8 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { ...@@ -184,8 +184,8 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
} }
} }
if (panelFocus->eventHandler) { if (Panel_eventHandlerFn(panelFocus)) {
HandlerResult result = panelFocus->eventHandler(panelFocus, ch); HandlerResult result = Panel_eventHandler(panelFocus, ch);
if (result == HANDLED) { if (result == HANDLED) {
continue; continue;
} else if (result == BREAK_LOOP) { } else if (result == BREAK_LOOP) {
......
...@@ -5,6 +5,7 @@ Released under the GNU GPL, see the COPYING file ...@@ -5,6 +5,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "Panel.h"
#include "SignalsPanel.h" #include "SignalsPanel.h"
#include "ListItem.h" #include "ListItem.h"
...@@ -16,26 +17,14 @@ in the source distribution for its full text. ...@@ -16,26 +17,14 @@ in the source distribution for its full text.
#include <ctype.h> #include <ctype.h>
/*{ /*{
#include "Panel.h"
typedef struct SignalItem_ { typedef struct SignalItem_ {
const char* name; const char* name;
int number; int number;
} SignalItem; } SignalItem;
typedef struct SignalsPanel_ {
Panel super;
} SignalsPanel;
}*/ }*/
static void SignalsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
SignalsPanel* this = (SignalsPanel*) object;
Panel_done(super);
free(this);
}
static SignalItem signals[] = { static SignalItem signals[] = {
{ .name = " 0 Cancel", .number = 0 }, { .name = " 0 Cancel", .number = 0 },
{ .name = " 1 SIGHUP", .number = 1 }, { .name = " 1 SIGHUP", .number = 1 },
...@@ -73,21 +62,11 @@ static SignalItem signals[] = { ...@@ -73,21 +62,11 @@ static SignalItem signals[] = {
{ .name = "31 SIGSYS", .number = 31 }, { .name = "31 SIGSYS", .number = 31 },
}; };
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h) { Panel* SignalsPanel_new() {
SignalsPanel* this = (SignalsPanel*) malloc(sizeof(SignalsPanel)); Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem));
Panel* super = (Panel*) this;
Panel_init(super, x, y, w, h, LISTITEM_CLASS, true);
((Object*)this)->delete = SignalsPanel_delete;
for(unsigned int i = 0; i < sizeof(signals)/sizeof(SignalItem); i++) for(unsigned int i = 0; i < sizeof(signals)/sizeof(SignalItem); i++)
Panel_set(super, i, (Object*) ListItem_new(signals[i].name, signals[i].number)); Panel_set(this, i, (Object*) ListItem_new(signals[i].name, signals[i].number));
SignalsPanel_reset(this); Panel_setHeader(this, "Send signal:");
Panel_setSelected(this, 16); // 16th item is SIGTERM
return 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
}
...@@ -9,20 +9,13 @@ Released under the GNU GPL, see the COPYING file ...@@ -9,20 +9,13 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "Panel.h"
typedef struct SignalItem_ { typedef struct SignalItem_ {
const char* name; const char* name;
int number; int number;
} SignalItem; } SignalItem;
typedef struct SignalsPanel_ {
Panel super;
} SignalsPanel;
Panel* SignalsPanel_new();
SignalsPanel* SignalsPanel_new(int x, int y, int w, int h);
void SignalsPanel_reset(SignalsPanel* this);
#endif #endif
...@@ -59,10 +59,14 @@ static void SwapMeter_display(Object* cast, RichString* out) { ...@@ -59,10 +59,14 @@ static void SwapMeter_display(Object* cast, RichString* out) {
RichString_append(out, CRT_colors[METER_VALUE], buffer); RichString_append(out, CRT_colors[METER_VALUE], buffer);
} }
MeterType SwapMeter = { MeterClass SwapMeter_class = {
.setValues = SwapMeter_setValues, .super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = SwapMeter_display, .display = SwapMeter_display,
.mode = BAR_METERMODE, },
.setValues = SwapMeter_setValues,
.defaultMode = BAR_METERMODE,
.items = 1, .items = 1,
.total = 100.0, .total = 100.0,
.attributes = SwapMeter_attributes, .attributes = SwapMeter_attributes,
......
...@@ -18,6 +18,6 @@ in the source distribution for its full text. ...@@ -18,6 +18,6 @@ in the source distribution for its full text.
extern int SwapMeter_attributes[]; extern int SwapMeter_attributes[];
/* NOTE: Value is in kilobytes */ /* NOTE: Value is in kilobytes */
extern MeterType SwapMeter; extern MeterClass SwapMeter_class;
#endif #endif
...@@ -55,10 +55,14 @@ static void TasksMeter_display(Object* cast, RichString* out) { ...@@ -55,10 +55,14 @@ static void TasksMeter_display(Object* cast, RichString* out) {
RichString_append(out, CRT_colors[METER_TEXT], " running"); RichString_append(out, CRT_colors[METER_TEXT], " running");
} }
MeterType TasksMeter = { MeterClass TasksMeter_class = {
.setValues = TasksMeter_setValues, .super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = TasksMeter_display, .display = TasksMeter_display,
.mode = TEXT_METERMODE, },
.setValues = TasksMeter_setValues,
.defaultMode = TEXT_METERMODE,
.items = 1, .items = 1,
.total = 100.0, .total = 100.0,
.attributes = TasksMeter_attributes, .attributes = TasksMeter_attributes,
......
...@@ -13,6 +13,6 @@ in the source distribution for its full text. ...@@ -13,6 +13,6 @@ in the source distribution for its full text.
extern int TasksMeter_attributes[]; extern int TasksMeter_attributes[];
extern MeterType TasksMeter; extern MeterClass TasksMeter_class;
#endif #endif
...@@ -46,7 +46,7 @@ static int tsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27}; ...@@ -46,7 +46,7 @@ static int tsEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27};
TraceScreen* TraceScreen_new(Process* process) { TraceScreen* TraceScreen_new(Process* process) {
TraceScreen* this = (TraceScreen*) malloc(sizeof(TraceScreen)); TraceScreen* this = (TraceScreen*) malloc(sizeof(TraceScreen));
this->process = process; this->process = process;
this->display = Panel_new(0, 1, COLS, LINES-2, LISTITEM_CLASS, false, ListItem_compare); this->display = Panel_new(0, 1, COLS, LINES-2, false, Class(ListItem));
this->tracing = true; this->tracing = true;
return this; return this;
} }
...@@ -106,7 +106,7 @@ void TraceScreen_run(TraceScreen* this) { ...@@ -106,7 +106,7 @@ void TraceScreen_run(TraceScreen* this) {
FunctionBar* bar = FunctionBar_new(tsFunctions, tsKeys, tsEvents); FunctionBar* bar = FunctionBar_new(tsFunctions, tsKeys, tsEvents);
IncSet* inc = IncSet_new(bar); IncSet* inc = IncSet_new(bar);
Vector* lines = Vector_new(panel->items->type, true, DEFAULT_SIZE, ListItem_compare); Vector* lines = Vector_new(panel->items->type, true, DEFAULT_SIZE);
TraceScreen_draw(this, inc); TraceScreen_draw(this, inc);
...@@ -122,11 +122,11 @@ void TraceScreen_run(TraceScreen* this) { ...@@ -122,11 +122,11 @@ void TraceScreen_run(TraceScreen* this) {
if (ch == ERR) { if (ch == ERR) {
fd_set fds; fd_set fds;
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds); // FD_SET(STDIN_FILENO, &fds);
FD_SET(fd_strace, &fds); FD_SET(fd_strace, &fds);
//struct timeval tv; struct timeval tv;
//tv.tv_sec = 0; tv.tv_usec = 500; tv.tv_sec = 0; tv.tv_usec = 500;
int ready = select(fd_strace+1, &fds, NULL, NULL, NULL/*&tv*/); int ready = select(fd_strace+1, &fds, NULL, NULL, &tv);
int nread = 0; int nread = 0;
if (ready > 0 && FD_ISSET(fd_strace, &fds)) if (ready > 0 && FD_ISSET(fd_strace, &fds))
nread = fread(buffer, 1, 1000, strace); nread = fread(buffer, 1, 1000, strace);
...@@ -218,6 +218,7 @@ void TraceScreen_run(TraceScreen* this) { ...@@ -218,6 +218,7 @@ void TraceScreen_run(TraceScreen* this) {
IncSet_delete(inc); IncSet_delete(inc);
FunctionBar_delete((Object*)bar); FunctionBar_delete((Object*)bar);
Vector_delete(lines);
kill(child, SIGTERM); kill(child, SIGTERM);
waitpid(child, NULL, 0); waitpid(child, NULL, 0);
......
...@@ -49,10 +49,13 @@ static void UptimeMeter_setValues(Meter* this, char* buffer, int len) { ...@@ -49,10 +49,13 @@ static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds); snprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds);
} }
MeterType UptimeMeter = { MeterClass UptimeMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete
},
.setValues = UptimeMeter_setValues, .setValues = UptimeMeter_setValues,
.display = NULL, .defaultMode = TEXT_METERMODE,
.mode = TEXT_METERMODE,
.items = 1, .items = 1,
.total = 100.0, .total = 100.0,
.attributes = UptimeMeter_attributes, .attributes = UptimeMeter_attributes,
......
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