ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

power.c
Go to the documentation of this file.
00001 /*
00002  *
00003  * COPYRIGHT:       See COPYING in the top level directory
00004  * PROJECT:         ReactOS system libraries
00005  * FILE:            dll/win32/kernel32/misc/power.c
00006  * PURPOSE:         Power Management Functions
00007  * PROGRAMMER:      Dmitry Chapyshev <dmitry@reactos.org>
00008  *
00009  * UPDATE HISTORY:
00010  *                  01/15/2009 Created
00011  */
00012 
00013 #include <k32.h>
00014 
00015 #define NDEBUG
00016 #include <debug.h>
00017 
00018 /* PUBLIC FUNCTIONS ***********************************************************/
00019 
00020 /*
00021  * @implemented
00022  */
00023 BOOL
00024 WINAPI
00025 GetSystemPowerStatus(IN LPSYSTEM_POWER_STATUS PowerStatus)
00026 {
00027     NTSTATUS Status;
00028     SYSTEM_BATTERY_STATE BattState;
00029     ULONG Max, Current;
00030 
00031     Status = NtPowerInformation(SystemBatteryState,
00032                                 NULL,
00033                                 0,
00034                                 &BattState,
00035                                 sizeof(SYSTEM_BATTERY_STATE));
00036 
00037     if (!NT_SUCCESS(Status))
00038     {
00039         BaseSetLastNTError(Status);
00040         return FALSE;
00041     }
00042 
00043     RtlZeroMemory(PowerStatus, sizeof(SYSTEM_POWER_STATUS));
00044 
00045     PowerStatus->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
00046     PowerStatus->BatteryFullLifeTime = BATTERY_LIFE_UNKNOWN;
00047     PowerStatus->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
00048     PowerStatus->ACLineStatus = AC_LINE_ONLINE;
00049 
00050     Max = BattState.MaxCapacity;
00051     Current = BattState.RemainingCapacity;
00052     if (Max)
00053     {
00054         if (Current <= Max)
00055         {
00056             PowerStatus->BatteryLifePercent = (100 * Current + Max / 2) / Max;
00057         }
00058         else
00059         {
00060             PowerStatus->BatteryLifePercent = 100;
00061         }
00062 
00063         if (PowerStatus->BatteryLifePercent <= 32) PowerStatus->BatteryFlag |= BATTERY_FLAG_LOW;
00064         if (PowerStatus->BatteryLifePercent >= 67) PowerStatus->BatteryFlag |= BATTERY_FLAG_HIGH;
00065     }
00066 
00067     if (!BattState.BatteryPresent) PowerStatus->BatteryFlag |= BATTERY_FLAG_NO_BATTERY;
00068 
00069     if (BattState.Charging) PowerStatus->BatteryFlag |= BATTERY_FLAG_CHARGING;
00070 
00071     if (!(BattState.AcOnLine) && (BattState.BatteryPresent)) PowerStatus->ACLineStatus = AC_LINE_OFFLINE;
00072 
00073     if (BattState.EstimatedTime) PowerStatus->BatteryLifeTime = BattState.EstimatedTime;
00074 
00075     return TRUE;
00076 }
00077 
00078 /*
00079  * @implemented
00080  */
00081 BOOL
00082 WINAPI
00083 SetSystemPowerState(IN BOOL fSuspend,
00084                     IN BOOL fForce)
00085 {
00086     NTSTATUS Status;
00087 
00088     Status = NtInitiatePowerAction(PowerActionSleep,
00089                                    (fSuspend != FALSE) ?
00090                                    PowerSystemSleeping1 : PowerSystemHibernate,
00091                                    fForce != TRUE,
00092                                    FALSE);
00093     if (!NT_SUCCESS(Status))
00094     {
00095         BaseSetLastNTError(Status);
00096         return FALSE;
00097     }
00098 
00099     return TRUE;
00100 }
00101 
00102 /*
00103  * @implemented
00104  */
00105 BOOL
00106 WINAPI
00107 GetDevicePowerState(IN HANDLE hDevice,
00108                     OUT BOOL *pfOn)
00109 {
00110     DEVICE_POWER_STATE DevicePowerState;
00111     NTSTATUS Status;
00112 
00113     Status = NtGetDevicePowerState(hDevice, &DevicePowerState);
00114     if (NT_SUCCESS(Status))
00115     {
00116         *pfOn = (DevicePowerState == PowerDeviceUnspecified) ||
00117                 (DevicePowerState == PowerDeviceD0);
00118         return TRUE;
00119     }
00120 
00121     BaseSetLastNTError(Status);
00122     return FALSE;
00123 }
00124 
00125 /*
00126  * @implemented
00127  */
00128 BOOL
00129 WINAPI
00130 RequestDeviceWakeup(IN HANDLE hDevice)
00131 {
00132     NTSTATUS Status;
00133 
00134     Status = NtRequestDeviceWakeup(hDevice);
00135     if (!NT_SUCCESS(Status))
00136     {
00137         BaseSetLastNTError(Status);
00138         return FALSE;
00139     }
00140 
00141     return TRUE;
00142 }
00143 
00144 /*
00145  * @implemented
00146  */
00147 BOOL
00148 WINAPI
00149 RequestWakeupLatency(IN LATENCY_TIME latency)
00150 {
00151     NTSTATUS Status;
00152 
00153     Status = NtRequestWakeupLatency(latency);
00154     if (!NT_SUCCESS(Status))
00155     {
00156         BaseSetLastNTError(Status);
00157         return FALSE;
00158     }
00159 
00160     return TRUE;
00161 }
00162 
00163 /*
00164  * @implemented
00165  */
00166 BOOL
00167 WINAPI
00168 CancelDeviceWakeupRequest(IN HANDLE hDevice)
00169 {
00170     NTSTATUS Status;
00171 
00172     Status = NtCancelDeviceWakeupRequest(hDevice);
00173     if (!NT_SUCCESS(Status))
00174     {
00175         BaseSetLastNTError(Status);
00176         return FALSE;
00177     }
00178 
00179     return TRUE;
00180 }
00181 
00182 /*
00183  * @implemented
00184  */
00185 BOOL
00186 WINAPI
00187 IsSystemResumeAutomatic(VOID)
00188 {
00189     return (BOOL)NtIsSystemResumeAutomatic();
00190 }
00191 
00192 /*
00193  * @implemented
00194  */
00195 BOOL
00196 WINAPI
00197 SetMessageWaitingIndicator(IN HANDLE hMsgIndicator,
00198                            IN ULONG ulMsgCount)
00199 {
00200     /* This is the correct Windows implementation */
00201     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
00202     return 0;
00203 }
00204 
00205 /*
00206  * @implemented
00207  */
00208 EXECUTION_STATE
00209 WINAPI
00210 SetThreadExecutionState(EXECUTION_STATE esFlags)
00211 {
00212     NTSTATUS Status;
00213 
00214     Status = NtSetThreadExecutionState(esFlags, &esFlags);
00215     if (!NT_SUCCESS(Status))
00216     {
00217         BaseSetLastNTError(Status);
00218         return 0;
00219     }
00220 
00221     return esFlags;
00222 }

Generated on Sat May 26 2012 04:23:00 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.