ddraw/tests: Add basic tests for DrawIndexedPrimitiveStrided.
[wine] / dlls / powrprof / powrprof.c
1 /*
2  * Copyright (C) 2005 Benjamin Cutler
3  *
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.
8  *
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.
13  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19
20 #include <stdarg.h>
21
22 #include "ntstatus.h"
23 #define WIN32_NO_STATUS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winnt.h"
27 #include "winreg.h"
28 #include "winternl.h"
29 #include "powrprof.h"
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(powrprof);
34
35 /* Notes to implementors:
36  * #1: The native implementation of these functions attempted to read in
37  * registry entries that I was unable to locate on any of the Windows
38  * machines I checked, but I only had desktops available, so maybe
39  * laptop users will have better luck. They return FNF errors because
40  * that's what the native DLL was returning during my tests.
41  * #2: These functions call NtPowerInformation but I don't know what they
42  * do with the results, and NtPowerInformation doesn't do much in WINE yet
43  * anyway.
44  * #3: Since I can't get several other functions working (see note #1),
45  * implementing these functions is going to have to wait until somebody can
46  * cobble together some sane test input. */
47
48 static const WCHAR szPowerCfgSubKey[] = { 'S', 'o', 'f', 't', 'w', 'a', 'r', 'e',
49         '\\', 'M', 'i', 'c', 'r', 'o', 's', 'o', 'f', 't', '\\', 'W', 'i',
50         'n', 'd', 'o', 'w', 's', '\\', 'C', 'u', 'r', 'r', 'e', 'n', 't',
51         'V', 'e', 'r', 's', 'i', 'o', 'n', '\\', 'C', 'o', 'n', 't', 'r',
52         'o', 'l', 's', ' ', 'F', 'o', 'l', 'd', 'e', 'r', '\\', 'P', 'o',
53         'w', 'e', 'r', 'C', 'f', 'g', 0 };
54 static const WCHAR szSemaphoreName[] = { 'P', 'o', 'w', 'e', 'r', 'P', 'r', 'o',
55         'f', 'i', 'l', 'e', 'R', 'e', 'g', 'i', 's', 't', 'r', 'y', 'S',
56         'e', 'm', 'a', 'p', 'h', 'o', 'r', 'e', 0 };
57 static const WCHAR szDiskMax[] = { 'D', 'i', 's', 'k', 'S', 'p', 'i', 'n', 'd',
58         'o', 'w', 'n', 'M', 'a', 'x', 0 };
59 static const WCHAR szDiskMin[] = { 'D', 'i', 's', 'k', 'S', 'p', 'i', 'n', 'd',
60         'o', 'w', 'n', 'M', 'i', 'n', 0 };
61 static const WCHAR szLastID[] = { 'L', 'a', 's', 't', 'I', 'D', 0 };
62 static HANDLE PPRegSemaphore = NULL;
63
64 NTSTATUS WINAPI CallNtPowerInformation(
65         POWER_INFORMATION_LEVEL InformationLevel,
66         PVOID lpInputBuffer, ULONG nInputBufferSize,
67         PVOID lpOutputBuffer, ULONG nOutputBufferSize)
68 {
69    return NtPowerInformation(InformationLevel, lpInputBuffer,
70       nInputBufferSize, lpOutputBuffer, nOutputBufferSize);
71 }
72
73 BOOLEAN WINAPI CanUserWritePwrScheme(VOID)
74 {
75    HKEY hKey = NULL;
76    LONG r;
77    BOOLEAN bSuccess = TRUE;
78
79    TRACE("()\n");
80
81    r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
82
83    if (r != ERROR_SUCCESS) {
84       TRACE("RegOpenKeyEx failed: %d\n", r);
85       bSuccess = FALSE;
86    }
87
88    SetLastError(r);
89    RegCloseKey(hKey);
90    return bSuccess;
91 }
92
93 BOOLEAN WINAPI DeletePwrScheme(UINT uiIndex)
94 {
95    /* FIXME: See note #1 */
96    FIXME("(%d) stub!\n", uiIndex);
97    SetLastError(ERROR_FILE_NOT_FOUND);
98    return FALSE;
99 }
100
101 BOOLEAN WINAPI EnumPwrSchemes(PWRSCHEMESENUMPROC lpfnPwrSchemesEnumProc,
102                         LPARAM lParam)
103 {
104    /* FIXME: See note #1 */
105    FIXME("(%p, %ld) stub!\n", lpfnPwrSchemesEnumProc, lParam);
106    SetLastError(ERROR_FILE_NOT_FOUND);
107    return FALSE;
108 }
109
110 BOOLEAN WINAPI GetActivePwrScheme(PUINT puiID)
111 {
112    /* FIXME: See note #1 */
113    FIXME("(%p) stub!\n", puiID);
114    SetLastError(ERROR_FILE_NOT_FOUND);
115    return FALSE;
116 }
117
118 BOOLEAN WINAPI GetCurrentPowerPolicies(
119         PGLOBAL_POWER_POLICY pGlobalPowerPolicy,
120         PPOWER_POLICY pPowerPolicy)
121 {
122    /* FIXME: See note #2 */
123    SYSTEM_POWER_POLICY ACPower, DCPower;
124
125    FIXME("(%p, %p) stub!\n", pGlobalPowerPolicy, pPowerPolicy);
126
127    NtPowerInformation(SystemPowerPolicyAc, 0, 0, &ACPower, sizeof(SYSTEM_POWER_POLICY));
128    NtPowerInformation(SystemPowerPolicyDc, 0, 0, &DCPower, sizeof(SYSTEM_POWER_POLICY));
129
130    return FALSE;
131 }
132
133 BOOLEAN WINAPI GetPwrCapabilities(
134         PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
135 {
136    NTSTATUS r;
137
138    TRACE("(%p)\n", lpSystemPowerCapabilities);
139
140    r = NtPowerInformation(SystemPowerCapabilities, 0, 0, lpSystemPowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
141
142    SetLastError(RtlNtStatusToDosError(r));
143
144    return r == STATUS_SUCCESS;
145 }
146
147 BOOLEAN WINAPI GetPwrDiskSpindownRange(PUINT RangeMax, PUINT RangeMin)
148 {
149    HKEY hKey;
150    BYTE lpValue[40];
151    LONG r;
152    DWORD cbValue = sizeof(lpValue);
153
154    TRACE("(%p, %p)\n", RangeMax, RangeMin);
155
156    if (RangeMax == NULL || RangeMin == NULL) {
157       SetLastError(ERROR_INVALID_PARAMETER);
158       return FALSE;
159    }
160
161    SetLastError(ERROR_SUCCESS);
162
163    WaitForSingleObject(PPRegSemaphore, INFINITE);
164
165    r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ, &hKey);
166    if (r != ERROR_SUCCESS) {
167       TRACE("RegOpenKeyEx failed: %d\n", r);
168       TRACE("Using defaults: 3600, 3\n");
169       *RangeMax = 3600;
170       *RangeMin = 3;
171       ReleaseSemaphore(PPRegSemaphore, 1, NULL);
172       return TRUE;
173    }
174
175    r = RegQueryValueExW(hKey, szDiskMax, 0, 0, lpValue, &cbValue);
176    if (r != ERROR_SUCCESS) {
177       TRACE("Couldn't open DiskSpinDownMax: %d\n", r);
178       TRACE("Using default: 3600\n");
179       *RangeMax = 3600;
180    } else {
181       *RangeMax = atoiW((LPCWSTR)lpValue);
182    }
183
184    cbValue = sizeof(lpValue);
185
186    r = RegQueryValueExW(hKey, szDiskMin, 0, 0, lpValue, &cbValue);
187    if (r != ERROR_SUCCESS) {
188       TRACE("Couldn't open DiskSpinDownMin: %d\n", r);
189       TRACE("Using default: 3\n");
190       *RangeMin = 3;
191    } else {
192       *RangeMin = atoiW((LPCWSTR)lpValue);
193    }
194
195    RegCloseKey(hKey);
196
197    ReleaseSemaphore(PPRegSemaphore, 1, NULL);
198
199    return TRUE;
200 }
201
202 BOOLEAN WINAPI IsAdminOverrideActive(PADMINISTRATOR_POWER_POLICY p)
203 {
204    FIXME("( %p) stub!\n", p);
205    return FALSE;
206 }
207
208 BOOLEAN WINAPI IsPwrHibernateAllowed(VOID)
209 {
210    SYSTEM_POWER_CAPABILITIES PowerCaps;
211    NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
212    return PowerCaps.SystemS4 && PowerCaps.HiberFilePresent;
213 }
214
215 BOOLEAN WINAPI IsPwrShutdownAllowed(VOID)
216 {
217    SYSTEM_POWER_CAPABILITIES PowerCaps;
218    NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
219    return PowerCaps.SystemS5;
220 }
221
222 BOOLEAN WINAPI IsPwrSuspendAllowed(VOID)
223 {
224    SYSTEM_POWER_CAPABILITIES PowerCaps;
225    NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
226    return PowerCaps.SystemS1 && PowerCaps.SystemS2 && PowerCaps.SystemS3;
227 }
228
229 BOOLEAN WINAPI ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
230 {
231    /* FIXME: See note #1 */
232    FIXME("(%p) stub!\n", pGlobalPowerPolicy);
233    SetLastError(ERROR_FILE_NOT_FOUND);
234    return FALSE;
235 }
236
237 BOOLEAN WINAPI ReadProcessorPwrScheme(UINT uiID,
238                         PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
239 {
240    /* FIXME: See note #1 */
241    FIXME("(%d, %p) stub!\n", uiID, pMachineProcessorPowerPolicy);
242    SetLastError(ERROR_FILE_NOT_FOUND);
243    return FALSE;
244 }
245
246 BOOLEAN WINAPI ReadPwrScheme(UINT uiID,
247         PPOWER_POLICY pPowerPolicy)
248 {
249    /* FIXME: See note #1 */
250    FIXME("(%d, %p) stub!\n", uiID, pPowerPolicy);
251    SetLastError(ERROR_FILE_NOT_FOUND);
252    return FALSE;
253 }
254
255 BOOLEAN WINAPI SetActivePwrScheme(UINT uiID,
256         PGLOBAL_POWER_POLICY lpGlobalPowerPolicy,
257         PPOWER_POLICY lpPowerPolicy)
258 {
259    /* FIXME: See note #1 */
260    FIXME("(%d, %p, %p) stub!\n", uiID, lpGlobalPowerPolicy, lpPowerPolicy);
261    SetLastError(ERROR_FILE_NOT_FOUND);
262    return FALSE;
263 }
264
265 BOOLEAN WINAPI SetSuspendState(BOOLEAN Hibernate, BOOLEAN ForceCritical,
266         BOOLEAN DisableWakeEvent)
267 {
268    /* FIXME: I have NO idea how you're supposed to call NtInitiatePowerAction
269     * here, because it's not a documented function that I can find */
270    FIXME("(%d, %d, %d) stub!\n", Hibernate, ForceCritical, DisableWakeEvent);
271    return TRUE;
272 }
273
274 BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
275 {
276    /* FIXME: See note #3 */
277    FIXME("(%p) stub!\n", pGlobalPowerPolicy);
278    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
279    return FALSE;
280 }
281
282 BOOLEAN WINAPI WriteProcessorPwrScheme(UINT ID,
283         PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
284 {
285    /* FIXME: See note #3 */
286    FIXME("(%d, %p) stub!\n", ID, pMachineProcessorPowerPolicy);
287    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
288    return FALSE;
289 }
290
291 BOOLEAN WINAPI WritePwrScheme(PUINT puiID, LPWSTR lpszName, LPWSTR lpszDescription,
292         PPOWER_POLICY pPowerPolicy)
293 {
294    /* FIXME: See note #3 */
295    FIXME("(%p, %s, %s, %p) stub!\n", puiID, debugstr_w(lpszName), debugstr_w(lpszDescription), pPowerPolicy);
296    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
297    return FALSE;
298 }
299
300 DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid)
301 {
302    FIXME("(%p,%p) stub!\n", UserRootPowerKey, polguid);
303    return ERROR_CALL_NOT_IMPLEMENTED;
304 }
305
306 DWORD WINAPI PowerReadDCValue(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, PULONG Type, PUCHAR Buffer, DWORD *BufferSize)
307 {
308    FIXME("(%p,%s,%s,%s,%p,%p,%p) stub!\n", RootPowerKey, debugstr_guid(Scheme), debugstr_guid(SubGroup), debugstr_guid(PowerSettings), Type, Buffer, BufferSize);
309    return ERROR_CALL_NOT_IMPLEMENTED;
310 }
311
312 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
313 {
314    switch(fdwReason) {
315       case DLL_PROCESS_ATTACH: {
316
317          HKEY hKey;
318          LONG r;
319
320          DisableThreadLibraryCalls(hinstDLL);
321
322          r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPowerCfgSubKey, 0, KEY_READ | KEY_WRITE, &hKey);
323
324          if (r != ERROR_SUCCESS) {
325             TRACE("Couldn't open registry key HKLM\\%s, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
326          } else {
327             BYTE lpValue[40];
328             DWORD cbValue = sizeof(lpValue);
329             r = RegQueryValueExW(hKey, szLastID, 0, 0, lpValue, &cbValue);
330             if (r != ERROR_SUCCESS) {
331                TRACE("Couldn't open registry entry HKLM\\%s\\LastID, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
332             }
333             RegCloseKey(hKey);
334          }
335
336          PPRegSemaphore = CreateSemaphoreW(NULL, 1, 1, szSemaphoreName);
337          if (PPRegSemaphore == NULL) {
338             ERR("Couldn't create Semaphore: %d\n", GetLastError());
339             return FALSE;
340          }
341          break;
342       }
343       case DLL_PROCESS_DETACH:
344          CloseHandle(PPRegSemaphore);
345          break;
346     }
347     return TRUE;
348 }