src/power/SDL_power.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 27 Mar 2016 22:22:13 +0200
changeset 10123 d2686deec646
parent 9998 f67cf37e9cd4
child 10609 d702ecbd8ba7
permissions -rw-r--r--
Fixed comment in gesture source.
icculus@3170
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9998
     3
  Copyright (C) 1997-2016 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
icculus@9700
    32
SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *, int *, int *);
slouken@3186
    33
SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
slouken@3186
    34
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
slouken@3186
    35
SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
slouken@3186
    36
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
icculus@7981
    37
SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *);
icculus@4444
    38
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
slouken@6448
    39
SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
kimonline@7009
    40
SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
dludwig@8611
    41
SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *);
icculus@9278
    42
SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *);
icculus@3170
    43
icculus@3170
    44
#ifndef SDL_POWER_DISABLED
icculus@3170
    45
#ifdef SDL_POWER_HARDWIRED
slouken@3272
    46
/* This is for things that _never_ have a battery */
icculus@3170
    47
static SDL_bool
slouken@3186
    48
SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
icculus@3170
    49
{
icculus@3170
    50
    *seconds = -1;
icculus@3170
    51
    *percent = -1;
icculus@3170
    52
    *state = SDL_POWERSTATE_NO_BATTERY;
icculus@3170
    53
    return SDL_TRUE;
icculus@3170
    54
}
icculus@3170
    55
#endif
icculus@3170
    56
#endif
icculus@3170
    57
icculus@3170
    58
icculus@3170
    59
static SDL_GetPowerInfo_Impl implementations[] = {
icculus@3170
    60
#ifndef SDL_POWER_DISABLED
slouken@3186
    61
#ifdef SDL_POWER_LINUX          /* in order of preference. More than could work. */
icculus@9700
    62
    SDL_GetPowerInfo_Linux_sys_class_power_supply,
bob@3174
    63
    SDL_GetPowerInfo_Linux_proc_acpi,
icculus@3170
    64
    SDL_GetPowerInfo_Linux_proc_apm,
icculus@3170
    65
#endif
slouken@3186
    66
#ifdef SDL_POWER_WINDOWS        /* handles Win32, Win64, PocketPC. */
icculus@3170
    67
    SDL_GetPowerInfo_Windows,
icculus@3170
    68
#endif
icculus@4444
    69
#ifdef SDL_POWER_UIKIT          /* handles iPhone/iPad/etc */
icculus@4444
    70
    SDL_GetPowerInfo_UIKit,
icculus@4444
    71
#endif
icculus@4444
    72
#ifdef SDL_POWER_MACOSX         /* handles Mac OS X, Darwin. */
icculus@3170
    73
    SDL_GetPowerInfo_MacOSX,
icculus@3170
    74
#endif
icculus@7981
    75
#ifdef SDL_POWER_HAIKU          /* with BeOS euc.jp apm driver. Does this work on Haiku? */
icculus@7981
    76
    SDL_GetPowerInfo_Haiku,
icculus@3173
    77
#endif
slouken@6448
    78
#ifdef SDL_POWER_ANDROID        /* handles Android. */
slouken@6448
    79
    SDL_GetPowerInfo_Android,
slouken@6448
    80
#endif
kimonline@7009
    81
#ifdef SDL_POWER_PSP        /* handles PSP. */
kimonline@7009
    82
    SDL_GetPowerInfo_PSP,
kimonline@7009
    83
#endif
dludwig@8611
    84
#ifdef SDL_POWER_WINRT          /* handles WinRT */
dludwig@8611
    85
    SDL_GetPowerInfo_WinRT,
dludwig@8611
    86
#endif
icculus@9278
    87
#ifdef SDL_POWER_EMSCRIPTEN     /* handles Emscripten */
icculus@9278
    88
    SDL_GetPowerInfo_Emscripten,
icculus@9278
    89
#endif
kimonline@7009
    90
icculus@3170
    91
#ifdef SDL_POWER_HARDWIRED
icculus@3170
    92
    SDL_GetPowerInfo_Hardwired,
icculus@3170
    93
#endif
icculus@3170
    94
#endif
icculus@3170
    95
};
icculus@3170
    96
icculus@3170
    97
SDL_PowerState
icculus@3170
    98
SDL_GetPowerInfo(int *seconds, int *percent)
icculus@3170
    99
{
slouken@3186
   100
    const int total = sizeof(implementations) / sizeof(implementations[0]);
icculus@3170
   101
    int _seconds, _percent;
slouken@8820
   102
    SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
icculus@3170
   103
    int i;
icculus@3170
   104
icculus@3170
   105
    /* Make these never NULL for platform-specific implementations. */
icculus@3170
   106
    if (seconds == NULL) {
icculus@3170
   107
        seconds = &_seconds;
icculus@3170
   108
    }
icculus@3170
   109
icculus@3170
   110
    if (percent == NULL) {
icculus@3170
   111
        percent = &_percent;
icculus@3170
   112
    }
icculus@3170
   113
icculus@3170
   114
    for (i = 0; i < total; i++) {
slouken@8820
   115
        if (implementations[i](&retval, seconds, percent)) {
icculus@3170
   116
            return retval;
icculus@3170
   117
        }
icculus@3170
   118
    }
icculus@3170
   119
icculus@3170
   120
    /* nothing was definitive. */
icculus@3170
   121
    *seconds = -1;
icculus@3170
   122
    *percent = -1;
icculus@3170
   123
    return SDL_POWERSTATE_UNKNOWN;
icculus@3170
   124
}
icculus@3170
   125
icculus@3170
   126
/* vi: set ts=4 sw=4 expandtab: */