Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bat: Fix deprecation declaration warnings #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/bat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
// Simple example to read battery detailsw
// Compile: gcc bat.c -o bat -framework IOKit -framework CoreFoundation

/// Power Mgmt Stuff
/// Power Mgmt Stuff

// from IOKitUser-755.18.10/ps.subproj/IOPowerSources.h
// from IOKitUser-755.18.10/ps.subproj/IOPowerSources.h
CFTypeRef IOPSCopyPowerSourcesInfo(void);
CFArrayRef IOPSCopyPowerSourcesList(CFTypeRef blob);
CFDictionaryRef IOPSGetPowerSourceDescription(CFTypeRef blob, CFTypeRef ps);

void
void
dumpDict (CFDictionaryRef Dict)
{

// Helper function to just dump a CFDictioary as XML

CFDataRef xml = CFPropertyListCreateXMLData(kCFAllocatorDefault, (CFPropertyListRef)Dict);
CFDataRef xml = CFPropertyListCreateData(kCFAllocatorDefault, (CFPropertyListRef)Dict, kCFPropertyListXMLFormat_v1_0, 0, NULL);
if (xml) { write(1, CFDataGetBytePtr(xml), CFDataGetLength(xml)); CFRelease(xml); }
}

Expand All @@ -30,7 +30,7 @@ getPowerDetails(int Debug)
CFDictionaryRef powerSourceInformation;

static char returned[80];

powerInfo = IOPSCopyPowerSourcesInfo();

if(! powerInfo) return ("Error: IOPsCopyPowerSourcesInfo()");
Expand All @@ -43,7 +43,7 @@ getPowerDetails(int Debug)

// Should only get one source. But in practice, check for > 0 sources

if (CFArrayGetCount(powerSourcesList))
if (CFArrayGetCount(powerSourcesList))
{
powerSourceInformation = IOPSGetPowerSourceDescription(powerInfo, CFArrayGetValueAtIndex(powerSourcesList, 0));

Expand All @@ -55,25 +55,25 @@ getPowerDetails(int Debug)
CFNumberRef capacityRef = (CFNumberRef) CFDictionaryGetValue(powerSourceInformation, CFSTR("Current Capacity"));
uint32_t capacity;
if ( ! CFNumberGetValue(capacityRef, // CFNumberRef number,
kCFNumberSInt32Type, // CFNumberType theType,
kCFNumberSInt32Type, // CFNumberType theType,
&capacity)) // void *valuePtr);
strcat (returned , "Battery: Unknown");
else
sprintf(returned +strlen(returned), "Battery: %d%%",capacity);

CFStringRef psStateRef = (CFStringRef) CFDictionaryGetValue(powerSourceInformation, CFSTR("Power Source State"));

const char *psState = CFStringGetCStringPtr(psStateRef, // CFStringRef theString,
const char *psState = CFStringGetCStringPtr(psStateRef, // CFStringRef theString,
kCFStringEncodingMacRoman); //CFStringEncoding encoding);

if (!psState) sprintf (returned + strlen(returned), " <unknown> ");
else sprintf (returned + strlen(returned), " (on %s,", psState);

CFBooleanRef isCharging = (CFBooleanRef) CFDictionaryGetValue(powerSourceInformation, CFSTR("Is Charging"));


sprintf(returned +strlen(returned), "%sCharging)", (CFBooleanGetValue(isCharging) ? "": " Not "));
}
}

CFRelease(powerInfo);
CFRelease(powerSourcesList);
Expand All @@ -84,15 +84,15 @@ getPowerDetails(int Debug)
/// End Power stuff


int
int
main (int argc, char **argv)
{


char *powerInfo = getPowerDetails(1);

if (powerInfo) printf ("%s\n", powerInfo);
return (0);


}
}