diff --git a/BatteryMeter.c b/BatteryMeter.c index 5cd0c389b0cc62930cb946d928cc403502f72062..32be457180699bc534192c3e9d1a0b5e7428d287 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -13,6 +13,7 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). #include "ProcessList.h" #include "CRT.h" #include "String.h" +#include "Platform.h" #include #include diff --git a/Process.c b/Process.c index de25cbbbad928090c8f5cf67819f73cdcdd29d77..dbdb4810cca1954b39f76ff8431afb12e6959db8 100644 --- a/Process.c +++ b/Process.c @@ -45,6 +45,8 @@ in the source distribution for its full text. #include +typedef struct Settings_ Settings; + #define PROCESS_FLAG_IO 1 #define PROCESS_FLAG_IOPRIO 2 #define PROCESS_FLAG_OPENVZ 4 @@ -643,14 +645,12 @@ static void Process_display(Object* cast, RichString* out) { assert(out->chlen > 0); } -void Process_delete(Object* cast) { - Process* this = (Process*) cast; +void Process_done(Process* this) { assert (this != NULL); free(this->comm); #ifdef HAVE_CGROUP free(this->cgroup); #endif - free(this); } ObjectClass Process_class = { @@ -660,9 +660,7 @@ ObjectClass Process_class = { .compare = Process_compare }; -Process* Process_new(struct ProcessList_ *pl) { - Process* this = calloc(1, sizeof(Process)); - Object_setClass(this, Class(Process)); +void Process_init(Process* this, struct Settings_* settings, struct ProcessList_* pl) { this->pid = 0; this->pl = pl; this->tag = false; @@ -678,7 +676,6 @@ Process* Process_new(struct ProcessList_ *pl) { this->cgroup = NULL; #endif if (Process_getuid == -1) Process_getuid = getuid(); - return this; } void Process_toggleTag(Process* this) { diff --git a/Process.h b/Process.h index 6bd40686a6569fe0c70f14bc6d2bbf6aa663cf38..f4d5a46354c4b9e412271d0fc2ff9bb35179450e 100644 --- a/Process.h +++ b/Process.h @@ -24,6 +24,8 @@ in the source distribution for its full text. #include +typedef struct Settings_ Settings; + #define PROCESS_FLAG_IO 1 #define PROCESS_FLAG_IOPRIO 2 #define PROCESS_FLAG_OPENVZ 4 @@ -189,11 +191,11 @@ void Process_setupColumnWidths(); #define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K) #define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K) -void Process_delete(Object* cast); +void Process_done(Process* this); extern ObjectClass Process_class; -Process* Process_new(struct ProcessList_ *pl); +void Process_init(Process* this, struct Settings_* settings, struct ProcessList_* pl); void Process_toggleTag(Process* this); diff --git a/Settings.c b/Settings.c index 1dc8b1b2cd6e27a1509fa6eaf3f6338f29cad018..52ab39eb81d3b5a85a1f3ed4bab1b30f09962e56 100644 --- a/Settings.c +++ b/Settings.c @@ -22,14 +22,14 @@ in the source distribution for its full text. #include "Header.h" #include -typedef struct Settings_ { +struct Settings_ { char* userSettings; ProcessList* pl; Header* header; int colorScheme; int delay; bool changed; -} Settings; +}; }*/ diff --git a/Settings.h b/Settings.h index 28fe55206cfb1216095b1b6dcf9fce6c730d7145..2fe27abe590ab21d629bb9bccd3c365d342ffdc9 100644 --- a/Settings.h +++ b/Settings.h @@ -15,14 +15,14 @@ in the source distribution for its full text. #include "Header.h" #include -typedef struct Settings_ { +struct Settings_ { char* userSettings; ProcessList* pl; Header* header; int colorScheme; int delay; bool changed; -} Settings; +}; void Settings_delete(Settings* this); diff --git a/configure.ac b/configure.ac index a952d5ea9dd250c6036607e9d0b6f5a9053d829c..0edf493def9e335fcb7c4d89ca5b45eacc065341 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,9 @@ case "$target" in ;; esac +my_htop_platform=unsupported + + # Checks for libraries. # ---------------------------------------------------------------------- AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"]) diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index be4e627abdb3a14add89877b111021c0e82cd3f2..9c26018d5712653bd9910d98aa2c5f9cdcab087b 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "LinuxProcess.h" #include "CRT.h" +#include #include #include @@ -22,8 +23,23 @@ typedef struct LinuxProcess_ { IOPriority ioPriority; } LinuxProcess; +#define Process_delete LinuxProcess_delete + }*/ +LinuxProcess* LinuxProcess_new(Settings* settings, ProcessList* pl) { + LinuxProcess* this = calloc(sizeof(LinuxProcess), 1); + Process_init(&this->super, settings, pl); + return this; +} + +void LinuxProcess_delete(Object* cast) { + LinuxProcess* this = (LinuxProcess*) this; + Object_setClass(this, Class(Process)); + Process_done((Process*)cast); + free(this); +} + /* [1] Note that before kernel 2.6.26 a process that has not asked for an io priority formally uses "none" as scheduling class, but the diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 97ddf90b0889ec771d74de358cb101501669b8a0..ec2740e9fbfe5234ff09371155731866586a6ab3 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -17,6 +17,12 @@ typedef struct LinuxProcess_ { IOPriority ioPriority; } LinuxProcess; +#define Process_delete LinuxProcess_delete + + +LinuxProcess* LinuxProcess_new(Settings* settings); + +void LinuxProcess_delete(Object* cast); /* [1] Note that before kernel 2.6.26 a process that has not asked for diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index c2d3fa7cd8ab7a33823f8a3bff9756c7c54e99f9..2bce78e54ba80ff18743e5102768060ac98febf6 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -319,6 +319,7 @@ static void LinuxProcessList_readCGroupFile(Process* process, const char* dirnam int nFields; char** fields = String_split(trimmed, ':', &nFields); free(trimmed); + free(process->cgroup); if (nFields >= 3) { process->cgroup = strndup(fields[2] + 1, 10); } else { @@ -464,7 +465,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna process = existingProcess; assert(process->pid == pid); } else { - process = Process_new(this); + process = (Process*) LinuxProcess_new(settings, this); assert(process->comm == NULL); process->pid = pid; process->tgid = parent ? parent->pid : pid; @@ -568,7 +569,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna if (existingProcess) ProcessList_remove(this, process); else - Process_delete((Object*)process); + LinuxProcess_delete((Object*)process); } } closedir(dir); diff --git a/linux/Platform.c b/linux/Platform.c index ee5abf815c9bdce7851a73152e386c2130eff5e8..70a0f55c0835b5d9768593f15d2a8740d491bce7 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -27,6 +27,7 @@ in the source distribution for its full text. /*{ #include "Action.h" #include "BatteryMeter.h" +#include "LinuxProcess.h" }*/ static Htop_Reaction Platform_actionSetIOPriority(Panel* panel, ProcessList* pl, Header* header) { diff --git a/linux/Platform.h b/linux/Platform.h index 2058419c16939566ae5b30bb8fd2ae387eb06014..446c51d142f0621369f2134af32bd0c7a1890113 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -11,6 +11,7 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +#include "LinuxProcess.h" void Platform_setBindings(Htop_Action* keys); diff --git a/unsupported/Platform.c b/unsupported/Platform.c index e5f22d2c9d71367bab3e92a0751b2c4a129653f7..2178a373a2bf1f380f5e70b3234087dc376a7278 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -60,3 +60,7 @@ int Platform_getMaxPid() { return -1; } +void Platform_getBatteryLevel(double* level, ACPresence* isOnAC) { + *level = -1; + *isOnAC = AC_ERROR; +} diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 888e8cf394996099ddf9db773a9deee789c878e9..0a822e75493d271c490f56a84669b3eea3f04471 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -23,5 +23,6 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen); int Platform_getMaxPid(); +void Platform_getBatteryLevel(double* level, ACPresence* isOnAC); #endif