src/power/SDL_power.c
author David Ludwig <dludwig@pobox.com>
Wed, 12 Mar 2014 11:57:15 -0400
changeset 8611 a762dfc67e1a
parent 8149 681eb46b8ac4
child 8820 0e935d5b193a
permissions -rw-r--r--
Fixed various build and runtime errors when using WinRT with VS2012.
icculus@3170
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
icculus@3170
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
icculus@3170
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
icculus@3170
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@3170
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
icculus@3170
    22
#include "SDL_power.h"
icculus@3170
    23
icculus@3170
    24
/*
icculus@3170
    25
 * Returns SDL_TRUE if we have a definitive answer.
icculus@3170
    26
 * SDL_FALSE to try next implementation.
icculus@3170
    27
 */
icculus@3170
    28
typedef SDL_bool
slouken@3186
    29
    (*SDL_GetPowerInfo_Impl) (SDL_PowerState * state, int *seconds,
slouken@3186
    30
                              int *percent);
icculus@3170
    31
slouken@3186
    32
SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
slouken@3186
    33
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
slouken@3186
    34
SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
slouken@3186
    35
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
icculus@7981
    36
SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *);
icculus@4444
    37
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
slouken@6448
    38
SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
kimonline@7009
    39
SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
dludwig@8611
    40
SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *);
icculus@3170
    41
icculus@3170
    42
#ifndef SDL_POWER_DISABLED
icculus@3170
    43
#ifdef SDL_POWER_HARDWIRED
slouken@3272
    44
/* This is for things that _never_ have a battery */
icculus@3170
    45
static SDL_bool
slouken@3186
    46
SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
icculus@3170
    47
{
icculus@3170
    48
    *seconds = -1;
icculus@3170
    49
    *percent = -1;
icculus@3170
    50
    *state = SDL_POWERSTATE_NO_BATTERY;
icculus@3170
    51
    return SDL_TRUE;
icculus@3170
    52
}
icculus@3170
    53
#endif
icculus@3170
    54
#endif
icculus@3170
    55
icculus@3170
    56
icculus@3170
    57
static SDL_GetPowerInfo_Impl implementations[] = {
icculus@3170
    58
#ifndef SDL_POWER_DISABLED
slouken@3186
    59
#ifdef SDL_POWER_LINUX          /* in order of preference. More than could work. */
bob@3174
    60
    SDL_GetPowerInfo_Linux_proc_acpi,
icculus@3170
    61
    SDL_GetPowerInfo_Linux_proc_apm,
icculus@3170
    62
#endif
slouken@3186
    63
#ifdef SDL_POWER_WINDOWS        /* handles Win32, Win64, PocketPC. */
icculus@3170
    64
    SDL_GetPowerInfo_Windows,
icculus@3170
    65
#endif
icculus@4444
    66
#ifdef SDL_POWER_UIKIT          /* handles iPhone/iPad/etc */
icculus@4444
    67
    SDL_GetPowerInfo_UIKit,
icculus@4444
    68
#endif
icculus@4444
    69
#ifdef SDL_POWER_MACOSX         /* handles Mac OS X, Darwin. */
icculus@3170
    70
    SDL_GetPowerInfo_MacOSX,
icculus@3170
    71
#endif
icculus@7981
    72
#ifdef SDL_POWER_HAIKU          /* with BeOS euc.jp apm driver. Does this work on Haiku? */
icculus@7981
    73
    SDL_GetPowerInfo_Haiku,
icculus@3173
    74
#endif
slouken@6448
    75
#ifdef SDL_POWER_ANDROID        /* handles Android. */
slouken@6448
    76
    SDL_GetPowerInfo_Android,
slouken@6448
    77
#endif
kimonline@7009
    78
#ifdef SDL_POWER_PSP        /* handles PSP. */
kimonline@7009
    79
    SDL_GetPowerInfo_PSP,
kimonline@7009
    80
#endif
dludwig@8611
    81
#ifdef SDL_POWER_WINRT          /* handles WinRT */
dludwig@8611
    82
    SDL_GetPowerInfo_WinRT,
dludwig@8611
    83
#endif
kimonline@7009
    84
icculus@3170
    85
#ifdef SDL_POWER_HARDWIRED
icculus@3170
    86
    SDL_GetPowerInfo_Hardwired,
icculus@3170
    87
#endif
icculus@3170
    88
#endif
icculus@3170
    89
};
icculus@3170
    90
icculus@3170
    91
SDL_PowerState
icculus@3170
    92
SDL_GetPowerInfo(int *seconds, int *percent)
icculus@3170
    93
{
slouken@3186
    94
    const int total = sizeof(implementations) / sizeof(implementations[0]);
icculus@3170
    95
    int _seconds, _percent;
icculus@3170
    96
    SDL_PowerState retval;
icculus@3170
    97
    int i;
icculus@3170
    98
icculus@3170
    99
    /* Make these never NULL for platform-specific implementations. */
icculus@3170
   100
    if (seconds == NULL) {
icculus@3170
   101
        seconds = &_seconds;
icculus@3170
   102
    }
icculus@3170
   103
icculus@3170
   104
    if (percent == NULL) {
icculus@3170
   105
        percent = &_percent;
icculus@3170
   106
    }
icculus@3170
   107
icculus@3170
   108
    for (i = 0; i < total; i++) {
slouken@3186
   109
        if (implementations[i] (&retval, seconds, percent)) {
icculus@3170
   110
            return retval;
icculus@3170
   111
        }
icculus@3170
   112
    }
icculus@3170
   113
icculus@3170
   114
    /* nothing was definitive. */
icculus@3170
   115
    *seconds = -1;
icculus@3170
   116
    *percent = -1;
icculus@3170
   117
    return SDL_POWERSTATE_UNKNOWN;
icculus@3170
   118
}
icculus@3170
   119
icculus@3170
   120
/* vi: set ts=4 sw=4 expandtab: */