#include "SDL_internal.h"
#include "SDL_syspower.h"
typedef bool (*SDL_GetPowerInfo_Impl)(SDL_PowerState *state, int *seconds,
int *percent);
#ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_HARDWIRED
static bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds, int *percent)
{
*seconds = -1;
*percent = -1;
*state = SDL_POWERSTATE_NO_BATTERY;
return true;
}
#endif
static SDL_GetPowerInfo_Impl implementations[] = {
#ifdef SDL_POWER_LINUX
SDL_GetPowerInfo_Linux_org_freedesktop_upower,
SDL_GetPowerInfo_Linux_sys_class_power_supply,
SDL_GetPowerInfo_Linux_proc_acpi,
SDL_GetPowerInfo_Linux_proc_apm,
#endif
#ifdef SDL_POWER_WINDOWS
SDL_GetPowerInfo_Windows,
#endif
#ifdef SDL_POWER_UIKIT
SDL_GetPowerInfo_UIKit,
#endif
#ifdef SDL_POWER_MACOSX
SDL_GetPowerInfo_MacOSX,
#endif
#ifdef SDL_POWER_HAIKU
SDL_GetPowerInfo_Haiku,
#endif
#ifdef SDL_POWER_ANDROID
SDL_GetPowerInfo_Android,
#endif
#ifdef SDL_POWER_PSP
SDL_GetPowerInfo_PSP,
#endif
#ifdef SDL_POWER_VITA
SDL_GetPowerInfo_VITA,
#endif
#ifdef SDL_POWER_N3DS
SDL_GetPowerInfo_N3DS,
#endif
#ifdef SDL_POWER_EMSCRIPTEN
SDL_GetPowerInfo_Emscripten,
#endif
#ifdef SDL_POWER_HARDWIRED
SDL_GetPowerInfo_Hardwired,
#endif
};
#endif
SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent)
{
#ifndef SDL_POWER_DISABLED
const int total = SDL_arraysize(implementations);
SDL_PowerState result = SDL_POWERSTATE_UNKNOWN;
int i;
#endif
int _seconds, _percent;
if (!seconds) {
seconds = &_seconds;
}
if (!percent) {
percent = &_percent;
}
#ifndef SDL_POWER_DISABLED
for (i = 0; i < total; i++) {
if (implementations[i](&result, seconds, percent)) {
return result;
}
}
#endif
*seconds = -1;
*percent = -1;
return SDL_POWERSTATE_UNKNOWN;
}