makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / kernel32 / powermgnt.c
blobd967dfefa76718b0abe478154502fa5b4c1132d4
1 /*
2 * Copyright 1995 Thomas Sandford (tdgsandf@prds-grn.demon.co.uk)
3 * Copyright 2003 Dimitrie O. Paun
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
24 #include "ntstatus.h"
25 #define WIN32_NO_STATUS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winternl.h"
29 #include "wine/debug.h"
30 #include "wine/heap.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(powermgnt);
34 /******************************************************************************
35 * GetDevicePowerState (KERNEL32.@)
37 BOOL WINAPI GetDevicePowerState(HANDLE hDevice, BOOL* pfOn)
39 WARN("(hDevice %p pfOn %p): stub\n", hDevice, pfOn);
40 return TRUE; /* no information */
43 /***********************************************************************
44 * GetSystemPowerStatus (KERNEL32.@)
46 BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS ps)
48 SYSTEM_BATTERY_STATE bs;
49 NTSTATUS status;
51 TRACE("(%p)\n", ps);
53 ps->ACLineStatus = AC_LINE_UNKNOWN;
54 ps->BatteryFlag = BATTERY_FLAG_UNKNOWN;
55 ps->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
56 ps->SystemStatusFlag = 0;
57 ps->BatteryLifeTime = BATTERY_LIFE_UNKNOWN;
58 ps->BatteryFullLifeTime = BATTERY_LIFE_UNKNOWN;
60 status = NtPowerInformation(SystemBatteryState, NULL, 0, &bs, sizeof(bs));
61 if (status == STATUS_NOT_IMPLEMENTED) return TRUE;
62 if (FAILED(status)) return FALSE;
64 ps->ACLineStatus = bs.AcOnLine;
66 if (bs.BatteryPresent)
68 ps->BatteryLifePercent = bs.MaxCapacity ? bs.RemainingCapacity / bs.MaxCapacity : 100;
69 ps->BatteryLifeTime = bs.EstimatedTime;
70 if (!bs.Charging && (LONG)bs.Rate < 0)
71 ps->BatteryFullLifeTime = 3600 * bs.MaxCapacity / -(LONG)bs.Rate;
73 ps->BatteryFlag = 0;
74 if (bs.Charging)
75 ps->BatteryFlag |= BATTERY_FLAG_CHARGING;
76 if (ps->BatteryLifePercent > 66)
77 ps->BatteryFlag |= BATTERY_FLAG_HIGH;
78 if (ps->BatteryLifePercent < 33)
79 ps->BatteryFlag |= BATTERY_FLAG_LOW;
80 if (ps->BatteryLifePercent < 5)
81 ps->BatteryFlag |= BATTERY_FLAG_CRITICAL;
83 else
85 ps->BatteryFlag = BATTERY_FLAG_NO_BATTERY;
88 return TRUE;
91 /***********************************************************************
92 * IsSystemResumeAutomatic (KERNEL32.@)
94 BOOL WINAPI IsSystemResumeAutomatic(void)
96 WARN("(): stub, harmless.\n");
97 return FALSE;
100 /***********************************************************************
101 * RequestWakeupLatency (KERNEL32.@)
103 BOOL WINAPI RequestWakeupLatency(LATENCY_TIME latency)
105 WARN("(): stub, harmless.\n");
106 return TRUE;
109 /***********************************************************************
110 * RequestDeviceWakeup (KERNEL32.@)
112 BOOL WINAPI RequestDeviceWakeup(HANDLE device)
114 FIXME("(%p): stub\n", device);
115 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
116 return FALSE;
119 /***********************************************************************
120 * SetSystemPowerState (KERNEL32.@)
122 BOOL WINAPI SetSystemPowerState(BOOL suspend_or_hibernate,
123 BOOL force_flag)
125 WARN("(): stub, harmless.\n");
126 return TRUE;
129 /***********************************************************************
130 * SetThreadExecutionState (KERNEL32.@)
132 * Informs the system that activity is taking place for
133 * power management purposes.
135 EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags)
137 EXECUTION_STATE old;
139 NtSetThreadExecutionState(flags, &old);
141 return old;
144 /***********************************************************************
145 * PowerCreateRequest (KERNEL32.@)
147 HANDLE WINAPI PowerCreateRequest(REASON_CONTEXT *context)
149 COUNTED_REASON_CONTEXT nt_context;
150 HANDLE handle;
151 NTSTATUS status;
152 WCHAR module_name[MAX_PATH];
154 TRACE( "(%p)\n", context );
156 nt_context.Version = context->Version;
157 nt_context.Flags = context->Flags;
158 if (context->Flags & POWER_REQUEST_CONTEXT_SIMPLE_STRING)
159 RtlInitUnicodeString( &nt_context.u.SimpleString, context->Reason.SimpleReasonString );
160 else if (context->Flags & POWER_REQUEST_CONTEXT_DETAILED_STRING)
162 int i;
164 GetModuleFileNameW( context->Reason.Detailed.LocalizedReasonModule, module_name, ARRAY_SIZE(module_name) );
165 RtlInitUnicodeString( &nt_context.u.s.ResourceFileName, module_name );
166 nt_context.u.s.ResourceReasonId = context->Reason.Detailed.LocalizedReasonId;
167 nt_context.u.s.StringCount = context->Reason.Detailed.ReasonStringCount;
168 nt_context.u.s.ReasonStrings = heap_alloc( nt_context.u.s.StringCount * sizeof(UNICODE_STRING) );
169 for (i = 0; i < nt_context.u.s.StringCount; i++)
170 RtlInitUnicodeString( &nt_context.u.s.ReasonStrings[i], context->Reason.Detailed.ReasonStrings[i] );
173 status = NtCreatePowerRequest( &handle, &nt_context );
174 if (nt_context.Flags & POWER_REQUEST_CONTEXT_DETAILED_STRING)
175 heap_free( nt_context.u.s.ReasonStrings );
176 if (status)
177 SetLastError( RtlNtStatusToDosError(status) );
178 return status == STATUS_SUCCESS ? handle : INVALID_HANDLE_VALUE;
181 /***********************************************************************
182 * PowerSetRequest (KERNEL32.@)
184 BOOL WINAPI PowerSetRequest(HANDLE request, POWER_REQUEST_TYPE type)
186 NTSTATUS status = NtSetPowerRequest( request, type );
187 if (status)
188 SetLastError( RtlNtStatusToDosError(status) );
189 return status == STATUS_SUCCESS;
192 /***********************************************************************
193 * PowerClearRequest (KERNEL32.@)
195 BOOL WINAPI PowerClearRequest(HANDLE request, POWER_REQUEST_TYPE type)
197 NTSTATUS status = NtClearPowerRequest( request, type );
198 if (status)
199 SetLastError( RtlNtStatusToDosError(status) );
200 return status == STATUS_SUCCESS;