29 #include <Cocoa/Cocoa.h>
31 #import <IOKit/ps/IOPowerSources.h>
32 #import <IOKit/ps/IOPSKeys.h>
40 static bool is_64 = (
sizeof(
void*) == 8);
43 Gestalt(gestaltSysArchitecture, &x);
44 if (x == gestaltPowerPC) {
46 }
else if (x == gestaltIntel) {
53 static bool init_power_sources_info(CFTypeRef *blobptr, CFArrayRef *sourcesptr)
55 *blobptr = IOPSCopyPowerSourcesInfo();
56 *sourcesptr = IOPSCopyPowerSourcesList(*blobptr);
57 if (CFArrayGetCount(*sourcesptr) == 0) {
58 klfDbg(
"Could not retrieve battery information. May be a system without battery.") ;
70 bool have_battery = init_power_sources_info(&blob, &sources);
80 CFDictionaryRef pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, 0));
82 bool powerConnected = [(NSString*)[(NSDictionary*)pSource objectForKey:@kIOPSPowerSourceStateKey]
83 isEqualToString:@kIOPSACPowerValue];
84 klfDbg(
"power is connected: "<<(
bool)powerConnected) ;
112 bool have_battery = init_power_sources_info(&blob, &sources);