summaryrefslogtreecommitdiffstats
path: root/darwin
diff options
context:
space:
mode:
authorDavid Hunt <dhunt@iolanthe.attlocal.net>2015-07-12 13:47:43 -0500
committerHisham Muhammad <hisham@gobolinux.org>2015-08-19 13:47:26 -0300
commit70e7c8db592408f45b958238d4bbf0048886f6fc (patch)
tree0ee699faad92f38d29d10b5c9faced3436f0c647 /darwin
parentfeb7a01fd32d4a63b9cfb178c67cc95c05c9dc00 (diff)
Added darwin with working battery meter
Diffstat (limited to 'darwin')
-rw-r--r--darwin/Battery.c75
-rw-r--r--darwin/Battery.h9
-rw-r--r--darwin/DarwinCRT.c34
-rw-r--r--darwin/DarwinCRT.h15
-rw-r--r--darwin/DarwinProcess.c33
-rw-r--r--darwin/DarwinProcess.h22
-rw-r--r--darwin/DarwinProcessList.c71
-rw-r--r--darwin/DarwinProcessList.h20
-rw-r--r--darwin/Platform.c136
-rw-r--r--darwin/Platform.h46
10 files changed, 461 insertions, 0 deletions
diff --git a/darwin/Battery.c b/darwin/Battery.c
new file mode 100644
index 00000000..2847f52f
--- /dev/null
+++ b/darwin/Battery.c
@@ -0,0 +1,75 @@
+
+#include "BatteryMeter.h"
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreFoundation/CFString.h>
+#include <IOKit/ps/IOPowerSources.h>
+#include <IOKit/ps/IOPSKeys.h>
+
+void Battery_getData(double* level, ACPresence* isOnAC) {
+ CFTypeRef power_sources = IOPSCopyPowerSourcesInfo();
+
+ *level = -1;
+ *isOnAC = AC_ERROR;
+
+ if(NULL == power_sources) {
+ return;
+ }
+
+ if(power_sources != NULL) {
+ CFArrayRef list = IOPSCopyPowerSourcesList(power_sources);
+ CFDictionaryRef battery = NULL;
+ int len;
+
+ if(NULL == list) {
+ CFRelease(power_sources);
+
+ return;
+ }
+
+ len = CFArrayGetCount(list);
+
+ /* Get the battery */
+ for(int i = 0; i < len && battery == NULL; ++i) {
+ CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources,
+ CFArrayGetValueAtIndex(list, i)); /* GET rule */
+ CFStringRef type;
+
+ if(NULL != candidate) {
+ type = (CFStringRef) CFDictionaryGetValue(candidate,
+ CFSTR(kIOPSTransportTypeKey)); /* GET rule */
+
+ if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
+ CFRetain(candidate);
+ battery = candidate;
+ }
+ }
+ }
+
+ if(NULL != battery) {
+ /* Determine the AC state */
+ CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey));
+
+ *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0))
+ ? AC_PRESENT
+ : AC_ABSENT;
+
+ /* Get the percentage remaining */
+ double current;
+ double max;
+
+ CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)),
+ kCFNumberDoubleType, &current);
+ CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
+ kCFNumberDoubleType, &max);
+
+ *level = (current * 100.0) / max;
+
+ CFRelease(battery);
+ }
+
+ CFRelease(list);
+ CFRelease(power_sources);
+ }
+}
+
diff --git a/darwin/Battery.h b/darwin/Battery.h
new file mode 100644
index 00000000..8dc0cef6
--- /dev/null
+++ b/darwin/Battery.h
@@ -0,0 +1,9 @@
+/* Do not edit this file. It was automatically generated. */
+
+#ifndef HEADER_Battery
+#define HEADER_Battery
+
+void Battery_getData(double* level, ACPresence* isOnAC);
+
+
+#endif
diff --git a/darwin/DarwinCRT.c b/darwin/DarwinCRT.c
new file mode 100644
index 00000000..49f98cdc
--- /dev/null
+++ b/darwin/DarwinCRT.c
@@ -0,0 +1,34 @@
+/*
+htop - DarwinCRT.c
+(C) 2014 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h"
+#include "CRT.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+void CRT_handleSIGSEGV(int sgn) {
+ (void) sgn;
+ CRT_done();
+ #ifdef __APPLE__
+ fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
+ #ifdef HAVE_EXECINFO_H
+ size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
+ fprintf(stderr, "\n Please include in your report the following backtrace: \n");
+ backtrace_symbols_fd(backtraceArray, size, 2);
+ fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
+ fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
+ fprintf(stderr, "\n\n otool -tvV `which htop` > ~/htop.otool");
+ fprintf(stderr, "\n\nand then attach the file ~/htop.otool to your bug report.");
+ fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
+ #endif
+ #else
+ fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!");
+ fprintf(stderr, "\nPlease contact your platform package mantainer!\n\n");
+ #endif
+ abort();
+}
+
diff --git a/darwin/DarwinCRT.h b/darwin/DarwinCRT.h
new file mode 100644
index 00000000..e1c22bbd
--- /dev/null
+++ b/darwin/DarwinCRT.h
@@ -0,0 +1,15 @@
+/* Do not edit this file. It was automatically generated. */
+
+#ifndef HEADER_DarwinCRT
+#define HEADER_DarwinCRT
+/*
+htop - DarwinCRT.h
+(C) 2014 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+void CRT_handleSIGSEGV(int sgn);
+
+
+#endif
diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c
new file mode 100644
index 00000000..7054cf46
--- /dev/null
+++ b/darwin/DarwinProcess.c
@@ -0,0 +1,33 @@
+/*
+htop - DarwinProcess.c
+(C) 2015 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "Process.h"
+#include "DarwinProcess.h"
+#include <stdlib.h>
+
+/*{
+#include "Settings.h"
+
+#define Process_delete UnsupportedProcess_delete
+
+}*/
+
+Process* DarwinProcess_new(Settings* settings) {
+ Process* this = calloc(sizeof(Process), 1);
+ Object_setClass(this, Class(Process));
+ Process_init(this, settings);
+ return this;
+}
+
+void DarwinProcess_delete(Object* cast) {
+ Process* this = (Process*) cast;
+ Object_setClass(this, Class(Process));
+ Process_done((Process*)cast);
+ // free platform-specific fields here
+ free(this);
+}
+
diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h
new file mode 100644
index 00000000..201650d5
--- /dev/null
+++ b/darwin/DarwinProcess.h
@@ -0,0 +1,22 @@
+/* Do not edit this file. It was automatically generated. */
+
+#ifndef HEADER_DarwinProcess
+#define HEADER_DarwinProcess
+/*
+htop - DarwinProcess.h
+(C) 2015 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "Settings.h"
+
+#define Process_delete DarwinProcess_delete
+
+
+Process* DarwinProcess_new(Settings* settings);
+
+void DarwinProcess_delete(Object* cast);
+
+
+#endif
diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c
new file mode 100644
index 00000000..3fb36365
--- /dev/null
+++ b/darwin/DarwinProcessList.c
@@ -0,0 +1,71 @@
+/*
+htop - DarwinProcessList.c
+(C) 2014 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "ProcessList.h"
+#include "DarwinProcess.h"
+#include "DarwinProcessList.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/*{
+
+}*/
+
+ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
+ ProcessList* this = calloc(1, sizeof(ProcessList));
+ ProcessList_init(this, Class(Process), usersTable, pidWhiteList, userId);
+
+ return this;
+}
+
+void ProcessList_delete(ProcessList* this) {
+ ProcessList_done(this);
+ free(this);
+}
+
+void ProcessList_goThroughEntries(ProcessList* super) {
+ bool preExisting = true;
+ Process *proc;
+
+ proc = ProcessList_getProcess(super, 1, &preExisting, DarwinProcess_new);
+
+ /* Empty values */
+ proc->time = proc->time + 10;
+ proc->pid = 1;
+ proc->ppid = 1;
+ proc->tgid = 0;
+ proc->comm = "<unsupported architecture>";
+ proc->basenameOffset = 0;
+ proc->updated = true;
+
+ proc->state = 'R';
+ proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */
+ proc->pgrp = 0;
+ proc->session = 0;
+ proc->tty_nr = 0;
+ proc->tpgid = 0;
+ proc->st_uid = 0;
+ proc->flags = 0;
+ proc->processor = 0;
+
+ proc->percent_cpu = 2.5;
+ proc->percent_mem = 2.5;
+ proc->user = "nobody";
+
+ proc->priority = 0;
+ proc->nice = 0;
+ proc->nlwp = 1;
+ strncpy(proc->starttime_show, "Jun 01 ", sizeof(proc->starttime_show));
+ proc->starttime_ctime = 1433116800; // Jun 01, 2015
+
+ proc->m_size = 100;
+ proc->m_resident = 100;
+
+ proc->minflt = 20;
+ proc->majflt = 20;
+}
diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h
new file mode 100644
index 00000000..ccdf718f
--- /dev/null
+++ b/darwin/DarwinProcessList.h
@@ -0,0 +1,20 @@
+/* Do not edit this file. It was automatically generated. */
+
+#ifndef HEADER_DarwinProcessList
+#define HEADER_DarwinProcessList
+/*
+htop - DarwinProcessList.h
+(C) 2014 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+
+
+ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
+
+void ProcessList_delete(ProcessList* this);
+
+void ProcessList_goThroughEntries(ProcessList* super);
+
+#endif
diff --git a/darwin/Platform.c b/darwin/Platform.c
new file mode 100644
index 00000000..99e90801
--- /dev/null
+++ b/darwin/Platform.c
@@ -0,0 +1,136 @@
+/*
+htop - darwin/Platform.c
+(C) 2014 Hisham H. Muhammad
+(C) 2015 David C. Hunt
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "Platform.h"
+#include "CPUMeter.h"
+#include "MemoryMeter.h"
+#include "SwapMeter.h"
+#include "TasksMeter.h"
+#include "LoadAverageMeter.h"
+#include "ClockMeter.h"
+#include "HostnameMeter.h"
+#include "UptimeMeter.h"
+
+/*{
+#include "Action.h"
+#include "BatteryMeter.h"
+#include "DarwinProcess.h"
+}*/
+
+ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
+
+ProcessFieldData Process_fields[] = {
+ [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
+ [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
+ [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
+ [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
+ [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
+ [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
+ [SESSION] = { .name = "SESSION", .title = " SESN ", .description = "Process's session ID", .flags = 0, },
+ [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
+ [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
+ [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
+ [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
+ [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
+ [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
+ [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
+
+ [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
+ [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
+ [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
+ [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
+ [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
+ [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
+ [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
+ [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
+ [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
+ [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
+ [100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
+};
+
+MeterClass* Platform_meterTypes[] = {
+ &CPUMeter_class,
+ &ClockMeter_class,
+ &LoadAverageMeter_class,
+ &LoadMeter_class,
+ &MemoryMeter_class,
+ &SwapMeter_class,
+ &TasksMeter_class,
+ &BatteryMeter_class,
+ &HostnameMeter_class,
+ &UptimeMeter_class,
+ &AllCPUsMeter_class,
+ &AllCPUs2Meter_class,
+ &LeftCPUsMeter_class,
+ &RightCPUsMeter_class,
+ &LeftCPUs2Meter_class,
+ &RightCPUs2Meter_class,
+ &BlankMeter_class,
+ NULL
+};
+
+void Platform_setBindings(Htop_Action* keys) {
+ (void) keys;
+}
+
+int Platform_numberOfFields = 100;
+char* Process_pidFormat = "%7u ";
+char* Process_tpgidFormat = "%7u ";
+
+int Platform_getUptime() {
+ return 0;
+}
+
+void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
+ *one = 0;
+ *five = 0;
+ *fifteen = 0;
+}
+
+int Platform_getMaxPid() {
+ return 1;
+}
+
+void Process_setupColumnWidths() {
+ int maxPid = Platform_getMaxPid();
+ if (maxPid == -1) return;
+ if (maxPid > 99999) {
+ Process_fields[PID].title = " PID ";
+ Process_fields[PPID].title = " PPID ";
+ Process_fields[TPGID].title = " TPGID ";
+ Process_fields[TGID].title = " TGID ";
+ Process_fields[PGRP].title = " PGRP ";
+ Process_fields[SESSION].title = " SESN ";
+ Process_pidFormat = "%7u ";
+ Process_tpgidFormat = "%7d ";
+ } else {
+ Process_fields[PID].title = " PID ";
+ Process_fields[PPID].title = " PPID ";
+ Process_fields[TPGID].title = "TPGID ";
+ Process_fields[TGID].title = " TGID ";
+ Process_fields[PGRP].title = " PGRP ";
+ Process_fields[SESSION].title = " SESN ";
+ Process_pidFormat = "%5u ";
+ Process_tpgidFormat = "%5d ";
+ }
+}
+
+double Platform_setCPUValues(Meter* this, int cpu) {
+ return 0.0;
+}
+
+void Platform_setMemoryValues(Meter* this) {
+}
+
+void Platform_setSwapValues(Meter* this) {
+}
+
+bool Process_isThread(Process* this) {
+ return false;
+}
+
diff --git a/darwin/Platform.h b/darwin/Platform.h
new file mode 100644
index 00000000..4fc06f71
--- /dev/null
+++ b/darwin/Platform.h
@@ -0,0 +1,46 @@
+/* Do not edit this file. It was automatically generated. */
+
+#ifndef HEADER_Platform
+#define HEADER_Platform
+/*
+htop - darwin/Platform.h
+(C) 2014 Hisham H. Muhammad
+(C) 2015 David C. Hunt
+Released under the GNU GPL, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "Action.h"
+#include "BatteryMeter.h"
+#include "DarwinProcess.h"
+
+extern ProcessField Platform_defaultFields[];
+
+extern ProcessFieldData Process_fields[];
+
+extern MeterClass* Platform_meterTypes[];
+
+void Platform_setBindings(Htop_Action* keys);
+
+extern int Platform_numberOfFields;
+extern char* Process_pidFormat;
+extern char* Process_tpgidFormat;
+
+int Platform_getUptime();
+
+void Platform_getLoadAverage(double* one, double* five, double* fifteen);
+
+int Platform_getMaxPid();
+
+void Process_setupColumnWidths();
+
+double Platform_setCPUValues(Meter* this, int cpu);
+
+void Platform_setMemoryValues(Meter* this);
+
+void Platform_setSwapValues(Meter* this);
+
+bool Process_isThread(Process* this);
+
+
+#endif

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