From 0f751e991d399769fb8d7800f7c4bccec2ca7f60 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 22 Aug 2023 16:11:05 +1000 Subject: Introduce Row and Table classes for screens beyond top-processes This commit refactors the Process and ProcessList structures such they each have a new parent - Row and Table, respectively. These new classes handle screen updates relating to anything that could be represented in tabular format, e.g. cgroups, filesystems, etc, without us having to reimplement the display logic repeatedly for each new entity. --- netbsd/NetBSDProcess.c | 20 ++++++++++++++------ netbsd/NetBSDProcessList.c | 23 ++++++++++++----------- 2 files changed, 26 insertions(+), 17 deletions(-) (limited to 'netbsd') diff --git a/netbsd/NetBSDProcess.c b/netbsd/NetBSDProcess.c index bdb0f50c..605b56c8 100644 --- a/netbsd/NetBSDProcess.c +++ b/netbsd/NetBSDProcess.c @@ -225,7 +225,8 @@ void Process_delete(Object* cast) { free(this); } -static void NetBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { +static void NetBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) { + const Process* this = (const Process*) super; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; @@ -254,11 +255,18 @@ static int NetBSDProcess_compareByKey(const Process* v1, const Process* v2, Proc const ProcessClass NetBSDProcess_class = { .super = { - .extends = Class(Process), - .display = Process_display, - .delete = Process_delete, - .compare = Process_compare + .super = { + .extends = Class(Process), + .display = Row_display, + .delete = Process_delete, + .compare = Process_compare + }, + .isHighlighted = Process_rowIsHighlighted, + .isVisible = Process_rowIsVisible, + .matchesFilter = Process_rowMatchesFilter, + .compareByParent = Process_compareByParent, + .sortKeyString = Process_rowGetSortKey, + .writeField = NetBSDProcess_rowWriteField }, - .writeField = NetBSDProcess_writeField, .compareByKey = NetBSDProcess_compareByKey }; diff --git a/netbsd/NetBSDProcessList.c b/netbsd/NetBSDProcessList.c index 9e5a9be4..1327de70 100644 --- a/netbsd/NetBSDProcessList.c +++ b/netbsd/NetBSDProcessList.c @@ -37,17 +37,18 @@ in the source distribution for its full text. ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList) { NetBSDProcessList* this = xCalloc(1, sizeof(NetBSDProcessList)); - ProcessList* super = (ProcessList*) this; + Object_setClass(this, Class(ProcessList)); + ProcessList* super = (ProcessList*) this; ProcessList_init(super, Class(NetBSDProcess), host, pidMatchList); return super; } -void ProcessList_delete(ProcessList* this) { - NetBSDProcessList* npl = (NetBSDProcessList*) this; - ProcessList_done(this); - free(npl); +void ProcessList_delete(Object* cast) { + NetBSDProcessList* this = (NetBSDProcessList*) cast; + ProcessList_done(&this->super); + free(this); } static void NetBSDProcessList_updateExe(const struct kinfo_proc2* kproc, Process* proc) { @@ -163,17 +164,17 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) { bool preExisting = false; Process* proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, NetBSDProcess_new); - proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); + proc->super.show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); if (!preExisting) { - proc->pid = kproc->p_pid; - proc->ppid = kproc->p_ppid; + Process_setPid(proc, kproc->p_pid); + Process_setParent(proc, kproc->p_ppid); + Process_setThreadGroup(proc, kproc->p_pid); proc->tpgid = kproc->p_tpgid; - proc->tgid = kproc->p_pid; proc->session = kproc->p_sid; proc->pgrp = kproc->p__pgid; proc->isKernelThread = !!(kproc->p_flag & P_SYSTEM); - proc->isUserlandThread = proc->pid != proc->tgid; + proc->isUserlandThread = Process_getPid(proc) != Process_getThreadGroup(proc); // eh? proc->starttime_ctime = kproc->p_ustart_sec; Process_fillStarttimeBuffer(proc); ProcessList_add(&this->super, proc); @@ -261,7 +262,7 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) { if (proc->state == RUNNING) { this->super.runningTasks++; } - proc->updated = true; + proc->super.updated = true; } } -- cgit v1.2.3