comparison src/power/SDL_power.c @ 3186:51750b7a966f

indent
author Sam Lantinga <slouken@libsdl.org>
date Wed, 10 Jun 2009 13:34:20 +0000
parents c8b9c6d27476
children f77f50add24f
comparison
equal deleted inserted replaced
3185:44d5474c2c8a 3186:51750b7a966f
25 /* 25 /*
26 * Returns SDL_TRUE if we have a definitive answer. 26 * Returns SDL_TRUE if we have a definitive answer.
27 * SDL_FALSE to try next implementation. 27 * SDL_FALSE to try next implementation.
28 */ 28 */
29 typedef SDL_bool 29 typedef SDL_bool
30 (*SDL_GetPowerInfo_Impl)(SDL_PowerState *state, int *seconds, int *percent); 30 (*SDL_GetPowerInfo_Impl) (SDL_PowerState * state, int *seconds,
31 int *percent);
31 32
32 SDL_bool SDL_GetPowerInfo_Linux_sys_power(SDL_PowerState*, int*, int*); 33 SDL_bool SDL_GetPowerInfo_Linux_sys_power(SDL_PowerState *, int *, int *);
33 SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState*, int*, int*); 34 SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
34 SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState*, int*, int*); 35 SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
35 SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState*, int*, int*); 36 SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
36 SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState*, int*, int*); 37 SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
37 SDL_bool SDL_GetPowerInfo_OS2(SDL_PowerState*, int*, int*); 38 SDL_bool SDL_GetPowerInfo_OS2(SDL_PowerState *, int *, int *);
38 SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState*, int*, int*); 39 SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *);
39 SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState*, int*, int*); 40 SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *);
40 41
41 #ifndef SDL_POWER_DISABLED 42 #ifndef SDL_POWER_DISABLED
42 #ifdef SDL_POWER_HARDWIRED 43 #ifdef SDL_POWER_HARDWIRED
43 /* This is for things that _never_ have a battery, like the Dreamcast, etc. */ 44 /* This is for things that _never_ have a battery, like the Dreamcast, etc. */
44 static SDL_bool 45 static SDL_bool
45 SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds, int *percent) 46 SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
46 { 47 {
47 *seconds = -1; 48 *seconds = -1;
48 *percent = -1; 49 *percent = -1;
49 *state = SDL_POWERSTATE_NO_BATTERY; 50 *state = SDL_POWERSTATE_NO_BATTERY;
50 return SDL_TRUE; 51 return SDL_TRUE;
53 #endif 54 #endif
54 55
55 56
56 static SDL_GetPowerInfo_Impl implementations[] = { 57 static SDL_GetPowerInfo_Impl implementations[] = {
57 #ifndef SDL_POWER_DISABLED 58 #ifndef SDL_POWER_DISABLED
58 #ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */ 59 #ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */
59 SDL_GetPowerInfo_Linux_sys_power, 60 SDL_GetPowerInfo_Linux_sys_power,
60 SDL_GetPowerInfo_Linux_proc_acpi, 61 SDL_GetPowerInfo_Linux_proc_acpi,
61 SDL_GetPowerInfo_Linux_proc_apm, 62 SDL_GetPowerInfo_Linux_proc_apm,
62 #endif 63 #endif
63 #ifdef SDL_POWER_WINDOWS /* handles Win32, Win64, PocketPC. */ 64 #ifdef SDL_POWER_WINDOWS /* handles Win32, Win64, PocketPC. */
64 SDL_GetPowerInfo_Windows, 65 SDL_GetPowerInfo_Windows,
65 #endif 66 #endif
66 #ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin, iPhone. */ 67 #ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin, iPhone. */
67 SDL_GetPowerInfo_MacOSX, 68 SDL_GetPowerInfo_MacOSX,
68 #endif 69 #endif
69 #ifdef SDL_POWER_OS2 /* handles OS/2, Warp, eComStation. */ 70 #ifdef SDL_POWER_OS2 /* handles OS/2, Warp, eComStation. */
70 SDL_GetPowerInfo_OS2, 71 SDL_GetPowerInfo_OS2,
71 #endif 72 #endif
72 #ifdef SDL_POWER_NINTENDODS /* handles Nintendo DS. */ 73 #ifdef SDL_POWER_NINTENDODS /* handles Nintendo DS. */
73 SDL_GetPowerInfo_NintendoDS, 74 SDL_GetPowerInfo_NintendoDS,
74 #endif 75 #endif
75 #ifdef SDL_POWER_BEOS /* handles BeOS, Zeta, with euc.jp apm driver. */ 76 #ifdef SDL_POWER_BEOS /* handles BeOS, Zeta, with euc.jp apm driver. */
76 SDL_GetPowerInfo_BeOS, 77 SDL_GetPowerInfo_BeOS,
77 #endif 78 #endif
78 #ifdef SDL_POWER_HARDWIRED 79 #ifdef SDL_POWER_HARDWIRED
79 SDL_GetPowerInfo_Hardwired, 80 SDL_GetPowerInfo_Hardwired,
80 #endif 81 #endif
82 }; 83 };
83 84
84 SDL_PowerState 85 SDL_PowerState
85 SDL_GetPowerInfo(int *seconds, int *percent) 86 SDL_GetPowerInfo(int *seconds, int *percent)
86 { 87 {
87 const int total = sizeof (implementations) / sizeof (implementations[0]); 88 const int total = sizeof(implementations) / sizeof(implementations[0]);
88 int _seconds, _percent; 89 int _seconds, _percent;
89 SDL_PowerState retval; 90 SDL_PowerState retval;
90 int i; 91 int i;
91 92
92 /* Make these never NULL for platform-specific implementations. */ 93 /* Make these never NULL for platform-specific implementations. */
97 if (percent == NULL) { 98 if (percent == NULL) {
98 percent = &_percent; 99 percent = &_percent;
99 } 100 }
100 101
101 for (i = 0; i < total; i++) { 102 for (i = 0; i < total; i++) {
102 if (implementations[i](&retval, seconds, percent)) { 103 if (implementations[i] (&retval, seconds, percent)) {
103 return retval; 104 return retval;
104 } 105 }
105 } 106 }
106 107
107 /* nothing was definitive. */ 108 /* nothing was definitive. */
109 *percent = -1; 110 *percent = -1;
110 return SDL_POWERSTATE_UNKNOWN; 111 return SDL_POWERSTATE_UNKNOWN;
111 } 112 }
112 113
113 /* vi: set ts=4 sw=4 expandtab: */ 114 /* vi: set ts=4 sw=4 expandtab: */
114