SDL  2.0
SDL_power.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../SDL_internal.h"
22 #include "SDL_power.h"
23 
24 /*
25  * Returns SDL_TRUE if we have a definitive answer.
26  * SDL_FALSE to try next implementation.
27  */
28 typedef SDL_bool
30  int *percent);
31 
43 
44 #ifndef SDL_POWER_DISABLED
45 #ifdef SDL_POWER_HARDWIRED
46 /* This is for things that _never_ have a battery */
47 static SDL_bool
48 SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
49 {
50  *seconds = -1;
51  *percent = -1;
53  return SDL_TRUE;
54 }
55 #endif
56 #endif
57 
58 
60 #ifndef SDL_POWER_DISABLED
61 #ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */
65 #endif
66 #ifdef SDL_POWER_WINDOWS /* handles Win32, Win64, PocketPC. */
68 #endif
69 #ifdef SDL_POWER_UIKIT /* handles iPhone/iPad/etc */
71 #endif
72 #ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin. */
74 #endif
75 #ifdef SDL_POWER_HAIKU /* with BeOS euc.jp apm driver. Does this work on Haiku? */
77 #endif
78 #ifdef SDL_POWER_ANDROID /* handles Android. */
80 #endif
81 #ifdef SDL_POWER_PSP /* handles PSP. */
83 #endif
84 #ifdef SDL_POWER_WINRT /* handles WinRT */
86 #endif
87 #ifdef SDL_POWER_EMSCRIPTEN /* handles Emscripten */
89 #endif
90 
91 #ifdef SDL_POWER_HARDWIRED
92  SDL_GetPowerInfo_Hardwired,
93 #endif
94 #endif
95 };
96 
98 SDL_GetPowerInfo(int *seconds, int *percent)
99 {
100  const int total = sizeof(implementations) / sizeof(implementations[0]);
101  int _seconds, _percent;
103  int i;
104 
105  /* Make these never NULL for platform-specific implementations. */
106  if (seconds == NULL) {
107  seconds = &_seconds;
108  }
109 
110  if (percent == NULL) {
111  percent = &_percent;
112  }
113 
114  for (i = 0; i < total; i++) {
115  if (implementations[i](&retval, seconds, percent)) {
116  return retval;
117  }
118  }
119 
120  /* nothing was definitive. */
121  *seconds = -1;
122  *percent = -1;
123  return SDL_POWERSTATE_UNKNOWN;
124 }
125 
126 /* vi: set ts=4 sw=4 expandtab: */
SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *)
SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *)
struct xkb_state * state
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *)
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *)
SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *, int *, int *)
SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *)
SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *)
SDL_bool retval
static SDL_GetPowerInfo_Impl implementations[]
Definition: SDL_power.c:59
SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *)
#define NULL
Definition: begin_code.h:143
SDL_bool
Definition: SDL_stdinc.h:130
SDL_PowerState
The basic state for the system&#39;s power supply.
Definition: SDL_power.h:42
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *)
SDL_bool(* SDL_GetPowerInfo_Impl)(SDL_PowerState *state, int *seconds, int *percent)
Definition: SDL_power.c:29
SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent)
Get the current power supply details.
Definition: SDL_power.c:98
SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *)