src/power/SDL_power.c
changeset 12331 43d46306c3ba
parent 11811 5d94cb6b24d3
child 12503 806492103856
equal deleted inserted replaced
12330:cf64a70ad02a 12331:43d46306c3ba
    40     *percent = -1;
    40     *percent = -1;
    41     *state = SDL_POWERSTATE_NO_BATTERY;
    41     *state = SDL_POWERSTATE_NO_BATTERY;
    42     return SDL_TRUE;
    42     return SDL_TRUE;
    43 }
    43 }
    44 #endif
    44 #endif
    45 #endif
       
    46 
       
    47 
    45 
    48 static SDL_GetPowerInfo_Impl implementations[] = {
    46 static SDL_GetPowerInfo_Impl implementations[] = {
    49 #ifndef SDL_POWER_DISABLED
       
    50 #ifdef SDL_POWER_LINUX          /* in order of preference. More than could work. */
    47 #ifdef SDL_POWER_LINUX          /* in order of preference. More than could work. */
    51     SDL_GetPowerInfo_Linux_org_freedesktop_upower,
    48     SDL_GetPowerInfo_Linux_org_freedesktop_upower,
    52     SDL_GetPowerInfo_Linux_sys_class_power_supply,
    49     SDL_GetPowerInfo_Linux_sys_class_power_supply,
    53     SDL_GetPowerInfo_Linux_proc_acpi,
    50     SDL_GetPowerInfo_Linux_proc_acpi,
    54     SDL_GetPowerInfo_Linux_proc_apm,
    51     SDL_GetPowerInfo_Linux_proc_apm,
    79 #endif
    76 #endif
    80 
    77 
    81 #ifdef SDL_POWER_HARDWIRED
    78 #ifdef SDL_POWER_HARDWIRED
    82     SDL_GetPowerInfo_Hardwired,
    79     SDL_GetPowerInfo_Hardwired,
    83 #endif
    80 #endif
       
    81 };
    84 #endif
    82 #endif
    85 };
       
    86 
    83 
    87 SDL_PowerState
    84 SDL_PowerState
    88 SDL_GetPowerInfo(int *seconds, int *percent)
    85 SDL_GetPowerInfo(int *seconds, int *percent)
    89 {
    86 {
       
    87 #ifndef SDL_POWER_DISABLED
    90     const int total = sizeof(implementations) / sizeof(implementations[0]);
    88     const int total = sizeof(implementations) / sizeof(implementations[0]);
    91     int _seconds, _percent;
       
    92     SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
    89     SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
    93     int i;
    90     int i;
       
    91 #endif
    94 
    92 
       
    93     int _seconds, _percent;
    95     /* Make these never NULL for platform-specific implementations. */
    94     /* Make these never NULL for platform-specific implementations. */
    96     if (seconds == NULL) {
    95     if (seconds == NULL) {
    97         seconds = &_seconds;
    96         seconds = &_seconds;
    98     }
    97     }
    99 
       
   100     if (percent == NULL) {
    98     if (percent == NULL) {
   101         percent = &_percent;
    99         percent = &_percent;
   102     }
   100     }
   103 
   101 
       
   102 #ifndef SDL_POWER_DISABLED
   104     for (i = 0; i < total; i++) {
   103     for (i = 0; i < total; i++) {
   105         if (implementations[i](&retval, seconds, percent)) {
   104         if (implementations[i](&retval, seconds, percent)) {
   106             return retval;
   105             return retval;
   107         }
   106         }
   108     }
   107     }
       
   108 #endif
   109 
   109 
   110     /* nothing was definitive. */
   110     /* nothing was definitive. */
   111     *seconds = -1;
   111     *seconds = -1;
   112     *percent = -1;
   112     *percent = -1;
   113     return SDL_POWERSTATE_UNKNOWN;
   113     return SDL_POWERSTATE_UNKNOWN;