src/power/SDL_power.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 07 Jun 2009 22:44:59 +0000
changeset 3173 510e3f36c04a
parent 3170 b7a48f533966
child 3174 c8b9c6d27476
permissions -rw-r--r--
BeOS support for power subsystem.
icculus@3170
     1
/*
icculus@3170
     2
    SDL - Simple DirectMedia Layer
icculus@3170
     3
    Copyright (C) 1997-2009 Sam Lantinga
icculus@3170
     4
icculus@3170
     5
    This library is free software; you can redistribute it and/or
icculus@3170
     6
    modify it under the terms of the GNU Lesser General Public
icculus@3170
     7
    License as published by the Free Software Foundation; either
icculus@3170
     8
    version 2.1 of the License, or (at your option) any later version.
icculus@3170
     9
icculus@3170
    10
    This library is distributed in the hope that it will be useful,
icculus@3170
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
icculus@3170
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
icculus@3170
    13
    Lesser General Public License for more details.
icculus@3170
    14
icculus@3170
    15
    You should have received a copy of the GNU Lesser General Public
icculus@3170
    16
    License along with this library; if not, write to the Free Software
icculus@3170
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
icculus@3170
    18
icculus@3170
    19
    Sam Lantinga
icculus@3170
    20
    slouken@libsdl.org
icculus@3170
    21
*/
icculus@3170
    22
#include "SDL_config.h"
icculus@3170
    23
#include "SDL_power.h"
icculus@3170
    24
icculus@3170
    25
/*
icculus@3170
    26
 * Returns SDL_TRUE if we have a definitive answer.
icculus@3170
    27
 * SDL_FALSE to try next implementation.
icculus@3170
    28
 */
icculus@3170
    29
typedef SDL_bool
icculus@3170
    30
(*SDL_GetPowerInfo_Impl)(SDL_PowerState *state, int *seconds, int *percent);
icculus@3170
    31
icculus@3170
    32
SDL_bool SDL_GetPowerInfo_Linux_sys_power(SDL_PowerState*, int*, int*);
icculus@3170
    33
SDL_bool SDL_GetPowerInfo_Linux_proc_apci(SDL_PowerState*, int*, int*);
icculus@3170
    34
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState*, int*, int*);
icculus@3170
    35
SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState*, int*, int*);
icculus@3170
    36
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState*, int*, int*);
icculus@3170
    37
SDL_bool SDL_GetPowerInfo_OS2(SDL_PowerState*, int*, int*);
icculus@3173
    38
SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState*, int*, int*);
icculus@3170
    39
SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState*, int*, int*);
icculus@3170
    40
icculus@3170
    41
#ifndef SDL_POWER_DISABLED
icculus@3170
    42
#ifdef SDL_POWER_HARDWIRED
icculus@3170
    43
/* This is for things that _never_ have a battery, like the Dreamcast, etc. */
icculus@3170
    44
static SDL_bool
icculus@3170
    45
SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds, int *percent)
icculus@3170
    46
{
icculus@3170
    47
    *seconds = -1;
icculus@3170
    48
    *percent = -1;
icculus@3170
    49
    *state = SDL_POWERSTATE_NO_BATTERY;
icculus@3170
    50
    return SDL_TRUE;
icculus@3170
    51
}
icculus@3170
    52
#endif
icculus@3170
    53
#endif
icculus@3170
    54
icculus@3170
    55
icculus@3170
    56
static SDL_GetPowerInfo_Impl implementations[] = {
icculus@3170
    57
#ifndef SDL_POWER_DISABLED
icculus@3170
    58
#ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */
icculus@3170
    59
    SDL_GetPowerInfo_Linux_sys_power,
icculus@3170
    60
    SDL_GetPowerInfo_Linux_proc_apci,
icculus@3170
    61
    SDL_GetPowerInfo_Linux_proc_apm,
icculus@3170
    62
#endif
icculus@3170
    63
#ifdef SDL_POWER_WINDOWS /* handles Win32, Win64, PocketPC. */
icculus@3170
    64
    SDL_GetPowerInfo_Windows,
icculus@3170
    65
#endif
icculus@3170
    66
#ifdef SDL_POWER_MACOSX  /* handles Mac OS X, Darwin, iPhone. */
icculus@3170
    67
    SDL_GetPowerInfo_MacOSX,
icculus@3170
    68
#endif
icculus@3170
    69
#ifdef SDL_POWER_OS2  /* handles OS/2, Warp, eComStation. */
icculus@3170
    70
    SDL_GetPowerInfo_OS2,
icculus@3170
    71
#endif
icculus@3170
    72
#ifdef SDL_POWER_NINTENDODS  /* handles Nintendo DS. */
icculus@3170
    73
    SDL_GetPowerInfo_NintendoDS,
icculus@3170
    74
#endif
icculus@3173
    75
#ifdef SDL_POWER_BEOS  /* handles BeOS, Zeta, with euc.jp apm driver. */
icculus@3173
    76
    SDL_GetPowerInfo_BeOS,
icculus@3173
    77
#endif
icculus@3170
    78
#ifdef SDL_POWER_HARDWIRED
icculus@3170
    79
    SDL_GetPowerInfo_Hardwired,
icculus@3170
    80
#endif
icculus@3170
    81
#endif
icculus@3170
    82
};
icculus@3170
    83
icculus@3170
    84
SDL_PowerState
icculus@3170
    85
SDL_GetPowerInfo(int *seconds, int *percent)
icculus@3170
    86
{
icculus@3170
    87
    const int total = sizeof (implementations) / sizeof (implementations[0]);
icculus@3170
    88
    int _seconds, _percent;
icculus@3170
    89
    SDL_PowerState retval;
icculus@3170
    90
    int i;
icculus@3170
    91
icculus@3170
    92
    /* Make these never NULL for platform-specific implementations. */
icculus@3170
    93
    if (seconds == NULL) {
icculus@3170
    94
        seconds = &_seconds;
icculus@3170
    95
    }
icculus@3170
    96
icculus@3170
    97
    if (percent == NULL) {
icculus@3170
    98
        percent = &_percent;
icculus@3170
    99
    }
icculus@3170
   100
icculus@3170
   101
    for (i = 0; i < total; i++) {
icculus@3170
   102
        if (implementations[i](&retval, seconds, percent)) {
icculus@3170
   103
            return retval;
icculus@3170
   104
        }
icculus@3170
   105
    }
icculus@3170
   106
icculus@3170
   107
    /* nothing was definitive. */
icculus@3170
   108
    *seconds = -1;
icculus@3170
   109
    *percent = -1;
icculus@3170
   110
    return SDL_POWERSTATE_UNKNOWN;
icculus@3170
   111
}
icculus@3170
   112
icculus@3170
   113
/* vi: set ts=4 sw=4 expandtab: */
icculus@3170
   114