summaryrefslogtreecommitdiff
path: root/platform/osx/power_osx.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /platform/osx/power_osx.cpp
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'platform/osx/power_osx.cpp')
-rw-r--r--platform/osx/power_osx.cpp66
1 files changed, 28 insertions, 38 deletions
diff --git a/platform/osx/power_osx.cpp b/platform/osx/power_osx.cpp
index 5c8f067f24..de9bcaf6fc 100644
--- a/platform/osx/power_osx.cpp
+++ b/platform/osx/power_osx.cpp
@@ -29,20 +29,19 @@
#include "power_osx.h"
#include <CoreFoundation/CoreFoundation.h>
-#include <IOKit/ps/IOPowerSources.h>
#include <IOKit/ps/IOPSKeys.h>
+#include <IOKit/ps/IOPowerSources.h>
// CODE CHUNK IMPORTED FROM SDL 2.0
/* CoreFoundation is so verbose... */
-#define STRMATCH(a,b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
-#define GETVAL(k,v) \
- CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **) v)
+#define STRMATCH(a, b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
+#define GETVAL(k, v) \
+ CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **)v)
/* Note that AC power sources also include a laptop battery it is charging. */
-void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery, bool * charging)
-{
- CFStringRef strval; /* don't CFRelease() this. */
+void power_osx::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging) {
+ CFStringRef strval; /* don't CFRelease() this. */
CFBooleanRef bval;
CFNumberRef numval;
bool charge = false;
@@ -53,7 +52,7 @@ void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_batter
int pct = -1;
if ((GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse)) {
- return; /* nothing to see here. */
+ return; /* nothing to see here. */
}
if (!GETVAL(kIOPSPowerSourceStateKey, &strval)) {
@@ -63,7 +62,7 @@ void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_batter
if (STRMATCH(strval, CFSTR(kIOPSACPowerValue))) {
is_ac = *have_ac = true;
} else if (!STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) {
- return; /* not a battery? */
+ return; /* not a battery? */
}
if ((GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) {
@@ -75,7 +74,7 @@ void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_batter
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
if (val > 0) {
*have_battery = true;
- maxpct = (int) val;
+ maxpct = (int)val;
}
}
@@ -84,7 +83,7 @@ void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_batter
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
if (val > 0) {
*have_battery = true;
- maxpct = (int) val;
+ maxpct = (int)val;
}
}
@@ -93,24 +92,24 @@ void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_batter
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
/* Mac OS X reports 0 minutes until empty if you're plugged in. :( */
- if ((val == 0) && (is_ac)) {
- val = -1; /* !!! FIXME: calc from timeToFull and capacity? */
- }
+ if ((val == 0) && (is_ac)) {
+ val = -1; /* !!! FIXME: calc from timeToFull and capacity? */
+ }
- secs = (int) val;
- if (secs > 0) {
- secs *= 60; /* value is in minutes, so convert to seconds. */
- }
+ secs = (int)val;
+ if (secs > 0) {
+ secs *= 60; /* value is in minutes, so convert to seconds. */
+ }
}
if (GETVAL(kIOPSCurrentCapacityKey, &numval)) {
SInt32 val = -1;
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
- pct = (int) val;
+ pct = (int)val;
}
if ((pct > 0) && (maxpct > 0)) {
- pct = (int) ((((double) pct) / ((double) maxpct)) * 100.0);
+ pct = (int)((((double)pct) / ((double)maxpct)) * 100.0);
}
if (pct > 100) {
@@ -123,7 +122,7 @@ void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_batter
*/
if ((secs < 0) && (nsecs_left < 0)) {
if ((pct < 0) && (percent_left < 0)) {
- choose = true; /* at least we know there's a battery. */
+ choose = true; /* at least we know there's a battery. */
}
if (pct > percent_left) {
choose = true;
@@ -143,8 +142,7 @@ void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_batter
#undef STRMATCH
// CODE CHUNK IMPORTED FROM SDL 2.0
-bool power_osx::GetPowerInfo_MacOSX()
-{
+bool power_osx::GetPowerInfo_MacOSX() {
CFTypeRef blob = IOPSCopyPowerSourcesInfo();
nsecs_left = -1;
@@ -161,7 +159,7 @@ bool power_osx::GetPowerInfo_MacOSX()
const CFIndex total = CFArrayGetCount(list);
CFIndex i;
for (i = 0; i < total; i++) {
- CFTypeRef ps = (CFTypeRef) CFArrayGetValueAtIndex(list, i);
+ CFTypeRef ps = (CFTypeRef)CFArrayGetValueAtIndex(list, i);
CFDictionaryRef dict = IOPSGetPowerSourceDescription(blob, ps);
if (dict != NULL) {
checkps(dict, &have_ac, &have_battery, &charging);
@@ -183,11 +181,9 @@ bool power_osx::GetPowerInfo_MacOSX()
CFRelease(blob);
}
- return true; /* always the definitive answer on Mac OS X. */
+ return true; /* always the definitive answer on Mac OS X. */
}
-
-
bool power_osx::UpdatePowerInfo() {
if (GetPowerInfo_MacOSX()) {
return true;
@@ -195,12 +191,10 @@ bool power_osx::UpdatePowerInfo() {
return false;
}
-
PowerState power_osx::get_power_state() {
if (UpdatePowerInfo()) {
return power_state;
- }
- else {
+ } else {
return POWERSTATE_UNKNOWN;
}
}
@@ -208,8 +202,7 @@ PowerState power_osx::get_power_state() {
int power_osx::get_power_seconds_left() {
if (UpdatePowerInfo()) {
return nsecs_left;
- }
- else {
+ } else {
return -1;
}
}
@@ -217,17 +210,14 @@ int power_osx::get_power_seconds_left() {
int power_osx::get_power_percent_left() {
if (UpdatePowerInfo()) {
return percent_left;
- }
- else {
+ } else {
return -1;
}
}
-
-power_osx::power_osx() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) {
-
+power_osx::power_osx()
+ : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) {
}
power_osx::~power_osx() {
-
}