From ea9622b8c9444d92007f24fc54597f83c498f11d Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 17 Nov 2020 18:12:38 +1100 Subject: Merge individual Battery.[ch] files into Platform.[ch] Consistent with everything else involving platform-specific calls from core htop code. --- dragonflybsd/Battery.c | 30 ------------------------------ dragonflybsd/Battery.h | 15 --------------- dragonflybsd/Platform.c | 16 ++++++++++++++++ dragonflybsd/Platform.h | 2 ++ 4 files changed, 18 insertions(+), 45 deletions(-) delete mode 100644 dragonflybsd/Battery.c delete mode 100644 dragonflybsd/Battery.h (limited to 'dragonflybsd') diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c deleted file mode 100644 index 1a690ee3..00000000 --- a/dragonflybsd/Battery.c +++ /dev/null @@ -1,30 +0,0 @@ -/* -htop - dragonflybsd/Battery.c -(C) 2015 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "Battery.h" - -#include -#include - -void Battery_getData(double* level, ACPresence* isOnAC) { - int life; - size_t life_len = sizeof(life); - if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) { - *level = NAN; - } else { - *level = life; - } - - int acline; - size_t acline_len = sizeof(acline); - if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) { - *isOnAC = AC_ERROR; - } else { - *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; - } -} diff --git a/dragonflybsd/Battery.h b/dragonflybsd/Battery.h deleted file mode 100644 index eed0f630..00000000 --- a/dragonflybsd/Battery.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HEADER_Battery -#define HEADER_Battery -/* -htop - dragonflybsd/Battery.h -(C) 2015 Hisham H. Muhammad -(C) 2017 Diederik de Groot -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "BatteryMeter.h" - -void Battery_getData(double* level, ACPresence* isOnAC); - -#endif diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index dd36bf0a..c6966c11 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -234,3 +234,19 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, *packetsTransmitted = 0; return false; } + +void Platform_getBattery(double* level, ACPresence* isOnAC) { + int life; + size_t life_len = sizeof(life); + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + *level = NAN; + else + *level = life; + + int acline; + size_t acline_len = sizeof(acline); + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + *isOnAC = AC_ERROR; + else + *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; +} diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 1da8811b..267b8f37 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -56,4 +56,6 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, unsigned long int* bytesTransmitted, unsigned long int* packetsTransmitted); +void Platform_getBattery(double* level, ACPresence* isOnAC); + #endif -- cgit v1.2.3