From 72235d8e098d9d79029dca65122605741e1aafad Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 2 May 2023 16:56:18 +1000 Subject: Adapt platform code for the new Machine base class Move host-centric data to new derived Machine classes, separate from process-list-centric data. --- unsupported/UnsupportedMachine.c | 56 ++++++++++++++++++++++++++++++++++++ unsupported/UnsupportedMachine.h | 17 +++++++++++ unsupported/UnsupportedProcessList.c | 35 ++++------------------ unsupported/UnsupportedProcessList.h | 14 ++------- 4 files changed, 81 insertions(+), 41 deletions(-) create mode 100644 unsupported/UnsupportedMachine.c create mode 100644 unsupported/UnsupportedMachine.h (limited to 'unsupported') diff --git a/unsupported/UnsupportedMachine.c b/unsupported/UnsupportedMachine.c new file mode 100644 index 00000000..a6635acc --- /dev/null +++ b/unsupported/UnsupportedMachine.c @@ -0,0 +1,56 @@ +/* +htop - UnsupportedMachine.c +(C) 2014 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "UnsupportedMachine.h" + +#include +#include + +#include "Machine.h" + + +Machine* Machine_new(UsersTable* usersTable, uid_t userId) { + UnsupportedMachine* this = xCalloc(1, sizeof(UnsupportedMachine)); + Machine* super = &this->super; + + Machine_init(super, usersTable, userId); + + super->existingCPUs = 1; + super->activeCPUs = 1; + + return super; +} + +void Machine_delete(Machine* super) { + UnsupportedMachine* this = (UnsupportedMachine*) super; + Machine_done(super); + free(this); +} + +bool Machine_isCPUonline(const Machine* host, unsigned int id) { + assert(id < host->existingCPUs); + + (void) host; (void) id; + + return true; +} + +void Machine_scan(Machine* super) { + super->existingCPUs = 1; + super->activeCPUs = 1; + + super->totalMem = 0; + super->usedMem = 0; + super->buffersMem = 0; + super->cachedMem = 0; + super->sharedMem = 0; + super->availableMem = 0; + + super->totalSwap = 0; + super->usedSwap = 0; + super->cachedSwap = 0; +} diff --git a/unsupported/UnsupportedMachine.h b/unsupported/UnsupportedMachine.h new file mode 100644 index 00000000..4ec760f1 --- /dev/null +++ b/unsupported/UnsupportedMachine.h @@ -0,0 +1,17 @@ +#ifndef HEADER_UnsupportedMachine +#define HEADER_UnsupportedMachine +/* +htop - UnsupportedMachine.h +(C) 2014 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Machine.h" + + +typedef struct UnsupportedMachine_ { + Machine super; +} UnsupportedMachine; + +#endif diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index e5b7af6d..e56f4978 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -16,10 +16,8 @@ in the source distribution for its full text. ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList) { ProcessList* this = xCalloc(1, sizeof(ProcessList)); - ProcessList_init(this, Class(Process), host, pidMatchList); - host->existingCPUs = 1; - host->activeCPUs = 1; + ProcessList_init(this, Class(Process), host, pidMatchList); return this; } @@ -29,13 +27,7 @@ void ProcessList_delete(ProcessList* this) { free(this); } -void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { - - // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) { - return; - } - +void ProcessList_goThroughEntries(ProcessList* super) { bool preExisting = true; Process* proc; @@ -51,7 +43,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { Process_updateCmdline(proc, "", 0, 0); Process_updateExe(proc, "/path/to/executable"); - if (proc->settings->ss->flags & PROCESS_FLAG_CWD) { + const Settings* settings = proc->host->settings; + if (settings->ss->flags & PROCESS_FLAG_CWD) { free_and_xStrdup(&proc->procCwd, "/current/working/directory"); } @@ -60,7 +53,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { proc->state = RUNNING; proc->isKernelThread = false; proc->isUserlandThread = false; - proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */ + proc->show = true; /* Reflected in settings-> "hideXXX" really */ proc->pgrp = 0; proc->session = 0; proc->tty_nr = 0; @@ -90,21 +83,3 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (!preExisting) ProcessList_add(super, proc); } - -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) host; (void) id; - - return true; -} diff --git a/unsupported/UnsupportedProcessList.h b/unsupported/UnsupportedProcessList.h index cdb0b601..96efdcd2 100644 --- a/unsupported/UnsupportedProcessList.h +++ b/unsupported/UnsupportedProcessList.h @@ -10,16 +10,8 @@ in the source distribution for its full text. #include "ProcessList.h" -ProcessList* ProcessList_new(Machine* host, Hashtable* pidMatchList); - -void ProcessList_delete(ProcessList* this); - -void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); - -Machine* Machine_new(UsersTable* usersTable, uid_t userId); - -bool Machine_isCPUonline(const Machine* host, unsigned int id); - -void Machine_delete(Machine* host); +typedef struct UnsupportedProcessList_ { + ProcessList super; +} UnsupportedProcessList; #endif -- cgit v1.2.3