summaryrefslogtreecommitdiffstats
path: root/freebsd
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-08-22 16:11:05 +1000
committerNathan Scott <nathans@redhat.com>2023-08-30 13:11:57 +1000
commit0f751e991d399769fb8d7800f7c4bccec2ca7f60 (patch)
tree34cd7838f7ebf51049816f9acb6a63cea175af06 /freebsd
parent68f4f10f012d11bd57bb725fe4113b2af937fc1d (diff)
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.
Diffstat (limited to 'freebsd')
-rw-r--r--freebsd/FreeBSDProcess.c27
-rw-r--r--freebsd/FreeBSDProcessList.c21
2 files changed, 27 insertions, 21 deletions
diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c
index 4970ff2c..f6d3451d 100644
--- a/freebsd/FreeBSDProcess.c
+++ b/freebsd/FreeBSDProcess.c
@@ -71,8 +71,8 @@ void Process_delete(Object* cast) {
free(this);
}
-static void FreeBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) {
- const FreeBSDProcess* fp = (const FreeBSDProcess*) this;
+static void FreeBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
+ const FreeBSDProcess* fp = (const FreeBSDProcess*) super;
char buffer[256];
size_t n = sizeof(buffer);
int attr = CRT_colors[DEFAULT_COLOR];
@@ -81,13 +81,13 @@ static void FreeBSDProcess_writeField(const Process* this, RichString* str, Proc
// add FreeBSD-specific fields here
case JID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, fp->jid); break;
case JAIL:
- Process_printLeftAlignedField(str, attr, fp->jname ? fp->jname : "N/A", 11);
+ Row_printLeftAlignedField(str, attr, fp->jname ? fp->jname : "N/A", 11);
return;
case EMULATION:
- Process_printLeftAlignedField(str, attr, fp->emul ? fp->emul : "N/A", 16);
+ Row_printLeftAlignedField(str, attr, fp->emul ? fp->emul : "N/A", 16);
return;
default:
- Process_writeField(this, str, field);
+ Process_writeField(&fp->super, str, field);
return;
}
RichString_appendWide(str, attr, buffer);
@@ -112,11 +112,18 @@ static int FreeBSDProcess_compareByKey(const Process* v1, const Process* v2, Pro
const ProcessClass FreeBSDProcess_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 = FreeBSDProcess_rowWriteField
},
- .writeField = FreeBSDProcess_writeField,
.compareByKey = FreeBSDProcess_compareByKey
};
diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c
index d8d4bbe0..aabb61cc 100644
--- a/freebsd/FreeBSDProcessList.c
+++ b/freebsd/FreeBSDProcessList.c
@@ -43,18 +43,17 @@ in the source distribution for its full text.
ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList) {
FreeBSDProcessList* this = xCalloc(1, sizeof(FreeBSDProcessList));
- ProcessList* super = &this->super;
+ Object_setClass(this, Class(ProcessList));
+ ProcessList* super = &this->super;
ProcessList_init(super, Class(FreeBSDProcess), host, pidMatchList);
return super;
}
-void ProcessList_delete(ProcessList* super) {
- FreeBSDProcessList* this = (FreeBSDProcessList*) super;
-
- ProcessList_done(super);
-
+void ProcessList_delete(Object* cast) {
+ FreeBSDProcessList* this = (FreeBSDProcessList*) cast;
+ ProcessList_done(&this->super);
free(this);
}
@@ -174,12 +173,12 @@ void ProcessList_goThroughEntries(ProcessList* super) {
if (!preExisting) {
fp->jid = kproc->ki_jid;
- proc->pid = kproc->ki_pid;
+ Process_setPid(proc, kproc->ki_pid);
+ Process_setThreadGroup(proc, kproc->ki_pid);
+ Process_setParent(proc, kproc->ki_ppid);
proc->isKernelThread = kproc->ki_pid != 1 && (kproc->ki_flag & P_SYSTEM);
proc->isUserlandThread = false;
- proc->ppid = kproc->ki_ppid;
proc->tpgid = kproc->ki_tpgid;
- proc->tgid = kproc->ki_pid;
proc->session = kproc->ki_sid;
proc->pgrp = kproc->ki_pgid;
proc->st_uid = kproc->ki_uid;
@@ -279,11 +278,11 @@ void ProcessList_goThroughEntries(ProcessList* super) {
Scheduling_readProcessPolicy(proc);
#endif
- proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
+ proc->super.show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc)));
super->totalTasks++;
if (proc->state == RUNNING)
super->runningTasks++;
- proc->updated = true;
+ proc->super.updated = true;
}
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy