Add support for vertex shader constants to the stateblock.
[wine/gsoc_dplay.git] / dlls / powrprof / powrprof.c
blobf82c4da26f1f6701d942238ced5f3a0f140e154b
1 /*
2 * Copyright (C) 2005 Benjamin Cutler
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winnt.h"
25 #include "winreg.h"
26 #include "winternl.h"
27 #include "ntstatus.h"
28 #include "powrprof.h"
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(powrprof);
34 /* Notes to implementors:
35 * #1: The native implementation of these functions attempted to read in
36 * registry entries that I was unable to locate on any of the Windows
37 * machines I checked, but I only had desktops available, so maybe
38 * laptop users will have better luck. They return FNF errors because
39 * that's what the native DLL was returning during my tests.
40 * #2: These functions call NtPowerInformation but I don't know what they
41 * do with the results, and NtPowerInformation doesn't do much in WINE yet
42 * anyway.
43 * #3: Since I can't get several other functions working (see note #1),
44 * implementing these functions is going to have to wait until somebody can
45 * cobble together some sane test input. */
47 static const WCHAR szPowerCfgSubKey[] = { 'S', 'o', 'f', 't', 'w', 'a', 'r', 'e',
48 '\\', 'M', 'i', 'c', 'r', 'o', 's', 'o', 'f', 't', '\\', 'W', 'i',
49 'n', 'd', 'o', 'w', 's', '\\', 'C', 'u', 'r', 'r', 'e', 'n', 't',
50 'V', 'e', 'r', 's', 'i', 'o', 'n', '\\', 'C', 'o', 'n', 't', 'r',
51 'o', 'l', 's', ' ', 'F', 'o', 'l', 'd', 'e', 'r', '\\', 'P', 'o',
52 'w', 'e', 'r', 'C', 'f', 'g', 0 };
53 static const WCHAR szSemaphoreName[] = { 'P', 'o', 'w', 'e', 'r', 'P', 'r', 'o',
54 'f', 'i', 'l', 'e', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', 'S',
55 'e', 'm', 'a', 'p', 'h', 'o', 'r', 'e', 0 };
56 static const WCHAR szDiskMax[] = { 'D', 'i', 's', 'k', 'S', 'p', 'i', 'n', 'd',
57 'o', 'w', 'n', 'M', 'a', 'x', 0 };
58 static const WCHAR szDiskMin[] = { 'D', 'i', 's', 'k', 'S', 'p', 'i', 'n', 'd',
59 'o', 'w', 'n', 'M', 'i', 'n', 0 };
60 static const WCHAR szLastID[] = { 'L', 'a', 's', 't', 'I', 'D', 0 };
61 static HANDLE PPRegSemaphore = NULL;
63 NTSTATUS WINAPI CallNtPowerInformation(
64 POWER_INFORMATION_LEVEL InformationLevel,
65 PVOID lpInputBuffer, ULONG nInputBufferSize,
66 PVOID lpOutputBuffer, ULONG nOutputBufferSize)
68 return NtPowerInformation(InformationLevel, lpInputBuffer,
69 nInputBufferSize, lpOutputBuffer, nOutputBufferSize);
72 BOOLEAN WINAPI CanUserWritePwrScheme(VOID)
74 HKEY hKey = NULL;
75 LONG r;
76 BOOLEAN bSuccess = TRUE;
78 TRACE("()\n");
80 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
82 if (r != ERROR_SUCCESS) {
83 TRACE("RegOpenKeyEx failed: %ld\n", r);
84 bSuccess = FALSE;
87 SetLastError(r);
88 RegCloseKey(hKey);
89 return bSuccess;
92 BOOLEAN WINAPI DeletePwrScheme(UINT uiIndex)
94 /* FIXME: See note #1 */
95 FIXME("(%d) stub!\n", uiIndex);
96 SetLastError(ERROR_FILE_NOT_FOUND);
97 return FALSE;
100 BOOLEAN WINAPI EnumPwrSchemes(PWRSCHEMESENUMPROC lpfnPwrSchemesEnumProc,
101 LPARAM lParam)
103 /* FIXME: See note #1 */
104 FIXME("(%p, %ld) stub!\n", lpfnPwrSchemesEnumProc, lParam);
105 SetLastError(ERROR_FILE_NOT_FOUND);
106 return FALSE;
109 BOOLEAN WINAPI GetActivePwrScheme(PUINT puiID)
111 /* FIXME: See note #1 */
112 FIXME("(%p) stub!\n", puiID);
113 SetLastError(ERROR_FILE_NOT_FOUND);
114 return FALSE;
117 BOOLEAN WINAPI GetCurrentPowerPolicies(
118 PGLOBAL_POWER_POLICY pGlobalPowerPolicy,
119 PPOWER_POLICY pPowerPolicy)
121 /* FIXME: See note #2 */
122 SYSTEM_POWER_POLICY ACPower, DCPower;
124 FIXME("(%p, %p) stub!\n", pGlobalPowerPolicy, pPowerPolicy);
126 NtPowerInformation(SystemPowerPolicyAc, 0, 0, &ACPower, sizeof(SYSTEM_POWER_POLICY));
127 NtPowerInformation(SystemPowerPolicyDc, 0, 0, &DCPower, sizeof(SYSTEM_POWER_POLICY));
129 return FALSE;
132 BOOLEAN WINAPI GetPwrCapabilities(
133 PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
135 NTSTATUS r;
137 TRACE("(%p)\n", lpSystemPowerCapabilities);
139 r = NtPowerInformation(SystemPowerCapabilities, 0, 0, lpSystemPowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
141 SetLastError(RtlNtStatusToDosError(r));
143 return r == STATUS_SUCCESS;
146 BOOLEAN WINAPI GetPwrDiskSpindownRange(PUINT RangeMax, PUINT RangeMin)
148 HKEY hKey;
149 BYTE lpValue[40];
150 LONG r;
151 DWORD cbValue = sizeof(lpValue);
153 TRACE("(%p, %p)\n", RangeMax, RangeMin);
155 if (RangeMax == NULL || RangeMin == NULL) {
156 SetLastError(ERROR_INVALID_PARAMETER);
157 return FALSE;
160 SetLastError(ERROR_SUCCESS);
162 WaitForSingleObject(PPRegSemaphore, INFINITE);
164 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ, &hKey);
165 if (r != ERROR_SUCCESS) {
166 TRACE("RegOpenKeyEx failed: %ld\n", r);
167 TRACE("Using defaults: 3600, 3\n");
168 *RangeMax = 3600;
169 *RangeMin = 3;
170 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
171 return TRUE;
174 r = RegQueryValueExW(hKey, szDiskMax, 0, 0, lpValue, &cbValue);
175 if (r != ERROR_SUCCESS) {
176 TRACE("Couldn't open DiskSpinDownMax: %ld\n", r);
177 TRACE("Using default: 3600\n");
178 *RangeMax = 3600;
179 } else {
180 *RangeMax = atoiW((LPCWSTR)lpValue);
183 cbValue = sizeof(lpValue);
185 r = RegQueryValueExW(hKey, szDiskMin, 0, 0, lpValue, &cbValue);
186 if (r != ERROR_SUCCESS) {
187 TRACE("Couldn't open DiskSpinDownMin: %ld\n", r);
188 TRACE("Using default: 3\n");
189 *RangeMin = 3;
190 } else {
191 *RangeMin = atoiW((LPCWSTR)lpValue);
194 RegCloseKey(hKey);
196 ReleaseSemaphore(PPRegSemaphore, 1, NULL);
198 return TRUE;
201 BOOLEAN WINAPI IsAdminOverrideActive(PADMINISTRATOR_POWER_POLICY p)
203 FIXME("( %p) stub!\n", p);
204 return FALSE;
207 BOOLEAN WINAPI IsPwrHibernateAllowed(VOID)
209 /* FIXME: See note #2 */
210 SYSTEM_POWER_CAPABILITIES PowerCaps;
211 FIXME("() stub!\n");
212 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
213 return FALSE;
216 BOOLEAN WINAPI IsPwrShutdownAllowed(VOID)
218 /* FIXME: See note #2 */
219 SYSTEM_POWER_CAPABILITIES PowerCaps;
220 FIXME("() stub!\n");
221 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
222 return FALSE;
225 BOOLEAN WINAPI IsPwrSuspendAllowed(VOID)
227 /* FIXME: See note #2 */
228 SYSTEM_POWER_CAPABILITIES PowerCaps;
229 FIXME("() stub!\n");
230 NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
231 return FALSE;
234 BOOLEAN WINAPI ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
236 /* FIXME: See note #1 */
237 FIXME("(%p) stub!\n", pGlobalPowerPolicy);
238 SetLastError(ERROR_FILE_NOT_FOUND);
239 return FALSE;
242 BOOLEAN WINAPI ReadProcessorPwrScheme(UINT uiID,
243 PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
245 /* FIXME: See note #1 */
246 FIXME("(%d, %p) stub!\n", uiID, pMachineProcessorPowerPolicy);
247 SetLastError(ERROR_FILE_NOT_FOUND);
248 return FALSE;
251 BOOLEAN WINAPI ReadPwrScheme(UINT uiID,
252 PPOWER_POLICY pPowerPolicy)
254 /* FIXME: See note #1 */
255 FIXME("(%d, %p) stub!\n", uiID, pPowerPolicy);
256 SetLastError(ERROR_FILE_NOT_FOUND);
257 return FALSE;
260 BOOLEAN WINAPI SetActivePwrScheme(UINT uiID,
261 PGLOBAL_POWER_POLICY lpGlobalPowerPolicy,
262 PPOWER_POLICY lpPowerPolicy)
264 /* FIXME: See note #1 */
265 FIXME("(%d, %p, %p) stub!\n", uiID, lpGlobalPowerPolicy, lpPowerPolicy);
266 SetLastError(ERROR_FILE_NOT_FOUND);
267 return FALSE;
270 BOOLEAN WINAPI SetSuspendState(BOOLEAN Hibernate, BOOLEAN ForceCritical,
271 BOOLEAN DisableWakeEvent)
273 /* FIXME: I have NO idea how you're supposed to call NtInitiatePowerAction
274 * here, because it's not a documented function that I can find */
275 FIXME("(%d, %d, %d) stub!\n", Hibernate, ForceCritical, DisableWakeEvent);
276 return TRUE;
279 BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
281 /* FIXME: See note #3 */
282 FIXME("(%p) stub!\n", pGlobalPowerPolicy);
283 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
284 return FALSE;
287 BOOLEAN WINAPI WriteProcessorPwrScheme(UINT ID,
288 PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
290 /* FIXME: See note #3 */
291 FIXME("(%d, %p) stub!\n", ID, pMachineProcessorPowerPolicy);
292 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
293 return FALSE;
296 BOOLEAN WINAPI WritePwrScheme(PUINT puiID, LPWSTR lpszName, LPWSTR lpszDescription,
297 PPOWER_POLICY pPowerPolicy)
299 /* FIXME: See note #3 */
300 FIXME("(%p, %s, %s, %p) stub!\n", puiID, debugstr_w(lpszName), debugstr_w(lpszDescription), pPowerPolicy);
301 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
302 return FALSE;
305 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
307 FIXME("(%p, %ld, %p) not fully implemented\n", hinstDLL, fdwReason, lpvReserved);
309 switch(fdwReason) {
310 case DLL_PROCESS_ATTACH: {
312 HKEY hKey;
313 LONG r;
315 DisableThreadLibraryCalls(hinstDLL);
317 r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
319 if (r != ERROR_SUCCESS) {
320 TRACE("Couldn't open registry key HKLM\\%s, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
321 } else {
322 BYTE lpValue[40];
323 DWORD cbValue = sizeof(lpValue);
324 r = RegQueryValueExW(hKey, szLastID, 0, 0, lpValue, &cbValue);
325 if (r != ERROR_SUCCESS) {
326 TRACE("Couldn't open registry entry HKLM\\%s\\LastID, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
328 RegCloseKey(hKey);
331 PPRegSemaphore = CreateSemaphoreW(NULL, 1, 1, szSemaphoreName);
332 if (PPRegSemaphore == NULL) {
333 ERR("Couldn't create Semaphore: %ld\n", GetLastError());
334 return FALSE;
336 break;
338 case DLL_PROCESS_DETACH:
339 CloseHandle(PPRegSemaphore);
340 break;
342 return TRUE;