Commit 4c24a9b4 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Fixes to subclassing Process.

parent 5320bab2
......@@ -192,6 +192,15 @@ typedef struct Process_ {
} Process;
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
typedef struct ProcessClass_ {
const ObjectClass super;
const Process_WriteField writeField;
} ProcessClass;
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
}*/
const char *Process_fieldNames[] = {
......@@ -470,7 +479,7 @@ static inline void Process_outputRate(RichString* str, int attr, char* buffer, i
RichString_append(str, attr, buffer);
}
static void Process_writeField(Process* this, RichString* str, ProcessField field) {
void Process_writeField(Process* this, RichString* str, ProcessField field) {
char buffer[256]; buffer[255] = '\0';
int attr = CRT_colors[DEFAULT_COLOR];
int baseattr = CRT_colors[PROCESS_BASENAME];
......@@ -630,12 +639,12 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
RichString_append(str, attr, buffer);
}
static void Process_display(Object* cast, RichString* out) {
void Process_display(Object* cast, RichString* out) {
Process* this = (Process*) cast;
ProcessField* fields = this->pl->fields;
RichString_prune(out);
for (int i = 0; fields[i]; i++)
Process_writeField(this, out, fields[i]);
As_Process(this)->writeField(this, out, fields[i]);
if (this->pl->shadowOtherUsers && (int)this->st_uid != Process_getuid)
RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]);
if (this->tag == true)
......@@ -651,11 +660,14 @@ void Process_done(Process* this) {
#endif
}
ObjectClass Process_class = {
ProcessClass Process_class = {
.super = {
.extends = Class(Object),
.display = Process_display,
.delete = Process_delete,
.compare = Process_compare
},
.writeField = Process_writeField,
};
void Process_init(Process* this, struct ProcessList_* pl) {
......
......@@ -171,6 +171,15 @@ typedef struct Process_ {
} Process;
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
typedef struct ProcessClass_ {
const ObjectClass super;
const Process_WriteField writeField;
} ProcessClass;
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
extern const char *Process_fieldNames[];
......@@ -189,9 +198,13 @@ void Process_setupColumnWidths();
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
void Process_writeField(Process* this, RichString* str, ProcessField field);
void Process_display(Object* cast, RichString* out);
void Process_done(Process* this);
extern ObjectClass Process_class;
extern ProcessClass Process_class;
void Process_init(Process* this, struct ProcessList_* pl);
......
......@@ -694,7 +694,7 @@ int main(int argc, char** argv) {
CRT_init(settings->delay, settings->colorScheme);
Panel* panel = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, false, &Process_class);
Panel* panel = Panel_new(0, headerHeight, COLS, LINES - headerHeight - 2, false, (ObjectClass*) &Process_class);
ProcessList_setPanel(pl, panel);
FunctionBar* defaultBar = FunctionBar_new(defaultFunctions, NULL, NULL);
......
......@@ -27,9 +27,19 @@ typedef struct LinuxProcess_ {
}*/
ProcessClass LinuxProcess_class = {
.super = {
.extends = Class(Process),
.display = Process_display,
.delete = Process_delete,
.compare = LinuxProcess_compare
},
.writeField = (Process_WriteField) LinuxProcess_writeField,
};
LinuxProcess* LinuxProcess_new(ProcessList* pl) {
LinuxProcess* this = calloc(sizeof(LinuxProcess), 1);
Object_setClass(this, Class(Process));
Object_setClass(this, Class(LinuxProcess));
Process_init(&this->super, pl);
return this;
}
......@@ -85,7 +95,8 @@ void LinuxProcess_writeField(LinuxProcess* this, RichString* str, ProcessField f
break;
}
default:
snprintf(buffer, n, "- ");
Process_writeField((Process*)this, str, field);
return;
}
RichString_append(str, attr, buffer);
}
......@@ -104,6 +115,6 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
case IO_PRIORITY:
return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2);
default:
return (p1->super.pid - p2->super.pid);
return Process_compare(v1, v2);
}
}
......@@ -20,6 +20,8 @@ typedef struct LinuxProcess_ {
#define Process_delete LinuxProcess_delete
extern ProcessClass LinuxProcess_class;
LinuxProcess* LinuxProcess_new(ProcessList* pl);
void LinuxProcess_delete(Object* cast);
......
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