From b291fba02b8d9bb52cd8a23ef5fffbba4f89ff0a Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 9 Apr 2015 15:40:27 -0300 Subject: [PATCH] Fixes to use platform-specific compare routines. --- ProcessList.c | 8 ++++---- ProcessList.h | 2 +- freebsd/FreeBSDProcess.c | 20 +++++++++++++++----- freebsd/FreeBSDProcessList.c | 2 +- linux/LinuxProcessList.c | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ProcessList.c b/ProcessList.c index 0e7d5262..050b74fa 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -74,15 +74,15 @@ void ProcessList_goThroughEntries(ProcessList* pl); }*/ -ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { - this->processes = Vector_new(Class(Process), true, DEFAULT_SIZE); +ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { + this->processes = Vector_new(klass, true, DEFAULT_SIZE); this->processTable = Hashtable_new(140, false); this->usersTable = usersTable; this->pidWhiteList = pidWhiteList; this->userId = userId; - // tree-view auxiliary buffers - this->processes2 = Vector_new(Class(Process), true, DEFAULT_SIZE); + // tree-view auxiliary buffer + this->processes2 = Vector_new(klass, true, DEFAULT_SIZE); // set later by platform-specific code this->cpuCount = 0; diff --git a/ProcessList.h b/ProcessList.h index e00585fd..f96481ea 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -67,7 +67,7 @@ void ProcessList_delete(ProcessList* pl); void ProcessList_goThroughEntries(ProcessList* pl); -ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); +ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_done(ProcessList* this); diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index ab99ef7e..6e5720bb 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -36,6 +36,16 @@ typedef struct FreeBSDProcess_ { }*/ +ProcessClass FreeBSDProcess_class = { + .super = { + .extends = Class(Process), + .display = Process_display, + .delete = Process_delete, + .compare = FreeBSDProcess_compare + }, + .writeField = (Process_WriteField) FreeBSDProcess_writeField, +}; + ProcessFieldData Process_fields[] = { [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, }, @@ -94,7 +104,7 @@ void Process_setupColumnWidths() { FreeBSDProcess* FreeBSDProcess_new(Settings* settings) { FreeBSDProcess* this = calloc(sizeof(FreeBSDProcess), 1); - Object_setClass(this, Class(Process)); + Object_setClass(this, Class(FreeBSDProcess)); Process_init(&this->super, settings); return this; } @@ -105,7 +115,7 @@ void Process_delete(Object* cast) { free(this); } -void Process_writeField(Process* this, RichString* str, ProcessField field) { +void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField field) { //FreeBSDProcess* fp = (FreeBSDProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; @@ -113,13 +123,13 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) { switch (field) { // add FreeBSD-specific fields here default: - Process_writeDefaultField(this, str, field); + Process_writeField(this, str, field); return; } RichString_append(str, attr, buffer); } -long Process_compare(const void* v1, const void* v2) { +long FreeBSDProcess_compare(const void* v1, const void* v2) { FreeBSDProcess *p1, *p2; Settings *settings = ((Process*)v1)->settings; if (settings->direction == 1) { @@ -132,7 +142,7 @@ long Process_compare(const void* v1, const void* v2) { switch (settings->sortKey) { // add FreeBSD-specific fields here default: - return Process_defaultCompare(v1, v2); + return Process_compare(v1, v2); } } diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 6a8a5fcb..aaebc928 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -45,7 +45,7 @@ static int pageSizeKb; ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { FreeBSDProcessList* fpl = calloc(1, sizeof(FreeBSDProcessList)); ProcessList* pl = (ProcessList*) fpl; - ProcessList_init(pl, usersTable, pidWhiteList, userId); + ProcessList_init(pl, Class(FreeBSDProcess), usersTable, pidWhiteList, userId); int cpus = 1; size_t sizeof_cpus = sizeof(cpus); diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index b9c4073c..bab709c2 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -83,7 +83,7 @@ typedef struct LinuxProcessList_ { ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { LinuxProcessList* this = calloc(1, sizeof(LinuxProcessList)); ProcessList* pl = &(this->super); - ProcessList_init(pl, usersTable, pidWhiteList, userId); + ProcessList_init(pl, Class(LinuxProcess), usersTable, pidWhiteList, userId); // Update CPU count: FILE* file = fopen(PROCSTATFILE, "r");