1 /*
2 * Copyright 2020-2022 The OSHI Project Contributors
3 * SPDX-License-Identifier: MIT
4 */
5 package oshi.driver.windows.wmi;
6
7 import java.util.Objects;
8
9 import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery;
10 import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;
11
12 import oshi.annotation.concurrent.ThreadSafe;
13 import oshi.util.platform.windows.WmiQueryHandler;
14
15 /**
16 * Utility to query WMI class {@code Win32_Processor}
17 */
18 @ThreadSafe
19 public final class Win32Processor {
20
21 private static final String WIN32_PROCESSOR = "Win32_Processor";
22
23 /**
24 * Processor voltage properties.
25 */
26 public enum VoltProperty {
27 CURRENTVOLTAGE, VOLTAGECAPS;
28 }
29
30 /**
31 * Processor ID property
32 */
33 public enum ProcessorIdProperty {
34 PROCESSORID;
35 }
36
37 /**
38 * Processor bitness property
39 */
40 public enum BitnessProperty {
41 ADDRESSWIDTH;
42 }
43
44 private Win32Processor() {
45 }
46
47 /**
48 * Returns processor voltage.
49 *
50 * @return Current voltage of the processor. If the eighth bit is set, bits 0-6 contain the voltage multiplied by
51 * 10. If the eighth bit is not set, then the bit setting in VoltageCaps represents the voltage value.
52 */
53 public static WmiResult<VoltProperty> queryVoltage() {
54 WmiQuery<VoltProperty> voltQuery = new WmiQuery<>(WIN32_PROCESSOR, VoltProperty.class);
55 return Objects.requireNonNull(WmiQueryHandler.createInstance()).queryWMI(voltQuery);
56 }
57
58 /**
59 * Returns processor ID.
60 *
61 * @return Processor information that describes the processor features. For an x86 class CPU, the field format
62 * depends on the processor support of the CPUID instruction. If the instruction is supported, the property
63 * contains 2 (two) DWORD formatted values. The first is an offset of 08h-0Bh, which is the EAX value that a
64 * CPUID instruction returns with input EAX set to 1. The second is an offset of 0Ch-0Fh, which is the EDX
65 * value that the instruction returns. Only the first two bytes of the property are significant and contain
66 * the contents of the DX register at CPU reset—all others are set to 0 (zero), and the contents are in
67 * DWORD format.
68 */
69 public static WmiResult<ProcessorIdProperty> queryProcessorId() {
70 WmiQuery<ProcessorIdProperty> idQuery = new WmiQuery<>(WIN32_PROCESSOR, ProcessorIdProperty.class);
71 return Objects.requireNonNull(WmiQueryHandler.createInstance()).queryWMI(idQuery);
72 }
73
74 /**
75 * Returns address width.
76 *
77 * @return On a 32-bit operating system, the value is 32 and on a 64-bit operating system it is 64.
78 */
79 public static WmiResult<BitnessProperty> queryBitness() {
80 WmiQuery<BitnessProperty> bitnessQuery = new WmiQuery<>(WIN32_PROCESSOR, BitnessProperty.class);
81 return Objects.requireNonNull(WmiQueryHandler.createInstance()).queryWMI(bitnessQuery);
82 }
83 }