From 0bdade1b6cb40c5bd374a93ac0489058a7421bb5 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 2 May 2023 09:02:22 +1000 Subject: Introduce Machine class for host-specific info (split from ProcessList) First stage in sanitizing the process list structure so that htop can support other types of lists too (cgroups, filesystems, ...), in the not-too-distant future. This introduces struct Machine for system-wide information while keeping process-list information in ProcessList (now much less). Next step is to propogate this separation into each platform, to match these core changes. --- unsupported/UnsupportedProcess.c | 6 +++--- unsupported/UnsupportedProcess.h | 4 ++-- unsupported/UnsupportedProcessList.c | 24 +++++++++++++++++------- unsupported/UnsupportedProcessList.h | 8 ++++++-- 4 files changed, 28 insertions(+), 14 deletions(-) (limited to 'unsupported') diff --git a/unsupported/UnsupportedProcess.c b/unsupported/UnsupportedProcess.c index 2aca0488..4d8cb080 100644 --- a/unsupported/UnsupportedProcess.c +++ b/unsupported/UnsupportedProcess.c @@ -44,10 +44,10 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, .pidColumn = true, }, }; -Process* UnsupportedProcess_new(const Settings* settings) { +Process* UnsupportedProcess_new(const Machine* host) { Process* this = xCalloc(1, sizeof(UnsupportedProcess)); Object_setClass(this, Class(UnsupportedProcess)); - Process_init(this, settings); + Process_init(this, host); return this; } @@ -60,7 +60,7 @@ void Process_delete(Object* cast) { static void UnsupportedProcess_writeField(const Process* this, RichString* str, ProcessField field) { const UnsupportedProcess* up = (const UnsupportedProcess*) this; - bool coloring = this->settings->highlightMegabytes; + bool coloring = this->host->settings->highlightMegabytes; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; size_t n = sizeof(buffer) - 1; diff --git a/unsupported/UnsupportedProcess.h b/unsupported/UnsupportedProcess.h index e30169c5..21956ddd 100644 --- a/unsupported/UnsupportedProcess.h +++ b/unsupported/UnsupportedProcess.h @@ -7,7 +7,7 @@ Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ -#include "Settings.h" +#include "Machine.h" typedef struct UnsupportedProcess_ { @@ -19,7 +19,7 @@ typedef struct UnsupportedProcess_ { extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD]; -Process* UnsupportedProcess_new(const Settings* settings); +Process* UnsupportedProcess_new(const Machine* host); void Process_delete(Object* cast); diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index fc226f76..e5b7af6d 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -14,12 +14,12 @@ in the source distribution for its full text. #include "UnsupportedProcess.h" -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { +ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList) { ProcessList* this = xCalloc(1, sizeof(ProcessList)); - ProcessList_init(this, Class(Process), usersTable, pidMatchList, userId); + ProcessList_init(this, Class(Process), host, pidMatchList); - this->existingCPUs = 1; - this->activeCPUs = 1; + host->existingCPUs = 1; + host->activeCPUs = 1; return this; } @@ -91,10 +91,20 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { ProcessList_add(super, proc); } -bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id) { - assert(id < super->existingCPUs); +Machine* Machine_new(UsersTable* usersTable, uid_t userId) { + Machine* this = xCalloc(1, sizeof(Machine)); + Machine_init(this, usersTable, userId); + return this; +} + +void Machine_delete(Machine* host) { + free(host); +} + +bool Machine_isCPUonline(const Machine* host, unsigned int id) { + assert(id < host->existingCPUs); - (void) super; (void) id; + (void) host; (void) id; return true; } diff --git a/unsupported/UnsupportedProcessList.h b/unsupported/UnsupportedProcessList.h index 9f4d23aa..cdb0b601 100644 --- a/unsupported/UnsupportedProcessList.h +++ b/unsupported/UnsupportedProcessList.h @@ -10,12 +10,16 @@ in the source distribution for its full text. #include "ProcessList.h" -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); +ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList); void ProcessList_delete(ProcessList* this); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); -bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id); +Machine* Machine_new(UsersTable* usersTable, uid_t userId); + +bool Machine_isCPUonline(const Machine* host, unsigned int id); + +void Machine_delete(Machine* host); #endif -- cgit v1.2.3