#include "../SDL_internal.h"
#include "SDL_power.h"
#include "SDL_syspower.h"
typedef SDL_bool
(*SDL_GetPowerInfo_Impl) (SDL_PowerState * state, int *seconds,
int *percent);
#ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_HARDWIRED
static SDL_bool
SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
{
*seconds = -1;
*percent = -1;
*state = SDL_POWERSTATE_NO_BATTERY;
return SDL_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_WINRT
SDL_GetPowerInfo_WinRT,
#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 = sizeof(implementations) / sizeof(implementations[0]);
SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
int i;
#endif
int _seconds, _percent;
if (seconds == NULL) {
seconds = &_seconds;
}
if (percent == NULL) {
percent = &_percent;
}
#ifndef SDL_POWER_DISABLED
for (i = 0; i < total; i++) {
if (implementations[i](&retval, seconds, percent)) {
return retval;
}
}
#endif
*seconds = -1;
*percent = -1;
return SDL_POWERSTATE_UNKNOWN;
}