1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package oshi.software.os.windows;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import oshi.hardware.HardwareAbstractionLayer;
23 import oshi.hardware.Memory;
24 import oshi.hardware.PowerSource;
25 import oshi.hardware.Processor;
26 import oshi.software.os.OSFileStore;
27 import oshi.software.os.windows.nt.CentralProcessor;
28 import oshi.software.os.windows.nt.GlobalMemory;
29 import oshi.software.os.windows.nt.WindowsFileSystem;
30 import oshi.software.os.windows.nt.WindowsPowerSource;
31
32 import com.sun.jna.platform.win32.Advapi32Util;
33 import com.sun.jna.platform.win32.WinReg;
34
35 public class WindowsHardwareAbstractionLayer implements
36 HardwareAbstractionLayer {
37
38 private Processor[] _processors = null;
39
40 private Memory _memory = null;
41
42 @Override
43 public Memory getMemory() {
44 if (this._memory == null) {
45 this._memory = new GlobalMemory();
46 }
47 return this._memory;
48 }
49
50 @Override
51 public Processor[] getProcessors() {
52
53 if (this._processors == null) {
54 final String cpuRegistryRoot = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor";
55 List<Processor> processors = new ArrayList<>();
56 String[] processorIds = Advapi32Util.registryGetKeys(
57 WinReg.HKEY_LOCAL_MACHINE, cpuRegistryRoot);
58 int numCPU = 0;
59 for (String processorId : processorIds) {
60 String cpuRegistryPath = cpuRegistryRoot + "\\" + processorId;
61 CentralProcessor cpu = new CentralProcessor(numCPU++);
62 cpu.setIdentifier(Advapi32Util.registryGetStringValue(
63 WinReg.HKEY_LOCAL_MACHINE, cpuRegistryPath,
64 "Identifier"));
65 cpu.setName(Advapi32Util.registryGetStringValue(
66 WinReg.HKEY_LOCAL_MACHINE, cpuRegistryPath,
67 "ProcessorNameString"));
68 cpu.setVendor(Advapi32Util.registryGetStringValue(
69 WinReg.HKEY_LOCAL_MACHINE, cpuRegistryPath,
70 "VendorIdentifier"));
71 processors.add(cpu);
72 }
73 this._processors = processors.toArray(new Processor[0]);
74 }
75
76 return this._processors;
77 }
78
79 @Override
80 public PowerSource[] getPowerSources() {
81 return WindowsPowerSource.getPowerSources();
82 }
83
84 @Override
85 public OSFileStore[] getFileStores() {
86 return WindowsFileSystem.getFileStores();
87 }
88 }